HUGE refactoring - rewriting rest client
DO NOT TRY TO BUILD THIS VERSION [ci skip]
This commit is contained in:
parent
5b6aecf852
commit
3328cd7a14
|
@ -4,7 +4,6 @@ import android.support.annotation.NonNull;
|
||||||
|
|
||||||
import org.apache.commons.lang3.tuple.ImmutablePair;
|
import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import org.mariotaku.simplerestapi.http.KeyValuePair;
|
|
||||||
import org.mariotaku.simplerestapi.http.ValueMap;
|
import org.mariotaku.simplerestapi.http.ValueMap;
|
||||||
import org.mariotaku.simplerestapi.http.mime.BaseTypedData;
|
import org.mariotaku.simplerestapi.http.mime.BaseTypedData;
|
||||||
import org.mariotaku.simplerestapi.http.mime.FormTypedBody;
|
import org.mariotaku.simplerestapi.http.mime.FormTypedBody;
|
||||||
|
@ -43,7 +42,7 @@ public final class RestMethodInfo {
|
||||||
private final HashMap<Extra, Object> extras;
|
private final HashMap<Extra, Object> extras;
|
||||||
private final FileValue file;
|
private final FileValue file;
|
||||||
|
|
||||||
private ArrayList<KeyValuePair> queriesCache, formsCache, headersCache;
|
private ArrayList<Pair<String, String>> queriesCache, formsCache, headersCache;
|
||||||
private ArrayList<Pair<String, TypedData>> partsCache;
|
private ArrayList<Pair<String, TypedData>> partsCache;
|
||||||
private Map<String, Object> extrasCache;
|
private Map<String, Object> extrasCache;
|
||||||
private TypedData bodyCache;
|
private TypedData bodyCache;
|
||||||
|
@ -105,9 +104,9 @@ public final class RestMethodInfo {
|
||||||
return extrasCache = map;
|
return extrasCache = map;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<KeyValuePair> getForms() {
|
public List<Pair<String, String>> getForms() {
|
||||||
if (formsCache != null) return formsCache;
|
if (formsCache != null) return formsCache;
|
||||||
final ArrayList<KeyValuePair> list = new ArrayList<>();
|
final ArrayList<Pair<String, String>> list = new ArrayList<>();
|
||||||
for (Map.Entry<Form, Object> entry : forms.entrySet()) {
|
for (Map.Entry<Form, Object> entry : forms.entrySet()) {
|
||||||
final Form form = entry.getKey();
|
final Form form = entry.getKey();
|
||||||
final Object value = entry.getValue();
|
final Object value = entry.getValue();
|
||||||
|
@ -115,12 +114,12 @@ public final class RestMethodInfo {
|
||||||
final ValueMap valueMap = (ValueMap) value;
|
final ValueMap valueMap = (ValueMap) value;
|
||||||
for (String key : form.value()) {
|
for (String key : form.value()) {
|
||||||
if (valueMap.has(key)) {
|
if (valueMap.has(key)) {
|
||||||
list.add(new KeyValuePair(key, String.valueOf(valueMap.get(key))));
|
list.add(new ImmutablePair<>(key, String.valueOf(valueMap.get(key))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (value != null) {
|
} else if (value != null) {
|
||||||
for (String key : form.value()) {
|
for (String key : form.value()) {
|
||||||
list.add(new KeyValuePair(key, String.valueOf(value)));
|
list.add(new ImmutablePair<>(key, String.valueOf(value)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,9 +143,9 @@ public final class RestMethodInfo {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public List<KeyValuePair> getHeaders() {
|
public List<Pair<String, String>> getHeaders() {
|
||||||
if (headersCache != null) return headersCache;
|
if (headersCache != null) return headersCache;
|
||||||
final ArrayList<KeyValuePair> list = new ArrayList<>();
|
final ArrayList<Pair<String, String>> list = new ArrayList<>();
|
||||||
for (Map.Entry<Header, Object> entry : headers.entrySet()) {
|
for (Map.Entry<Header, Object> entry : headers.entrySet()) {
|
||||||
final Header form = entry.getKey();
|
final Header form = entry.getKey();
|
||||||
final Object value = entry.getValue();
|
final Object value = entry.getValue();
|
||||||
|
@ -154,12 +153,12 @@ public final class RestMethodInfo {
|
||||||
final ValueMap valueMap = (ValueMap) value;
|
final ValueMap valueMap = (ValueMap) value;
|
||||||
for (String key : form.value()) {
|
for (String key : form.value()) {
|
||||||
if (valueMap.has(key)) {
|
if (valueMap.has(key)) {
|
||||||
list.add(new KeyValuePair(key, String.valueOf(valueMap.get(key))));
|
list.add(new ImmutablePair<>(key, String.valueOf(valueMap.get(key))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (value != null) {
|
} else if (value != null) {
|
||||||
for (String key : form.value()) {
|
for (String key : form.value()) {
|
||||||
list.add(new KeyValuePair(key, String.valueOf(value)));
|
list.add(new ImmutablePair<>(key, String.valueOf(value)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,9 +185,9 @@ public final class RestMethodInfo {
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<KeyValuePair> getQueries() {
|
public List<Pair<String, String>> getQueries() {
|
||||||
if (queriesCache != null) return queriesCache;
|
if (queriesCache != null) return queriesCache;
|
||||||
final ArrayList<KeyValuePair> list = new ArrayList<>();
|
final ArrayList<Pair<String, String>> list = new ArrayList<>();
|
||||||
for (Map.Entry<Query, Object> entry : queries.entrySet()) {
|
for (Map.Entry<Query, Object> entry : queries.entrySet()) {
|
||||||
final Query form = entry.getKey();
|
final Query form = entry.getKey();
|
||||||
final Object value = entry.getValue();
|
final Object value = entry.getValue();
|
||||||
|
@ -196,12 +195,12 @@ public final class RestMethodInfo {
|
||||||
final ValueMap valueMap = (ValueMap) value;
|
final ValueMap valueMap = (ValueMap) value;
|
||||||
for (String key : form.value()) {
|
for (String key : form.value()) {
|
||||||
if (valueMap.has(key)) {
|
if (valueMap.has(key)) {
|
||||||
list.add(new KeyValuePair(key, String.valueOf(valueMap.get(key))));
|
list.add(new ImmutablePair<>(key, String.valueOf(valueMap.get(key))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (value != null) {
|
} else if (value != null) {
|
||||||
for (String key : form.value()) {
|
for (String key : form.value()) {
|
||||||
list.add(new KeyValuePair(key, String.valueOf(value)));
|
list.add(new ImmutablePair<>(key, String.valueOf(value)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.mariotaku.simplerestapi.http;
|
package org.mariotaku.simplerestapi.http;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
import org.mariotaku.simplerestapi.RestMethodInfo;
|
import org.mariotaku.simplerestapi.RestMethodInfo;
|
||||||
import org.mariotaku.simplerestapi.Utils;
|
import org.mariotaku.simplerestapi.Utils;
|
||||||
|
|
||||||
|
@ -25,15 +26,15 @@ public class Endpoint {
|
||||||
return constructUrl(endpoint, requestInfo.getPath(), requestInfo.getQueries());
|
return constructUrl(endpoint, requestInfo.getPath(), requestInfo.getQueries());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String construct(String path, List<KeyValuePair> queries) {
|
public String construct(String path, List<Pair<String, String>> queries) {
|
||||||
return constructUrl(url, path, queries);
|
return constructUrl(url, path, queries);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String construct(String path, KeyValuePair... queries) {
|
public String construct(String path, Pair<String, String>... queries) {
|
||||||
return constructUrl(url, path, Arrays.asList(queries));
|
return constructUrl(url, path, Arrays.asList(queries));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String constructUrl(String endpoint, String path, List<KeyValuePair> queries) {
|
public static String constructUrl(String endpoint, String path, List<Pair<String, String>> queries) {
|
||||||
final StringBuilder urlBuilder = new StringBuilder();
|
final StringBuilder urlBuilder = new StringBuilder();
|
||||||
if (endpoint.charAt(endpoint.length() - 1) == '/') {
|
if (endpoint.charAt(endpoint.length() - 1) == '/') {
|
||||||
urlBuilder.append(endpoint.substring(0, endpoint.length() - 1));
|
urlBuilder.append(endpoint.substring(0, endpoint.length() - 1));
|
||||||
|
@ -49,7 +50,7 @@ public class Endpoint {
|
||||||
return constructUrl(urlBuilder.toString(), queries);
|
return constructUrl(urlBuilder.toString(), queries);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String constructUrl(String url, List<KeyValuePair> queries) {
|
public static String constructUrl(String url, List<Pair<String, String>> queries) {
|
||||||
if (queries == null || queries.isEmpty()) return url;
|
if (queries == null || queries.isEmpty()) return url;
|
||||||
final StringBuilder urlBuilder = new StringBuilder(url);
|
final StringBuilder urlBuilder = new StringBuilder(url);
|
||||||
for (int i = 0, j = queries.size(); i < j; i++) {
|
for (int i = 0, j = queries.size(); i < j; i++) {
|
||||||
|
|
Loading…
Reference in New Issue