mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-17 04:00:48 +01:00
supports card again
This commit is contained in:
parent
e23c00505c
commit
5689edf58e
@ -1,8 +1,7 @@
|
||||
package org.mariotaku.simplerestapi;
|
||||
|
||||
import org.mariotaku.simplerestapi.http.RestResponse;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
@ -10,6 +9,6 @@ import java.lang.reflect.Type;
|
||||
*/
|
||||
public interface Converter {
|
||||
|
||||
Object convert(RestResponse response, Type type) throws Exception;
|
||||
Object convert(RestHttpResponse response, Type type) throws Exception;
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package org.mariotaku.simplerestapi;
|
||||
|
||||
import org.mariotaku.simplerestapi.http.RestResponse;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@ -8,6 +8,6 @@ import java.io.IOException;
|
||||
* Created by mariotaku on 15/2/7.
|
||||
*/
|
||||
public interface RawCallback extends ErrorCallback {
|
||||
void result(RestResponse result) throws IOException;
|
||||
void result(RestHttpResponse result) throws IOException;
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.mariotaku.simplerestapi;
|
||||
|
||||
import android.util.Pair;
|
||||
|
||||
import org.mariotaku.simplerestapi.http.mime.TypedData;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/5/11.
|
||||
*/
|
||||
public final class RequestInfo {
|
||||
|
||||
private String method;
|
||||
private String path;
|
||||
|
||||
private List<Pair<String, String>> queries, forms, headers;
|
||||
private List<Pair<String, TypedData>> parts;
|
||||
private Map<String, Object> extras;
|
||||
private TypedData body;
|
||||
|
||||
public RequestInfo(String method, String path, List<Pair<String, String>> queries,
|
||||
List<Pair<String, String>> forms, List<Pair<String, String>> headers,
|
||||
List<Pair<String, TypedData>> parts, Map<String, Object> extras, TypedData body) {
|
||||
this.method = method;
|
||||
this.path = path;
|
||||
this.queries = queries;
|
||||
this.forms = forms;
|
||||
this.headers = headers;
|
||||
this.parts = parts;
|
||||
this.extras = extras;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public List<Pair<String, String>> getQueries() {
|
||||
return queries;
|
||||
}
|
||||
|
||||
public List<Pair<String, String>> getForms() {
|
||||
return forms;
|
||||
}
|
||||
|
||||
public List<Pair<String, String>> getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public List<Pair<String, TypedData>> getParts() {
|
||||
return parts;
|
||||
}
|
||||
|
||||
public Map<String, Object> getExtras() {
|
||||
return extras;
|
||||
}
|
||||
|
||||
public TypedData getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
public interface Factory {
|
||||
RequestInfo create(RestMethodInfo methodInfo);
|
||||
}
|
||||
}
|
@ -3,8 +3,8 @@ package org.mariotaku.simplerestapi;
|
||||
import org.mariotaku.simplerestapi.http.Authorization;
|
||||
import org.mariotaku.simplerestapi.http.Endpoint;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpClient;
|
||||
import org.mariotaku.simplerestapi.http.RestRequest;
|
||||
import org.mariotaku.simplerestapi.http.RestResponse;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpRequest;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
@ -21,8 +21,9 @@ public class RestAPIFactory {
|
||||
private Authorization authorization;
|
||||
private Converter converter;
|
||||
private RestHttpClient restClient;
|
||||
private RestRequest.Factory requestFactory;
|
||||
private RestHttpRequest.Factory requestFactory;
|
||||
private ExceptionFactory exceptionFactory;
|
||||
private RequestInfo.Factory requestInfoFactory;
|
||||
|
||||
public void setEndpoint(Endpoint endpoint) {
|
||||
this.endpoint = endpoint;
|
||||
@ -40,7 +41,7 @@ public class RestAPIFactory {
|
||||
this.restClient = restClient;
|
||||
}
|
||||
|
||||
public void setRequestFactory(RestRequest.Factory factory) {
|
||||
public void setRequestFactory(RestHttpRequest.Factory factory) {
|
||||
this.requestFactory = factory;
|
||||
}
|
||||
|
||||
@ -57,7 +58,7 @@ public class RestAPIFactory {
|
||||
final ClassLoader classLoader = cls.getClassLoader();
|
||||
final Class[] interfaces = new Class[]{cls};
|
||||
return (T) Proxy.newProxyInstance(classLoader, interfaces, new RestInvocationHandler(endpoint,
|
||||
authorization, restClient, converter, requestFactory, exceptionFactory));
|
||||
authorization, restClient, converter, requestInfoFactory, requestFactory, exceptionFactory));
|
||||
}
|
||||
|
||||
public static RestClient getRestClient(Object obj) {
|
||||
@ -66,12 +67,17 @@ public class RestAPIFactory {
|
||||
return (RestClient) handler;
|
||||
}
|
||||
|
||||
public void setRequestInfoFactory(RequestInfo.Factory requestInfoFactory) {
|
||||
this.requestInfoFactory = requestInfoFactory;
|
||||
}
|
||||
|
||||
private static class RestInvocationHandler implements InvocationHandler, RestClient {
|
||||
private final Endpoint endpoint;
|
||||
private final Authorization authorization;
|
||||
private final Converter converter;
|
||||
private final RestRequest.Factory requestFactory;
|
||||
private final RestHttpRequest.Factory requestFactory;
|
||||
private final ExceptionFactory exceptionFactory;
|
||||
private final RequestInfo.Factory requestInfoFactory;
|
||||
|
||||
@Override
|
||||
public Endpoint getEndpoint() {
|
||||
@ -97,12 +103,13 @@ public class RestAPIFactory {
|
||||
|
||||
public RestInvocationHandler(Endpoint endpoint, Authorization authorization,
|
||||
RestHttpClient restClient, Converter converter,
|
||||
RestRequest.Factory requestFactory, ExceptionFactory exceptionFactory) {
|
||||
RequestInfo.Factory requestInfoFactory, RestHttpRequest.Factory requestFactory, ExceptionFactory exceptionFactory) {
|
||||
this.endpoint = endpoint;
|
||||
this.authorization = authorization;
|
||||
this.restClient = restClient;
|
||||
this.converter = converter;
|
||||
this.requestFactory = requestFactory != null ? requestFactory : new RestRequest.DefaultFactory();
|
||||
this.requestInfoFactory = requestInfoFactory;
|
||||
this.requestFactory = requestFactory != null ? requestFactory : new RestHttpRequest.DefaultFactory();
|
||||
this.exceptionFactory = exceptionFactory != null ? exceptionFactory : new DefaultExceptionFactory();
|
||||
}
|
||||
|
||||
@ -110,11 +117,17 @@ public class RestAPIFactory {
|
||||
@Override
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Exception {
|
||||
final RestMethodInfo methodInfo = RestMethodInfo.get(method, args);
|
||||
final RestRequest restRequest = requestFactory.create(endpoint, methodInfo.toRequestInfo(), authorization);
|
||||
final RequestInfo requestInfo;
|
||||
if (requestInfoFactory != null) {
|
||||
requestInfo = requestInfoFactory.create(methodInfo);
|
||||
} else {
|
||||
requestInfo = methodInfo.toRequestInfo();
|
||||
}
|
||||
final RestHttpRequest restHttpRequest = requestFactory.create(endpoint, requestInfo, authorization);
|
||||
final Class<?>[] parameterTypes = method.getParameterTypes();
|
||||
RestResponse response = null;
|
||||
RestHttpResponse response = null;
|
||||
try {
|
||||
response = restClient.execute(restRequest);
|
||||
response = restClient.execute(restHttpRequest);
|
||||
if (parameterTypes.length > 0) {
|
||||
final Class<?> lastParameterType = parameterTypes[parameterTypes.length - 1];
|
||||
if (RestCallback.class.isAssignableFrom(lastParameterType)) {
|
||||
@ -159,14 +172,14 @@ public class RestAPIFactory {
|
||||
|
||||
public interface ExceptionFactory {
|
||||
|
||||
Exception newException(Throwable cause, RestResponse response);
|
||||
Exception newException(Throwable cause, RestHttpResponse response);
|
||||
|
||||
}
|
||||
|
||||
public static final class DefaultExceptionFactory implements ExceptionFactory {
|
||||
|
||||
@Override
|
||||
public Exception newException(Throwable cause, RestResponse response) {
|
||||
public Exception newException(Throwable cause, RestHttpResponse response) {
|
||||
final RestException e = new RestException(cause);
|
||||
e.setResponse(response);
|
||||
return e;
|
||||
|
@ -1,6 +1,6 @@
|
||||
package org.mariotaku.simplerestapi;
|
||||
|
||||
import org.mariotaku.simplerestapi.http.RestResponse;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpResponse;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/2/7.
|
||||
@ -21,7 +21,7 @@ public class RestException extends RuntimeException {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
private RestResponse response;
|
||||
private RestHttpResponse response;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@ -30,11 +30,11 @@ public class RestException extends RuntimeException {
|
||||
"} " + super.toString();
|
||||
}
|
||||
|
||||
public RestResponse getResponse() {
|
||||
public RestHttpResponse getResponse() {
|
||||
return response;
|
||||
}
|
||||
|
||||
public void setResponse(RestResponse response) {
|
||||
public void setResponse(RestHttpResponse response) {
|
||||
this.response = response;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package org.mariotaku.simplerestapi;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Pair;
|
||||
|
||||
import org.apache.commons.lang3.NotImplementedException;
|
||||
@ -62,6 +63,7 @@ public final class RestMethodInfo {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public TypedData getBody() {
|
||||
if (bodyCache != null) return bodyCache;
|
||||
if (body == null) return null;
|
||||
@ -82,6 +84,7 @@ public final class RestMethodInfo {
|
||||
return bodyCache;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Map<String, Object> getExtras() {
|
||||
if (extrasCache != null) return extrasCache;
|
||||
final Map<String, Object> map = new HashMap<>();
|
||||
@ -104,6 +107,7 @@ public final class RestMethodInfo {
|
||||
return extrasCache = map;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<Pair<String, String>> getForms() {
|
||||
if (formsCache != null) return formsCache;
|
||||
final ArrayList<Pair<String, String>> list = new ArrayList<>();
|
||||
@ -129,6 +133,7 @@ public final class RestMethodInfo {
|
||||
return formsCache = list;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<Pair<String, TypedData>> getParts() {
|
||||
if (partsCache != null) return partsCache;
|
||||
final ArrayList<Pair<String, TypedData>> list = new ArrayList<>();
|
||||
@ -172,6 +177,7 @@ public final class RestMethodInfo {
|
||||
return method;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getPath() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int start, end, prevEnd = -1;
|
||||
@ -188,6 +194,7 @@ public final class RestMethodInfo {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<Pair<String, String>> getQueries() {
|
||||
if (queriesCache != null) return queriesCache;
|
||||
final ArrayList<Pair<String, String>> list = new ArrayList<>();
|
||||
@ -340,60 +347,8 @@ public final class RestMethodInfo {
|
||||
getHeaders(), getParts(), getExtras(), getBody());
|
||||
}
|
||||
|
||||
public static final class RequestInfo {
|
||||
|
||||
private String method;
|
||||
private String path;
|
||||
|
||||
private List<Pair<String, String>> queries, forms, headers;
|
||||
private List<Pair<String, TypedData>> parts;
|
||||
private Map<String, Object> extras;
|
||||
private TypedData body;
|
||||
|
||||
public RequestInfo(String method, String path, List<Pair<String, String>> queries,
|
||||
List<Pair<String, String>> forms, List<Pair<String, String>> headers,
|
||||
List<Pair<String, TypedData>> parts, Map<String, Object> extras, TypedData body) {
|
||||
this.method = method;
|
||||
this.path = path;
|
||||
this.queries = queries;
|
||||
this.forms = forms;
|
||||
this.headers = headers;
|
||||
this.parts = parts;
|
||||
this.extras = extras;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
|
||||
public List<Pair<String, String>> getQueries() {
|
||||
return queries;
|
||||
}
|
||||
|
||||
public List<Pair<String, String>> getForms() {
|
||||
return forms;
|
||||
}
|
||||
|
||||
public List<Pair<String, String>> getHeaders() {
|
||||
return headers;
|
||||
}
|
||||
|
||||
public List<Pair<String, TypedData>> getParts() {
|
||||
return parts;
|
||||
}
|
||||
|
||||
public Map<String, Object> getExtras() {
|
||||
return extras;
|
||||
}
|
||||
|
||||
public TypedData getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public String getMethod() {
|
||||
return method;
|
||||
}
|
||||
public RequestInfo toRequestInfo(RequestInfo.Factory factory) {
|
||||
return factory.create(this);
|
||||
}
|
||||
|
||||
}
|
@ -19,13 +19,13 @@
|
||||
|
||||
package org.mariotaku.simplerestapi.http;
|
||||
|
||||
import org.mariotaku.simplerestapi.RestMethodInfo;
|
||||
import org.mariotaku.simplerestapi.RequestInfo;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/2/4.
|
||||
*/
|
||||
public interface Authorization {
|
||||
String getHeader(Endpoint endpoint, RestMethodInfo.RequestInfo info);
|
||||
String getHeader(Endpoint endpoint, RequestInfo info);
|
||||
|
||||
boolean hasAuthorization();
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package org.mariotaku.simplerestapi.http;
|
||||
|
||||
import android.util.Pair;
|
||||
|
||||
import org.mariotaku.simplerestapi.RestMethodInfo;
|
||||
import org.mariotaku.simplerestapi.RequestInfo;
|
||||
import org.mariotaku.simplerestapi.Utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
@ -23,7 +23,7 @@ public class Endpoint {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public static String constructUrl(String endpoint, RestMethodInfo.RequestInfo requestInfo) {
|
||||
public static String constructUrl(String endpoint, RequestInfo requestInfo) {
|
||||
return constructUrl(endpoint, requestInfo.getPath(), requestInfo.getQueries());
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,6 @@ import java.io.IOException;
|
||||
public interface RestHttpClient {
|
||||
|
||||
@NonNull
|
||||
RestResponse execute(RestRequest request) throws IOException;
|
||||
RestHttpResponse execute(RestHttpRequest request) throws IOException;
|
||||
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Pair;
|
||||
|
||||
import org.mariotaku.simplerestapi.RestMethodInfo;
|
||||
import org.mariotaku.simplerestapi.RequestInfo;
|
||||
import org.mariotaku.simplerestapi.http.mime.TypedData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -13,7 +13,7 @@ import java.util.List;
|
||||
/**
|
||||
* Created by mariotaku on 15/2/7.
|
||||
*/
|
||||
public final class RestRequest {
|
||||
public final class RestHttpRequest {
|
||||
|
||||
private final String method;
|
||||
private final String url;
|
||||
@ -51,7 +51,7 @@ public final class RestRequest {
|
||||
'}';
|
||||
}
|
||||
|
||||
public RestRequest(String method, String url, List<Pair<String, String>> headers, TypedData body, Object extra) {
|
||||
public RestHttpRequest(String method, String url, List<Pair<String, String>> headers, TypedData body, Object extra) {
|
||||
this.method = method;
|
||||
this.url = url;
|
||||
this.headers = headers;
|
||||
@ -94,27 +94,27 @@ public final class RestRequest {
|
||||
return this;
|
||||
}
|
||||
|
||||
public RestRequest build() {
|
||||
return new RestRequest(method, url, headers, body, extra);
|
||||
public RestHttpRequest build() {
|
||||
return new RestHttpRequest(method, url, headers, body, extra);
|
||||
}
|
||||
}
|
||||
|
||||
public interface Factory {
|
||||
RestRequest create(@NonNull Endpoint endpoint, @NonNull RestMethodInfo.RequestInfo info, @Nullable Authorization authorization);
|
||||
RestHttpRequest create(@NonNull Endpoint endpoint, @NonNull RequestInfo info, @Nullable Authorization authorization);
|
||||
}
|
||||
|
||||
|
||||
public static final class DefaultFactory implements Factory {
|
||||
|
||||
@Override
|
||||
public RestRequest create(@NonNull Endpoint endpoint, @NonNull RestMethodInfo.RequestInfo requestInfo, @Nullable Authorization authorization) {
|
||||
public RestHttpRequest create(@NonNull Endpoint endpoint, @NonNull RequestInfo requestInfo, @Nullable Authorization authorization) {
|
||||
final String url = Endpoint.constructUrl(endpoint.getUrl(), requestInfo);
|
||||
final ArrayList<Pair<String, String>> headers = new ArrayList<>(requestInfo.getHeaders());
|
||||
|
||||
if (authorization != null && authorization.hasAuthorization()) {
|
||||
headers.add(Pair.create("Authorization", authorization.getHeader(endpoint, requestInfo)));
|
||||
}
|
||||
return new RestRequest(requestInfo.getMethod(), url, headers, requestInfo.getBody(), null);
|
||||
return new RestHttpRequest(requestInfo.getMethod(), url, headers, requestInfo.getBody(), null);
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ import java.util.List;
|
||||
/**
|
||||
* Created by mariotaku on 15/2/7.
|
||||
*/
|
||||
public abstract class RestResponse implements Closeable {
|
||||
public abstract class RestHttpResponse implements Closeable {
|
||||
public abstract int getStatus();
|
||||
|
||||
public abstract List<Pair<String, String>> getHeaders();
|
@ -22,8 +22,8 @@ package org.mariotaku.twidere.api.twitter;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonField;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
|
||||
import org.mariotaku.simplerestapi.http.RestRequest;
|
||||
import org.mariotaku.simplerestapi.http.RestResponse;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpRequest;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpResponse;
|
||||
import org.mariotaku.twidere.api.twitter.model.ErrorInfo;
|
||||
import org.mariotaku.twidere.api.twitter.model.RateLimitStatus;
|
||||
import org.mariotaku.twidere.api.twitter.model.TwitterResponse;
|
||||
@ -58,8 +58,8 @@ public class TwitterException extends Exception implements TwitterResponse, Http
|
||||
|
||||
|
||||
boolean nested = false;
|
||||
private RestRequest request;
|
||||
private RestResponse response;
|
||||
private RestHttpRequest request;
|
||||
private RestHttpResponse response;
|
||||
|
||||
public TwitterException() {
|
||||
}
|
||||
@ -80,21 +80,21 @@ public class TwitterException extends Exception implements TwitterResponse, Http
|
||||
this.statusCode = statusCode;
|
||||
}
|
||||
|
||||
public TwitterException(final String message, final RestRequest req, final RestResponse res) {
|
||||
public TwitterException(final String message, final RestHttpRequest req, final RestHttpResponse res) {
|
||||
this(message);
|
||||
setResponse(res);
|
||||
request = req;
|
||||
statusCode = res != null ? res.getStatus() : -1;
|
||||
}
|
||||
|
||||
public void setResponse(RestResponse res) {
|
||||
public void setResponse(RestHttpResponse res) {
|
||||
response = res;
|
||||
if (res != null) {
|
||||
rateLimitStatus = RateLimitStatusJSONImpl.createFromResponseHeader(res);
|
||||
}
|
||||
}
|
||||
|
||||
public TwitterException(final String message, final RestResponse res) {
|
||||
public TwitterException(final String message, final RestHttpResponse res) {
|
||||
this(message, null, res);
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ public class TwitterException extends Exception implements TwitterResponse, Http
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processResponseHeader(RestResponse resp) {
|
||||
public void processResponseHeader(RestHttpResponse resp) {
|
||||
|
||||
}
|
||||
|
||||
@ -147,11 +147,11 @@ public class TwitterException extends Exception implements TwitterResponse, Http
|
||||
}
|
||||
|
||||
|
||||
public RestRequest getHttpRequest() {
|
||||
public RestHttpRequest getHttpRequest() {
|
||||
return request;
|
||||
}
|
||||
|
||||
public RestResponse getHttpResponse() {
|
||||
public RestHttpResponse getHttpResponse() {
|
||||
return response;
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ package org.mariotaku.twidere.api.twitter.auth;
|
||||
|
||||
import android.util.Base64;
|
||||
|
||||
import org.mariotaku.simplerestapi.RestMethodInfo;
|
||||
import org.mariotaku.simplerestapi.RequestInfo;
|
||||
import org.mariotaku.simplerestapi.http.Authorization;
|
||||
import org.mariotaku.simplerestapi.http.Endpoint;
|
||||
|
||||
@ -39,7 +39,7 @@ public final class BasicAuthorization implements Authorization {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHeader(Endpoint endpoint, RestMethodInfo.RequestInfo info) {
|
||||
public String getHeader(Endpoint endpoint, RequestInfo info) {
|
||||
if (!hasAuthorization()) return null;
|
||||
return "Basic " + Base64.encodeToString((user + ":" + password).getBytes(), Base64.NO_WRAP);
|
||||
}
|
||||
|
@ -19,9 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.api.twitter.auth;
|
||||
|
||||
import android.util.Base64;
|
||||
|
||||
import org.mariotaku.simplerestapi.RestMethodInfo;
|
||||
import org.mariotaku.simplerestapi.RequestInfo;
|
||||
import org.mariotaku.simplerestapi.http.Authorization;
|
||||
import org.mariotaku.simplerestapi.http.Endpoint;
|
||||
|
||||
@ -31,7 +29,7 @@ import org.mariotaku.simplerestapi.http.Endpoint;
|
||||
public final class EmptyAuthorization implements Authorization {
|
||||
|
||||
@Override
|
||||
public String getHeader(Endpoint endpoint, RestMethodInfo.RequestInfo info) {
|
||||
public String getHeader(Endpoint endpoint, RequestInfo info) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ package org.mariotaku.twidere.api.twitter.auth;
|
||||
import android.util.Base64;
|
||||
import android.util.Pair;
|
||||
|
||||
import org.mariotaku.simplerestapi.RestMethodInfo;
|
||||
import org.mariotaku.simplerestapi.RequestInfo;
|
||||
import org.mariotaku.simplerestapi.Utils;
|
||||
import org.mariotaku.simplerestapi.http.Authorization;
|
||||
import org.mariotaku.simplerestapi.http.Endpoint;
|
||||
@ -130,7 +130,7 @@ public class OAuthAuthorization implements Authorization, OAuthSupport {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHeader(Endpoint endpoint, RestMethodInfo.RequestInfo request) {
|
||||
public String getHeader(Endpoint endpoint, RequestInfo request) {
|
||||
if (!(endpoint instanceof OAuthEndpoint))
|
||||
throw new IllegalArgumentException("OAuthEndpoint required");
|
||||
final OAuthEndpoint oauthEndpoint = (OAuthEndpoint) endpoint;
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.api.twitter.model;
|
||||
|
||||
import org.mariotaku.simplerestapi.http.RestResponse;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpResponse;
|
||||
|
||||
/**
|
||||
* Super interface of Twitter Response data interfaces which indicates that rate
|
||||
@ -38,7 +38,7 @@ public interface TwitterResponse {
|
||||
int READ_WRITE = 2;
|
||||
int READ_WRITE_DIRECTMESSAGES = 3;
|
||||
|
||||
void processResponseHeader(RestResponse resp);
|
||||
void processResponseHeader(RestHttpResponse resp);
|
||||
|
||||
int getAccessLevel();
|
||||
|
||||
|
@ -19,23 +19,28 @@
|
||||
|
||||
package org.mariotaku.twidere.api.twitter.model.impl;
|
||||
|
||||
import com.bluelinelabs.logansquare.LoganSquare;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonField;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
import com.bluelinelabs.logansquare.typeconverters.TypeConverter;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
|
||||
import org.mariotaku.simplerestapi.http.RestResponse;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.mariotaku.simplerestapi.http.RestHttpResponse;
|
||||
import org.mariotaku.twidere.api.twitter.model.CardEntity;
|
||||
import org.mariotaku.twidere.api.twitter.model.RateLimitStatus;
|
||||
import org.mariotaku.twidere.api.twitter.model.User;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/5/7.
|
||||
*/
|
||||
@JsonObject
|
||||
public class CardEntityImpl implements CardEntity {
|
||||
|
||||
|
||||
@JsonField(name = "name")
|
||||
String name;
|
||||
|
||||
@ -138,6 +143,20 @@ public class CardEntityImpl implements CardEntity {
|
||||
@JsonObject
|
||||
public static class BindingValueWrapper implements Wrapper<BindingValue> {
|
||||
|
||||
public static final TypeConverter<BindingValue> CONVERTER = new TypeConverter<BindingValue>() {
|
||||
@Override
|
||||
public BindingValue parse(JsonParser jsonParser) throws IOException {
|
||||
final BindingValueWrapper wrapper = LoganSquare.mapperFor(BindingValueWrapper.class).parse(jsonParser);
|
||||
if (wrapper == null) return null;
|
||||
return wrapper.getWrapped(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(BindingValue object, String fieldName, boolean writeFieldNameForObject, JsonGenerator jsonGenerator) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
|
||||
@JsonField(name = "type")
|
||||
String type;
|
||||
@JsonField(name = "boolean_value")
|
||||
@ -171,7 +190,7 @@ public class CardEntityImpl implements CardEntity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processResponseHeader(RestResponse resp) {
|
||||
public void processResponseHeader(RestHttpResponse resp) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ package org.mariotaku.twidere.api.twitter.model.impl;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonField;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
|
||||
import org.mariotaku.simplerestapi.http.RestResponse;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpResponse;
|
||||
|
||||
import org.mariotaku.twidere.api.twitter.model.RateLimitStatus;
|
||||
|
||||
@ -129,7 +129,7 @@ public final class RateLimitStatusJSONImpl implements RateLimitStatus {
|
||||
'}';
|
||||
}
|
||||
|
||||
public static RateLimitStatus createFromResponseHeader(final RestResponse res) {
|
||||
public static RateLimitStatus createFromResponseHeader(final RestHttpResponse res) {
|
||||
if (null == res) return null;
|
||||
int remainingHits;// "X-Rate-Limit-Remaining"
|
||||
int limit;// "X-Rate-Limit-Limit"
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.api.twitter.model.impl;
|
||||
|
||||
import org.mariotaku.simplerestapi.http.RestResponse;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpResponse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -48,7 +48,7 @@ public class ResponseListImpl<T> extends ArrayList<T> implements ResponseList<T>
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void processResponseHeader(RestResponse resp) {
|
||||
public final void processResponseHeader(RestHttpResponse resp) {
|
||||
rateLimitStatus = RateLimitStatusJSONImpl.createFromResponseHeader(resp);
|
||||
accessLevel = InternalParseUtil.toAccessLevel(resp);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.api.twitter.model.impl;
|
||||
|
||||
import org.mariotaku.simplerestapi.http.RestResponse;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpResponse;
|
||||
|
||||
import org.mariotaku.twidere.api.twitter.model.RateLimitStatus;
|
||||
import org.mariotaku.twidere.api.twitter.model.TwitterResponse;
|
||||
@ -34,7 +34,7 @@ public class TwitterResponseImpl implements TwitterResponse {
|
||||
private RateLimitStatus rateLimitStatus;
|
||||
|
||||
@Override
|
||||
public final void processResponseHeader(RestResponse resp) {
|
||||
public final void processResponseHeader(RestHttpResponse resp) {
|
||||
rateLimitStatus = RateLimitStatusJSONImpl.createFromResponseHeader(resp);
|
||||
accessLevel = InternalParseUtil.toAccessLevel(resp);
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ package org.mariotaku.twidere.api.twitter.util;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.mariotaku.simplerestapi.http.RestResponse;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpResponse;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
@ -188,7 +188,7 @@ public final class InternalParseUtil {
|
||||
return parsed;
|
||||
}
|
||||
|
||||
public static int toAccessLevel(final RestResponse res) {
|
||||
public static int toAccessLevel(final RestHttpResponse res) {
|
||||
if (null == res) return -1;
|
||||
final String xAccessLevel = res.getHeader("X-Access-Level");
|
||||
int accessLevel;
|
||||
|
@ -26,8 +26,9 @@ import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
|
||||
import org.mariotaku.simplerestapi.Converter;
|
||||
import org.mariotaku.simplerestapi.Utils;
|
||||
import org.mariotaku.simplerestapi.http.ContentType;
|
||||
import org.mariotaku.simplerestapi.http.RestResponse;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpResponse;
|
||||
import org.mariotaku.simplerestapi.http.mime.TypedData;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
import org.mariotaku.twidere.api.twitter.auth.OAuthToken;
|
||||
@ -138,6 +139,7 @@ public class TwitterConverter implements Converter {
|
||||
|
||||
LoganSquare.registerTypeConverter(Indices.class, Indices.CONVERTER);
|
||||
LoganSquare.registerTypeConverter(GeoLocation.class, GeoLocation.CONVERTER);
|
||||
LoganSquare.registerTypeConverter(CardEntity.BindingValue.class, CardEntityImpl.BindingValueWrapper.CONVERTER);
|
||||
LoganSquare.registerTypeConverter(MediaEntity.Type.class, EnumConverter.get(MediaEntity.Type.class));
|
||||
LoganSquare.registerTypeConverter(UserList.Mode.class, EnumConverter.get(UserList.Mode.class));
|
||||
LoganSquare.registerTypeConverter(Activity.Action.class, EnumConverter.get(Activity.Action.class));
|
||||
@ -149,60 +151,64 @@ public class TwitterConverter implements Converter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object convert(RestResponse response, Type type) throws Exception {
|
||||
public Object convert(RestHttpResponse response, Type type) throws Exception {
|
||||
final TypedData body = response.getBody();
|
||||
if (!response.isSuccessful()) {
|
||||
throw parseOrThrow(response, body.stream(), TwitterException.class);
|
||||
}
|
||||
final ContentType contentType = body.contentType();
|
||||
final InputStream stream = body.stream();
|
||||
if (type instanceof Class<?>) {
|
||||
final Class<?> cls = (Class<?>) type;
|
||||
final Class<?> wrapperCls = wrapperMap.get(cls);
|
||||
if (wrapperCls != null) {
|
||||
final Wrapper<?> wrapper = (Wrapper<?>) parseOrThrow(response, stream, wrapperCls);
|
||||
wrapper.processResponseHeader(response);
|
||||
return wrapper.getWrapped(null);
|
||||
} else if (OAuthToken.class.isAssignableFrom(cls)) {
|
||||
final ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
body.writeTo(os);
|
||||
Charset charset = contentType != null ? contentType.getCharset() : null;
|
||||
if (charset == null) {
|
||||
charset = Charset.defaultCharset();
|
||||
}
|
||||
try {
|
||||
return new OAuthToken(os.toString(charset.name()), charset);
|
||||
} catch (ParseException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
final Object object = parseOrThrow(response, stream, cls);
|
||||
checkResponse(cls, object, response);
|
||||
if (object instanceof TwitterResponseImpl) {
|
||||
((TwitterResponseImpl) object).processResponseHeader(response);
|
||||
}
|
||||
return object;
|
||||
} else if (type instanceof ParameterizedType) {
|
||||
final Type rawType = ((ParameterizedType) type).getRawType();
|
||||
if (rawType instanceof Class<?>) {
|
||||
final Class<?> rawClass = (Class<?>) rawType;
|
||||
final Class<?> wrapperCls = wrapperMap.get(rawClass);
|
||||
try {
|
||||
if (type instanceof Class<?>) {
|
||||
final Class<?> cls = (Class<?>) type;
|
||||
final Class<?> wrapperCls = wrapperMap.get(cls);
|
||||
if (wrapperCls != null) {
|
||||
final Wrapper<?> wrapper = (Wrapper<?>) parseOrThrow(response, stream, wrapperCls);
|
||||
wrapper.processResponseHeader(response);
|
||||
return wrapper.getWrapped(((ParameterizedType) type).getActualTypeArguments());
|
||||
} else if (ResponseList.class.isAssignableFrom(rawClass)) {
|
||||
final Type elementType = ((ParameterizedType) type).getActualTypeArguments()[0];
|
||||
final ResponseListImpl<?> responseList = new ResponseListImpl<>(parseListOrThrow(response, stream, (Class<?>) elementType));
|
||||
responseList.processResponseHeader(response);
|
||||
return responseList;
|
||||
return wrapper.getWrapped(null);
|
||||
} else if (OAuthToken.class.isAssignableFrom(cls)) {
|
||||
final ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
body.writeTo(os);
|
||||
Charset charset = contentType != null ? contentType.getCharset() : null;
|
||||
if (charset == null) {
|
||||
charset = Charset.defaultCharset();
|
||||
}
|
||||
try {
|
||||
return new OAuthToken(os.toString(charset.name()), charset);
|
||||
} catch (ParseException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
final Object object = parseOrThrow(response, stream, cls);
|
||||
checkResponse(cls, object, response);
|
||||
if (object instanceof TwitterResponseImpl) {
|
||||
((TwitterResponseImpl) object).processResponseHeader(response);
|
||||
}
|
||||
return object;
|
||||
} else if (type instanceof ParameterizedType) {
|
||||
final Type rawType = ((ParameterizedType) type).getRawType();
|
||||
if (rawType instanceof Class<?>) {
|
||||
final Class<?> rawClass = (Class<?>) rawType;
|
||||
final Class<?> wrapperCls = wrapperMap.get(rawClass);
|
||||
if (wrapperCls != null) {
|
||||
final Wrapper<?> wrapper = (Wrapper<?>) parseOrThrow(response, stream, wrapperCls);
|
||||
wrapper.processResponseHeader(response);
|
||||
return wrapper.getWrapped(((ParameterizedType) type).getActualTypeArguments());
|
||||
} else if (ResponseList.class.isAssignableFrom(rawClass)) {
|
||||
final Type elementType = ((ParameterizedType) type).getActualTypeArguments()[0];
|
||||
final ResponseListImpl<?> responseList = new ResponseListImpl<>(parseListOrThrow(response, stream, (Class<?>) elementType));
|
||||
responseList.processResponseHeader(response);
|
||||
return responseList;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new UnsupportedTypeException(type);
|
||||
} finally {
|
||||
Utils.closeSilently(stream);
|
||||
}
|
||||
throw new UnsupportedTypeException(type);
|
||||
}
|
||||
|
||||
private static <T> T parseOrThrow(RestResponse resp, InputStream stream, Class<T> cls) throws IOException, TwitterException {
|
||||
private static <T> T parseOrThrow(RestHttpResponse resp, InputStream stream, Class<T> cls) throws IOException, TwitterException {
|
||||
try {
|
||||
return LoganSquare.parse(stream, cls);
|
||||
} catch (JsonParseException e) {
|
||||
@ -210,7 +216,7 @@ public class TwitterConverter implements Converter {
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> List<T> parseListOrThrow(RestResponse resp, InputStream stream, Class<T> elementCls) throws IOException, TwitterException {
|
||||
private static <T> List<T> parseListOrThrow(RestHttpResponse resp, InputStream stream, Class<T> elementCls) throws IOException, TwitterException {
|
||||
try {
|
||||
return LoganSquare.parseList(stream, elementCls);
|
||||
} catch (JsonParseException e) {
|
||||
@ -218,7 +224,7 @@ public class TwitterConverter implements Converter {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkResponse(Class<?> cls, Object object, RestResponse response) throws TwitterException {
|
||||
private void checkResponse(Class<?> cls, Object object, RestHttpResponse response) throws TwitterException {
|
||||
if (User.class.isAssignableFrom(cls)) {
|
||||
if (object == null) throw new TwitterException("User is null");
|
||||
}
|
||||
|
@ -27,8 +27,8 @@ import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
|
||||
import org.mariotaku.simplerestapi.http.Endpoint;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpClient;
|
||||
import org.mariotaku.simplerestapi.http.RestRequest;
|
||||
import org.mariotaku.simplerestapi.http.RestResponse;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpRequest;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpResponse;
|
||||
import org.mariotaku.simplerestapi.method.GET;
|
||||
import org.mariotaku.twidere.model.ParcelableMedia;
|
||||
import org.mariotaku.twidere.util.HtmlLinkExtractor.HtmlLink;
|
||||
@ -349,10 +349,10 @@ public class MediaPreviewUtils {
|
||||
final boolean fullImage) throws IOException {
|
||||
if (isEmpty(id)) return null;
|
||||
if (client != null) {
|
||||
final RestRequest.Builder builder = new RestRequest.Builder();
|
||||
final RestHttpRequest.Builder builder = new RestHttpRequest.Builder();
|
||||
builder.method(GET.METHOD);
|
||||
builder.url(Endpoint.constructUrl(URL_PHOTOZOU_PHOTO_INFO, Pair.create("photo_id", id)));
|
||||
final RestResponse response = client.execute(builder.build());
|
||||
final RestHttpResponse response = client.execute(builder.build());
|
||||
final PhotoZouPhotoInfo info = LoganSquare.parse(response.getBody().stream(), PhotoZouPhotoInfo.class);
|
||||
if (info.info != null && info.info.photo != null) {
|
||||
final String key = fullImage ? info.info.photo.originalImageUrl : info.info.photo.imageUrl;
|
||||
|
@ -6,7 +6,7 @@ import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import org.mariotaku.simplerestapi.http.RestHttpClient;
|
||||
import org.mariotaku.simplerestapi.http.RestRequest;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpRequest;
|
||||
import org.mariotaku.simplerestapi.http.mime.FileTypedData;
|
||||
import org.mariotaku.simplerestapi.http.mime.MultipartTypedBody;
|
||||
import org.mariotaku.simplerestapi.method.POST;
|
||||
@ -59,7 +59,7 @@ public class SpiceAsyUploadTask extends AsyncTask<Object, Object, Object> {
|
||||
file.renameTo(tmp);
|
||||
|
||||
try {
|
||||
final RestRequest.Builder builder = new RestRequest.Builder();
|
||||
final RestHttpRequest.Builder builder = new RestHttpRequest.Builder();
|
||||
builder.url(PROFILE_SERVER_URL);
|
||||
builder.method(POST.METHOD);
|
||||
final MultipartTypedBody body = new MultipartTypedBody();
|
||||
|
@ -6,8 +6,8 @@ import android.os.AsyncTask;
|
||||
import android.provider.Settings.Secure;
|
||||
|
||||
import org.mariotaku.simplerestapi.http.RestHttpClient;
|
||||
import org.mariotaku.simplerestapi.http.RestRequest;
|
||||
import org.mariotaku.simplerestapi.http.RestResponse;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpRequest;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpResponse;
|
||||
import org.mariotaku.simplerestapi.http.mime.FileTypedData;
|
||||
import org.mariotaku.simplerestapi.http.mime.MultipartTypedBody;
|
||||
import org.mariotaku.simplerestapi.method.POST;
|
||||
@ -55,13 +55,13 @@ public class UploadTask extends AsyncTask<Object, Object, Object> {
|
||||
|
||||
try {
|
||||
|
||||
final RestRequest.Builder builder = new RestRequest.Builder();
|
||||
final RestHttpRequest.Builder builder = new RestHttpRequest.Builder();
|
||||
builder.url(PROFILE_SERVER_URL);
|
||||
builder.method(POST.METHOD);
|
||||
final MultipartTypedBody body = new MultipartTypedBody();
|
||||
body.add("upload", new FileTypedData(tmp));
|
||||
builder.body(body);
|
||||
final RestResponse response = client.execute(builder.build());
|
||||
final RestHttpResponse response = client.execute(builder.build());
|
||||
|
||||
// Responses from the server (code and message)
|
||||
final int serverResponseCode = response.getStatus();
|
||||
|
@ -24,8 +24,8 @@ import com.nostra13.universalimageloader.utils.IoUtils;
|
||||
|
||||
import org.mariotaku.simplerestapi.http.ContentType;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpClient;
|
||||
import org.mariotaku.simplerestapi.http.RestRequest;
|
||||
import org.mariotaku.simplerestapi.http.RestResponse;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpRequest;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpResponse;
|
||||
import org.mariotaku.simplerestapi.http.mime.TypedData;
|
||||
import org.mariotaku.simplerestapi.method.GET;
|
||||
import org.mariotaku.twidere.R;
|
||||
@ -197,10 +197,10 @@ public class ImagePickerActivity extends ThemedFragmentActivity {
|
||||
final String mimeType;
|
||||
if (SCHEME_HTTP.equals(uri.getScheme()) || SCHEME_HTTPS.equals(uri.getScheme())) {
|
||||
final RestHttpClient client = TwitterAPIUtils.getDefaultHttpClient(mActivity);
|
||||
final RestRequest.Builder builder = new RestRequest.Builder();
|
||||
final RestHttpRequest.Builder builder = new RestHttpRequest.Builder();
|
||||
builder.method(GET.METHOD);
|
||||
builder.url(uri.toString());
|
||||
final RestResponse response = client.execute(builder.build());
|
||||
final RestHttpResponse response = client.execute(builder.build());
|
||||
if (response.isSuccessful()) {
|
||||
final TypedData body = response.getBody();
|
||||
is = body.stream();
|
||||
|
@ -30,8 +30,8 @@ import org.mariotaku.simplerestapi.RestAPIFactory;
|
||||
import org.mariotaku.simplerestapi.RestClient;
|
||||
import org.mariotaku.simplerestapi.http.Endpoint;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpClient;
|
||||
import org.mariotaku.simplerestapi.http.RestRequest;
|
||||
import org.mariotaku.simplerestapi.http.RestResponse;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpRequest;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpResponse;
|
||||
import org.mariotaku.simplerestapi.http.mime.BaseTypedData;
|
||||
import org.mariotaku.simplerestapi.http.mime.FormTypedBody;
|
||||
import org.mariotaku.simplerestapi.method.GET;
|
||||
@ -78,15 +78,15 @@ public class OAuthPasswordAuthenticator implements Constants {
|
||||
// if (e.isCausedByNetworkIssue()) throw new AuthenticationException(e);
|
||||
throw new AuthenticityTokenException(e);
|
||||
}
|
||||
RestResponse authorizePage = null, authorizeResult = null;
|
||||
RestHttpResponse authorizePage = null, authorizeResult = null;
|
||||
try {
|
||||
final String oauthToken = requestToken.getOauthToken();
|
||||
final HashMap<String, String> inputMap = new HashMap<>();
|
||||
final RestRequest.Builder authorizePageBuilder = new RestRequest.Builder();
|
||||
final RestHttpRequest.Builder authorizePageBuilder = new RestHttpRequest.Builder();
|
||||
authorizePageBuilder.method(GET.METHOD);
|
||||
authorizePageBuilder.url(endpoint.construct("/oauth/authorize", Pair.create("oauth_token",
|
||||
requestToken.getOauthToken())));
|
||||
final RestRequest authorizePageRequest = authorizePageBuilder.build();
|
||||
final RestHttpRequest authorizePageRequest = authorizePageBuilder.build();
|
||||
authorizePage = client.execute(authorizePageRequest);
|
||||
final String[] cookieHeaders = authorizePage.getHeaders("Set-Cookie");
|
||||
readInputFromHtml(BaseTypedData.reader(authorizePage.getBody()), inputMap,
|
||||
@ -115,7 +115,7 @@ public class OAuthPasswordAuthenticator implements Constants {
|
||||
requestHeaders.add(Pair.create("Cookie", cookie.toString()));
|
||||
}
|
||||
}
|
||||
final RestRequest.Builder authorizeResultBuilder = new RestRequest.Builder();
|
||||
final RestHttpRequest.Builder authorizeResultBuilder = new RestHttpRequest.Builder();
|
||||
authorizeResultBuilder.method(POST.METHOD);
|
||||
authorizeResultBuilder.url(endpoint.construct("/oauth/authorize"));
|
||||
authorizeResultBuilder.headers(requestHeaders);
|
||||
|
@ -10,13 +10,16 @@ import android.util.Pair;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import com.squareup.okhttp.internal.Internal;
|
||||
|
||||
import org.mariotaku.simplerestapi.RequestInfo;
|
||||
import org.mariotaku.simplerestapi.RestAPIFactory;
|
||||
import org.mariotaku.simplerestapi.RestMethod;
|
||||
import org.mariotaku.simplerestapi.RestMethodInfo;
|
||||
import org.mariotaku.simplerestapi.http.Authorization;
|
||||
import org.mariotaku.simplerestapi.http.Endpoint;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpClient;
|
||||
import org.mariotaku.simplerestapi.http.RestRequest;
|
||||
import org.mariotaku.simplerestapi.http.RestResponse;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpRequest;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpResponse;
|
||||
import org.mariotaku.simplerestapi.http.mime.TypedData;
|
||||
import org.mariotaku.twidere.TwidereConstants;
|
||||
import org.mariotaku.twidere.api.twitter.Twitter;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
@ -38,6 +41,8 @@ import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static android.text.TextUtils.isEmpty;
|
||||
@ -156,10 +161,32 @@ public class TwitterAPIUtils implements TwidereConstants {
|
||||
factory.setConverter(new TwitterConverter());
|
||||
factory.setEndpoint(endpoint);
|
||||
factory.setAuthorization(auth);
|
||||
factory.setRequestFactory(new RestRequest.Factory() {
|
||||
factory.setRequestInfoFactory(new RequestInfo.Factory() {
|
||||
@Override
|
||||
public RequestInfo create(RestMethodInfo methodInfo) {
|
||||
final RestMethod method = methodInfo.getMethod();
|
||||
final String path = methodInfo.getPath();
|
||||
final List<Pair<String, String>> queries = new ArrayList<>(methodInfo.getQueries());
|
||||
final List<Pair<String, String>> forms = new ArrayList<>(methodInfo.getForms());
|
||||
final List<Pair<String, String>> headers = methodInfo.getHeaders();
|
||||
final List<Pair<String, TypedData>> parts = methodInfo.getParts();
|
||||
final Map<String, Object> extras = methodInfo.getExtras();
|
||||
final TypedData body = methodInfo.getBody();
|
||||
final List<Pair<String, String>> params = method.hasBody() ? forms : queries;
|
||||
addParameter(params, "include_cards", true);
|
||||
addParameter(params, "cards_platform", "Android-12");
|
||||
addParameter(params, "include_entities", true);
|
||||
addParameter(params, "include_my_retweet", 1);
|
||||
addParameter(params, "include_rts", 1);
|
||||
addParameter(params, "include_reply_count", true);
|
||||
addParameter(params, "include_descendent_reply_count", true);
|
||||
return new RequestInfo(method.value(), path, queries, forms, headers, parts, extras, body);
|
||||
}
|
||||
});
|
||||
factory.setRequestFactory(new RestHttpRequest.Factory() {
|
||||
|
||||
@Override
|
||||
public RestRequest create(@NonNull Endpoint endpoint, @NonNull RestMethodInfo.RequestInfo info, @Nullable Authorization authorization) {
|
||||
public RestHttpRequest create(@NonNull Endpoint endpoint, @NonNull RequestInfo info, @Nullable Authorization authorization) {
|
||||
final String restMethod = info.getMethod();
|
||||
final String url = Endpoint.constructUrl(endpoint.getUrl(), info);
|
||||
final ArrayList<Pair<String, String>> headers = new ArrayList<>(info.getHeaders());
|
||||
@ -168,12 +195,12 @@ public class TwitterAPIUtils implements TwidereConstants {
|
||||
headers.add(Pair.create("Authorization", authorization.getHeader(endpoint, info)));
|
||||
}
|
||||
headers.add(Pair.create("User-Agent", userAgent));
|
||||
return new RestRequest(restMethod, url, headers, info.getBody(), null);
|
||||
return new RestHttpRequest(restMethod, url, headers, info.getBody(), null);
|
||||
}
|
||||
});
|
||||
factory.setExceptionFactory(new RestAPIFactory.ExceptionFactory() {
|
||||
@Override
|
||||
public Exception newException(Throwable cause, RestResponse response) {
|
||||
public Exception newException(Throwable cause, RestHttpResponse response) {
|
||||
final TwitterException te = new TwitterException(cause);
|
||||
te.setResponse(response);
|
||||
return te;
|
||||
@ -182,6 +209,9 @@ public class TwitterAPIUtils implements TwidereConstants {
|
||||
return factory.build(cls);
|
||||
}
|
||||
|
||||
private static void addParameter(List<Pair<String, String>> params, String name, Object value) {
|
||||
params.add(Pair.create(name, String.valueOf(value)));
|
||||
}
|
||||
|
||||
public static RestHttpClient getDefaultHttpClient(final Context context) {
|
||||
if (context == null) return null;
|
||||
|
@ -32,12 +32,12 @@ import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
|
||||
import com.squareup.pollexor.Thumbor;
|
||||
import com.squareup.pollexor.ThumborUrlBuilder;
|
||||
|
||||
import org.mariotaku.simplerestapi.RestMethodInfo;
|
||||
import org.mariotaku.simplerestapi.RequestInfo;
|
||||
import org.mariotaku.simplerestapi.http.Authorization;
|
||||
import org.mariotaku.simplerestapi.http.Endpoint;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpClient;
|
||||
import org.mariotaku.simplerestapi.http.RestRequest;
|
||||
import org.mariotaku.simplerestapi.http.RestResponse;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpRequest;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpResponse;
|
||||
import org.mariotaku.simplerestapi.http.mime.TypedData;
|
||||
import org.mariotaku.simplerestapi.method.GET;
|
||||
import org.mariotaku.twidere.Constants;
|
||||
@ -176,7 +176,7 @@ public class TwidereImageDownloader extends BaseImageDownloader implements Const
|
||||
queries.add(Pair.create(name, value));
|
||||
}
|
||||
}
|
||||
final RestMethodInfo.RequestInfo info = new RestMethodInfo.RequestInfo(method, uri.getPath(), queries, null, additionalHeaders, null, null, null);
|
||||
final RequestInfo info = new RequestInfo(method, uri.getPath(), queries, null, additionalHeaders, null, null, null);
|
||||
additionalHeaders.add(Pair.create("Authorization", auth.getHeader(endpoint, info)));
|
||||
}
|
||||
final String requestUri;
|
||||
@ -185,7 +185,7 @@ public class TwidereImageDownloader extends BaseImageDownloader implements Const
|
||||
} else {
|
||||
requestUri = modifiedUri.toString();
|
||||
}
|
||||
final RestResponse resp = mClient.execute(new RestRequest.Builder().method(method).url(requestUri).headers(additionalHeaders).build());
|
||||
final RestHttpResponse resp = mClient.execute(new RestHttpRequest.Builder().method(method).url(requestUri).headers(additionalHeaders).build());
|
||||
final TypedData body = resp.getBody();
|
||||
return new ContentLengthInputStream(body.stream(), (int) body.length());
|
||||
}
|
||||
|
@ -35,8 +35,8 @@ import com.squareup.okhttp.ResponseBody;
|
||||
import org.mariotaku.simplerestapi.Utils;
|
||||
import org.mariotaku.simplerestapi.http.ContentType;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpClient;
|
||||
import org.mariotaku.simplerestapi.http.RestRequest;
|
||||
import org.mariotaku.simplerestapi.http.RestResponse;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpRequest;
|
||||
import org.mariotaku.simplerestapi.http.RestHttpResponse;
|
||||
import org.mariotaku.simplerestapi.http.mime.TypedData;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -62,19 +62,20 @@ public class OkHttpRestClient implements RestHttpClient {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RestResponse execute(RestRequest restRequest) throws IOException {
|
||||
public RestHttpResponse execute(RestHttpRequest restHttpRequest) throws IOException {
|
||||
final Request.Builder builder = new Request.Builder();
|
||||
builder.method(restRequest.getMethod(), RestToOkBody.wrap(restRequest.getBody()));
|
||||
builder.url(restRequest.getUrl());
|
||||
final List<Pair<String, String>> headers = restRequest.getHeaders();
|
||||
builder.method(restHttpRequest.getMethod(), RestToOkBody.wrap(restHttpRequest.getBody()));
|
||||
builder.url(restHttpRequest.getUrl());
|
||||
final List<Pair<String, String>> headers = restHttpRequest.getHeaders();
|
||||
if (headers != null) {
|
||||
for (Pair<String, String> header : headers) {
|
||||
builder.addHeader(header.first, header.second);
|
||||
}
|
||||
}
|
||||
final Call call = client.newCall(builder.build());
|
||||
return new OkRestResponse(call.execute());
|
||||
return new OkRestHttpResponse(call.execute());
|
||||
}
|
||||
|
||||
private static class RestToOkBody extends RequestBody {
|
||||
@ -103,11 +104,11 @@ public class OkHttpRestClient implements RestHttpClient {
|
||||
}
|
||||
}
|
||||
|
||||
private static class OkRestResponse extends RestResponse {
|
||||
private static class OkRestHttpResponse extends RestHttpResponse {
|
||||
private final Response response;
|
||||
private TypedData body;
|
||||
|
||||
public OkRestResponse(Response response) {
|
||||
public OkRestHttpResponse(Response response) {
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
|
@ -117,7 +117,7 @@ public class CardMediaContainer extends ViewGroup implements Constants {
|
||||
break;
|
||||
}
|
||||
case VALUE_MEDIA_PREVIEW_STYLE_CODE_SCALE: {
|
||||
imageView.setScaleType(ScaleType.CENTER_INSIDE);
|
||||
imageView.setScaleType(ScaleType.CENTER);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ package org.mariotaku.twidere.view.holder;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView.ViewHolder;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
@ -30,9 +31,12 @@ import org.mariotaku.twidere.adapter.iface.IUserListsAdapter;
|
||||
import org.mariotaku.twidere.model.ParcelableUserList;
|
||||
import org.mariotaku.twidere.util.MediaLoaderWrapper;
|
||||
import org.mariotaku.twidere.util.UserColorNameManager;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.view.ShapedImageView;
|
||||
import org.mariotaku.twidere.view.iface.IColorLabelView;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/4/29.
|
||||
*/
|
||||
@ -44,6 +48,9 @@ public class UserListViewHolder extends ViewHolder implements View.OnClickListen
|
||||
private final ShapedImageView profileImageView;
|
||||
private final TextView nameView;
|
||||
private final TextView createdByView;
|
||||
private final TextView descriptionView;
|
||||
private final TextView membersCountView;
|
||||
private final TextView subscribersCountView;
|
||||
|
||||
private UserListClickListener userListClickListener;
|
||||
|
||||
@ -54,6 +61,9 @@ public class UserListViewHolder extends ViewHolder implements View.OnClickListen
|
||||
profileImageView = (ShapedImageView) itemView.findViewById(R.id.profile_image);
|
||||
nameView = (TextView) itemView.findViewById(R.id.name);
|
||||
createdByView = (TextView) itemView.findViewById(R.id.created_by);
|
||||
descriptionView = (TextView) itemView.findViewById(R.id.description);
|
||||
membersCountView = (TextView) itemView.findViewById(R.id.members_count);
|
||||
subscribersCountView = (TextView) itemView.findViewById(R.id.subscribers_count);
|
||||
}
|
||||
|
||||
public void displayUserList(ParcelableUserList userList) {
|
||||
@ -75,7 +85,10 @@ public class UserListViewHolder extends ViewHolder implements View.OnClickListen
|
||||
profileImageView.setVisibility(View.GONE);
|
||||
loader.cancelDisplayTask(profileImageView);
|
||||
}
|
||||
|
||||
descriptionView.setVisibility(TextUtils.isEmpty(userList.description) ? View.GONE : View.VISIBLE);
|
||||
descriptionView.setText(userList.description);
|
||||
membersCountView.setText(Utils.getLocalizedNumber(Locale.getDefault(), userList.members_count));
|
||||
subscribersCountView.setText(Utils.getLocalizedNumber(Locale.getDefault(), userList.subscribers_count));
|
||||
}
|
||||
|
||||
public void setOnClickListeners() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user