mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2025-02-11 09:10:50 +01:00
updated libraries
This commit is contained in:
parent
0ed4b28252
commit
d634ecb276
@ -43,7 +43,7 @@ dependencies {
|
||||
compile 'com.android.support:support-v4:23.1.1'
|
||||
compile 'com.bluelinelabs:logansquare:1.3.4'
|
||||
compile 'org.apache.commons:commons-lang3:3.4'
|
||||
compile 'com.github.mariotaku.RestFu:library:0.9.9'
|
||||
compile 'com.github.mariotaku.RestFu:library:0.9.10'
|
||||
compile 'com.hannesdorfmann.parcelableplease:annotation:1.0.2'
|
||||
compile 'com.github.mariotaku.SQLiteQB:library:0.9.3'
|
||||
compile 'com.github.mariotaku.ObjectCursor:core:0.9.3'
|
||||
|
@ -19,20 +19,15 @@
|
||||
|
||||
package org.mariotaku.twidere.api.twitter;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import org.mariotaku.restfu.annotation.method.GET;
|
||||
import org.mariotaku.restfu.annotation.method.POST;
|
||||
import org.mariotaku.restfu.annotation.param.Body;
|
||||
import org.mariotaku.restfu.annotation.param.Form;
|
||||
import org.mariotaku.restfu.annotation.param.Param;
|
||||
import org.mariotaku.restfu.annotation.param.Query;
|
||||
import org.mariotaku.restfu.http.BodyType;
|
||||
import org.mariotaku.twidere.api.twitter.model.CardDataMap;
|
||||
import org.mariotaku.twidere.api.twitter.model.CardEntity;
|
||||
import org.mariotaku.twidere.api.twitter.model.CardResponse;
|
||||
import org.mariotaku.twidere.api.twitter.model.CreateCardData;
|
||||
import org.mariotaku.twidere.api.twitter.model.CreateCardResult;
|
||||
import org.mariotaku.twidere.api.twitter.model.ResponseCode;
|
||||
|
||||
/**
|
||||
* Card API maybe??
|
||||
@ -46,9 +41,9 @@ public interface TwitterCaps {
|
||||
throws TwitterException;
|
||||
|
||||
@POST("/v2/capi/passthrough/1")
|
||||
@Body(BodyType.FORM)
|
||||
CardResponse sendPassThrough(@Form CardDataMap params) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
CardResponse sendPassThrough(@Param CardDataMap params) throws TwitterException;
|
||||
|
||||
@POST("/v2/cards/create.json")
|
||||
CreateCardResult createCard(@Form("card_data") CreateCardData cardData) throws TwitterException;
|
||||
CreateCardResult createCard(@Param("card_data") CreateCardData cardData) throws TwitterException;
|
||||
}
|
||||
|
@ -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.restfu.http.RestHttpRequest;
|
||||
import org.mariotaku.restfu.http.RestHttpResponse;
|
||||
import org.mariotaku.restfu.http.HttpRequest;
|
||||
import org.mariotaku.restfu.http.HttpResponse;
|
||||
import org.mariotaku.twidere.api.twitter.http.HttpResponseCode;
|
||||
import org.mariotaku.twidere.api.twitter.model.ErrorInfo;
|
||||
import org.mariotaku.twidere.api.twitter.model.RateLimitStatus;
|
||||
@ -52,13 +52,13 @@ public class TwitterException extends Exception implements TwitterResponse, Http
|
||||
boolean nested = false;
|
||||
private int statusCode = -1;
|
||||
private RateLimitStatus rateLimitStatus;
|
||||
private RestHttpRequest httpRequest;
|
||||
private RestHttpResponse httpResponse;
|
||||
private HttpRequest httpRequest;
|
||||
private HttpResponse httpResponse;
|
||||
|
||||
public TwitterException() {
|
||||
}
|
||||
|
||||
public TwitterException(RestHttpResponse httpResponse) {
|
||||
public TwitterException(HttpResponse httpResponse) {
|
||||
setHttpResponse(httpResponse);
|
||||
}
|
||||
|
||||
@ -78,23 +78,23 @@ public class TwitterException extends Exception implements TwitterResponse, Http
|
||||
setStatusCode(statusCode);
|
||||
}
|
||||
|
||||
public TwitterException(final String message, final RestHttpRequest req, final RestHttpResponse res) {
|
||||
public TwitterException(final String message, final HttpRequest req, final HttpResponse res) {
|
||||
this(message);
|
||||
setHttpResponse(res);
|
||||
setHttpRequest(req);
|
||||
}
|
||||
|
||||
public TwitterException(final String message, final Throwable cause, final RestHttpRequest req, final RestHttpResponse res) {
|
||||
public TwitterException(final String message, final Throwable cause, final HttpRequest req, final HttpResponse res) {
|
||||
this(message, cause);
|
||||
setHttpResponse(res);
|
||||
setHttpRequest(req);
|
||||
}
|
||||
|
||||
public TwitterException(final String message, final RestHttpResponse res) {
|
||||
public TwitterException(final String message, final HttpResponse res) {
|
||||
this(message, null, null, res);
|
||||
}
|
||||
|
||||
public TwitterException(final String message, final Throwable cause, final RestHttpResponse res) {
|
||||
public TwitterException(final String message, final Throwable cause, final HttpResponse res) {
|
||||
this(message, cause, null, res);
|
||||
}
|
||||
|
||||
@ -102,7 +102,7 @@ public class TwitterException extends Exception implements TwitterResponse, Http
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
private void setHttpRequest(RestHttpRequest httpRequest) {
|
||||
private void setHttpRequest(HttpRequest httpRequest) {
|
||||
this.httpRequest = httpRequest;
|
||||
}
|
||||
|
||||
@ -113,7 +113,7 @@ public class TwitterException extends Exception implements TwitterResponse, Http
|
||||
return errors;
|
||||
}
|
||||
|
||||
public void setHttpResponse(RestHttpResponse res) {
|
||||
public void setHttpResponse(HttpResponse res) {
|
||||
httpResponse = res;
|
||||
if (res != null) {
|
||||
rateLimitStatus = RateLimitStatus.createFromResponseHeader(res);
|
||||
@ -139,7 +139,7 @@ public class TwitterException extends Exception implements TwitterResponse, Http
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processResponseHeader(RestHttpResponse resp) {
|
||||
public void processResponseHeader(HttpResponse resp) {
|
||||
|
||||
}
|
||||
|
||||
@ -156,11 +156,11 @@ public class TwitterException extends Exception implements TwitterResponse, Http
|
||||
return errors[0].getCode();
|
||||
}
|
||||
|
||||
public RestHttpRequest getHttpRequest() {
|
||||
public HttpRequest getHttpRequest() {
|
||||
return httpRequest;
|
||||
}
|
||||
|
||||
public RestHttpResponse getHttpResponse() {
|
||||
public HttpResponse getHttpResponse() {
|
||||
return httpResponse;
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,10 @@ package org.mariotaku.twidere.api.twitter;
|
||||
|
||||
|
||||
import org.mariotaku.restfu.annotation.method.POST;
|
||||
import org.mariotaku.restfu.annotation.param.Body;
|
||||
import org.mariotaku.restfu.annotation.param.Extra;
|
||||
import org.mariotaku.restfu.annotation.param.Form;
|
||||
import org.mariotaku.restfu.http.BodyType;
|
||||
import org.mariotaku.restfu.annotation.param.KeyValue;
|
||||
import org.mariotaku.restfu.annotation.param.Param;
|
||||
import org.mariotaku.restfu.annotation.param.Params;
|
||||
import org.mariotaku.twidere.api.twitter.auth.OAuthToken;
|
||||
|
||||
/**
|
||||
@ -33,22 +33,16 @@ import org.mariotaku.twidere.api.twitter.auth.OAuthToken;
|
||||
public interface TwitterOAuth {
|
||||
|
||||
@POST("/oauth/request_token")
|
||||
@Body(BodyType.FORM)
|
||||
OAuthToken getRequestToken(@Form("oauth_callback") String oauthCallback) throws TwitterException;
|
||||
OAuthToken getRequestToken(@Param("oauth_callback") String oauthCallback) throws TwitterException;
|
||||
|
||||
@POST("/oauth/access_token")
|
||||
@Body(BodyType.FORM)
|
||||
OAuthToken getAccessToken(@Form("x_auth_username") String xauthUsername,
|
||||
@Form("x_auth_password") String xauthPassword,
|
||||
@Form("x_auth_mode") @XAuthMode String xauthMode) throws TwitterException;
|
||||
@Params(@KeyValue(key = "x_auth_mode", value = "client_auth"))
|
||||
OAuthToken getAccessToken(@Param("x_auth_username") String xauthUsername,
|
||||
@Param("x_auth_password") String xauthPassword) throws TwitterException;
|
||||
|
||||
|
||||
@POST("/oauth/access_token")
|
||||
@Body(BodyType.FORM)
|
||||
OAuthToken getAccessToken(@Extra({"oauth_token", "oauth_token_secret"}) OAuthToken requestToken, @Form("oauth_verifier") String oauthVerifier) throws TwitterException;
|
||||
OAuthToken getAccessToken(@Extra({"oauth_token", "oauth_token_secret"}) OAuthToken requestToken,
|
||||
@Param("oauth_verifier") String oauthVerifier) throws TwitterException;
|
||||
|
||||
@interface XAuthMode {
|
||||
String CLIENT = "client_auth";
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,8 @@ package org.mariotaku.twidere.api.twitter;
|
||||
|
||||
import org.mariotaku.restfu.annotation.method.POST;
|
||||
import org.mariotaku.restfu.annotation.param.Header;
|
||||
import org.mariotaku.restfu.annotation.param.KeyValue;
|
||||
import org.mariotaku.restfu.annotation.param.Params;
|
||||
import org.mariotaku.twidere.api.twitter.auth.OAuth2GetTokenHeader;
|
||||
import org.mariotaku.twidere.api.twitter.auth.OAuth2Token;
|
||||
|
||||
@ -11,6 +13,7 @@ import org.mariotaku.twidere.api.twitter.auth.OAuth2Token;
|
||||
public interface TwitterOAuth2 {
|
||||
|
||||
@POST("/oauth2/token")
|
||||
@Params(@KeyValue(key = "grant_type", value = "client_credentials"))
|
||||
OAuth2Token getApplicationOnlyAccessToken(@Header("Authorization") OAuth2GetTokenHeader token)
|
||||
throws TwitterException;
|
||||
}
|
||||
|
@ -20,24 +20,22 @@
|
||||
package org.mariotaku.twidere.api.twitter;
|
||||
|
||||
import org.mariotaku.restfu.annotation.method.POST;
|
||||
import org.mariotaku.restfu.annotation.param.Body;
|
||||
import org.mariotaku.restfu.annotation.param.Part;
|
||||
import org.mariotaku.restfu.annotation.param.Param;
|
||||
import org.mariotaku.restfu.http.BodyType;
|
||||
import org.mariotaku.restfu.http.mime.FileTypedData;
|
||||
import org.mariotaku.restfu.http.mime.FileBody;
|
||||
import org.mariotaku.twidere.api.twitter.model.MediaUploadResponse;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.mariotaku.twidere.api.twitter.model.MediaUploadResponse;
|
||||
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
public interface TwitterUpload {
|
||||
|
||||
@POST("/media/upload.json")
|
||||
@Body(BodyType.MULTIPART)
|
||||
MediaUploadResponse uploadMedia(@Part("media") File file) throws TwitterException;
|
||||
@BodyType(BodyType.MULTIPART)
|
||||
MediaUploadResponse uploadMedia(@Param("media") File file) throws TwitterException;
|
||||
|
||||
@POST("/media/upload.json")
|
||||
@Body(BodyType.MULTIPART)
|
||||
MediaUploadResponse uploadMedia(@Part("media") FileTypedData data) throws TwitterException;
|
||||
@BodyType(BodyType.MULTIPART)
|
||||
MediaUploadResponse uploadMedia(@Param("media") FileBody data) throws TwitterException;
|
||||
|
||||
}
|
||||
|
@ -21,9 +21,9 @@ package org.mariotaku.twidere.api.twitter.api;
|
||||
|
||||
import org.mariotaku.restfu.annotation.method.GET;
|
||||
import org.mariotaku.restfu.annotation.method.POST;
|
||||
import org.mariotaku.restfu.annotation.param.Body;
|
||||
import org.mariotaku.restfu.annotation.param.Form;
|
||||
import org.mariotaku.restfu.annotation.param.MethodExtra;
|
||||
import org.mariotaku.restfu.annotation.param.KeyValue;
|
||||
import org.mariotaku.restfu.annotation.param.Param;
|
||||
import org.mariotaku.restfu.annotation.param.Queries;
|
||||
import org.mariotaku.restfu.annotation.param.Query;
|
||||
import org.mariotaku.restfu.http.BodyType;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
@ -32,12 +32,15 @@ import org.mariotaku.twidere.api.twitter.model.Paging;
|
||||
import org.mariotaku.twidere.api.twitter.model.ResponseList;
|
||||
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
@MethodExtra(name = "extra_params", values = {"full_text", "include_entities", "include_cards", "cards_platform"})
|
||||
@Queries({@KeyValue(key = "full_text", valueKey = "full_text"),
|
||||
@KeyValue(key = "include_entities", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_cards", valueKey = "include_cards"),
|
||||
@KeyValue(key = "cards_platform", valueKey = "cards_platform")})
|
||||
public interface DirectMessagesResources {
|
||||
|
||||
@POST("/direct_messages/destroy.json")
|
||||
@Body(BodyType.FORM)
|
||||
DirectMessage destroyDirectMessage(@Form("id") long id) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
DirectMessage destroyDirectMessage(@Param("id") long id) throws TwitterException;
|
||||
|
||||
@GET("/direct_messages.json")
|
||||
ResponseList<DirectMessage> getDirectMessages(@Query Paging paging) throws TwitterException;
|
||||
@ -46,24 +49,24 @@ public interface DirectMessagesResources {
|
||||
ResponseList<DirectMessage> getSentDirectMessages(@Query Paging paging) throws TwitterException;
|
||||
|
||||
@POST("/direct_messages/new.json")
|
||||
@Body(BodyType.FORM)
|
||||
DirectMessage sendDirectMessage(@Form("user_id") long userId, @Form("text") String text)
|
||||
@BodyType(BodyType.FORM)
|
||||
DirectMessage sendDirectMessage(@Param("user_id") long userId, @Param("text") String text)
|
||||
throws TwitterException;
|
||||
|
||||
@POST("/direct_messages/new.json")
|
||||
@Body(BodyType.FORM)
|
||||
DirectMessage sendDirectMessage(@Form("user_id") long userId, @Form("text") String text,
|
||||
@Form("media_id") long mediaId) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
DirectMessage sendDirectMessage(@Param("user_id") long userId, @Param("text") String text,
|
||||
@Param("media_id") long mediaId) throws TwitterException;
|
||||
|
||||
@POST("/direct_messages/new.json")
|
||||
@Body(BodyType.FORM)
|
||||
DirectMessage sendDirectMessage(@Form("screen_name") String screenName, @Form("text") String text)
|
||||
@BodyType(BodyType.FORM)
|
||||
DirectMessage sendDirectMessage(@Param("screen_name") String screenName, @Param("text") String text)
|
||||
throws TwitterException;
|
||||
|
||||
@POST("/direct_messages/new.json")
|
||||
@Body(BodyType.FORM)
|
||||
DirectMessage sendDirectMessage(@Form("screen_name") String screenName, @Form("text") String text,
|
||||
@Form("media_id") long mediaId) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
DirectMessage sendDirectMessage(@Param("screen_name") String screenName, @Param("text") String text,
|
||||
@Param("media_id") long mediaId) throws TwitterException;
|
||||
|
||||
@GET("/direct_messages/show.json")
|
||||
DirectMessage showDirectMessage(@Query("id") long id) throws TwitterException;
|
||||
|
@ -21,9 +21,9 @@ package org.mariotaku.twidere.api.twitter.api;
|
||||
|
||||
import org.mariotaku.restfu.annotation.method.GET;
|
||||
import org.mariotaku.restfu.annotation.method.POST;
|
||||
import org.mariotaku.restfu.annotation.param.Body;
|
||||
import org.mariotaku.restfu.annotation.param.Form;
|
||||
import org.mariotaku.restfu.annotation.param.MethodExtra;
|
||||
import org.mariotaku.restfu.annotation.param.KeyValue;
|
||||
import org.mariotaku.restfu.annotation.param.Param;
|
||||
import org.mariotaku.restfu.annotation.param.Queries;
|
||||
import org.mariotaku.restfu.annotation.param.Query;
|
||||
import org.mariotaku.restfu.http.BodyType;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
@ -31,21 +31,23 @@ import org.mariotaku.twidere.api.twitter.model.Paging;
|
||||
import org.mariotaku.twidere.api.twitter.model.ResponseList;
|
||||
import org.mariotaku.twidere.api.twitter.model.Status;
|
||||
|
||||
/**
|
||||
* @author Joern Huxhorn - jhuxhorn at googlemail.com
|
||||
*/
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
@MethodExtra(name = "extra_params", values = {"include_my_retweet", "include_rts", "include_entities",
|
||||
"include_cards", "cards_platform", "include_reply_count", "include_descendent_reply_count"})
|
||||
@Queries({@KeyValue(key = "include_my_retweet", valueKey = "include_my_retweet"),
|
||||
@KeyValue(key = "include_rts", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_entities", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_cards", valueKey = "include_cards"),
|
||||
@KeyValue(key = "cards_platform", valueKey = "cards_platform"),
|
||||
@KeyValue(key = "include_reply_count", valueKey = "include_reply_count"),
|
||||
@KeyValue(key = "include_descendent_reply_count", valueKey = "include_descendent_reply_count")})
|
||||
public interface FavoritesResources {
|
||||
|
||||
@POST("/favorites/create.json")
|
||||
@Body(BodyType.FORM)
|
||||
Status createFavorite(@Form("id") long id) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
Status createFavorite(@Param("id") long id) throws TwitterException;
|
||||
|
||||
@POST("/favorites/destroy.json")
|
||||
@Body(BodyType.FORM)
|
||||
Status destroyFavorite(@Form("id") long id) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
Status destroyFavorite(@Param("id") long id) throws TwitterException;
|
||||
|
||||
@GET("/favorites/list.json")
|
||||
ResponseList<Status> getFavorites() throws TwitterException;
|
||||
|
@ -21,9 +21,9 @@ package org.mariotaku.twidere.api.twitter.api;
|
||||
|
||||
import org.mariotaku.restfu.annotation.method.GET;
|
||||
import org.mariotaku.restfu.annotation.method.POST;
|
||||
import org.mariotaku.restfu.annotation.param.Body;
|
||||
import org.mariotaku.restfu.annotation.param.Form;
|
||||
import org.mariotaku.restfu.annotation.param.MethodExtra;
|
||||
import org.mariotaku.restfu.annotation.param.KeyValue;
|
||||
import org.mariotaku.restfu.annotation.param.Param;
|
||||
import org.mariotaku.restfu.annotation.param.Queries;
|
||||
import org.mariotaku.restfu.annotation.param.Query;
|
||||
import org.mariotaku.restfu.http.BodyType;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
@ -37,32 +37,32 @@ import org.mariotaku.twidere.api.twitter.model.ResponseList;
|
||||
import org.mariotaku.twidere.api.twitter.model.User;
|
||||
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
@MethodExtra(name = "extra_params", values = {"include_entities"})
|
||||
@Queries({@KeyValue(key = "include_entities", valueKey = "include_entities")})
|
||||
public interface FriendsFollowersResources {
|
||||
|
||||
@POST("/friendships/create.json")
|
||||
@Body(BodyType.FORM)
|
||||
User createFriendship(@Form("user_id") long userId) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
User createFriendship(@Param("user_id") long userId) throws TwitterException;
|
||||
|
||||
@POST("/friendships/create.json")
|
||||
@Body(BodyType.FORM)
|
||||
User createFriendship(@Form("user_id") long userId, @Form("follow") boolean follow) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
User createFriendship(@Param("user_id") long userId, @Param("follow") boolean follow) throws TwitterException;
|
||||
|
||||
@POST("/friendships/create.json")
|
||||
@Body(BodyType.FORM)
|
||||
User createFriendship(@Form("screen_name") String screenName) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
User createFriendship(@Param("screen_name") String screenName) throws TwitterException;
|
||||
|
||||
@POST("/friendships/create.json")
|
||||
@Body(BodyType.FORM)
|
||||
User createFriendship(@Form("screen_name") String screenName, @Form("follow") boolean follow) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
User createFriendship(@Param("screen_name") String screenName, @Param("follow") boolean follow) throws TwitterException;
|
||||
|
||||
@POST("/friendships/destroy.json")
|
||||
@Body(BodyType.FORM)
|
||||
User destroyFriendship(@Form("user_id") long userId) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
User destroyFriendship(@Param("user_id") long userId) throws TwitterException;
|
||||
|
||||
@POST("/friendships/destroy.json")
|
||||
@Body(BodyType.FORM)
|
||||
User destroyFriendship(@Form("screen_name") String screenName) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
User destroyFriendship(@Param("screen_name") String screenName) throws TwitterException;
|
||||
|
||||
IDs getFollowersIDs(@Query Paging paging) throws TwitterException;
|
||||
|
||||
@ -100,9 +100,10 @@ public interface FriendsFollowersResources {
|
||||
@GET("/friendships/outgoing.json")
|
||||
IDs getOutgoingFriendships(@Query Paging paging) throws TwitterException;
|
||||
|
||||
ResponseList<Friendship> lookupFriendships(long[] ids) throws TwitterException;
|
||||
|
||||
ResponseList<Friendship> lookupFriendships(String[] screenNames) throws TwitterException;
|
||||
@POST("/friendships/lookup.json")
|
||||
ResponseList<Friendship> lookupFriendships(@Param(value = "id",arrayDelimiter = ',')long[] ids) throws TwitterException;
|
||||
@POST("/friendships/lookup.json")
|
||||
ResponseList<Friendship> lookupFriendships(@Param(value = "id",arrayDelimiter = ',')String[] screenNames) throws TwitterException;
|
||||
|
||||
@GET("/friendships/show.json")
|
||||
Relationship showFriendship(@Query("source_id") long sourceId, @Query("target_id") long targetId) throws TwitterException;
|
||||
@ -115,10 +116,10 @@ public interface FriendsFollowersResources {
|
||||
@Query("target_screen_name") String targetScreenName) throws TwitterException;
|
||||
|
||||
@POST("/friendships/update.json")
|
||||
@Body(BodyType.FORM)
|
||||
Relationship updateFriendship(@Form("user_id") long userId, @Form FriendshipUpdate update) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
Relationship updateFriendship(@Param("user_id") long userId, @Param FriendshipUpdate update) throws TwitterException;
|
||||
|
||||
@POST("/friendships/update.json")
|
||||
@Body(BodyType.FORM)
|
||||
Relationship updateFriendship(@Form("screen_name") String screenName, @Form FriendshipUpdate update) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
Relationship updateFriendship(@Param("screen_name") String screenName, @Param FriendshipUpdate update) throws TwitterException;
|
||||
}
|
||||
|
@ -21,11 +21,10 @@ package org.mariotaku.twidere.api.twitter.api;
|
||||
|
||||
import org.mariotaku.restfu.annotation.method.GET;
|
||||
import org.mariotaku.restfu.annotation.method.POST;
|
||||
import org.mariotaku.restfu.annotation.param.Body;
|
||||
import org.mariotaku.restfu.annotation.param.Form;
|
||||
import org.mariotaku.restfu.annotation.param.MethodExtra;
|
||||
import org.mariotaku.restfu.annotation.param.KeyValue;
|
||||
import org.mariotaku.restfu.annotation.param.Param;
|
||||
import org.mariotaku.restfu.annotation.param.Queries;
|
||||
import org.mariotaku.restfu.annotation.param.Query;
|
||||
import org.mariotaku.restfu.http.BodyType;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
import org.mariotaku.twidere.api.twitter.model.PageableResponseList;
|
||||
import org.mariotaku.twidere.api.twitter.model.Paging;
|
||||
@ -38,52 +37,40 @@ import org.mariotaku.twidere.api.twitter.model.UserListUpdate;
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
public interface ListsResources {
|
||||
@POST("/lists/members/create.json")
|
||||
@Body(BodyType.FORM)
|
||||
UserList addUserListMember(@Query("list_id") long listId, @Query("user_id") long userId) throws TwitterException;
|
||||
|
||||
@POST("/lists/members/create.json")
|
||||
@Body(BodyType.FORM)
|
||||
UserList addUserListMember(@Query("list_id") long listId, @Query("screen_name") String userScreenName) throws TwitterException;
|
||||
|
||||
@POST("/lists/members/create_all.json")
|
||||
@Body(BodyType.FORM)
|
||||
UserList addUserListMembers(@Form("list_id") long listId, @Form("user_id") long[] userIds) throws TwitterException;
|
||||
UserList addUserListMembers(@Param("list_id") long listId, @Param(value = "user_id", arrayDelimiter = ',') long[] userIds) throws TwitterException;
|
||||
|
||||
@POST("/lists/members/create_all.json")
|
||||
@Body(BodyType.FORM)
|
||||
UserList addUserListMembers(@Form("list_id") long listId, @Form("screen_name") String[] screenNames) throws TwitterException;
|
||||
UserList addUserListMembers(@Param("list_id") long listId, @Param(value = "screen_name", arrayDelimiter = ',') String[] screenNames) throws TwitterException;
|
||||
|
||||
@POST("/lists/create.json")
|
||||
@Body(BodyType.FORM)
|
||||
UserList createUserList(@Form UserListUpdate update) throws TwitterException;
|
||||
UserList createUserList(@Param UserListUpdate update) throws TwitterException;
|
||||
|
||||
@POST("/lists/subscribers/create.json")
|
||||
@Body(BodyType.FORM)
|
||||
UserList createUserListSubscription(@Form("list_id") long listId) throws TwitterException;
|
||||
UserList createUserListSubscription(@Param("list_id") long listId) throws TwitterException;
|
||||
|
||||
@POST("/lists/members/destroy.json")
|
||||
@Body(BodyType.FORM)
|
||||
UserList deleteUserListMember(@Query("list_id") long listId, @Query("user_id") long userId) throws TwitterException;
|
||||
|
||||
@POST("/lists/members/destroy.json")
|
||||
@Body(BodyType.FORM)
|
||||
UserList deleteUserListMember(@Query("list_id") long listId, @Form("screen_name") String screenName) throws TwitterException;
|
||||
UserList deleteUserListMember(@Query("list_id") long listId, @Param("screen_name") String screenName) throws TwitterException;
|
||||
|
||||
@POST("/lists/members/destroy_all.json")
|
||||
@Body(BodyType.FORM)
|
||||
UserList deleteUserListMembers(@Form("list_id") long listId, @Form("user_id") long[] userIds) throws TwitterException;
|
||||
UserList deleteUserListMembers(@Param("list_id") long listId, @Param(value = "user_id", arrayDelimiter = ',') long[] userIds) throws TwitterException;
|
||||
|
||||
@POST("/lists/members/destroy_all.json")
|
||||
@Body(BodyType.FORM)
|
||||
UserList deleteUserListMembers(@Query("list_id") long listId, @Form("screen_name") String[] screenNames) throws TwitterException;
|
||||
UserList deleteUserListMembers(@Query("list_id") long listId, @Param(value = "screen_name", arrayDelimiter = ',') String[] screenNames) throws TwitterException;
|
||||
|
||||
@POST("/lists/destroy.json")
|
||||
@Body(BodyType.FORM)
|
||||
UserList destroyUserList(@Form("list_id") long listId) throws TwitterException;
|
||||
UserList destroyUserList(@Param("list_id") long listId) throws TwitterException;
|
||||
|
||||
@POST("/lists/subscribers/destroy.json")
|
||||
@Body(BodyType.FORM)
|
||||
UserList destroyUserListSubscription(@Form("list_id") long listId) throws TwitterException;
|
||||
UserList destroyUserListSubscription(@Param("list_id") long listId) throws TwitterException;
|
||||
|
||||
@GET("/lists/members.json")
|
||||
PageableResponseList<User> getUserListMembers(@Query("list_id") long listId, @Query Paging paging) throws TwitterException;
|
||||
@ -131,18 +118,33 @@ public interface ListsResources {
|
||||
ResponseList<UserList> getUserLists(@Query("screen_name") String screenName, @Query("reverse") boolean reverse) throws TwitterException;
|
||||
|
||||
@GET("/lists/statuses.json")
|
||||
@MethodExtra(name = "extra_params", values = {"include_my_retweet", "include_rts", "include_entities",
|
||||
"include_cards", "cards_platform", "include_reply_count", "include_descendent_reply_count"})
|
||||
@Queries({@KeyValue(key = "include_my_retweet", valueKey = "include_my_retweet"),
|
||||
@KeyValue(key = "include_rts", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_entities", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_cards", valueKey = "include_cards"),
|
||||
@KeyValue(key = "cards_platform", valueKey = "cards_platform"),
|
||||
@KeyValue(key = "include_reply_count", valueKey = "include_reply_count"),
|
||||
@KeyValue(key = "include_descendent_reply_count", valueKey = "include_descendent_reply_count")})
|
||||
ResponseList<Status> getUserListStatuses(@Query("list_id") long listId, @Query Paging paging) throws TwitterException;
|
||||
|
||||
@GET("/lists/statuses.json")
|
||||
@MethodExtra(name = "extra_params", values = {"include_my_retweet", "include_rts", "include_entities",
|
||||
"include_cards", "cards_platform", "include_reply_count", "include_descendent_reply_count"})
|
||||
@Queries({@KeyValue(key = "include_my_retweet", valueKey = "include_my_retweet"),
|
||||
@KeyValue(key = "include_rts", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_entities", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_cards", valueKey = "include_cards"),
|
||||
@KeyValue(key = "cards_platform", valueKey = "cards_platform"),
|
||||
@KeyValue(key = "include_reply_count", valueKey = "include_reply_count"),
|
||||
@KeyValue(key = "include_descendent_reply_count", valueKey = "include_descendent_reply_count")})
|
||||
ResponseList<Status> getUserListStatuses(@Query("slug") String slug, @Query("owner_id") long ownerId, @Query Paging paging) throws TwitterException;
|
||||
|
||||
@GET("/lists/statuses.json")
|
||||
@MethodExtra(name = "extra_params", values = {"include_my_retweet", "include_rts", "include_entities",
|
||||
"include_cards", "cards_platform", "include_reply_count", "include_descendent_reply_count"})
|
||||
@Queries({@KeyValue(key = "include_my_retweet", valueKey = "include_my_retweet"),
|
||||
@KeyValue(key = "include_rts", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_entities", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_cards", valueKey = "include_cards"),
|
||||
@KeyValue(key = "cards_platform", valueKey = "cards_platform"),
|
||||
@KeyValue(key = "include_reply_count", valueKey = "include_reply_count"),
|
||||
@KeyValue(key = "include_descendent_reply_count", valueKey = "include_descendent_reply_count")})
|
||||
ResponseList<Status> getUserListStatuses(@Query("slug") String slug, @Query("owner_screen_name") String ownerScreenName, @Query Paging paging)
|
||||
throws TwitterException;
|
||||
|
||||
@ -176,6 +178,5 @@ public interface ListsResources {
|
||||
UserList showUserList(@Query("slug") String slug, @Query("owner_screen_name") String ownerScreenName) throws TwitterException;
|
||||
|
||||
@POST("/lists/update.json")
|
||||
@Body(BodyType.FORM)
|
||||
UserList updateUserList(@Form("list_id") long listId, @Form UserListUpdate update) throws TwitterException;
|
||||
UserList updateUserList(@Param("list_id") long listId, @Param UserListUpdate update) throws TwitterException;
|
||||
}
|
||||
|
@ -21,9 +21,9 @@ package org.mariotaku.twidere.api.twitter.api;
|
||||
|
||||
import org.mariotaku.restfu.annotation.method.GET;
|
||||
import org.mariotaku.restfu.annotation.method.POST;
|
||||
import org.mariotaku.restfu.annotation.param.Body;
|
||||
import org.mariotaku.restfu.annotation.param.Form;
|
||||
import org.mariotaku.restfu.annotation.param.MethodExtra;
|
||||
import org.mariotaku.restfu.annotation.param.KeyValue;
|
||||
import org.mariotaku.restfu.annotation.param.Param;
|
||||
import org.mariotaku.restfu.annotation.param.Queries;
|
||||
import org.mariotaku.restfu.annotation.param.Query;
|
||||
import org.mariotaku.restfu.http.BodyType;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
@ -33,9 +33,15 @@ import org.mariotaku.twidere.api.twitter.model.Paging;
|
||||
import org.mariotaku.twidere.api.twitter.model.ResponseList;
|
||||
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
@MethodExtra(name = "extra_params", values = {"include_my_retweet", "include_rts", "include_entities",
|
||||
"include_cards", "cards_platform", "include_reply_count", "include_descendent_reply_count",
|
||||
"model_version", "skip_aggregation"})
|
||||
@Queries({@KeyValue(key = "include_my_retweet", valueKey = "include_my_retweet"),
|
||||
@KeyValue(key = "include_rts", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_entities", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_cards", valueKey = "include_cards"),
|
||||
@KeyValue(key = "cards_platform", valueKey = "cards_platform"),
|
||||
@KeyValue(key = "include_reply_count", valueKey = "include_reply_count"),
|
||||
@KeyValue(key = "include_descendent_reply_count", valueKey = "include_descendent_reply_count"),
|
||||
@KeyValue(key = "model_version", valueKey = "model_version"),
|
||||
@KeyValue(key = "skip_aggregation", valueKey = "skip_aggregation")})
|
||||
public interface PrivateActivityResources extends PrivateResources {
|
||||
|
||||
@GET("/activity/about_me.json")
|
||||
@ -44,14 +50,14 @@ public interface PrivateActivityResources extends PrivateResources {
|
||||
@GET("/activity/by_friends.json")
|
||||
ResponseList<Activity> getActivitiesByFriends(@Query Paging paging) throws TwitterException;
|
||||
|
||||
@MethodExtra(name = "extra_params", values = {})
|
||||
@Queries({})
|
||||
@GET("/activity/about_me/unread.json")
|
||||
CursorTimestampResponse getActivitiesAboutMeUnread(@Query("cursor") boolean cursor) throws TwitterException;
|
||||
|
||||
@MethodExtra(name = "extra_params", values = {})
|
||||
@Queries({})
|
||||
@POST("/activity/about_me/unread.json")
|
||||
@Body(BodyType.FORM)
|
||||
CursorTimestampResponse setActivitiesAboutMeUnread(@Form("cursor") long cursor) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
CursorTimestampResponse setActivitiesAboutMeUnread(@Param("cursor") long cursor) throws TwitterException;
|
||||
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ package org.mariotaku.twidere.api.twitter.api;
|
||||
|
||||
import org.mariotaku.restfu.annotation.method.GET;
|
||||
import org.mariotaku.restfu.annotation.method.POST;
|
||||
import org.mariotaku.restfu.annotation.param.Body;
|
||||
import org.mariotaku.restfu.annotation.param.Path;
|
||||
import org.mariotaku.restfu.annotation.param.Query;
|
||||
import org.mariotaku.restfu.http.BodyType;
|
||||
@ -34,11 +33,11 @@ import org.mariotaku.twidere.api.twitter.model.ResponseCode;
|
||||
public interface PrivateDirectMessagesResources extends PrivateResources {
|
||||
|
||||
@POST("/dm/conversation/{conversation_id}/delete.json")
|
||||
@Body(BodyType.FORM)
|
||||
@BodyType(BodyType.FORM)
|
||||
ResponseCode destroyDirectMessagesConversation(@Path("conversation_id") String conversationId) throws TwitterException;
|
||||
|
||||
@POST("/dm/conversation/{account_id}-{user_id}/delete.json")
|
||||
@Body(BodyType.FORM)
|
||||
@BodyType(BodyType.FORM)
|
||||
ResponseCode destroyDirectMessagesConversation(@Path("account_id") long accountId, @Path("user_id") long userId) throws TwitterException;
|
||||
|
||||
@GET("/dm/user_updates.json")
|
||||
|
@ -19,12 +19,13 @@
|
||||
|
||||
package org.mariotaku.twidere.api.twitter.api;
|
||||
|
||||
import org.mariotaku.restfu.annotation.param.MethodExtra;
|
||||
import org.mariotaku.restfu.annotation.param.KeyValue;
|
||||
import org.mariotaku.restfu.annotation.param.Queries;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
import org.mariotaku.twidere.api.twitter.model.User;
|
||||
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
@MethodExtra(name = "extra_params", values = {"include_entities"})
|
||||
@Queries({@KeyValue(key = "include_entities", valueKey = "include_entities")})
|
||||
public interface PrivateFriendsFollowersResources extends PrivateResources {
|
||||
|
||||
User acceptFriendship(long userId) throws TwitterException;
|
||||
|
@ -23,12 +23,11 @@ import org.mariotaku.restfu.annotation.method.DELETE;
|
||||
import org.mariotaku.restfu.annotation.method.GET;
|
||||
import org.mariotaku.restfu.annotation.method.POST;
|
||||
import org.mariotaku.restfu.annotation.method.PUT;
|
||||
import org.mariotaku.restfu.annotation.param.Body;
|
||||
import org.mariotaku.restfu.annotation.param.Form;
|
||||
import org.mariotaku.restfu.annotation.param.MethodExtra;
|
||||
import org.mariotaku.restfu.annotation.param.KeyValue;
|
||||
import org.mariotaku.restfu.annotation.param.Param;
|
||||
import org.mariotaku.restfu.annotation.param.Path;
|
||||
import org.mariotaku.restfu.annotation.param.Queries;
|
||||
import org.mariotaku.restfu.annotation.param.Query;
|
||||
import org.mariotaku.restfu.http.BodyType;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
import org.mariotaku.twidere.api.twitter.model.Paging;
|
||||
import org.mariotaku.twidere.api.twitter.model.ResponseList;
|
||||
@ -41,18 +40,19 @@ import org.mariotaku.twidere.api.twitter.model.StatusSchedule;
|
||||
public interface PrivateScheduleResources {
|
||||
|
||||
@POST("/schedule/status/tweet.json")
|
||||
@Body(BodyType.FORM)
|
||||
ScheduledStatus scheduleTweet(@Form StatusSchedule schedule) throws TwitterException;
|
||||
ScheduledStatus scheduleTweet(@Param StatusSchedule schedule) throws TwitterException;
|
||||
|
||||
@DELETE("/schedule/status/{id}.json")
|
||||
ScheduledStatus destroyScheduleTweet(@Path("id") long id) throws TwitterException;
|
||||
|
||||
@PUT("/schedule/status/{id}.json")
|
||||
@Body(BodyType.FORM)
|
||||
ScheduledStatus updateScheduleTweet(@Path("id") long id, @Form StatusSchedule schedule) throws TwitterException;
|
||||
ScheduledStatus updateScheduleTweet(@Path("id") long id, @Param StatusSchedule schedule) throws TwitterException;
|
||||
|
||||
@GET("/schedule/status/list.json")
|
||||
@MethodExtra(name = "extra_params", values = {"include_entities", "include_cards", "cards_platform"})
|
||||
ResponseList<ScheduledStatus> getScheduledStatusesList(@Query Paging paging, @Query("state") ScheduledStatus.State[] states) throws TwitterException;
|
||||
@Queries({@KeyValue(key = "include_entities", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_cards", valueKey = "include_cards"),
|
||||
@KeyValue(key = "cards_platform", valueKey = "cards_platform")})
|
||||
ResponseList<ScheduledStatus> getScheduledStatuses(@Query Paging paging,
|
||||
@Query(value = "state", arrayDelimiter = ',') @ScheduledStatus.State String[] states) throws TwitterException;
|
||||
|
||||
}
|
||||
|
@ -20,7 +20,8 @@
|
||||
package org.mariotaku.twidere.api.twitter.api;
|
||||
|
||||
import org.mariotaku.restfu.annotation.method.GET;
|
||||
import org.mariotaku.restfu.annotation.param.MethodExtra;
|
||||
import org.mariotaku.restfu.annotation.param.KeyValue;
|
||||
import org.mariotaku.restfu.annotation.param.Queries;
|
||||
import org.mariotaku.restfu.annotation.param.Query;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
import org.mariotaku.twidere.api.twitter.model.Paging;
|
||||
@ -28,8 +29,13 @@ import org.mariotaku.twidere.api.twitter.model.ResponseList;
|
||||
import org.mariotaku.twidere.api.twitter.model.Status;
|
||||
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
@MethodExtra(name = "extra_params", values = {"include_my_retweet", "include_rts", "include_entities",
|
||||
"include_cards", "cards_platform", "include_reply_count", "include_descendent_reply_count"})
|
||||
@Queries({@KeyValue(key = "include_my_retweet", valueKey = "include_my_retweet"),
|
||||
@KeyValue(key = "include_rts", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_entities", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_cards", valueKey = "include_cards"),
|
||||
@KeyValue(key = "cards_platform", valueKey = "cards_platform"),
|
||||
@KeyValue(key = "include_reply_count", valueKey = "include_reply_count"),
|
||||
@KeyValue(key = "include_descendent_reply_count", valueKey = "include_descendent_reply_count")})
|
||||
public interface PrivateTimelinesResources extends PrivateResources {
|
||||
|
||||
@GET("/statuses/media_timeline.json")
|
||||
|
@ -20,8 +20,9 @@
|
||||
package org.mariotaku.twidere.api.twitter.api;
|
||||
|
||||
import org.mariotaku.restfu.annotation.method.GET;
|
||||
import org.mariotaku.restfu.annotation.param.MethodExtra;
|
||||
import org.mariotaku.restfu.annotation.param.KeyValue;
|
||||
import org.mariotaku.restfu.annotation.param.Path;
|
||||
import org.mariotaku.restfu.annotation.param.Queries;
|
||||
import org.mariotaku.restfu.annotation.param.Query;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
import org.mariotaku.twidere.api.twitter.model.Paging;
|
||||
@ -31,8 +32,13 @@ import org.mariotaku.twidere.api.twitter.model.StatusActivitySummary;
|
||||
import org.mariotaku.twidere.api.twitter.model.TranslationResult;
|
||||
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
@MethodExtra(name = "extra_params", values = {"include_my_retweet", "include_rts", "include_entities",
|
||||
"include_cards", "cards_platform", "include_reply_count", "include_descendent_reply_count"})
|
||||
@Queries({@KeyValue(key = "include_my_retweet", valueKey = "include_my_retweet"),
|
||||
@KeyValue(key = "include_rts", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_entities", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_cards", valueKey = "include_cards"),
|
||||
@KeyValue(key = "cards_platform", valueKey = "cards_platform"),
|
||||
@KeyValue(key = "include_reply_count", valueKey = "include_reply_count"),
|
||||
@KeyValue(key = "include_descendent_reply_count", valueKey = "include_descendent_reply_count")})
|
||||
public interface PrivateTweetResources extends PrivateResources {
|
||||
|
||||
@GET("/statuses/{id}/activity/summary.json")
|
||||
|
@ -21,8 +21,7 @@ package org.mariotaku.twidere.api.twitter.api;
|
||||
|
||||
import org.mariotaku.restfu.annotation.method.GET;
|
||||
import org.mariotaku.restfu.annotation.method.POST;
|
||||
import org.mariotaku.restfu.annotation.param.Body;
|
||||
import org.mariotaku.restfu.annotation.param.Form;
|
||||
import org.mariotaku.restfu.annotation.param.Param;
|
||||
import org.mariotaku.restfu.annotation.param.Path;
|
||||
import org.mariotaku.restfu.http.BodyType;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
@ -33,11 +32,11 @@ import org.mariotaku.twidere.api.twitter.model.SavedSearch;
|
||||
public interface SavedSearchesResources {
|
||||
|
||||
@POST("/saved_searches/create.json")
|
||||
@Body(BodyType.FORM)
|
||||
SavedSearch createSavedSearch(@Form("query") String query) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
SavedSearch createSavedSearch(@Param("query") String query) throws TwitterException;
|
||||
|
||||
@POST("/saved_searches/destroy/{id}.json")
|
||||
@Body(BodyType.FORM)
|
||||
@BodyType(BodyType.FORM)
|
||||
SavedSearch destroySavedSearch(@Path("id") long id) throws TwitterException;
|
||||
|
||||
@GET("/saved_searches/list.json")
|
||||
|
@ -20,15 +20,21 @@
|
||||
package org.mariotaku.twidere.api.twitter.api;
|
||||
|
||||
import org.mariotaku.restfu.annotation.method.GET;
|
||||
import org.mariotaku.restfu.annotation.param.MethodExtra;
|
||||
import org.mariotaku.restfu.annotation.param.KeyValue;
|
||||
import org.mariotaku.restfu.annotation.param.Queries;
|
||||
import org.mariotaku.restfu.annotation.param.Query;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
import org.mariotaku.twidere.api.twitter.model.QueryResult;
|
||||
import org.mariotaku.twidere.api.twitter.model.SearchQuery;
|
||||
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
@MethodExtra(name = "extra_params", values = {"include_my_retweet", "include_rts", "include_entities",
|
||||
"include_cards", "cards_platform", "include_reply_count", "include_descendent_reply_count"})
|
||||
@Queries({@KeyValue(key = "include_my_retweet", valueKey = "include_my_retweet"),
|
||||
@KeyValue(key = "include_rts", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_entities", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_cards", valueKey = "include_cards"),
|
||||
@KeyValue(key = "cards_platform", valueKey = "cards_platform"),
|
||||
@KeyValue(key = "include_reply_count", valueKey = "include_reply_count"),
|
||||
@KeyValue(key = "include_descendent_reply_count", valueKey = "include_descendent_reply_count")})
|
||||
public interface SearchResource {
|
||||
@GET("/search/tweets.json")
|
||||
QueryResult search(@Query SearchQuery query) throws TwitterException;
|
||||
|
@ -20,8 +20,7 @@
|
||||
package org.mariotaku.twidere.api.twitter.api;
|
||||
|
||||
import org.mariotaku.restfu.annotation.method.POST;
|
||||
import org.mariotaku.restfu.annotation.param.Body;
|
||||
import org.mariotaku.restfu.annotation.param.Form;
|
||||
import org.mariotaku.restfu.annotation.param.Param;
|
||||
import org.mariotaku.restfu.http.BodyType;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
import org.mariotaku.twidere.api.twitter.model.User;
|
||||
@ -33,10 +32,10 @@ import org.mariotaku.twidere.api.twitter.model.User;
|
||||
public interface SpamReportingResources {
|
||||
|
||||
@POST("/users/report_spam.json")
|
||||
@Body(BodyType.FORM)
|
||||
User reportSpam(@Form("user_id") long userId) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
User reportSpam(@Param("user_id") long userId) throws TwitterException;
|
||||
|
||||
@POST("/users/report_spam.json")
|
||||
@Body(BodyType.FORM)
|
||||
User reportSpam(@Form("screen_name") String screenName) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
User reportSpam(@Param("screen_name") String screenName) throws TwitterException;
|
||||
}
|
||||
|
@ -21,7 +21,8 @@ package org.mariotaku.twidere.api.twitter.api;
|
||||
|
||||
|
||||
import org.mariotaku.restfu.annotation.method.GET;
|
||||
import org.mariotaku.restfu.annotation.param.MethodExtra;
|
||||
import org.mariotaku.restfu.annotation.param.KeyValue;
|
||||
import org.mariotaku.restfu.annotation.param.Queries;
|
||||
import org.mariotaku.restfu.annotation.param.Query;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
import org.mariotaku.twidere.api.twitter.model.Paging;
|
||||
@ -29,8 +30,13 @@ import org.mariotaku.twidere.api.twitter.model.ResponseList;
|
||||
import org.mariotaku.twidere.api.twitter.model.Status;
|
||||
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
@MethodExtra(name = "extra_params", values = {"include_my_retweet", "include_rts", "include_entities",
|
||||
"include_cards", "cards_platform", "include_reply_count", "include_descendent_reply_count"})
|
||||
@Queries({@KeyValue(key = "include_my_retweet", valueKey = "include_my_retweet"),
|
||||
@KeyValue(key = "include_rts", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_entities", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_cards", valueKey = "include_cards"),
|
||||
@KeyValue(key = "cards_platform", valueKey = "cards_platform"),
|
||||
@KeyValue(key = "include_reply_count", valueKey = "include_reply_count"),
|
||||
@KeyValue(key = "include_descendent_reply_count", valueKey = "include_descendent_reply_count")})
|
||||
public interface TimelinesResources {
|
||||
|
||||
@GET("/statuses/home_timeline.json")
|
||||
|
@ -21,12 +21,11 @@ package org.mariotaku.twidere.api.twitter.api;
|
||||
|
||||
import org.mariotaku.restfu.annotation.method.GET;
|
||||
import org.mariotaku.restfu.annotation.method.POST;
|
||||
import org.mariotaku.restfu.annotation.param.Body;
|
||||
import org.mariotaku.restfu.annotation.param.Form;
|
||||
import org.mariotaku.restfu.annotation.param.MethodExtra;
|
||||
import org.mariotaku.restfu.annotation.param.KeyValue;
|
||||
import org.mariotaku.restfu.annotation.param.Param;
|
||||
import org.mariotaku.restfu.annotation.param.Path;
|
||||
import org.mariotaku.restfu.annotation.param.Queries;
|
||||
import org.mariotaku.restfu.annotation.param.Query;
|
||||
import org.mariotaku.restfu.http.BodyType;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
import org.mariotaku.twidere.api.twitter.model.IDs;
|
||||
import org.mariotaku.twidere.api.twitter.model.Paging;
|
||||
@ -35,11 +34,15 @@ import org.mariotaku.twidere.api.twitter.model.Status;
|
||||
import org.mariotaku.twidere.api.twitter.model.StatusUpdate;
|
||||
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
@MethodExtra(name = "extra_params", values = {"include_my_retweet", "include_rts", "include_entities",
|
||||
"include_cards", "cards_platform", "include_reply_count", "include_descendent_reply_count"})
|
||||
@Queries({@KeyValue(key = "include_my_retweet", valueKey = "include_my_retweet"),
|
||||
@KeyValue(key = "include_rts", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_entities", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_cards", valueKey = "include_cards"),
|
||||
@KeyValue(key = "cards_platform", valueKey = "cards_platform"),
|
||||
@KeyValue(key = "include_reply_count", valueKey = "include_reply_count"),
|
||||
@KeyValue(key = "include_descendent_reply_count", valueKey = "include_descendent_reply_count")})
|
||||
public interface TweetResources {
|
||||
@POST("/statuses/destroy/{id}.json")
|
||||
@Body(BodyType.FORM)
|
||||
Status destroyStatus(@Path("id") long statusId) throws TwitterException;
|
||||
|
||||
@GET("/statuses/retweeters/ids.json")
|
||||
@ -49,18 +52,15 @@ public interface TweetResources {
|
||||
ResponseList<Status> getRetweets(@Path("id") long statusId, @Query Paging paging) throws TwitterException;
|
||||
|
||||
@POST("/statuses/retweet/{id}.json")
|
||||
@Body(BodyType.FORM)
|
||||
Status retweetStatus(@Path("id") long statusId) throws TwitterException;
|
||||
|
||||
@GET("/statuses/show.json")
|
||||
Status showStatus(@Query("id") long id) throws TwitterException;
|
||||
|
||||
@POST("/statuses/update.json")
|
||||
@Body(BodyType.FORM)
|
||||
Status updateStatus(@Form StatusUpdate latestStatus) throws TwitterException;
|
||||
Status updateStatus(@Param StatusUpdate latestStatus) throws TwitterException;
|
||||
|
||||
@POST("/statuses/lookup.json")
|
||||
@Body(BodyType.FORM)
|
||||
ResponseList<Status> lookupStatuses(@Form("id") long[] ids) throws TwitterException;
|
||||
ResponseList<Status> lookupStatuses(@Param(value = "id", arrayDelimiter = ',') long[] ids) throws TwitterException;
|
||||
|
||||
}
|
||||
|
@ -21,13 +21,12 @@ package org.mariotaku.twidere.api.twitter.api;
|
||||
|
||||
import org.mariotaku.restfu.annotation.method.GET;
|
||||
import org.mariotaku.restfu.annotation.method.POST;
|
||||
import org.mariotaku.restfu.annotation.param.Body;
|
||||
import org.mariotaku.restfu.annotation.param.Form;
|
||||
import org.mariotaku.restfu.annotation.param.MethodExtra;
|
||||
import org.mariotaku.restfu.annotation.param.Part;
|
||||
import org.mariotaku.restfu.annotation.param.KeyValue;
|
||||
import org.mariotaku.restfu.annotation.param.Param;
|
||||
import org.mariotaku.restfu.annotation.param.Queries;
|
||||
import org.mariotaku.restfu.annotation.param.Query;
|
||||
import org.mariotaku.restfu.http.BodyType;
|
||||
import org.mariotaku.restfu.http.mime.FileTypedData;
|
||||
import org.mariotaku.restfu.http.mime.FileBody;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
import org.mariotaku.twidere.api.twitter.model.AccountSettings;
|
||||
import org.mariotaku.twidere.api.twitter.model.Category;
|
||||
@ -41,39 +40,41 @@ import org.mariotaku.twidere.api.twitter.model.SettingsUpdate;
|
||||
import org.mariotaku.twidere.api.twitter.model.User;
|
||||
|
||||
@SuppressWarnings("RedundantThrows")
|
||||
@MethodExtra(name = "extra_params", values = {"include_entities"})
|
||||
@Queries({@KeyValue(key = "include_entities", valueKey = "include_entities"),
|
||||
@KeyValue(key = "include_cards", valueKey = "include_cards"),
|
||||
@KeyValue(key = "cards_platform", valueKey = "cards_platform")})
|
||||
public interface UsersResources {
|
||||
|
||||
@POST("/blocks/create.json")
|
||||
@Body(BodyType.FORM)
|
||||
User createBlock(@Form("user_id") long userId) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
User createBlock(@Param("user_id") long userId) throws TwitterException;
|
||||
|
||||
@POST("/blocks/create.json")
|
||||
@Body(BodyType.FORM)
|
||||
@BodyType(BodyType.FORM)
|
||||
User createBlock(@Query("screen_name") String screenName) throws TwitterException;
|
||||
|
||||
@POST("/mutes/users/create.json")
|
||||
@Body(BodyType.FORM)
|
||||
User createMute(@Form("user_id") long userId) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
User createMute(@Param("user_id") long userId) throws TwitterException;
|
||||
|
||||
@POST("/mutes/users/create.json")
|
||||
@Body(BodyType.FORM)
|
||||
@BodyType(BodyType.FORM)
|
||||
User createMute(@Query("screen_name") String screenName) throws TwitterException;
|
||||
|
||||
@POST("/blocks/destroy.json")
|
||||
@Body(BodyType.FORM)
|
||||
User destroyBlock(@Form("user_id") long userId) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
User destroyBlock(@Param("user_id") long userId) throws TwitterException;
|
||||
|
||||
@POST("/blocks/destroy.json")
|
||||
@Body(BodyType.FORM)
|
||||
@BodyType(BodyType.FORM)
|
||||
User destroyBlock(@Query("screen_name") String screenName) throws TwitterException;
|
||||
|
||||
@POST("/mutes/users/destroy.json")
|
||||
@Body(BodyType.FORM)
|
||||
User destroyMute(@Form("user_id") long userId) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
User destroyMute(@Param("user_id") long userId) throws TwitterException;
|
||||
|
||||
@POST("/mutes/users/destroy.json")
|
||||
@Body(BodyType.FORM)
|
||||
@BodyType(BodyType.FORM)
|
||||
User destroyMute(@Query("screen_name") String screenName) throws TwitterException;
|
||||
|
||||
@GET("/account/settings.json")
|
||||
@ -98,14 +99,14 @@ public interface UsersResources {
|
||||
ResponseList<User> getUserSuggestions(String categorySlug) throws TwitterException;
|
||||
|
||||
@POST("/users/lookup.json")
|
||||
@Body(BodyType.FORM)
|
||||
ResponseList<User> lookupUsers(@Form("user_id") long[] ids) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
ResponseList<User> lookupUsers(@Param(value = "user_id", arrayDelimiter = ',') long[] ids) throws TwitterException;
|
||||
|
||||
@GET("/users/lookup.json")
|
||||
ResponseList<User> lookupUsers(@Form("screen_name") String[] screenNames) throws TwitterException;
|
||||
ResponseList<User> lookupUsers(@Param(value = "screen_name", arrayDelimiter = ',') String[] screenNames) throws TwitterException;
|
||||
|
||||
@POST("/account/remove_profile_banner.json")
|
||||
@Body(BodyType.FORM)
|
||||
@BodyType(BodyType.FORM)
|
||||
ResponseCode removeProfileBannerImage() throws TwitterException;
|
||||
|
||||
@GET("/users/search.json")
|
||||
@ -118,35 +119,35 @@ public interface UsersResources {
|
||||
User showUser(@Query("screen_name") String screenName) throws TwitterException;
|
||||
|
||||
@POST("/account/settings.json")
|
||||
@Body(BodyType.FORM)
|
||||
AccountSettings updateAccountSettings(@Form SettingsUpdate settingsUpdate) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
AccountSettings updateAccountSettings(@Param SettingsUpdate settingsUpdate) throws TwitterException;
|
||||
|
||||
@POST("/account/update_profile.json")
|
||||
@Body(BodyType.FORM)
|
||||
User updateProfile(@Form ProfileUpdate profileUpdate) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
User updateProfile(@Param ProfileUpdate profileUpdate) throws TwitterException;
|
||||
|
||||
@POST("/account/update_profile_background_image.json")
|
||||
@Body(BodyType.MULTIPART)
|
||||
User updateProfileBackgroundImage(@Part("image") FileTypedData data, @Part("tile") boolean tile) throws TwitterException;
|
||||
@BodyType(BodyType.MULTIPART)
|
||||
User updateProfileBackgroundImage(@Param("image") FileBody data, @Param("tile") boolean tile) throws TwitterException;
|
||||
|
||||
@POST("/account/update_profile_background_image.json")
|
||||
@Body(BodyType.FORM)
|
||||
User updateProfileBackgroundImage(@Form("media_id") long mediaId, @Part("tile") boolean tile) throws TwitterException;
|
||||
@BodyType(BodyType.FORM)
|
||||
User updateProfileBackgroundImage(@Param("media_id") long mediaId, @Param("tile") boolean tile) throws TwitterException;
|
||||
|
||||
@POST("/account/update_profile_banner.json")
|
||||
@Body(BodyType.MULTIPART)
|
||||
ResponseCode updateProfileBannerImage(@Part("banner") FileTypedData data, @Part("width") int width,
|
||||
@Part("height") int height, @Part("offset_left") int offsetLeft,
|
||||
@Part("offset_top") int offsetTop)
|
||||
@BodyType(BodyType.MULTIPART)
|
||||
ResponseCode updateProfileBannerImage(@Param("banner") FileBody data, @Param("width") int width,
|
||||
@Param("height") int height, @Param("offset_left") int offsetLeft,
|
||||
@Param("offset_top") int offsetTop)
|
||||
throws TwitterException;
|
||||
|
||||
@POST("/account/update_profile_banner.json")
|
||||
@Body(BodyType.MULTIPART)
|
||||
ResponseCode updateProfileBannerImage(@Part("banner") FileTypedData data) throws TwitterException;
|
||||
@BodyType(BodyType.MULTIPART)
|
||||
ResponseCode updateProfileBannerImage(@Param("banner") FileBody data) throws TwitterException;
|
||||
|
||||
@POST("/account/update_profile_image.json")
|
||||
@Body(BodyType.MULTIPART)
|
||||
User updateProfileImage(@Part("image") FileTypedData data) throws TwitterException;
|
||||
@BodyType(BodyType.MULTIPART)
|
||||
User updateProfileImage(@Param("image") FileBody data) throws TwitterException;
|
||||
|
||||
@GET("/account/verify_credentials.json")
|
||||
User verifyCredentials() throws TwitterException;
|
||||
|
@ -21,7 +21,7 @@ package org.mariotaku.twidere.api.twitter.auth;
|
||||
|
||||
import android.util.Base64;
|
||||
|
||||
import org.mariotaku.restfu.RestRequestInfo;
|
||||
import org.mariotaku.restfu.RestRequest;
|
||||
import org.mariotaku.restfu.http.Authorization;
|
||||
import org.mariotaku.restfu.http.Endpoint;
|
||||
|
||||
@ -39,7 +39,7 @@ public final class BasicAuthorization implements Authorization {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHeader(Endpoint endpoint, RestRequestInfo info) {
|
||||
public String getHeader(Endpoint endpoint, RestRequest info) {
|
||||
if (!hasAuthorization()) return null;
|
||||
return "Basic " + Base64.encodeToString((user + ":" + password).getBytes(), Base64.NO_WRAP);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package org.mariotaku.twidere.api.twitter.auth;
|
||||
|
||||
import org.mariotaku.restfu.RestRequestInfo;
|
||||
import org.mariotaku.restfu.RestRequest;
|
||||
import org.mariotaku.restfu.http.Authorization;
|
||||
import org.mariotaku.restfu.http.Endpoint;
|
||||
|
||||
@ -16,7 +16,7 @@ public class BearerAuthorization implements Authorization {
|
||||
|
||||
|
||||
@Override
|
||||
public String getHeader(Endpoint endpoint, RestRequestInfo info) {
|
||||
public String getHeader(Endpoint endpoint, RestRequest info) {
|
||||
return "Bearer " + accessToken;
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.api.twitter.auth;
|
||||
|
||||
import org.mariotaku.restfu.RestRequestInfo;
|
||||
import org.mariotaku.restfu.RestRequest;
|
||||
import org.mariotaku.restfu.http.Authorization;
|
||||
import org.mariotaku.restfu.http.Endpoint;
|
||||
|
||||
@ -29,7 +29,7 @@ import org.mariotaku.restfu.http.Endpoint;
|
||||
public final class EmptyAuthorization implements Authorization {
|
||||
|
||||
@Override
|
||||
public String getHeader(Endpoint endpoint, RestRequestInfo info) {
|
||||
public String getHeader(Endpoint endpoint, RestRequest info) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -19,14 +19,19 @@
|
||||
|
||||
package org.mariotaku.twidere.api.twitter.auth;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Base64;
|
||||
|
||||
import org.mariotaku.restfu.Pair;
|
||||
import org.mariotaku.restfu.RestRequestInfo;
|
||||
import org.mariotaku.restfu.RestRequest;
|
||||
import org.mariotaku.restfu.Utils;
|
||||
import org.mariotaku.restfu.http.Authorization;
|
||||
import org.mariotaku.restfu.http.BodyType;
|
||||
import org.mariotaku.restfu.http.Endpoint;
|
||||
import org.mariotaku.restfu.http.MultiValueMap;
|
||||
import org.mariotaku.restfu.http.mime.Body;
|
||||
import org.mariotaku.restfu.http.mime.StringBody;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.InvalidKeyException;
|
||||
@ -41,8 +46,6 @@ import java.util.Map;
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
|
||||
import okio.ByteString;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/2/4.
|
||||
*/
|
||||
@ -82,8 +85,9 @@ public class OAuthAuthorization implements Authorization, OAuthSupport {
|
||||
private String generateOAuthSignature(String method, String url,
|
||||
String oauthNonce, long timestamp,
|
||||
String oauthToken, String oauthTokenSecret,
|
||||
@Nullable List<Pair<String, String>> queries,
|
||||
@Nullable List<Pair<String, String>> forms) {
|
||||
@Nullable MultiValueMap<String> queries,
|
||||
@Nullable MultiValueMap<Body> params,
|
||||
@NonNull String bodyType) {
|
||||
final List<String> encodeParams = new ArrayList<>();
|
||||
encodeParams.add(encodeParameter("oauth_consumer_key", consumerKey));
|
||||
encodeParams.add(encodeParameter("oauth_nonce", oauthNonce));
|
||||
@ -94,13 +98,13 @@ public class OAuthAuthorization implements Authorization, OAuthSupport {
|
||||
encodeParams.add(encodeParameter("oauth_token", oauthToken));
|
||||
}
|
||||
if (queries != null) {
|
||||
for (Pair<String, String> query : queries) {
|
||||
for (Pair<String, String> query : queries.toList()) {
|
||||
encodeParams.add(encodeParameter(query.first, query.second));
|
||||
}
|
||||
}
|
||||
if (forms != null) {
|
||||
for (Pair<String, String> form : forms) {
|
||||
encodeParams.add(encodeParameter(form.first, form.second));
|
||||
if (params != null && BodyType.FORM.equals(bodyType)) {
|
||||
for (Pair<String, Body> form : params.toList()) {
|
||||
encodeParams.add(encodeParameter(form.first, ((StringBody) form.second).value()));
|
||||
}
|
||||
}
|
||||
Collections.sort(encodeParams);
|
||||
@ -133,7 +137,7 @@ public class OAuthAuthorization implements Authorization, OAuthSupport {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHeader(Endpoint endpoint, RestRequestInfo request) {
|
||||
public String getHeader(Endpoint endpoint, RestRequest request) {
|
||||
if (!(endpoint instanceof OAuthEndpoint))
|
||||
throw new IllegalArgumentException("OAuthEndpoint required");
|
||||
final Map<String, Object> extras = request.getExtras();
|
||||
@ -148,10 +152,10 @@ public class OAuthAuthorization implements Authorization, OAuthSupport {
|
||||
final OAuthEndpoint oauthEndpoint = (OAuthEndpoint) endpoint;
|
||||
final String method = request.getMethod();
|
||||
final String url = Endpoint.constructUrl(oauthEndpoint.getSignUrl(), request);
|
||||
final List<Pair<String, String>> queries = request.getQueries();
|
||||
final List<Pair<String, String>> forms = request.getForms();
|
||||
final MultiValueMap<String> queries = request.getQueries();
|
||||
final MultiValueMap<Body> params = request.getParams();
|
||||
final List<Pair<String, String>> encodeParams = generateOAuthParams(oauthToken, oauthTokenSecret,
|
||||
method, url, queries, forms);
|
||||
method, url, queries, params, request.getBodyType());
|
||||
final StringBuilder headerBuilder = new StringBuilder();
|
||||
headerBuilder.append("OAuth ");
|
||||
for (int i = 0, j = encodeParams.size(); i < j; i++) {
|
||||
@ -169,12 +173,13 @@ public class OAuthAuthorization implements Authorization, OAuthSupport {
|
||||
|
||||
public List<Pair<String, String>> generateOAuthParams(String oauthToken,
|
||||
String oauthTokenSecret, String method,
|
||||
String url, List<Pair<String, String>> queries,
|
||||
List<Pair<String, String>> forms) {
|
||||
String url, MultiValueMap<String> queries,
|
||||
MultiValueMap<Body> params,
|
||||
String bodyType) {
|
||||
final String oauthNonce = generateOAuthNonce();
|
||||
final long timestamp = System.currentTimeMillis() / 1000;
|
||||
final String oauthSignature = generateOAuthSignature(method, url, oauthNonce, timestamp, oauthToken,
|
||||
oauthTokenSecret, queries, forms);
|
||||
oauthTokenSecret, queries, params, bodyType);
|
||||
final List<Pair<String, String>> encodeParams = new ArrayList<>();
|
||||
encodeParams.add(Pair.create("oauth_consumer_key", consumerKey));
|
||||
encodeParams.add(Pair.create("oauth_nonce", oauthNonce));
|
||||
@ -210,10 +215,9 @@ public class OAuthAuthorization implements Authorization, OAuthSupport {
|
||||
private String generateOAuthNonce() {
|
||||
final byte[] input = new byte[32];
|
||||
secureRandom.nextBytes(input);
|
||||
final ByteString byteString = ByteString.of(input);
|
||||
final String encodedString = byteString.base64Url();
|
||||
final String encodedString = Base64.encodeToString(input, Base64.URL_SAFE);
|
||||
if (encodedString == null) {
|
||||
throw new IllegalStateException("Bad nonce " + byteString.hex());
|
||||
throw new IllegalStateException("Bad nonce " + Utils.bytesToHex(input));
|
||||
}
|
||||
return encodedString.replaceAll("[^\\w\\d]", "");
|
||||
}
|
||||
|
@ -20,21 +20,18 @@
|
||||
package org.mariotaku.twidere.api.twitter.auth;
|
||||
|
||||
|
||||
import org.mariotaku.restfu.Pair;
|
||||
import org.mariotaku.restfu.RestConverter;
|
||||
import org.mariotaku.restfu.Utils;
|
||||
import org.mariotaku.restfu.http.ContentType;
|
||||
import org.mariotaku.restfu.http.HeaderValue;
|
||||
import org.mariotaku.restfu.http.RestHttpResponse;
|
||||
import org.mariotaku.restfu.http.HttpResponse;
|
||||
import org.mariotaku.restfu.http.ValueMap;
|
||||
import org.mariotaku.restfu.http.mime.TypedData;
|
||||
import org.mariotaku.restfu.http.mime.Body;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.Charset;
|
||||
import java.text.ParseException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/2/4.
|
||||
@ -68,28 +65,30 @@ public class OAuthToken implements ValueMap {
|
||||
}
|
||||
|
||||
public OAuthToken(String body, Charset charset) throws ParseException {
|
||||
List<Pair<String, String>> params = new ArrayList<>();
|
||||
Utils.parseGetParameters(body, params, charset.name());
|
||||
for (Pair<String, String> param : params) {
|
||||
switch (param.first) {
|
||||
Utils.parseQuery(body, charset.name(), new Utils.KeyValueConsumer() {
|
||||
|
||||
@Override
|
||||
public void consume(String key, String value) {
|
||||
switch (key) {
|
||||
case "oauth_token": {
|
||||
oauthToken = param.second;
|
||||
oauthToken = value;
|
||||
break;
|
||||
}
|
||||
case "oauth_token_secret": {
|
||||
oauthTokenSecret = param.second;
|
||||
oauthTokenSecret = value;
|
||||
break;
|
||||
}
|
||||
case "user_id": {
|
||||
userId = Long.parseLong(param.second);
|
||||
userId = Long.parseLong(value);
|
||||
break;
|
||||
}
|
||||
case "screen_name": {
|
||||
screenName = param.second;
|
||||
screenName = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
if (oauthToken == null || oauthTokenSecret == null) {
|
||||
throw new ParseException("Unable to parse request token", -1);
|
||||
}
|
||||
@ -125,10 +124,10 @@ public class OAuthToken implements ValueMap {
|
||||
return new String[]{"oauth_token", "oauth_token_secret"};
|
||||
}
|
||||
|
||||
public static class Converter implements org.mariotaku.restfu.Converter {
|
||||
public static class Converter implements RestConverter<HttpResponse, OAuthToken> {
|
||||
@Override
|
||||
public Object convert(RestHttpResponse response, Type type) throws IOException {
|
||||
final TypedData body = response.getBody();
|
||||
public OAuthToken convert(HttpResponse response) throws IOException {
|
||||
final Body body = response.getBody();
|
||||
try {
|
||||
final ContentType contentType = body.contentType();
|
||||
final ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
|
@ -65,9 +65,8 @@ public class Activity$$JsonObjectMapper extends JsonMapper<Activity> {
|
||||
|
||||
public void parseField(Activity instance, String fieldName, JsonParser jsonParser) throws IOException {
|
||||
if ("action".equals(fieldName)) {
|
||||
final String rawAction = jsonParser.getValueAsString();
|
||||
instance.action = Activity.Action.parse(rawAction);
|
||||
instance.rawAction = rawAction;
|
||||
//noinspection ResourceType
|
||||
instance.action = jsonParser.getValueAsString();
|
||||
} else if ("created_at".equals(fieldName)) {
|
||||
try {
|
||||
instance.createdAt = DATE_FORMAT.parse(jsonParser.getValueAsString());
|
||||
@ -89,27 +88,27 @@ public class Activity$$JsonObjectMapper extends JsonMapper<Activity> {
|
||||
} else if ("targets".equals(fieldName)) {
|
||||
if (instance.action == null) throw new IOException();
|
||||
switch (instance.action) {
|
||||
case FAVORITE:
|
||||
case REPLY:
|
||||
case RETWEET:
|
||||
case QUOTE:
|
||||
case FAVORITED_RETWEET:
|
||||
case RETWEETED_RETWEET:
|
||||
case RETWEETED_MENTION:
|
||||
case FAVORITED_MENTION:
|
||||
case MEDIA_TAGGED:
|
||||
case FAVORITED_MEDIA_TAGGED:
|
||||
case RETWEETED_MEDIA_TAGGED: {
|
||||
case Activity.Action.FAVORITE:
|
||||
case Activity.Action.REPLY:
|
||||
case Activity.Action.RETWEET:
|
||||
case Activity.Action.QUOTE:
|
||||
case Activity.Action.FAVORITED_RETWEET:
|
||||
case Activity.Action.RETWEETED_RETWEET:
|
||||
case Activity.Action.RETWEETED_MENTION:
|
||||
case Activity.Action.FAVORITED_MENTION:
|
||||
case Activity.Action.MEDIA_TAGGED:
|
||||
case Activity.Action.FAVORITED_MEDIA_TAGGED:
|
||||
case Activity.Action.RETWEETED_MEDIA_TAGGED: {
|
||||
instance.targetStatuses = LoganSquare.mapperFor(Status.class).parseList(jsonParser).toArray(new Status[instance.targetsSize]);
|
||||
break;
|
||||
}
|
||||
case FOLLOW:
|
||||
case MENTION:
|
||||
case LIST_MEMBER_ADDED: {
|
||||
case Activity.Action.FOLLOW:
|
||||
case Activity.Action.MENTION:
|
||||
case Activity.Action.LIST_MEMBER_ADDED: {
|
||||
instance.targetUsers = LoganSquare.mapperFor(User.class).parseList(jsonParser).toArray(new User[instance.targetsSize]);
|
||||
break;
|
||||
}
|
||||
case LIST_CREATED: {
|
||||
case Activity.Action.LIST_CREATED: {
|
||||
instance.targetUserLists = LoganSquare.mapperFor(UserList.class).parseList(jsonParser).toArray(new UserList[instance.targetsSize]);
|
||||
break;
|
||||
}
|
||||
@ -117,27 +116,27 @@ public class Activity$$JsonObjectMapper extends JsonMapper<Activity> {
|
||||
} else if ("target_objects".equals(fieldName)) {
|
||||
if (instance.action == null) throw new IOException();
|
||||
switch (instance.action) {
|
||||
case FAVORITE:
|
||||
case FOLLOW:
|
||||
case MENTION:
|
||||
case REPLY:
|
||||
case RETWEET:
|
||||
case LIST_CREATED:
|
||||
case QUOTE: {
|
||||
case Activity.Action.FAVORITE:
|
||||
case Activity.Action.FOLLOW:
|
||||
case Activity.Action.MENTION:
|
||||
case Activity.Action.REPLY:
|
||||
case Activity.Action.RETWEET:
|
||||
case Activity.Action.LIST_CREATED:
|
||||
case Activity.Action.QUOTE: {
|
||||
instance.targetObjectStatuses = LoganSquare.mapperFor(Status.class).parseList(jsonParser).toArray(new Status[instance.targetObjectsSize]);
|
||||
break;
|
||||
}
|
||||
case LIST_MEMBER_ADDED: {
|
||||
case Activity.Action.LIST_MEMBER_ADDED: {
|
||||
instance.targetObjectUserLists = LoganSquare.mapperFor(UserList.class).parseList(jsonParser).toArray(new UserList[instance.targetObjectsSize]);
|
||||
break;
|
||||
}
|
||||
case FAVORITED_RETWEET:
|
||||
case RETWEETED_RETWEET:
|
||||
case RETWEETED_MENTION:
|
||||
case FAVORITED_MENTION:
|
||||
case MEDIA_TAGGED:
|
||||
case FAVORITED_MEDIA_TAGGED:
|
||||
case RETWEETED_MEDIA_TAGGED: {
|
||||
case Activity.Action.FAVORITED_RETWEET:
|
||||
case Activity.Action.RETWEETED_RETWEET:
|
||||
case Activity.Action.RETWEETED_MENTION:
|
||||
case Activity.Action.FAVORITED_MENTION:
|
||||
case Activity.Action.MEDIA_TAGGED:
|
||||
case Activity.Action.FAVORITED_MEDIA_TAGGED:
|
||||
case Activity.Action.RETWEETED_MEDIA_TAGGED: {
|
||||
instance.targetObjectUsers = LoganSquare.mapperFor(User.class).parseList(jsonParser).toArray(new User[instance.targetObjectsSize]);
|
||||
break;
|
||||
}
|
||||
|
@ -20,19 +20,15 @@
|
||||
package org.mariotaku.twidere.api.twitter.model;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.StringDef;
|
||||
|
||||
import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
public class Activity extends TwitterResponseObject implements TwitterResponse, Comparable<Activity> {
|
||||
|
||||
Action action;
|
||||
@Action
|
||||
String action;
|
||||
String rawAction;
|
||||
|
||||
Date createdAt;
|
||||
@ -48,10 +44,6 @@ public class Activity extends TwitterResponseObject implements TwitterResponse,
|
||||
Activity() {
|
||||
}
|
||||
|
||||
public String getRawAction() {
|
||||
return rawAction;
|
||||
}
|
||||
|
||||
public User[] getTargetObjectUsers() {
|
||||
return targetObjectUsers;
|
||||
}
|
||||
@ -63,7 +55,9 @@ public class Activity extends TwitterResponseObject implements TwitterResponse,
|
||||
return thisDate.compareTo(thatDate);
|
||||
}
|
||||
|
||||
public Action getAction() {
|
||||
public
|
||||
@Action
|
||||
String getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
@ -160,70 +154,44 @@ public class Activity extends TwitterResponseObject implements TwitterResponse,
|
||||
return activity;
|
||||
}
|
||||
|
||||
public enum Action {
|
||||
FAVORITE("favorite"),
|
||||
@StringDef({Action.FAVORITE, Action.FOLLOW, Action.MENTION, Action.REPLY, Action.RETWEET,
|
||||
Action.LIST_MEMBER_ADDED, Action.LIST_CREATED, Action.FAVORITED_RETWEET,
|
||||
Action.RETWEETED_RETWEET, Action.QUOTE, Action.RETWEETED_MENTION,
|
||||
Action.FAVORITED_MENTION, Action.JOINED_TWITTER, Action.MEDIA_TAGGED,
|
||||
Action.FAVORITED_MEDIA_TAGGED, Action.RETWEETED_MEDIA_TAGGED})
|
||||
public @interface Action {
|
||||
String FAVORITE = ("favorite");
|
||||
/**
|
||||
* Sources: followers to targets (User)
|
||||
* Targets: following user (User)
|
||||
*/
|
||||
FOLLOW("follow"),
|
||||
String FOLLOW = ("follow");
|
||||
/**
|
||||
* Targets: mentioned users (User)
|
||||
* Target objects: mention status (Status)
|
||||
*/
|
||||
MENTION("mention"),
|
||||
String MENTION = ("mention");
|
||||
/**
|
||||
* Targets: reply status (Status)
|
||||
* Target objects: in reply to status (Status)
|
||||
*/
|
||||
REPLY("reply"),
|
||||
RETWEET("retweet"),
|
||||
LIST_MEMBER_ADDED("list_member_added"),
|
||||
LIST_CREATED("list_created"),
|
||||
FAVORITED_RETWEET("favorited_retweet"),
|
||||
RETWEETED_RETWEET("retweeted_retweet"),
|
||||
String REPLY = ("reply");
|
||||
String RETWEET = ("retweet");
|
||||
String LIST_MEMBER_ADDED = ("list_member_added");
|
||||
String LIST_CREATED = ("list_created");
|
||||
String FAVORITED_RETWEET = ("favorited_retweet");
|
||||
String RETWEETED_RETWEET = ("retweeted_retweet");
|
||||
/**
|
||||
* Targets: Quote result (Status)
|
||||
* Target objects: Original status (Status)
|
||||
*/
|
||||
QUOTE("quote"),
|
||||
RETWEETED_MENTION("retweeted_mention"),
|
||||
FAVORITED_MENTION("favorited_mention"),
|
||||
JOINED_TWITTER("joined_twitter"),
|
||||
MEDIA_TAGGED("media_tagged"),
|
||||
FAVORITED_MEDIA_TAGGED("favorited_media_tagged"),
|
||||
RETWEETED_MEDIA_TAGGED("retweeted_media_tagged"),
|
||||
UNKNOWN(null);
|
||||
String QUOTE = ("quote");
|
||||
String RETWEETED_MENTION = ("retweeted_mention");
|
||||
String FAVORITED_MENTION = ("favorited_mention");
|
||||
String JOINED_TWITTER = ("joined_twitter");
|
||||
String MEDIA_TAGGED = ("media_tagged");
|
||||
String FAVORITED_MEDIA_TAGGED = ("favorited_media_tagged");
|
||||
String RETWEETED_MEDIA_TAGGED = ("retweeted_media_tagged");
|
||||
|
||||
public final String literal;
|
||||
|
||||
Action(final String literal) {
|
||||
this.literal = literal;
|
||||
}
|
||||
|
||||
public static Action parse(final String string) {
|
||||
for (Action action : values()) {
|
||||
if (StringUtils.equalsIgnoreCase(action.literal, string)) return action;
|
||||
}
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
public String getLiteral() {
|
||||
return literal;
|
||||
}
|
||||
|
||||
public static class Converter extends StringBasedTypeConverter<Action> {
|
||||
|
||||
@Override
|
||||
public Action getFromString(String string) {
|
||||
return Action.parse(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToString(Action object) {
|
||||
if (object == null) return null;
|
||||
return object.literal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -19,9 +19,10 @@
|
||||
|
||||
package org.mariotaku.twidere.api.twitter.model;
|
||||
|
||||
import android.support.annotation.StringDef;
|
||||
|
||||
import com.bluelinelabs.logansquare.annotation.JsonField;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/7/8.
|
||||
@ -51,10 +52,12 @@ public class ExtendedProfile {
|
||||
int month;
|
||||
@JsonField(name = "year")
|
||||
int year;
|
||||
@JsonField(name = "visibility", typeConverter = Visibility.Converter.class)
|
||||
Visibility visibility;
|
||||
@JsonField(name = "year_visibility", typeConverter = Visibility.Converter.class)
|
||||
Visibility yearVisibility;
|
||||
@JsonField(name = "visibility")
|
||||
@Visibility
|
||||
String visibility;
|
||||
@JsonField(name = "year_visibility")
|
||||
@Visibility
|
||||
String yearVisibility;
|
||||
|
||||
public int getDay() {
|
||||
return day;
|
||||
@ -68,41 +71,23 @@ public class ExtendedProfile {
|
||||
return year;
|
||||
}
|
||||
|
||||
public Visibility getVisibility() {
|
||||
public
|
||||
@Visibility
|
||||
String getVisibility() {
|
||||
return visibility;
|
||||
}
|
||||
|
||||
public Visibility getYearVisibility() {
|
||||
public
|
||||
@Visibility
|
||||
String getYearVisibility() {
|
||||
return yearVisibility;
|
||||
}
|
||||
|
||||
public enum Visibility {
|
||||
MUTUALFOLLOW("mutualfollow"), PUBLIC("public"), UNKNOWN(null);
|
||||
@StringDef({Visibility.MUTUALFOLLOW, Visibility.PUBLIC})
|
||||
public @interface Visibility {
|
||||
String MUTUALFOLLOW = ("mutualfollow");
|
||||
String PUBLIC = ("public");
|
||||
|
||||
private final String literal;
|
||||
|
||||
Visibility(String literal) {
|
||||
this.literal = literal;
|
||||
}
|
||||
|
||||
public static Visibility parse(String s) {
|
||||
if ("mutualfollow".equals(s)) return MUTUALFOLLOW;
|
||||
if ("public".equals(s)) return PUBLIC;
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
public static class Converter extends StringBasedTypeConverter<Visibility> {
|
||||
|
||||
@Override
|
||||
public Visibility getFromString(String string) {
|
||||
return Visibility.parse(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToString(Visibility object) {
|
||||
return object.literal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,9 +21,6 @@ package org.mariotaku.twidere.api.twitter.model;
|
||||
|
||||
import com.bluelinelabs.logansquare.annotation.JsonField;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter;
|
||||
|
||||
import org.mariotaku.twidere.util.BugReporter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -51,8 +48,9 @@ public class MediaEntity extends UrlEntity {
|
||||
String displayUrl;
|
||||
@JsonField(name = "expanded_url")
|
||||
String expandedUrl;
|
||||
@JsonField(name = "type", typeConverter = Type.Converter.class)
|
||||
Type type;
|
||||
@JsonField(name = "type")
|
||||
@Type
|
||||
String type;
|
||||
@JsonField(name = "sizes")
|
||||
HashMap<String, Size> sizes;
|
||||
@JsonField(name = "source_status_id")
|
||||
@ -111,7 +109,9 @@ public class MediaEntity extends UrlEntity {
|
||||
return url;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
public
|
||||
@Type
|
||||
String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@ -131,39 +131,11 @@ public class MediaEntity extends UrlEntity {
|
||||
return id;
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
PHOTO("photo"), VIDEO("video"), ANIMATED_GIF("animated_gif"), UNKNOWN(null);
|
||||
public @interface Type {
|
||||
String PHOTO = "photo";
|
||||
String VIDEO = "video";
|
||||
String ANIMATED_GIF = "animated_gif";
|
||||
|
||||
private final String literal;
|
||||
|
||||
Type(String literal) {
|
||||
this.literal = literal;
|
||||
}
|
||||
|
||||
public static Type parse(String typeString) {
|
||||
if ("photo".equalsIgnoreCase(typeString)) {
|
||||
return PHOTO;
|
||||
} else if ("video".equalsIgnoreCase(typeString)) {
|
||||
return VIDEO;
|
||||
} else if ("animated_gif".equalsIgnoreCase(typeString)) {
|
||||
return ANIMATED_GIF;
|
||||
}
|
||||
BugReporter.error("Unknown MediaEntity.Type " + typeString);
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
public static class Converter extends StringBasedTypeConverter<Type> {
|
||||
|
||||
@Override
|
||||
public Type getFromString(String string) {
|
||||
return Type.parse(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToString(Type object) {
|
||||
return object.literal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.api.twitter.model;
|
||||
|
||||
import org.mariotaku.restfu.http.RestHttpResponse;
|
||||
import org.mariotaku.restfu.http.HttpResponse;
|
||||
import org.mariotaku.twidere.api.twitter.util.InternalParseUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -36,7 +36,7 @@ public class PageableResponseList<T> extends ArrayList<T> implements TwitterResp
|
||||
|
||||
|
||||
@Override
|
||||
public final void processResponseHeader(RestHttpResponse resp) {
|
||||
public final void processResponseHeader(HttpResponse resp) {
|
||||
rateLimitStatus = RateLimitStatus.createFromResponseHeader(resp);
|
||||
accessLevel = InternalParseUtil.toAccessLevel(resp);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ package org.mariotaku.twidere.api.twitter.model;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonField;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
|
||||
import org.mariotaku.restfu.http.RestHttpResponse;
|
||||
import org.mariotaku.restfu.http.HttpResponse;
|
||||
import org.mariotaku.twidere.api.twitter.util.InternalParseUtil;
|
||||
|
||||
import java.util.AbstractList;
|
||||
@ -49,7 +49,7 @@ public class QueryResult extends AbstractList<Status> implements TwitterResponse
|
||||
private RateLimitStatus rateLimitStatus;
|
||||
|
||||
@Override
|
||||
public final void processResponseHeader(RestHttpResponse resp) {
|
||||
public final void processResponseHeader(HttpResponse resp) {
|
||||
rateLimitStatus = RateLimitStatus.createFromResponseHeader(resp);
|
||||
accessLevel = InternalParseUtil.toAccessLevel(resp);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ package org.mariotaku.twidere.api.twitter.model;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonField;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
|
||||
import org.mariotaku.restfu.http.RestHttpResponse;
|
||||
import org.mariotaku.restfu.http.HttpResponse;
|
||||
|
||||
/**
|
||||
* A data class representing Twitter REST API's rate limit status
|
||||
@ -122,7 +122,7 @@ public final class RateLimitStatus {
|
||||
'}';
|
||||
}
|
||||
|
||||
public static RateLimitStatus createFromResponseHeader(final RestHttpResponse res) {
|
||||
public static RateLimitStatus createFromResponseHeader(final HttpResponse res) {
|
||||
if (null == res) return null;
|
||||
int remainingHits;// "X-Rate-Limit-Remaining"
|
||||
int limit;// "X-Rate-Limit-Limit"
|
||||
|
@ -19,9 +19,8 @@
|
||||
|
||||
package org.mariotaku.twidere.api.twitter.model;
|
||||
|
||||
import org.mariotaku.restfu.http.RestHttpResponse;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import org.mariotaku.restfu.RestConverter;
|
||||
import org.mariotaku.restfu.http.HttpResponse;
|
||||
|
||||
/**
|
||||
* Created by mariotaku on 15/6/15.
|
||||
@ -30,7 +29,7 @@ public class ResponseCode {
|
||||
|
||||
private final int responseCode;
|
||||
|
||||
public ResponseCode(RestHttpResponse response) {
|
||||
public ResponseCode(HttpResponse response) {
|
||||
responseCode = response.getStatus();
|
||||
}
|
||||
|
||||
@ -42,10 +41,10 @@ public class ResponseCode {
|
||||
return responseCode >= 200 && responseCode < 300;
|
||||
}
|
||||
|
||||
public static class Converter implements org.mariotaku.restfu.Converter {
|
||||
public static class Converter implements RestConverter<HttpResponse, ResponseCode> {
|
||||
|
||||
@Override
|
||||
public Object convert(RestHttpResponse response, Type type) throws Exception {
|
||||
public ResponseCode convert(HttpResponse response) {
|
||||
return new ResponseCode(response);
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.api.twitter.model;
|
||||
|
||||
import org.mariotaku.restfu.http.RestHttpResponse;
|
||||
import org.mariotaku.restfu.http.HttpResponse;
|
||||
import org.mariotaku.twidere.api.twitter.util.InternalParseUtil;
|
||||
|
||||
import java.util.AbstractList;
|
||||
@ -64,7 +64,7 @@ public class ResponseList<T> extends AbstractList<T> implements TwitterResponse
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void processResponseHeader(RestHttpResponse resp) {
|
||||
public final void processResponseHeader(HttpResponse resp) {
|
||||
rateLimitStatus = RateLimitStatus.createFromResponseHeader(resp);
|
||||
accessLevel = InternalParseUtil.toAccessLevel(resp);
|
||||
}
|
||||
|
@ -19,9 +19,10 @@
|
||||
|
||||
package org.mariotaku.twidere.api.twitter.model;
|
||||
|
||||
import android.support.annotation.StringDef;
|
||||
|
||||
import com.bluelinelabs.logansquare.annotation.JsonField;
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject;
|
||||
import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter;
|
||||
|
||||
import org.mariotaku.twidere.api.twitter.util.TwitterDateConverter;
|
||||
|
||||
@ -49,8 +50,9 @@ public class ScheduledStatus {
|
||||
boolean possiblySensitive;
|
||||
@JsonField(name = "user_id")
|
||||
long userId;
|
||||
@JsonField(name = "state", typeConverter = State.Converter.class)
|
||||
State state;
|
||||
@JsonField(name = "state")
|
||||
@State
|
||||
String state;
|
||||
|
||||
public long getUserId() {
|
||||
return userId;
|
||||
@ -84,46 +86,15 @@ public class ScheduledStatus {
|
||||
return text;
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
public
|
||||
@State
|
||||
String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public enum State {
|
||||
SCHEDULED("scheduled"), FAILED("failed"), CANCELED("canceled");
|
||||
@StringDef({State.SCHEDULED, State.FAILED, State.CANCELED})
|
||||
public @interface State {
|
||||
String SCHEDULED = ("scheduled"), FAILED = ("failed"), CANCELED = ("canceled");
|
||||
|
||||
private final String literal;
|
||||
|
||||
State(String literal) {
|
||||
this.literal = literal;
|
||||
}
|
||||
|
||||
public static State parse(String value) {
|
||||
if (SCHEDULED.literal.equalsIgnoreCase(value)) {
|
||||
return SCHEDULED;
|
||||
} else if (FAILED.literal.equalsIgnoreCase(value)) {
|
||||
return FAILED;
|
||||
} else if (CANCELED.literal.equalsIgnoreCase(value)) {
|
||||
return CANCELED;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return literal;
|
||||
}
|
||||
|
||||
public static class Converter extends StringBasedTypeConverter<State> {
|
||||
|
||||
@Override
|
||||
public State getFromString(String string) {
|
||||
return State.parse(string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertToString(State object) {
|
||||
return object.literal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.api.twitter.model;
|
||||
|
||||
import org.mariotaku.restfu.http.RestHttpResponse;
|
||||
import org.mariotaku.restfu.http.HttpResponse;
|
||||
|
||||
/**
|
||||
* 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(RestHttpResponse resp);
|
||||
void processResponseHeader(HttpResponse resp);
|
||||
|
||||
int getAccessLevel();
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.api.twitter.model;
|
||||
|
||||
import org.mariotaku.restfu.http.RestHttpResponse;
|
||||
import org.mariotaku.restfu.http.HttpResponse;
|
||||
|
||||
import org.mariotaku.twidere.api.twitter.model.RateLimitStatus;
|
||||
import org.mariotaku.twidere.api.twitter.model.TwitterResponse;
|
||||
@ -34,7 +34,7 @@ public class TwitterResponseObject implements TwitterResponse {
|
||||
private RateLimitStatus rateLimitStatus;
|
||||
|
||||
@Override
|
||||
public final void processResponseHeader(RestHttpResponse resp) {
|
||||
public final void processResponseHeader(HttpResponse resp) {
|
||||
rateLimitStatus = RateLimitStatus.createFromResponseHeader(resp);
|
||||
accessLevel = InternalParseUtil.toAccessLevel(resp);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
package org.mariotaku.twidere.api.twitter.util;
|
||||
|
||||
import org.mariotaku.restfu.http.RestHttpResponse;
|
||||
import org.mariotaku.restfu.http.HttpResponse;
|
||||
import org.mariotaku.twidere.api.twitter.model.TwitterResponse;
|
||||
|
||||
/**
|
||||
@ -34,7 +34,7 @@ public final class InternalParseUtil {
|
||||
throw new AssertionError("This class should never be instantiated");
|
||||
}
|
||||
|
||||
public static int toAccessLevel(final RestHttpResponse res) {
|
||||
public static int toAccessLevel(final HttpResponse res) {
|
||||
if (null == res) return -1;
|
||||
final String xAccessLevel = res.getHeader("X-Access-Level");
|
||||
int accessLevel;
|
||||
|
@ -26,10 +26,9 @@ import com.bluelinelabs.logansquare.ParameterizedType;
|
||||
import com.bluelinelabs.logansquare.ParameterizedTypeAccessor;
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
|
||||
import org.mariotaku.restfu.Converter;
|
||||
import org.mariotaku.restfu.Utils;
|
||||
import org.mariotaku.restfu.http.RestHttpResponse;
|
||||
import org.mariotaku.restfu.http.mime.TypedData;
|
||||
import org.mariotaku.restfu.RestConverter;
|
||||
import org.mariotaku.restfu.http.HttpResponse;
|
||||
import org.mariotaku.restfu.http.mime.Body;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
import org.mariotaku.twidere.api.twitter.auth.OAuthToken;
|
||||
import org.mariotaku.twidere.api.twitter.model.ResponseCode;
|
||||
@ -44,18 +43,19 @@ import java.util.List;
|
||||
/**
|
||||
* Created by mariotaku on 15/5/5.
|
||||
*/
|
||||
public class TwitterConverter implements Converter {
|
||||
public class TwitterConverterFactory extends RestConverter.SimpleFactory {
|
||||
|
||||
private static SimpleArrayMap<Type, Converter> sConverters = new SimpleArrayMap<>();
|
||||
private static SimpleArrayMap<Type, RestConverter<HttpResponse, ?>> sResponseConverters = new SimpleArrayMap<>();
|
||||
private static SimpleArrayMap<Type, RestConverter<?, Body>> sBodyConverters = new SimpleArrayMap<>();
|
||||
|
||||
static {
|
||||
sConverters.put(ResponseCode.class, new ResponseCode.Converter());
|
||||
sConverters.put(OAuthToken.class, new OAuthToken.Converter());
|
||||
sResponseConverters.put(ResponseCode.class, new ResponseCode.Converter());
|
||||
sResponseConverters.put(OAuthToken.class, new OAuthToken.Converter());
|
||||
}
|
||||
|
||||
public static TwitterException parseTwitterException(RestHttpResponse resp) {
|
||||
public static TwitterException parseTwitterException(HttpResponse resp) {
|
||||
try {
|
||||
final TypedData body = resp.getBody();
|
||||
final Body body = resp.getBody();
|
||||
if (body == null) return new TwitterException(resp);
|
||||
final TwitterException parse = LoganSquare.parse(body.stream(), TwitterException.class);
|
||||
if (parse != null) return parse;
|
||||
@ -67,7 +67,7 @@ public class TwitterConverter implements Converter {
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> T parseOrThrow(RestHttpResponse resp, InputStream stream, Type type) throws IOException, TwitterException {
|
||||
private static <T> T parseOrThrow(HttpResponse resp, InputStream stream, Type type) throws IOException, TwitterException {
|
||||
try {
|
||||
final ParameterizedType<T> parameterizedType = ParameterizedTypeAccessor.create(type);
|
||||
final T parse = LoganSquare.parse(stream, parameterizedType);
|
||||
@ -80,7 +80,7 @@ public class TwitterConverter implements Converter {
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> List<T> parseListOrThrow(RestHttpResponse resp, InputStream stream, Class<T> elementCls) throws IOException, TwitterException {
|
||||
private static <T> List<T> parseListOrThrow(HttpResponse resp, InputStream stream, Class<T> elementCls) throws IOException, TwitterException {
|
||||
try {
|
||||
return LoganSquare.parseList(stream, elementCls);
|
||||
} catch (JsonParseException e) {
|
||||
@ -88,33 +88,28 @@ public class TwitterConverter implements Converter {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object convert(RestHttpResponse response, Type type) throws Exception {
|
||||
final TypedData body = response.getBody();
|
||||
if (!response.isSuccessful()) {
|
||||
throw TwitterConverter.<TwitterException>parseOrThrow(response, body.stream(), TwitterException.class);
|
||||
}
|
||||
try {
|
||||
Converter converter = sConverters.get(type);
|
||||
if (converter != null) {
|
||||
return converter.convert(response, type);
|
||||
}
|
||||
final InputStream stream = body.stream();
|
||||
final Object object = parseOrThrow(response, stream, type);
|
||||
checkResponse(type, object, response);
|
||||
if (object instanceof TwitterResponseObject) {
|
||||
((TwitterResponseObject) object).processResponseHeader(response);
|
||||
}
|
||||
return object;
|
||||
} finally {
|
||||
Utils.closeSilently(body);
|
||||
private static void checkResponse(Type type, Object object, HttpResponse response) throws TwitterException {
|
||||
if (User.class == type) {
|
||||
if (object == null) throw new TwitterException("User is null");
|
||||
}
|
||||
}
|
||||
|
||||
private void checkResponse(Type type, Object object, RestHttpResponse response) throws TwitterException {
|
||||
if (User.class.equals(type)) {
|
||||
if (object == null) throw new TwitterException("User is null");
|
||||
@Override
|
||||
public RestConverter<HttpResponse, ?> fromResponse(Type type) {
|
||||
RestConverter<HttpResponse, ?> converter = sResponseConverters.get(type);
|
||||
if (converter != null) {
|
||||
return converter;
|
||||
}
|
||||
return new TwitterConverter(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestConverter<?, Body> toParam(Type type) {
|
||||
final RestConverter<?, Body> converter = sBodyConverters.get(type);
|
||||
if (converter != null) {
|
||||
return converter;
|
||||
}
|
||||
return super.toParam(type);
|
||||
}
|
||||
|
||||
public static class UnsupportedTypeException extends UnsupportedOperationException {
|
||||
@ -122,4 +117,28 @@ public class TwitterConverter implements Converter {
|
||||
super("Unsupported type " + type);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TwitterConverter implements RestConverter<HttpResponse, Object> {
|
||||
private final Type type;
|
||||
|
||||
public TwitterConverter(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object convert(HttpResponse httpResponse) throws IOException {
|
||||
try {
|
||||
final Body body = httpResponse.getBody();
|
||||
final InputStream stream = body.stream();
|
||||
final Object object = parseOrThrow(httpResponse, stream, type);
|
||||
checkResponse(type, object, httpResponse);
|
||||
if (object instanceof TwitterResponseObject) {
|
||||
((TwitterResponseObject) object).processResponseHeader(httpResponse);
|
||||
}
|
||||
return object;
|
||||
} catch (TwitterException e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -120,7 +120,7 @@ public class ParcelableActivity implements Comparable<ParcelableActivity>, Parce
|
||||
public ParcelableActivity(final Activity activity, final long accountId, boolean isGap) {
|
||||
this.account_id = accountId;
|
||||
timestamp = activity.getCreatedAt().getTime();
|
||||
action = activity.getRawAction();
|
||||
action = activity.getAction();
|
||||
max_position = activity.getMaxPosition();
|
||||
min_position = activity.getMinPosition();
|
||||
sources = ParcelableUser.fromUsers(activity.getSources(), accountId);
|
||||
@ -141,11 +141,11 @@ public class ParcelableActivity implements Comparable<ParcelableActivity>, Parce
|
||||
|
||||
@Nullable
|
||||
public static ParcelableStatus getActivityStatus(ParcelableActivity activity) {
|
||||
if (Activity.Action.MENTION.literal.equals(activity.action)) {
|
||||
if (Activity.Action.MENTION.equals(activity.action)) {
|
||||
return activity.target_object_statuses[0];
|
||||
} else if (Activity.Action.REPLY.literal.equals(activity.action)) {
|
||||
} else if (Activity.Action.REPLY.equals(activity.action)) {
|
||||
return activity.target_statuses[0];
|
||||
} else if (Activity.Action.QUOTE.literal.equals(activity.action)) {
|
||||
} else if (Activity.Action.QUOTE.equals(activity.action)) {
|
||||
return activity.target_statuses[0];
|
||||
}
|
||||
return null;
|
||||
|
@ -243,13 +243,13 @@ public class ParcelableMedia implements Parcelable {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static int getTypeInt(MediaEntity.Type type) {
|
||||
private static int getTypeInt(String type) {
|
||||
switch (type) {
|
||||
case PHOTO:
|
||||
case MediaEntity.Type.PHOTO:
|
||||
return Type.TYPE_IMAGE;
|
||||
case VIDEO:
|
||||
case MediaEntity.Type.VIDEO:
|
||||
return Type.TYPE_VIDEO;
|
||||
case ANIMATED_GIF:
|
||||
case MediaEntity.Type.ANIMATED_GIF:
|
||||
return Type.TYPE_ANIMATED_GIF;
|
||||
}
|
||||
return Type.TYPE_UNKNOWN;
|
||||
|
@ -109,8 +109,8 @@ dependencies {
|
||||
compile 'com.soundcloud.android:android-crop:1.0.1@aar'
|
||||
compile 'com.hannesdorfmann.parcelableplease:annotation:1.0.2'
|
||||
compile 'com.github.mariotaku:PickNCrop:0.9.2'
|
||||
compile 'com.github.mariotaku.RestFu:library:0.9.8'
|
||||
compile 'com.github.mariotaku.RestFu:okhttp:0.9.8'
|
||||
compile 'com.github.mariotaku.RestFu:library:0.9.10'
|
||||
compile 'com.github.mariotaku.RestFu:okhttp:0.9.10'
|
||||
compile 'com.diogobernardino:williamchart:2.1'
|
||||
compile 'com.lnikkila:extendedtouchview:0.1.0'
|
||||
compile 'com.google.dagger:dagger:2.0.2'
|
||||
@ -123,7 +123,7 @@ dependencies {
|
||||
fdroidCompile 'org.osmdroid:osmdroid-android:5.0.1'
|
||||
debugCompile 'com.facebook.stetho:stetho:1.2.0'
|
||||
debugCompile 'com.facebook.stetho:stetho-okhttp:1.2.0'
|
||||
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3'
|
||||
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta1'
|
||||
compile project(':twidere.component.common')
|
||||
compile project(':twidere.component.nyan')
|
||||
compile 'com.github.mariotaku.ObjectCursor:core:0.9.3'
|
||||
|
@ -20,15 +20,15 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<application>
|
||||
<application tools:ignore="AllowBackup,GoogleAppIndexingWarning">
|
||||
|
||||
<activity
|
||||
android:name="com.squareup.leakcanary.internal.DisplayLeakActivity"
|
||||
android:enabled="false"
|
||||
android:icon="@drawable/__leak_canary_icon"
|
||||
android:label="@string/__leak_canary_display_activity_label"
|
||||
android:icon="@drawable/leak_canary_icon"
|
||||
android:label="@string/leak_canary_display_activity_label"
|
||||
android:taskAffinity="com.squareup.leakcanary"
|
||||
android:theme="@style/__LeakCanary.Base">
|
||||
android:theme="@style/leak_canary_LeakCanary.Base">
|
||||
<intent-filter>
|
||||
<action
|
||||
android:name="android.intent.action.MAIN"
|
||||
|
@ -20,7 +20,6 @@
|
||||
package org.mariotaku.twidere.util;
|
||||
|
||||
import android.app.Application;
|
||||
import android.os.Build;
|
||||
|
||||
import com.facebook.stetho.Stetho;
|
||||
import com.facebook.stetho.okhttp.StethoInterceptor;
|
||||
@ -49,10 +48,8 @@ public class DebugModeUtils {
|
||||
.enableWebKitInspector(Stetho.defaultInspectorModulesProvider(application))
|
||||
.build());
|
||||
// LeakCanary not working on Android Marshmallow, see https://github.com/square/leakcanary/issues/267
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||
sRefWatcher = LeakCanary.install(application);
|
||||
}
|
||||
}
|
||||
|
||||
public static void watchReferenceLeak(final Object object) {
|
||||
if (sRefWatcher == null) return;
|
||||
|
@ -24,12 +24,12 @@ import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.mariotaku.restfu.Pair;
|
||||
import org.mariotaku.restfu.annotation.method.POST;
|
||||
import org.mariotaku.restfu.http.HttpRequest;
|
||||
import org.mariotaku.restfu.http.HttpResponse;
|
||||
import org.mariotaku.restfu.http.MultiValueMap;
|
||||
import org.mariotaku.restfu.http.RestHttpClient;
|
||||
import org.mariotaku.restfu.http.RestHttpRequest;
|
||||
import org.mariotaku.restfu.http.RestHttpResponse;
|
||||
import org.mariotaku.restfu.http.mime.FileTypedData;
|
||||
import org.mariotaku.restfu.http.mime.FileBody;
|
||||
import org.mariotaku.twidere.BuildConfig;
|
||||
import org.mariotaku.twidere.util.BugReporter;
|
||||
import org.mariotaku.twidere.util.TwitterAPIFactory;
|
||||
@ -38,9 +38,7 @@ import org.mariotaku.twidere.util.Utils;
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import edu.tsinghua.hotmobi.model.UploadLogEvent;
|
||||
@ -95,24 +93,24 @@ public class UploadLogsTask implements Runnable {
|
||||
boolean succeeded = true;
|
||||
for (Object logFileObj : ArrayUtils.nullToEmpty(dayLogsDir.listFiles())) {
|
||||
File logFile = (File) logFileObj;
|
||||
FileTypedData body = null;
|
||||
RestHttpResponse response = null;
|
||||
FileBody body = null;
|
||||
HttpResponse response = null;
|
||||
try {
|
||||
final RestHttpRequest.Builder builder = new RestHttpRequest.Builder();
|
||||
final HttpRequest.Builder builder = new HttpRequest.Builder();
|
||||
builder.method(POST.METHOD);
|
||||
builder.url("http://www.dnext.xyz/usage/upload");
|
||||
final List<Pair<String, String>> headers = new ArrayList<>();
|
||||
headers.add(Pair.create("X-HotMobi-UUID", uuid));
|
||||
headers.add(Pair.create("X-HotMobi-Date", dayLogsDir.getName()));
|
||||
headers.add(Pair.create("X-HotMobi-FileName", logFile.getName()));
|
||||
headers.add(Pair.create("User-Agent", String.format(Locale.ROOT,
|
||||
final MultiValueMap<String> headers = new MultiValueMap<>();
|
||||
headers.add("X-HotMobi-UUID", uuid);
|
||||
headers.add("X-HotMobi-Date", dayLogsDir.getName());
|
||||
headers.add("X-HotMobi-FileName", logFile.getName());
|
||||
headers.add("User-Agent", String.format(Locale.ROOT,
|
||||
"HotMobi (Twidere %s %d)", BuildConfig.VERSION_NAME,
|
||||
BuildConfig.VERSION_CODE)));
|
||||
BuildConfig.VERSION_CODE));
|
||||
builder.headers(headers);
|
||||
body = new FileTypedData(logFile);
|
||||
body = new FileBody(logFile);
|
||||
builder.body(body);
|
||||
final UploadLogEvent uploadLogEvent = UploadLogEvent.create(context, logFile);
|
||||
response = client.execute(builder.build());
|
||||
response = client.newCall(builder.build()).execute();
|
||||
if (response.isSuccessful()) {
|
||||
uploadLogEvent.finish(response);
|
||||
if (!uploadLogEvent.shouldSkip()) {
|
||||
|
@ -14,7 +14,7 @@ import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.mariotaku.restfu.Pair;
|
||||
import org.mariotaku.restfu.http.RestHttpResponse;
|
||||
import org.mariotaku.restfu.http.HttpResponse;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
@ -82,9 +82,9 @@ public class UploadLogEvent extends BaseEvent implements Parcelable {
|
||||
UploadLogEventParcelablePlease.writeToParcel(this, dest, flags);
|
||||
}
|
||||
|
||||
public void finish(RestHttpResponse response) {
|
||||
public void finish(HttpResponse response) {
|
||||
HashMap<String, String> extraHeaders = new HashMap<>();
|
||||
for (Pair<String, String> pair : response.getHeaders()) {
|
||||
for (Pair<String, String> pair : response.getHeaders().toList()) {
|
||||
if (StringUtils.startsWithIgnoreCase(pair.first, "X-Dnext")) {
|
||||
extraHeaders.put(pair.first, pair.second);
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ public class BrowserSignInActivity extends BaseSupportDialogActivity {
|
||||
return;
|
||||
}
|
||||
final OAuthEndpoint endpoint = new OAuthEndpoint(TwitterAPIFactory.getApiUrl(DEFAULT_TWITTER_API_URL_FORMAT, "api", null));
|
||||
mActivity.loadUrl(endpoint.construct("/oauth/authorize", Pair.create("oauth_token", data.getOauthToken())));
|
||||
mActivity.loadUrl(endpoint.construct("/oauth/authorize", new String[]{"oauth_token", data.getOauthToken()}));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -789,7 +789,7 @@ public class SignInActivity extends BaseAppCompatActivity implements OnClickList
|
||||
Endpoint endpoint = TwitterAPIFactory.getOAuthEndpoint(apiUrlFormat, "api", null, sameOAuthSigningUrl);
|
||||
OAuthAuthorization auth = new OAuthAuthorization(consumerKey.getOauthToken(), consumerKey.getOauthTokenSecret());
|
||||
final TwitterOAuth oauth = TwitterAPIFactory.getInstance(activity, endpoint, auth, TwitterOAuth.class);
|
||||
final OAuthToken accessToken = oauth.getAccessToken(username, password, TwitterOAuth.XAuthMode.CLIENT);
|
||||
final OAuthToken accessToken = oauth.getAccessToken(username, password);
|
||||
final long userId = accessToken.getUserId();
|
||||
if (userId <= 0) return new SignInResponse(false, false, null);
|
||||
auth = new OAuthAuthorization(consumerKey.getOauthToken(), consumerKey.getOauthTokenSecret(), accessToken);
|
||||
|
@ -265,29 +265,29 @@ public abstract class AbsActivitiesAdapter<Data> extends LoadMoreSupportAdapter<
|
||||
return ITEM_VIEW_TYPE_GAP;
|
||||
}
|
||||
final String action = getActivityAction(position);
|
||||
if (Activity.Action.MENTION.literal.equals(action)) {
|
||||
if (Activity.Action.MENTION.equals(action)) {
|
||||
if (ArrayUtils.isEmpty(activity.target_object_statuses)) {
|
||||
return ITEM_VIEW_TYPE_STUB;
|
||||
}
|
||||
if (mFollowingOnly && !activity.status_user_following) return ITEM_VIEW_TYPE_EMPTY;
|
||||
return ITEM_VIEW_TYPE_STATUS;
|
||||
} else if (Activity.Action.REPLY.literal.equals(action)) {
|
||||
} else if (Activity.Action.REPLY.equals(action)) {
|
||||
if (ArrayUtils.isEmpty(activity.target_statuses)) {
|
||||
return ITEM_VIEW_TYPE_STUB;
|
||||
}
|
||||
if (mFollowingOnly && !activity.status_user_following) return ITEM_VIEW_TYPE_EMPTY;
|
||||
return ITEM_VIEW_TYPE_STATUS;
|
||||
} else if (Activity.Action.QUOTE.literal.equals(action)) {
|
||||
} else if (Activity.Action.QUOTE.equals(action)) {
|
||||
if (ArrayUtils.isEmpty(activity.target_statuses)) {
|
||||
return ITEM_VIEW_TYPE_STUB;
|
||||
}
|
||||
if (mFollowingOnly && !activity.status_user_following) return ITEM_VIEW_TYPE_EMPTY;
|
||||
return ITEM_VIEW_TYPE_STATUS;
|
||||
} else if (Activity.Action.FOLLOW.literal.equals(action) || Activity.Action.FAVORITE.literal.equals(action)
|
||||
|| Activity.Action.RETWEET.literal.equals(action) || Activity.Action.FAVORITED_RETWEET.literal.equals(action)
|
||||
|| Activity.Action.RETWEETED_RETWEET.literal.equals(action) || Activity.Action.RETWEETED_MENTION.literal.equals(action)
|
||||
|| Activity.Action.FAVORITED_MENTION.literal.equals(action) || Activity.Action.LIST_CREATED.literal.equals(action)
|
||||
|| Activity.Action.LIST_MEMBER_ADDED.literal.equals(action)) {
|
||||
} else if (Activity.Action.FOLLOW.equals(action) || Activity.Action.FAVORITE.equals(action)
|
||||
|| Activity.Action.RETWEET.equals(action) || Activity.Action.FAVORITED_RETWEET.equals(action)
|
||||
|| Activity.Action.RETWEETED_RETWEET.equals(action) || Activity.Action.RETWEETED_MENTION.equals(action)
|
||||
|| Activity.Action.FAVORITED_MENTION.equals(action) || Activity.Action.LIST_CREATED.equals(action)
|
||||
|| Activity.Action.LIST_MEMBER_ADDED.equals(action)) {
|
||||
ParcelableActivityUtils.getAfterFilteredSourceIds(activity, mFilteredUserIds,
|
||||
mFollowingOnly);
|
||||
if (ArrayUtils.isEmpty(activity.after_filtered_source_ids)) {
|
||||
|
@ -26,7 +26,7 @@ import com.fasterxml.jackson.core.TreeNode;
|
||||
import com.fasterxml.jackson.jr.tree.JacksonJrSimpleTreeCodec;
|
||||
|
||||
import org.mariotaku.restfu.callback.RawCallback;
|
||||
import org.mariotaku.restfu.http.RestHttpResponse;
|
||||
import org.mariotaku.restfu.http.HttpResponse;
|
||||
import org.mariotaku.twidere.api.twitter.model.DirectMessage;
|
||||
import org.mariotaku.twidere.api.twitter.model.Status;
|
||||
import org.mariotaku.twidere.api.twitter.model.StatusDeletionNotice;
|
||||
@ -49,7 +49,7 @@ public abstract class UserStreamCallback implements RawCallback {
|
||||
private boolean disconnected;
|
||||
|
||||
@Override
|
||||
public final void result(final RestHttpResponse response) throws IOException {
|
||||
public final void result(final HttpResponse response) throws IOException {
|
||||
if (!response.isSuccessful()) {
|
||||
final TwitterException cause = new TwitterException();
|
||||
cause.setHttpResponse(response);
|
||||
|
@ -38,6 +38,8 @@ import android.support.multidex.MultiDexApplication;
|
||||
import com.squareup.okhttp.Dns;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.mariotaku.restfu.http.RestHttpClient;
|
||||
import org.mariotaku.restfu.okhttp.OkHttpRestClient;
|
||||
import org.mariotaku.twidere.BuildConfig;
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.activity.AssistLauncherActivity;
|
||||
@ -49,6 +51,7 @@ import org.mariotaku.twidere.util.DebugModeUtils;
|
||||
import org.mariotaku.twidere.util.ExternalThemeManager;
|
||||
import org.mariotaku.twidere.util.StrictModeUtils;
|
||||
import org.mariotaku.twidere.util.TwidereBugReporter;
|
||||
import org.mariotaku.twidere.util.TwitterAPIFactory;
|
||||
import org.mariotaku.twidere.util.Utils;
|
||||
import org.mariotaku.twidere.util.content.TwidereSQLiteOpenHelper;
|
||||
import org.mariotaku.twidere.util.dagger.ApplicationModule;
|
||||
@ -200,8 +203,7 @@ public class TwidereApplication extends MultiDexApplication implements Constants
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
final ApplicationModule module = getApplicationModule();
|
||||
module.onLowMemory();
|
||||
final DependencyHolder holder = DependencyHolder.get(this);
|
||||
super.onLowMemory();
|
||||
}
|
||||
|
||||
@ -252,7 +254,12 @@ public class TwidereApplication extends MultiDexApplication implements Constants
|
||||
}
|
||||
|
||||
public void reloadConnectivitySettings() {
|
||||
getApplicationModule().reloadConnectivitySettings();
|
||||
DependencyHolder holder = DependencyHolder.get(this);
|
||||
final RestHttpClient client = holder.getRestHttpClient();
|
||||
if (client instanceof OkHttpRestClient) {
|
||||
TwitterAPIFactory.initDefaultHttpClient(this, getSharedPreferences(),
|
||||
((OkHttpRestClient) client).getClient());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -18,8 +18,8 @@ import android.support.v4.content.Loader;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.mariotaku.restfu.annotation.method.GET;
|
||||
import org.mariotaku.restfu.http.HttpRequest;
|
||||
import org.mariotaku.restfu.http.RestHttpClient;
|
||||
import org.mariotaku.restfu.http.RestHttpRequest;
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.activity.iface.IExtendedActivity;
|
||||
import org.mariotaku.twidere.fragment.ProgressDialogFragment;
|
||||
@ -242,10 +242,10 @@ public abstract class CacheDownloadFragment extends BaseSupportFragment implemen
|
||||
|
||||
@Override
|
||||
public InputStream get(String url) throws IOException {
|
||||
final RestHttpRequest.Builder builder = new RestHttpRequest.Builder();
|
||||
final HttpRequest.Builder builder = new HttpRequest.Builder();
|
||||
builder.method(GET.METHOD);
|
||||
builder.url(url);
|
||||
return mRestHttpClient.execute(builder.build()).getBody().stream();
|
||||
return mRestHttpClient.newCall(builder.build()).execute().getBody().stream();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ public class ScheduledStatusesFragment extends AbsContentListRecyclerViewFragmen
|
||||
final long accountId = args.getLong(EXTRA_ACCOUNT_ID, -1);
|
||||
final long sinceId = args.getLong(EXTRA_SINCE_ID, -1);
|
||||
final long maxId = args.getLong(EXTRA_MAX_ID, -1);
|
||||
final ScheduledStatus.State[] states = {ScheduledStatus.State.SCHEDULED, ScheduledStatus.State.FAILED};
|
||||
final String[] states = {ScheduledStatus.State.SCHEDULED, ScheduledStatus.State.FAILED};
|
||||
return new ScheduledStatusesLoader(getActivity(), accountId, sinceId, maxId, states, null);
|
||||
}
|
||||
|
||||
|
@ -38,9 +38,11 @@ public class ScheduledStatusesLoader extends AsyncTaskLoader<List<ScheduledStatu
|
||||
private final long mAccountId;
|
||||
private final long mSinceId;
|
||||
private final long mMaxId;
|
||||
private final ScheduledStatus.State[] mStates;
|
||||
@ScheduledStatus.State
|
||||
private final String[] mStates;
|
||||
|
||||
public ScheduledStatusesLoader(Context context, long accountId, long sinceId, long maxId, ScheduledStatus.State[] states, List<ScheduledStatus> data) {
|
||||
public ScheduledStatusesLoader(Context context, long accountId, long sinceId, long maxId,
|
||||
@ScheduledStatus.State String[] states, List<ScheduledStatus> data) {
|
||||
super(context);
|
||||
mAccountId = accountId;
|
||||
mSinceId = sinceId;
|
||||
@ -60,7 +62,7 @@ public class ScheduledStatusesLoader extends AsyncTaskLoader<List<ScheduledStatu
|
||||
paging.setMaxId(mMaxId);
|
||||
}
|
||||
try {
|
||||
return twitter.getScheduledStatusesList(paging, mStates);
|
||||
return twitter.getScheduledStatuses(paging, mStates);
|
||||
} catch (TwitterException e) {
|
||||
return null;
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ public class ActivityTitleSummaryMessage {
|
||||
boolean shouldUseStarsForLikes,
|
||||
boolean nameFirst) {
|
||||
final Resources resources = context.getResources();
|
||||
if (Activity.Action.FOLLOW.literal.equals(activity.action)) {
|
||||
if (Activity.Action.FOLLOW.equals(activity.action)) {
|
||||
int typeIcon = (R.drawable.ic_activity_action_follow);
|
||||
int color = ContextCompat.getColor(context, R.color.highlight_follow);
|
||||
CharSequence title;
|
||||
@ -47,7 +47,7 @@ public class ActivityTitleSummaryMessage {
|
||||
R.string.activity_about_me_follow_multi, sources, nameFirst));
|
||||
}
|
||||
return new ActivityTitleSummaryMessage(typeIcon, color, title, null);
|
||||
} else if (Activity.Action.FAVORITE.literal.equals(activity.action)) {
|
||||
} else if (Activity.Action.FAVORITE.equals(activity.action)) {
|
||||
int typeIcon;
|
||||
int color;
|
||||
CharSequence title;
|
||||
@ -75,7 +75,7 @@ public class ActivityTitleSummaryMessage {
|
||||
}
|
||||
final String summary = activity.target_statuses[0].text_unescaped;
|
||||
return new ActivityTitleSummaryMessage(typeIcon, color, title, summary);
|
||||
} else if (Activity.Action.RETWEET.literal.equals(activity.action)) {
|
||||
} else if (Activity.Action.RETWEET.equals(activity.action)) {
|
||||
int typeIcon = (R.drawable.ic_activity_action_retweet);
|
||||
int color = ContextCompat.getColor(context, R.color.highlight_retweet);
|
||||
CharSequence title;
|
||||
@ -88,7 +88,7 @@ public class ActivityTitleSummaryMessage {
|
||||
}
|
||||
final String summary = activity.target_statuses[0].text_unescaped;
|
||||
return new ActivityTitleSummaryMessage(typeIcon, color, title, summary);
|
||||
} else if (Activity.Action.FAVORITED_RETWEET.literal.equals(activity.action)) {
|
||||
} else if (Activity.Action.FAVORITED_RETWEET.equals(activity.action)) {
|
||||
if (byFriends) return null;
|
||||
int typeIcon;
|
||||
int color;
|
||||
@ -106,7 +106,7 @@ public class ActivityTitleSummaryMessage {
|
||||
}
|
||||
final String summary = activity.target_statuses[0].text_unescaped;
|
||||
return new ActivityTitleSummaryMessage(typeIcon, color, title, summary);
|
||||
} else if (Activity.Action.RETWEETED_RETWEET.literal.equals(activity.action)) {
|
||||
} else if (Activity.Action.RETWEETED_RETWEET.equals(activity.action)) {
|
||||
if (byFriends) return null;
|
||||
int typeIcon = (R.drawable.ic_activity_action_retweet);
|
||||
int color = ContextCompat.getColor(context, R.color.highlight_retweet);
|
||||
@ -114,7 +114,7 @@ public class ActivityTitleSummaryMessage {
|
||||
R.string.activity_about_me_retweeted_retweet_multi, sources, nameFirst));
|
||||
final String summary = activity.target_statuses[0].text_unescaped;
|
||||
return new ActivityTitleSummaryMessage(typeIcon, color, title, summary);
|
||||
} else if (Activity.Action.RETWEETED_MENTION.literal.equals(activity.action)) {
|
||||
} else if (Activity.Action.RETWEETED_MENTION.equals(activity.action)) {
|
||||
if (byFriends) return null;
|
||||
int typeIcon = (R.drawable.ic_activity_action_retweet);
|
||||
int color = ContextCompat.getColor(context, R.color.highlight_retweet);
|
||||
@ -122,7 +122,7 @@ public class ActivityTitleSummaryMessage {
|
||||
R.string.activity_about_me_retweeted_mention_multi, sources, nameFirst));
|
||||
final String summary = activity.target_statuses[0].text_unescaped;
|
||||
return new ActivityTitleSummaryMessage(typeIcon, color, title, summary);
|
||||
} else if (Activity.Action.FAVORITED_MENTION.literal.equals(activity.action)) {
|
||||
} else if (Activity.Action.FAVORITED_MENTION.equals(activity.action)) {
|
||||
if (byFriends) return null;
|
||||
int typeIcon;
|
||||
int color;
|
||||
@ -140,7 +140,7 @@ public class ActivityTitleSummaryMessage {
|
||||
}
|
||||
final String summary = activity.target_statuses[0].text_unescaped;
|
||||
return new ActivityTitleSummaryMessage(typeIcon, color, title, summary);
|
||||
} else if (Activity.Action.LIST_CREATED.literal.equals(activity.action)) {
|
||||
} else if (Activity.Action.LIST_CREATED.equals(activity.action)) {
|
||||
if (!byFriends) return null;
|
||||
int typeIcon = (R.drawable.ic_activity_action_list_added);
|
||||
CharSequence title = (getTitleStringByFriends(resources, manager, R.string.activity_by_friends_list_created,
|
||||
@ -156,7 +156,7 @@ public class ActivityTitleSummaryMessage {
|
||||
firstLine = false;
|
||||
}
|
||||
return new ActivityTitleSummaryMessage(typeIcon, defaultColor, title, sb);
|
||||
} else if (Activity.Action.LIST_MEMBER_ADDED.literal.equals(activity.action)) {
|
||||
} else if (Activity.Action.LIST_MEMBER_ADDED.equals(activity.action)) {
|
||||
if (byFriends) return null;
|
||||
CharSequence title;
|
||||
int icon = R.drawable.ic_activity_action_list_added;
|
||||
|
@ -45,7 +45,7 @@ import com.twitter.Extractor;
|
||||
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.mariotaku.restfu.http.ContentType;
|
||||
import org.mariotaku.restfu.http.mime.FileTypedData;
|
||||
import org.mariotaku.restfu.http.mime.FileBody;
|
||||
import org.mariotaku.sqliteqb.library.Expression;
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.R;
|
||||
@ -554,8 +554,8 @@ public class BackgroundOperationService extends IntentService implements Constan
|
||||
} else {
|
||||
contentType = ContentType.parse(o.outMimeType);
|
||||
}
|
||||
final MediaUploadResponse uploadResp = upload.uploadMedia(new FileTypedData(is,
|
||||
file.getName(), file.length(), contentType));
|
||||
final MediaUploadResponse uploadResp = upload.uploadMedia(
|
||||
new FileBody(is, file.getName(), file.length(), contentType));
|
||||
mediaIds[i] = uploadResp.getId();
|
||||
}
|
||||
} catch (final FileNotFoundException e) {
|
||||
|
@ -18,8 +18,8 @@ import android.util.Log;
|
||||
import org.mariotaku.restfu.http.Authorization;
|
||||
import org.mariotaku.restfu.http.ContentType;
|
||||
import org.mariotaku.restfu.http.Endpoint;
|
||||
import org.mariotaku.restfu.http.RestHttpResponse;
|
||||
import org.mariotaku.restfu.http.mime.TypedData;
|
||||
import org.mariotaku.restfu.http.HttpResponse;
|
||||
import org.mariotaku.restfu.http.mime.Body;
|
||||
import org.mariotaku.sqliteqb.library.Expression;
|
||||
import org.mariotaku.twidere.BuildConfig;
|
||||
import org.mariotaku.twidere.Constants;
|
||||
@ -267,10 +267,10 @@ public class StreamingService extends Service implements Constants {
|
||||
public void onException(final Throwable ex) {
|
||||
if (ex instanceof TwitterException) {
|
||||
Log.w(LOGTAG, String.format("Error %d", ((TwitterException) ex).getStatusCode()), ex);
|
||||
final RestHttpResponse response = ((TwitterException) ex).getHttpResponse();
|
||||
final HttpResponse response = ((TwitterException) ex).getHttpResponse();
|
||||
if (response != null) {
|
||||
try {
|
||||
final TypedData body = response.getBody();
|
||||
final Body body = response.getBody();
|
||||
if (body != null) {
|
||||
final ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
body.writeTo(os);
|
||||
|
@ -34,16 +34,16 @@ import org.attoparser.markup.MarkupAttoParser;
|
||||
import org.attoparser.markup.html.AbstractStandardNonValidatingHtmlAttoHandler;
|
||||
import org.attoparser.markup.html.HtmlParsingConfiguration;
|
||||
import org.attoparser.markup.html.elements.IHtmlElement;
|
||||
import org.mariotaku.restfu.Pair;
|
||||
import org.mariotaku.restfu.RestAPIFactory;
|
||||
import org.mariotaku.restfu.RestClient;
|
||||
import org.mariotaku.restfu.annotation.method.GET;
|
||||
import org.mariotaku.restfu.annotation.method.POST;
|
||||
import org.mariotaku.restfu.http.Endpoint;
|
||||
import org.mariotaku.restfu.http.RestHttpRequest;
|
||||
import org.mariotaku.restfu.http.RestHttpResponse;
|
||||
import org.mariotaku.restfu.http.mime.BaseTypedData;
|
||||
import org.mariotaku.restfu.http.mime.FormTypedBody;
|
||||
import org.mariotaku.restfu.http.HttpRequest;
|
||||
import org.mariotaku.restfu.http.HttpResponse;
|
||||
import org.mariotaku.restfu.http.MultiValueMap;
|
||||
import org.mariotaku.restfu.http.mime.BaseBody;
|
||||
import org.mariotaku.restfu.http.mime.FormBody;
|
||||
import org.mariotaku.restfu.okhttp.OkHttpRestClient;
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
@ -55,8 +55,6 @@ import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.net.CookieManager;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class OAuthPasswordAuthenticator implements Constants {
|
||||
@ -149,32 +147,32 @@ public class OAuthPasswordAuthenticator implements Constants {
|
||||
|
||||
private AuthorizeRequestData getVerificationData(AuthorizeResponseData authorizeResponseData,
|
||||
@Nullable String challengeResponse) throws IOException, LoginVerificationException {
|
||||
RestHttpResponse response = null;
|
||||
HttpResponse response = null;
|
||||
try {
|
||||
final AuthorizeRequestData data = new AuthorizeRequestData();
|
||||
final List<Pair<String, String>> params = new ArrayList<>();
|
||||
final MultiValueMap<String> params = new MultiValueMap<>();
|
||||
final AuthorizeResponseData.Verification verification = authorizeResponseData.verification;
|
||||
params.add(Pair.create("authenticity_token", verification.authenticityToken));
|
||||
params.add(Pair.create("user_id", verification.userId));
|
||||
params.add(Pair.create("challenge_id", verification.challengeId));
|
||||
params.add(Pair.create("challenge_type", verification.challengeType));
|
||||
params.add(Pair.create("platform", verification.platform));
|
||||
params.add(Pair.create("redirect_after_login", verification.redirectAfterLogin));
|
||||
final ArrayList<Pair<String, String>> requestHeaders = new ArrayList<>();
|
||||
requestHeaders.add(Pair.create("User-Agent", userAgent));
|
||||
params.add("authenticity_token", verification.authenticityToken);
|
||||
params.add("user_id", verification.userId);
|
||||
params.add("challenge_id", verification.challengeId);
|
||||
params.add("challenge_type", verification.challengeType);
|
||||
params.add("platform", verification.platform);
|
||||
params.add("redirect_after_login", verification.redirectAfterLogin);
|
||||
final MultiValueMap<String> requestHeaders = new MultiValueMap<>();
|
||||
requestHeaders.add("User-Agent", userAgent);
|
||||
|
||||
if (!TextUtils.isEmpty(challengeResponse)) {
|
||||
params.add(Pair.create("challenge_response", challengeResponse));
|
||||
params.add("challenge_response", challengeResponse);
|
||||
}
|
||||
final FormTypedBody authorizationResultBody = new FormTypedBody(params);
|
||||
final FormBody authorizationResultBody = new FormBody(params);
|
||||
|
||||
final RestHttpRequest.Builder authorizeResultBuilder = new RestHttpRequest.Builder();
|
||||
final HttpRequest.Builder authorizeResultBuilder = new HttpRequest.Builder();
|
||||
authorizeResultBuilder.method(POST.METHOD);
|
||||
authorizeResultBuilder.url(endpoint.construct("/account/login_verification"));
|
||||
authorizeResultBuilder.headers(requestHeaders);
|
||||
authorizeResultBuilder.body(authorizationResultBody);
|
||||
authorizeResultBuilder.extra(RequestType.API);
|
||||
response = client.execute(authorizeResultBuilder.build());
|
||||
authorizeResultBuilder.tag(RequestType.API);
|
||||
response = client.newCall(authorizeResultBuilder.build()).execute();
|
||||
parseAuthorizeRequestData(response, data);
|
||||
if (TextUtils.isEmpty(data.authenticityToken)) {
|
||||
throw new LoginVerificationException();
|
||||
@ -187,7 +185,7 @@ public class OAuthPasswordAuthenticator implements Constants {
|
||||
}
|
||||
}
|
||||
|
||||
private void parseAuthorizeRequestData(RestHttpResponse response, final AuthorizeRequestData data) throws AttoParseException, IOException {
|
||||
private void parseAuthorizeRequestData(HttpResponse response, final AuthorizeRequestData data) throws AttoParseException, IOException {
|
||||
final HtmlParsingConfiguration conf = new HtmlParsingConfiguration();
|
||||
final IAttoHandler handler = new AbstractStandardNonValidatingHtmlAttoHandler(conf) {
|
||||
boolean isOAuthFormOpened;
|
||||
@ -233,35 +231,35 @@ public class OAuthPasswordAuthenticator implements Constants {
|
||||
}
|
||||
}
|
||||
};
|
||||
PARSER.parse(BaseTypedData.reader(response.getBody()), handler);
|
||||
PARSER.parse(BaseBody.reader(response.getBody()), handler);
|
||||
}
|
||||
|
||||
private AuthorizeResponseData getAuthorizeResponseData(OAuthToken requestToken,
|
||||
AuthorizeRequestData authorizeRequestData,
|
||||
String username, String password) throws IOException, AuthenticationException {
|
||||
RestHttpResponse response = null;
|
||||
HttpResponse response = null;
|
||||
try {
|
||||
final AuthorizeResponseData data = new AuthorizeResponseData();
|
||||
final List<Pair<String, String>> params = new ArrayList<>();
|
||||
params.add(Pair.create("oauth_token", requestToken.getOauthToken()));
|
||||
params.add(Pair.create("authenticity_token", authorizeRequestData.authenticityToken));
|
||||
params.add(Pair.create("redirect_after_login", authorizeRequestData.redirectAfterLogin));
|
||||
final MultiValueMap<String> params = new MultiValueMap<>();
|
||||
params.add("oauth_token", requestToken.getOauthToken());
|
||||
params.add("authenticity_token", authorizeRequestData.authenticityToken);
|
||||
params.add("redirect_after_login", authorizeRequestData.redirectAfterLogin);
|
||||
if (!TextUtils.isEmpty(username) && !TextUtils.isEmpty(password)) {
|
||||
params.add(Pair.create("session[username_or_email]", username));
|
||||
params.add(Pair.create("session[password]", password));
|
||||
params.add("session[username_or_email]", username);
|
||||
params.add("session[password]", password);
|
||||
}
|
||||
final FormTypedBody authorizationResultBody = new FormTypedBody(params);
|
||||
final ArrayList<Pair<String, String>> requestHeaders = new ArrayList<>();
|
||||
requestHeaders.add(Pair.create("User-Agent", userAgent));
|
||||
final FormBody authorizationResultBody = new FormBody(params);
|
||||
final MultiValueMap<String> requestHeaders = new MultiValueMap<>();
|
||||
requestHeaders.add("User-Agent", userAgent);
|
||||
data.referer = authorizeRequestData.referer;
|
||||
|
||||
final RestHttpRequest.Builder authorizeResultBuilder = new RestHttpRequest.Builder();
|
||||
final HttpRequest.Builder authorizeResultBuilder = new HttpRequest.Builder();
|
||||
authorizeResultBuilder.method(POST.METHOD);
|
||||
authorizeResultBuilder.url(endpoint.construct("/oauth/authorize"));
|
||||
authorizeResultBuilder.headers(requestHeaders);
|
||||
authorizeResultBuilder.body(authorizationResultBody);
|
||||
authorizeResultBuilder.extra(RequestType.API);
|
||||
response = client.execute(authorizeResultBuilder.build());
|
||||
authorizeResultBuilder.tag(RequestType.API);
|
||||
response = client.newCall(authorizeResultBuilder.build()).execute();
|
||||
final HtmlParsingConfiguration conf = new HtmlParsingConfiguration();
|
||||
final IAttoHandler handler = new AbstractStandardNonValidatingHtmlAttoHandler(conf) {
|
||||
boolean isOAuthPinDivOpened;
|
||||
@ -363,7 +361,7 @@ public class OAuthPasswordAuthenticator implements Constants {
|
||||
}
|
||||
}
|
||||
};
|
||||
PARSER.parse(BaseTypedData.reader(response.getBody()), handler);
|
||||
PARSER.parse(BaseBody.reader(response.getBody()), handler);
|
||||
return data;
|
||||
} catch (AttoParseException e) {
|
||||
throw new AuthenticationException("Malformed HTML", e);
|
||||
@ -374,21 +372,21 @@ public class OAuthPasswordAuthenticator implements Constants {
|
||||
|
||||
private AuthorizeRequestData getAuthorizeRequestData(OAuthToken requestToken) throws IOException,
|
||||
AuthenticationException {
|
||||
RestHttpResponse response = null;
|
||||
HttpResponse response = null;
|
||||
try {
|
||||
final AuthorizeRequestData data = new AuthorizeRequestData();
|
||||
final RestHttpRequest.Builder authorizePageBuilder = new RestHttpRequest.Builder();
|
||||
final HttpRequest.Builder authorizePageBuilder = new HttpRequest.Builder();
|
||||
authorizePageBuilder.method(GET.METHOD);
|
||||
authorizePageBuilder.url(endpoint.construct("/oauth/authorize",
|
||||
Pair.create("oauth_token", requestToken.getOauthToken())));
|
||||
authorizePageBuilder.url(endpoint.construct("/oauth/authorize", new String[]{"oauth_token",
|
||||
requestToken.getOauthToken()}));
|
||||
data.referer = Endpoint.constructUrl("https://api.twitter.com/oauth/authorize",
|
||||
Pair.create("oauth_token", requestToken.getOauthToken()));
|
||||
final ArrayList<Pair<String, String>> requestHeaders = new ArrayList<>();
|
||||
requestHeaders.add(Pair.create("User-Agent", userAgent));
|
||||
new String[]{"oauth_token", requestToken.getOauthToken()});
|
||||
final MultiValueMap<String> requestHeaders = new MultiValueMap<>();
|
||||
requestHeaders.add("User-Agent", userAgent);
|
||||
authorizePageBuilder.headers(requestHeaders);
|
||||
authorizePageBuilder.extra(RequestType.API);
|
||||
final RestHttpRequest authorizePageRequest = authorizePageBuilder.build();
|
||||
response = client.execute(authorizePageRequest);
|
||||
authorizePageBuilder.tag(RequestType.API);
|
||||
final HttpRequest authorizePageRequest = authorizePageBuilder.build();
|
||||
response = client.newCall(authorizePageRequest).execute();
|
||||
parseAuthorizeRequestData(response, data);
|
||||
if (TextUtils.isEmpty(data.authenticityToken)) {
|
||||
throw new AuthenticationException();
|
||||
|
@ -24,10 +24,10 @@ import android.net.Uri;
|
||||
|
||||
import org.mariotaku.restfu.annotation.method.GET;
|
||||
import org.mariotaku.restfu.http.ContentType;
|
||||
import org.mariotaku.restfu.http.HttpRequest;
|
||||
import org.mariotaku.restfu.http.HttpResponse;
|
||||
import org.mariotaku.restfu.http.RestHttpClient;
|
||||
import org.mariotaku.restfu.http.RestHttpRequest;
|
||||
import org.mariotaku.restfu.http.RestHttpResponse;
|
||||
import org.mariotaku.restfu.http.mime.TypedData;
|
||||
import org.mariotaku.restfu.http.mime.Body;
|
||||
import org.mariotaku.twidere.activity.support.ThemedImagePickerActivity;
|
||||
import org.mariotaku.twidere.model.RequestType;
|
||||
|
||||
@ -44,13 +44,13 @@ public class RestFuNetworkStreamDownloader extends ThemedImagePickerActivity.Net
|
||||
|
||||
public DownloadResult get(Uri uri) throws IOException {
|
||||
final RestHttpClient client = TwitterAPIFactory.getDefaultHttpClient(getContext());
|
||||
final RestHttpRequest.Builder builder = new RestHttpRequest.Builder();
|
||||
final HttpRequest.Builder builder = new HttpRequest.Builder();
|
||||
builder.method(GET.METHOD);
|
||||
builder.url(uri.toString());
|
||||
builder.extra(RequestType.MEDIA);
|
||||
final RestHttpResponse response = client.execute(builder.build());
|
||||
builder.tag(RequestType.MEDIA);
|
||||
final HttpResponse response = client.newCall(builder.build()).execute();
|
||||
if (response.isSuccessful()) {
|
||||
final TypedData body = response.getBody();
|
||||
final Body body = response.getBody();
|
||||
final ContentType contentType = body.contentType();
|
||||
return DownloadResult.get(body.stream(), contentType != null ? contentType.getContentType() : "image/*");
|
||||
} else {
|
||||
|
@ -22,23 +22,18 @@ import com.squareup.okhttp.Response;
|
||||
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.mariotaku.restfu.ExceptionFactory;
|
||||
import org.mariotaku.restfu.HttpRequestFactory;
|
||||
import org.mariotaku.restfu.Pair;
|
||||
import org.mariotaku.restfu.RequestInfoFactory;
|
||||
import org.mariotaku.restfu.RestAPIFactory;
|
||||
import org.mariotaku.restfu.RestClient;
|
||||
import org.mariotaku.restfu.RestMethodInfo;
|
||||
import org.mariotaku.restfu.RestRequestInfo;
|
||||
import org.mariotaku.restfu.annotation.RestMethod;
|
||||
import org.mariotaku.restfu.annotation.param.MethodExtra;
|
||||
import org.mariotaku.restfu.RestRequest;
|
||||
import org.mariotaku.restfu.http.Authorization;
|
||||
import org.mariotaku.restfu.http.Endpoint;
|
||||
import org.mariotaku.restfu.http.FileValue;
|
||||
import org.mariotaku.restfu.http.HttpRequest;
|
||||
import org.mariotaku.restfu.http.HttpResponse;
|
||||
import org.mariotaku.restfu.http.MultiValueMap;
|
||||
import org.mariotaku.restfu.http.RestHttpClient;
|
||||
import org.mariotaku.restfu.http.RestHttpRequest;
|
||||
import org.mariotaku.restfu.http.RestHttpResponse;
|
||||
import org.mariotaku.restfu.http.mime.StringTypedData;
|
||||
import org.mariotaku.restfu.http.mime.TypedData;
|
||||
import org.mariotaku.restfu.http.SimpleValueMap;
|
||||
import org.mariotaku.restfu.http.mime.BaseBody;
|
||||
import org.mariotaku.restfu.http.mime.Body;
|
||||
import org.mariotaku.restfu.okhttp.OkHttpRestClient;
|
||||
import org.mariotaku.sqliteqb.library.Expression;
|
||||
import org.mariotaku.twidere.BuildConfig;
|
||||
@ -55,7 +50,7 @@ import org.mariotaku.twidere.api.twitter.auth.OAuthAuthorization;
|
||||
import org.mariotaku.twidere.api.twitter.auth.OAuthEndpoint;
|
||||
import org.mariotaku.twidere.api.twitter.auth.OAuthSupport;
|
||||
import org.mariotaku.twidere.api.twitter.auth.OAuthToken;
|
||||
import org.mariotaku.twidere.api.twitter.util.TwitterConverter;
|
||||
import org.mariotaku.twidere.api.twitter.util.TwitterConverterFactory;
|
||||
import org.mariotaku.twidere.model.ConsumerKeyType;
|
||||
import org.mariotaku.twidere.model.ParcelableCredentials;
|
||||
import org.mariotaku.twidere.model.RequestType;
|
||||
@ -68,11 +63,7 @@ import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -90,6 +81,22 @@ public class TwitterAPIFactory implements TwidereConstants {
|
||||
|
||||
public static final String CARDS_PLATFORM_ANDROID_12 = "Android-12";
|
||||
|
||||
|
||||
private static final SimpleValueMap sConstantPoll = new SimpleValueMap();
|
||||
|
||||
static {
|
||||
sConstantPoll.put("include_cards", "true");
|
||||
sConstantPoll.put("cards_platform", CARDS_PLATFORM_ANDROID_12);
|
||||
sConstantPoll.put("include_entities", "true");
|
||||
sConstantPoll.put("include_my_retweet", "true");
|
||||
sConstantPoll.put("include_rts", "true");
|
||||
sConstantPoll.put("include_reply_count", "true");
|
||||
sConstantPoll.put("include_descendent_reply_count", "true");
|
||||
sConstantPoll.put("full_text", "true");
|
||||
sConstantPoll.put("model_version", "7");
|
||||
sConstantPoll.put("skip_aggregation", "false");
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
public static Twitter getDefaultTwitterInstance(final Context context, final boolean includeEntities) {
|
||||
if (context == null) return null;
|
||||
@ -138,10 +145,14 @@ public class TwitterAPIFactory implements TwidereConstants {
|
||||
|
||||
public static RestHttpClient createHttpClient(final Context context, final SharedPreferences prefs) {
|
||||
final OkHttpClient client = new OkHttpClient();
|
||||
initDefaultHttpClient(context, prefs, client);
|
||||
return new OkHttpRestClient(client);
|
||||
}
|
||||
|
||||
public static void initDefaultHttpClient(Context context, SharedPreferences prefs, OkHttpClient client) {
|
||||
updateHttpClientConfiguration(context, prefs, client);
|
||||
DebugModeUtils.initForHttpClient(client);
|
||||
NetworkUsageUtils.initForHttpClient(context, client);
|
||||
return new OkHttpRestClient(client);
|
||||
}
|
||||
|
||||
@SuppressLint("SSLCertificateSocketFactoryGetInsecure")
|
||||
@ -152,8 +163,6 @@ public class TwitterAPIFactory implements TwidereConstants {
|
||||
final boolean enableProxy = prefs.getBoolean(KEY_ENABLE_PROXY, false);
|
||||
|
||||
client.setConnectTimeout(connectionTimeout, TimeUnit.SECONDS);
|
||||
client.setReadTimeout(0, TimeUnit.SECONDS);
|
||||
client.setWriteTimeout(0, TimeUnit.SECONDS);
|
||||
final SSLSocketFactory sslSocketFactory;
|
||||
if (ignoreSslError) {
|
||||
// We intentionally use insecure connections
|
||||
@ -235,12 +244,13 @@ public class TwitterAPIFactory implements TwidereConstants {
|
||||
userAgent = getTwidereUserAgent(context);
|
||||
}
|
||||
DependencyHolder holder = DependencyHolder.get(context);
|
||||
factory.setClient(holder.getRestHttpClient());
|
||||
factory.setConverter(new TwitterConverter());
|
||||
factory.setHttpClient(holder.getRestHttpClient());
|
||||
final TwitterConverterFactory restConverterFactory = new TwitterConverterFactory();
|
||||
factory.setRestConverterFactory(restConverterFactory);
|
||||
factory.setEndpoint(endpoint);
|
||||
factory.setAuthorization(auth);
|
||||
factory.setRequestInfoFactory(new TwidereRequestInfoFactory(extraRequestParams));
|
||||
factory.setHttpRequestFactory(new TwidereHttpRequestFactory(userAgent));
|
||||
factory.setConstantPool(sConstantPoll);
|
||||
factory.setExceptionFactory(new TwidereExceptionFactory());
|
||||
return factory.build(cls);
|
||||
}
|
||||
@ -262,8 +272,7 @@ public class TwitterAPIFactory implements TwidereConstants {
|
||||
public static <T> T getInstance(final Context context, final Endpoint endpoint,
|
||||
final ParcelableCredentials credentials,
|
||||
final Map<String, String> extraRequestParams, final Class<T> cls) {
|
||||
return TwitterAPIFactory.getInstance(context, endpoint, getAuthorization(credentials),
|
||||
extraRequestParams, cls);
|
||||
return getInstance(context, endpoint, getAuthorization(credentials), extraRequestParams, cls);
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
@ -306,7 +315,7 @@ public class TwitterAPIFactory implements TwidereConstants {
|
||||
domain = "caps";
|
||||
versionSuffix = null;
|
||||
} else {
|
||||
throw new TwitterConverter.UnsupportedTypeException(cls);
|
||||
throw new TwitterConverterFactory.UnsupportedTypeException(cls);
|
||||
}
|
||||
final String endpointUrl;
|
||||
endpointUrl = getApiUrl(apiUrlFormat, domain, versionSuffix);
|
||||
@ -348,13 +357,13 @@ public class TwitterAPIFactory implements TwidereConstants {
|
||||
return new EmptyAuthorization();
|
||||
}
|
||||
|
||||
private static void addParam(List<Pair<String, String>> params, String name, Object value) {
|
||||
params.add(Pair.create(name, String.valueOf(value)));
|
||||
private static void addParam(MultiValueMap<String> params, String name, Object value) {
|
||||
params.add(name, String.valueOf(value));
|
||||
}
|
||||
|
||||
private static void addPart(List<Pair<String, TypedData>> params, String name, Object value) {
|
||||
final TypedData typedData = new StringTypedData(String.valueOf(value), Charset.defaultCharset());
|
||||
params.add(Pair.create(name, typedData));
|
||||
private static void addPart(MultiValueMap<Body> params, String name, Object value) {
|
||||
final Body typedData = BaseBody.wrap(value);
|
||||
params.add(name, typedData);
|
||||
}
|
||||
|
||||
public static boolean verifyApiFormat(@NonNull String format) {
|
||||
@ -489,6 +498,7 @@ public class TwitterAPIFactory implements TwidereConstants {
|
||||
final String[] projection = {TwidereDataStore.Accounts.CONSUMER_KEY, TwidereDataStore.Accounts.CONSUMER_SECRET};
|
||||
final String selection = Expression.equals(TwidereDataStore.Accounts.ACCOUNT_ID, accountId).getSQL();
|
||||
final Cursor c = context.getContentResolver().query(TwidereDataStore.Accounts.CONTENT_URI, projection, selection, null, null);
|
||||
if (c == null) return ConsumerKeyType.UNKNOWN;
|
||||
//noinspection TryFinallyCanBeTryWithResources
|
||||
try {
|
||||
if (c.moveToPosition(0))
|
||||
@ -509,82 +519,7 @@ public class TwitterAPIFactory implements TwidereConstants {
|
||||
return TwitterContentUtils.isOfficialKey(context, consumerKey, consumerSecret);
|
||||
}
|
||||
|
||||
public static class Options {
|
||||
|
||||
final HashMap<String, String> extras = new HashMap<>();
|
||||
|
||||
public void putExtra(String key, String value) {
|
||||
extras.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TwidereRequestInfoFactory implements RequestInfoFactory {
|
||||
|
||||
private static Map<String, String> sDefaultRequestParams;
|
||||
|
||||
static {
|
||||
final HashMap<String, String> map = new HashMap<>();
|
||||
try {
|
||||
map.put("include_cards", "true");
|
||||
map.put("cards_platform", CARDS_PLATFORM_ANDROID_12);
|
||||
map.put("include_entities", "true");
|
||||
map.put("include_my_retweet", "true");
|
||||
map.put("include_rts", "true");
|
||||
map.put("include_reply_count", "true");
|
||||
map.put("include_descendent_reply_count", "true");
|
||||
map.put("full_text", "true");
|
||||
map.put("model_version", "7");
|
||||
map.put("skip_aggregation", "false");
|
||||
} finally {
|
||||
sDefaultRequestParams = Collections.unmodifiableMap(map);
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<String, String> extraRequestParams;
|
||||
|
||||
TwidereRequestInfoFactory(Map<String, String> extraRequestParams) {
|
||||
this.extraRequestParams = extraRequestParams;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RestRequestInfo 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 FileValue file = methodInfo.getFile();
|
||||
final Map<String, Object> extras = methodInfo.getExtras();
|
||||
final MethodExtra methodExtra = methodInfo.getMethodExtra();
|
||||
if (methodExtra != null && "extra_params".equals(methodExtra.name())) {
|
||||
final String[] extraParamKeys = methodExtra.values();
|
||||
if (parts.isEmpty()) {
|
||||
final List<Pair<String, String>> params = method.hasBody() ? forms : queries;
|
||||
for (String key : extraParamKeys) {
|
||||
if (extraRequestParams != null && extraRequestParams.containsKey(key)) {
|
||||
addParam(params, key, extraRequestParams.get(key));
|
||||
} else {
|
||||
addParam(params, key, sDefaultRequestParams.get(key));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (String key : extraParamKeys) {
|
||||
if (extraRequestParams != null && extraRequestParams.containsKey(key)) {
|
||||
addPart(parts, key, extraRequestParams.get(key));
|
||||
} else {
|
||||
addPart(parts, key, sDefaultRequestParams.get(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new RestRequestInfo(method.value(), path, queries, forms, headers, parts, file,
|
||||
methodInfo.getBody(), extras);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TwidereHttpRequestFactory implements HttpRequestFactory {
|
||||
public static class TwidereHttpRequestFactory implements HttpRequest.Factory {
|
||||
|
||||
private final String userAgent;
|
||||
|
||||
@ -593,28 +528,31 @@ public class TwitterAPIFactory implements TwidereConstants {
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestHttpRequest create(@NonNull Endpoint endpoint, @NonNull RestRequestInfo info,
|
||||
public HttpRequest create(@NonNull Endpoint endpoint, @NonNull RestRequest 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());
|
||||
MultiValueMap<String> headers = info.getHeaders();
|
||||
if (headers == null) {
|
||||
headers = new MultiValueMap<>();
|
||||
}
|
||||
|
||||
if (authorization != null && authorization.hasAuthorization()) {
|
||||
headers.add(Pair.create("Authorization", authorization.getHeader(endpoint, info)));
|
||||
headers.add("Authorization", authorization.getHeader(endpoint, info));
|
||||
}
|
||||
headers.add(Pair.create("User-Agent", userAgent));
|
||||
return new RestHttpRequest(restMethod, url, headers, info.getBody(), RequestType.API);
|
||||
headers.add("User-Agent", userAgent);
|
||||
return new HttpRequest(restMethod, url, headers, info.getBody(), RequestType.API);
|
||||
}
|
||||
}
|
||||
|
||||
public static class TwidereExceptionFactory implements ExceptionFactory {
|
||||
@Override
|
||||
public Exception newException(Throwable cause, RestHttpRequest request, RestHttpResponse response) {
|
||||
public Exception newException(Throwable cause, HttpRequest request, HttpResponse response) {
|
||||
final TwitterException te;
|
||||
if (cause != null) {
|
||||
te = new TwitterException(cause);
|
||||
} else {
|
||||
te = TwitterConverter.parseTwitterException(response);
|
||||
te = TwitterConverterFactory.parseTwitterException(response);
|
||||
}
|
||||
te.setHttpResponse(response);
|
||||
return te;
|
||||
|
@ -25,7 +25,7 @@ import android.support.annotation.NonNull;
|
||||
import android.support.v4.util.LongSparseArray;
|
||||
import android.util.Log;
|
||||
|
||||
import org.mariotaku.restfu.http.mime.FileTypedData;
|
||||
import org.mariotaku.restfu.http.mime.FileBody;
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.api.twitter.Twitter;
|
||||
import org.mariotaku.twidere.api.twitter.TwitterException;
|
||||
@ -174,7 +174,7 @@ public class TwitterWrapper implements Constants {
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = context.getContentResolver().openInputStream(imageUri);
|
||||
twitter.updateProfileBannerImage(new FileTypedData(is, "image", -1, null));
|
||||
twitter.updateProfileBannerImage(new FileBody(is, "image", -1, null));
|
||||
} finally {
|
||||
Utils.closeSilently(is);
|
||||
if (deleteImage && "file".equals(imageUri.getScheme())) {
|
||||
@ -192,7 +192,7 @@ public class TwitterWrapper implements Constants {
|
||||
InputStream is = null;
|
||||
try {
|
||||
is = context.getContentResolver().openInputStream(imageUri);
|
||||
return twitter.updateProfileImage(new FileTypedData(is, "image", -1, null));
|
||||
return twitter.updateProfileImage(new FileBody(is, "image", -1, null));
|
||||
} finally {
|
||||
Utils.closeSilently(is);
|
||||
if (deleteImage && "file".equals(imageUri.getScheme())) {
|
||||
|
@ -31,10 +31,12 @@ import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
||||
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
|
||||
import com.nostra13.universalimageloader.utils.L;
|
||||
import com.squareup.okhttp.Dns;
|
||||
import com.squareup.okhttp.OkHttpClient;
|
||||
import com.squareup.otto.Bus;
|
||||
import com.squareup.otto.ThreadEnforcer;
|
||||
|
||||
import org.mariotaku.restfu.http.RestHttpClient;
|
||||
import org.mariotaku.restfu.okhttp.OkHttpRestClient;
|
||||
import org.mariotaku.twidere.BuildConfig;
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.app.TwidereApplication;
|
||||
@ -219,17 +221,6 @@ public class ApplicationModule implements Constants {
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadConnectivitySettings() {
|
||||
// imageDownloader.reloadConnectivitySettings();
|
||||
// if (restHttpClient instanceof OkHttpRestClient) {
|
||||
// OkHttpClient okHttpClient = ((OkHttpRestClient) restHttpClient).getClient();
|
||||
// TwitterAPIFactory.updateHttpClientConfiguration(application, sharedPreferences, okHttpClient);
|
||||
// }
|
||||
}
|
||||
|
||||
public void onLowMemory() {
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public HotMobiLogger hotMobiLogger() {
|
||||
|
@ -31,15 +31,15 @@ import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
|
||||
import com.squareup.pollexor.Thumbor;
|
||||
import com.squareup.pollexor.ThumborUrlBuilder;
|
||||
|
||||
import org.mariotaku.restfu.Pair;
|
||||
import org.mariotaku.restfu.RestRequestInfo;
|
||||
import org.mariotaku.restfu.RestRequest;
|
||||
import org.mariotaku.restfu.annotation.method.GET;
|
||||
import org.mariotaku.restfu.http.Authorization;
|
||||
import org.mariotaku.restfu.http.Endpoint;
|
||||
import org.mariotaku.restfu.http.HttpRequest;
|
||||
import org.mariotaku.restfu.http.HttpResponse;
|
||||
import org.mariotaku.restfu.http.MultiValueMap;
|
||||
import org.mariotaku.restfu.http.RestHttpClient;
|
||||
import org.mariotaku.restfu.http.RestHttpRequest;
|
||||
import org.mariotaku.restfu.http.RestHttpResponse;
|
||||
import org.mariotaku.restfu.http.mime.TypedData;
|
||||
import org.mariotaku.restfu.http.mime.Body;
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.mariotaku.twidere.api.twitter.auth.OAuthAuthorization;
|
||||
@ -58,8 +58,6 @@ import org.mariotaku.twidere.util.media.preview.PreviewMediaExtractor;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class TwidereImageDownloader extends BaseImageDownloader implements Constants {
|
||||
@ -161,11 +159,11 @@ public class TwidereImageDownloader extends BaseImageDownloader implements Const
|
||||
}
|
||||
Uri modifiedUri = getReplacedUri(uri, account != null ? account.api_url_format : null);
|
||||
|
||||
final List<Pair<String, String>> additionalHeaders = new ArrayList<>();
|
||||
final MultiValueMap<String> additionalHeaders = new MultiValueMap<>();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
||||
additionalHeaders.add(Pair.create("Accept", "image/webp, */*"));
|
||||
additionalHeaders.add("Accept", "image/webp, */*");
|
||||
}
|
||||
additionalHeaders.add(Pair.create("User-Agent", mUserAgent));
|
||||
additionalHeaders.add("User-Agent", mUserAgent);
|
||||
final String method = GET.METHOD;
|
||||
final String requestUri;
|
||||
if (auth != null && auth.hasAuthorization()) {
|
||||
@ -175,28 +173,28 @@ public class TwidereImageDownloader extends BaseImageDownloader implements Const
|
||||
} else {
|
||||
endpoint = new Endpoint(getEndpoint(modifiedUri));
|
||||
}
|
||||
final List<Pair<String, String>> queries = new ArrayList<>();
|
||||
final MultiValueMap<String> queries = new MultiValueMap<>();
|
||||
for (String name : uri.getQueryParameterNames()) {
|
||||
for (String value : uri.getQueryParameters(name)) {
|
||||
queries.add(Pair.create(name, value));
|
||||
queries.add(name, value);
|
||||
}
|
||||
}
|
||||
final RestRequestInfo info = new RestRequestInfo(method, uri.getPath(), queries, null,
|
||||
additionalHeaders, null, null, null, null);
|
||||
additionalHeaders.add(Pair.create("Authorization", auth.getHeader(endpoint, info)));
|
||||
final RestRequest info = new RestRequest(method, false, uri.getPath(), additionalHeaders,
|
||||
queries, null, null, null, null);
|
||||
additionalHeaders.add("Authorization", auth.getHeader(endpoint, info));
|
||||
requestUri = modifiedUri.toString();
|
||||
} else if (mThumbor != null) {
|
||||
requestUri = mThumbor.buildImage(modifiedUri.toString()).filter(ThumborUrlBuilder.quality(85)).toUrl();
|
||||
} else {
|
||||
requestUri = modifiedUri.toString();
|
||||
}
|
||||
final RestHttpRequest.Builder builder = new RestHttpRequest.Builder();
|
||||
final HttpRequest.Builder builder = new HttpRequest.Builder();
|
||||
builder.method(method);
|
||||
builder.url(requestUri);
|
||||
builder.headers(additionalHeaders);
|
||||
builder.extra(RequestType.MEDIA);
|
||||
final RestHttpResponse resp = mClient.execute(builder.build());
|
||||
final TypedData body = resp.getBody();
|
||||
builder.tag(RequestType.MEDIA);
|
||||
final HttpResponse resp = mClient.newCall(builder.build()).execute();
|
||||
final Body body = resp.getBody();
|
||||
return new ContentLengthInputStream(body.stream(), (int) body.length());
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user