Skip to content

Commit

Permalink
Add support for multiple query values with same key
Browse files Browse the repository at this point in the history
  • Loading branch information
amitshekhariitbhu committed Dec 20, 2017
1 parent b4b827d commit 3f55ab5
Showing 1 changed file with 64 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class ANRequest<T extends ANRequest> {
private HashMap<String, String> mBodyParameterMap = new HashMap<>();
private HashMap<String, String> mUrlEncodedFormBodyParameterMap = new HashMap<>();
private HashMap<String, String> mMultiPartParameterMap = new HashMap<>();
private HashMap<String, String> mQueryParameterMap = new HashMap<>();
private HashMap<String, List<String>> mQueryParameterMap = new HashMap<>();
private HashMap<String, String> mPathParameterMap = new HashMap<>();
private HashMap<String, File> mMultiPartFileMap = new HashMap<>();
private String mDirPath;
Expand Down Expand Up @@ -407,8 +407,17 @@ public String getUrl() {
tempUrl = tempUrl.replace("{" + entry.getKey() + "}", String.valueOf(entry.getValue()));
}
HttpUrl.Builder urlBuilder = HttpUrl.parse(tempUrl).newBuilder();
for (HashMap.Entry<String, String> entry : mQueryParameterMap.entrySet()) {
urlBuilder.addQueryParameter(entry.getKey(), entry.getValue());
if (mQueryParameterMap != null) {
Set<Map.Entry<String, List<String>>> entries = mQueryParameterMap.entrySet();
for (Map.Entry<String, List<String>> entry : entries) {
String name = entry.getKey();
List<String> list = entry.getValue();
if (list != null) {
for (String value : list) {
urlBuilder.addQueryParameter(name, value);
}
}
}
}
return urlBuilder.build().toString();
}
Expand Down Expand Up @@ -892,7 +901,7 @@ public static class GetRequestBuilder<T extends GetRequestBuilder> implements Re
private int mMaxHeight;
private ImageView.ScaleType mScaleType;
private HashMap<String, List<String>> mHeadersMap = new HashMap<>();
private HashMap<String, String> mQueryParameterMap = new HashMap<>();
private HashMap<String, List<String>> mQueryParameterMap = new HashMap<>();
private HashMap<String, String> mPathParameterMap = new HashMap<>();
private CacheControl mCacheControl;
private Executor mExecutor;
Expand Down Expand Up @@ -923,22 +932,31 @@ public T setTag(Object tag) {

@Override
public T addQueryParameter(String key, String value) {
mQueryParameterMap.put(key, value);
List<String> list = mQueryParameterMap.get(key);
if (list == null) {
list = new ArrayList<>();
mQueryParameterMap.put(key, list);
}
if (!list.contains(value)) {
list.add(value);
}
return (T) this;
}

@Override
public T addQueryParameter(Map<String, String> queryParameterMap) {
if (queryParameterMap != null) {
mQueryParameterMap.putAll(queryParameterMap);
for (HashMap.Entry<String, String> entry : queryParameterMap.entrySet()) {
addQueryParameter(entry.getKey(), entry.getValue());
}
}
return (T) this;
}

@Override
public T addQueryParameter(Object object) {
if (object != null) {
mQueryParameterMap.putAll(ParseUtil
return addQueryParameter(ParseUtil
.getParserFactory()
.getStringMap(object));
}
Expand Down Expand Up @@ -1114,7 +1132,7 @@ public static class PostRequestBuilder<T extends PostRequestBuilder> implements
private HashMap<String, List<String>> mHeadersMap = new HashMap<>();
private HashMap<String, String> mBodyParameterMap = new HashMap<>();
private HashMap<String, String> mUrlEncodedFormBodyParameterMap = new HashMap<>();
private HashMap<String, String> mQueryParameterMap = new HashMap<>();
private HashMap<String, List<String>> mQueryParameterMap = new HashMap<>();
private HashMap<String, String> mPathParameterMap = new HashMap<>();
private CacheControl mCacheControl;
private Executor mExecutor;
Expand Down Expand Up @@ -1146,22 +1164,31 @@ public T setTag(Object tag) {

@Override
public T addQueryParameter(String key, String value) {
mQueryParameterMap.put(key, value);
List<String> list = mQueryParameterMap.get(key);
if (list == null) {
list = new ArrayList<>();
mQueryParameterMap.put(key, list);
}
if (!list.contains(value)) {
list.add(value);
}
return (T) this;
}

@Override
public T addQueryParameter(Map<String, String> queryParameterMap) {
if (queryParameterMap != null) {
mQueryParameterMap.putAll(queryParameterMap);
for (HashMap.Entry<String, String> entry : queryParameterMap.entrySet()) {
addQueryParameter(entry.getKey(), entry.getValue());
}
}
return (T) this;
}

@Override
public T addQueryParameter(Object object) {
if (object != null) {
mQueryParameterMap.putAll(ParseUtil
return addQueryParameter(ParseUtil
.getParserFactory()
.getStringMap(object));
}
Expand Down Expand Up @@ -1369,7 +1396,7 @@ public static class DownloadBuilder<T extends DownloadBuilder> implements Reques
private String mUrl;
private Object mTag;
private HashMap<String, List<String>> mHeadersMap = new HashMap<>();
private HashMap<String, String> mQueryParameterMap = new HashMap<>();
private HashMap<String, List<String>> mQueryParameterMap = new HashMap<>();
private HashMap<String, String> mPathParameterMap = new HashMap<>();
private String mDirPath;
private String mFileName;
Expand Down Expand Up @@ -1432,22 +1459,31 @@ public T addHeaders(Object object) {

@Override
public T addQueryParameter(String key, String value) {
mQueryParameterMap.put(key, value);
List<String> list = mQueryParameterMap.get(key);
if (list == null) {
list = new ArrayList<>();
mQueryParameterMap.put(key, list);
}
if (!list.contains(value)) {
list.add(value);
}
return (T) this;
}

@Override
public T addQueryParameter(Map<String, String> queryParameterMap) {
if (queryParameterMap != null) {
mQueryParameterMap.putAll(queryParameterMap);
for (HashMap.Entry<String, String> entry : queryParameterMap.entrySet()) {
addQueryParameter(entry.getKey(), entry.getValue());
}
}
return (T) this;
}

@Override
public T addQueryParameter(Object object) {
if (object != null) {
mQueryParameterMap.putAll(ParseUtil
return addQueryParameter(ParseUtil
.getParserFactory()
.getStringMap(object));
}
Expand Down Expand Up @@ -1543,7 +1579,7 @@ public static class MultiPartBuilder<T extends MultiPartBuilder> implements Requ
private Object mTag;
private HashMap<String, List<String>> mHeadersMap = new HashMap<>();
private HashMap<String, String> mMultiPartParameterMap = new HashMap<>();
private HashMap<String, String> mQueryParameterMap = new HashMap<>();
private HashMap<String, List<String>> mQueryParameterMap = new HashMap<>();
private HashMap<String, String> mPathParameterMap = new HashMap<>();
private HashMap<String, File> mMultiPartFileMap = new HashMap<>();
private CacheControl mCacheControl;
Expand Down Expand Up @@ -1571,22 +1607,31 @@ public T setTag(Object tag) {

@Override
public T addQueryParameter(String key, String value) {
mQueryParameterMap.put(key, value);
List<String> list = mQueryParameterMap.get(key);
if (list == null) {
list = new ArrayList<>();
mQueryParameterMap.put(key, list);
}
if (!list.contains(value)) {
list.add(value);
}
return (T) this;
}

@Override
public T addQueryParameter(Map<String, String> queryParameterMap) {
if (queryParameterMap != null) {
mQueryParameterMap.putAll(queryParameterMap);
for (HashMap.Entry<String, String> entry : queryParameterMap.entrySet()) {
addQueryParameter(entry.getKey(), entry.getValue());
}
}
return (T) this;
}

@Override
public T addQueryParameter(Object object) {
if (object != null) {
mQueryParameterMap.putAll(ParseUtil
return addQueryParameter(ParseUtil
.getParserFactory()
.getStringMap(object));
}
Expand Down

0 comments on commit 3f55ab5

Please sign in to comment.