implemented some api

This commit is contained in:
Mariotaku Lee 2015-05-07 15:53:14 +08:00
parent 762e102866
commit 1b532ba23e
41 changed files with 1132 additions and 1044 deletions

View File

@ -55,6 +55,12 @@ public class RestAPIFactory {
authorization, restClient, converter, requestFactory));
}
public static RestClient getRestClient(Object obj) {
final InvocationHandler handler = Proxy.getInvocationHandler(obj);
if (!(handler instanceof RestClient)) throw new IllegalArgumentException();
return (RestClient) handler;
}
private static class RestInvocationHandler implements InvocationHandler, org.mariotaku.simplerestapi.RestClient {
private final Endpoint endpoint;
private final Authorization authorization;

View File

@ -19,6 +19,9 @@
package org.mariotaku.simplerestapi;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
@ -136,4 +139,10 @@ public class Utils {
os.flush();
return true;
}
@NonNull
public static <T> T assertNotNull(@Nullable T obj) {
if (obj == null) throw new NullPointerException();
return obj;
}
}

View File

@ -32,14 +32,20 @@ import org.mariotaku.twidere.api.twitter.auth.OAuthToken;
import org.mariotaku.twidere.api.twitter.model.impl.HashtagEntityImpl;
import org.mariotaku.twidere.api.twitter.model.impl.Indices;
import org.mariotaku.twidere.api.twitter.model.impl.MediaEntityImpl;
import org.mariotaku.twidere.api.twitter.model.impl.PageableResponseListWrapper;
import org.mariotaku.twidere.api.twitter.model.impl.PlaceImpl;
import org.mariotaku.twidere.api.twitter.model.impl.QueryResultWrapper;
import org.mariotaku.twidere.api.twitter.model.impl.RelationshipImpl;
import org.mariotaku.twidere.api.twitter.model.impl.RelationshipWrapper;
import org.mariotaku.twidere.api.twitter.model.impl.ResponseListImpl;
import org.mariotaku.twidere.api.twitter.model.impl.SavedSearchImpl;
import org.mariotaku.twidere.api.twitter.model.impl.StatusImpl;
import org.mariotaku.twidere.api.twitter.model.impl.TwitterResponseImpl;
import org.mariotaku.twidere.api.twitter.model.impl.TypeConverterMapper;
import org.mariotaku.twidere.api.twitter.model.impl.UrlEntityImpl;
import org.mariotaku.twidere.api.twitter.model.impl.UserImpl;
import org.mariotaku.twidere.api.twitter.model.impl.UserMentionEntityImpl;
import org.mariotaku.twidere.api.twitter.model.impl.Wrapper;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@ -50,11 +56,16 @@ import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.nio.charset.Charset;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;
import twitter4j.GeoLocation;
import twitter4j.HashtagEntity;
import twitter4j.MediaEntity;
import twitter4j.PageableResponseList;
import twitter4j.Place;
import twitter4j.QueryResult;
import twitter4j.Relationship;
import twitter4j.ResponseList;
import twitter4j.SavedSearch;
import twitter4j.Status;
@ -68,19 +79,31 @@ import twitter4j.UserMentionEntity;
*/
public class TwitterConverter implements Converter {
private static final Map<Class<?>, Class<? extends Wrapper<?>>> wrapperMap = new HashMap<>();
static {
TypeConverterMapper.register(Status.class, StatusImpl.class);
TypeConverterMapper.register(User.class, UserImpl.class);
TypeConverterMapper.register(SavedSearch.class, SavedSearchImpl.class);
TypeConverterMapper.register(UrlEntity.class, UrlEntityImpl.class);
TypeConverterMapper.register(MediaEntity.class, MediaEntityImpl.class);
TypeConverterMapper.register(MediaEntity.Size.class, MediaEntityImpl.SizeImpl.class);
TypeConverterMapper.register(MediaEntity.Feature.class, MediaEntityImpl.FeatureImpl.class);
TypeConverterMapper.register(MediaEntity.Feature.Face.class, MediaEntityImpl.FeatureImpl.FaceImpl.class);
TypeConverterMapper.register(MediaEntity.VideoInfo.class, MediaEntityImpl.VideoInfoImpl.class);
TypeConverterMapper.register(MediaEntity.VideoInfo.Variant.class, MediaEntityImpl.VideoInfoImpl.VariantImpl.class);
TypeConverterMapper.register(UserMentionEntity.class, UserMentionEntityImpl.class);
TypeConverterMapper.register(HashtagEntity.class, HashtagEntityImpl.class);
TypeConverterMapper.register(Place.class, PlaceImpl.class);
TypeConverterMapper.register(Relationship.class, RelationshipImpl.class);
LoganSquare.registerTypeConverter(Indices.class, Indices.CONVERTER);
LoganSquare.registerTypeConverter(GeoLocation.class, GeoLocation.CONVERTER);
LoganSquare.registerTypeConverter(MediaEntity.Type.class, new EnumConverter(MediaEntity.Type.class));
LoganSquare.registerTypeConverter(MediaEntity.Type.class, EnumConverter.get(MediaEntity.Type.class));
registerWrapper(QueryResult.class, QueryResultWrapper.class);
registerWrapper(PageableResponseList.class, PageableResponseListWrapper.class);
registerWrapper(Relationship.class, RelationshipWrapper.class);
// TypeConverterMapper.register(DirectMessage.class, DirectMessageImpl.class);
}
@ -103,7 +126,12 @@ public class TwitterConverter implements Converter {
final InputStream stream = body.stream();
if (type instanceof Class<?>) {
final Class<?> cls = (Class<?>) type;
if (OAuthToken.class.isAssignableFrom(cls)) {
final Class<?> wrapperCls = wrapperMap.get(cls);
if (wrapperCls != null) {
final Wrapper<?> wrapper = (Wrapper<?>) LoganSquare.parse(stream, wrapperCls);
wrapper.processResponseHeader(response);
return wrapper.getWrapped(null);
} else if (OAuthToken.class.isAssignableFrom(cls)) {
final ByteArrayOutputStream os = new ByteArrayOutputStream();
body.writeTo(os);
Charset charset = contentType != null ? contentType.getCharset() : null;
@ -116,20 +144,42 @@ public class TwitterConverter implements Converter {
throw new IOException(e);
}
}
LoganSquare.parse(stream, cls);
final Object object = LoganSquare.parse(stream, cls);
checkResponse(cls, object, response);
if (object instanceof TwitterResponseImpl) {
((TwitterResponseImpl) object).processResponseHeader(response);
}
return object;
} else if (type instanceof ParameterizedType) {
final Type rawType = ((ParameterizedType) type).getRawType();
if (rawType instanceof Class<?>) {
final Class<?> rawClass = (Class<?>) rawType;
if (ResponseList.class.isAssignableFrom(rawClass)) {
final Class<?> wrapperCls = wrapperMap.get(rawClass);
if (wrapperCls != null) {
final Wrapper<?> wrapper = (Wrapper<?>) LoganSquare.parse(stream, wrapperCls);
wrapper.processResponseHeader(response);
return wrapper.getWrapped(((ParameterizedType) type).getActualTypeArguments());
} else if (ResponseList.class.isAssignableFrom(rawClass)) {
final Type elementType = ((ParameterizedType) type).getActualTypeArguments()[0];
return new ResponseListImpl<>(LoganSquare.parseList(stream, (Class<?>) elementType));
final ResponseListImpl<?> responseList = new ResponseListImpl<>(LoganSquare.parseList(stream, (Class<?>) elementType));
responseList.processResponseHeader(response);
return responseList;
}
}
}
throw new UnsupportedTypeException(type);
}
private void checkResponse(Class<?> cls, Object object, RestResponse response) throws TwitterException {
if (User.class.isAssignableFrom(cls)) {
if (object == null) throw new TwitterException("User is null");
}
}
private static <T> void registerWrapper(Class<T> cls, Class<? extends Wrapper<? extends T>> wrapperCls) {
wrapperMap.put(cls, wrapperCls);
}
private static class EnumConverter<T extends Enum<T>> implements TypeConverter<T> {
private final Class<T> cls;
@ -156,9 +206,13 @@ public class TwitterConverter implements Converter {
public void serialize(T object, String fieldName, boolean writeFieldNameForObject, JsonGenerator jsonGenerator) {
throw new UnsupportedOperationException();
}
public static <T extends Enum<T>> EnumConverter<T> get(Class<T> cls) {
return new EnumConverter<>(cls);
}
}
private class UnsupportedTypeException extends UnsupportedOperationException {
public static class UnsupportedTypeException extends UnsupportedOperationException {
public UnsupportedTypeException(Type type) {
super("Unsupported type " + type);
}

View File

@ -44,16 +44,14 @@ import javax.crypto.spec.SecretKeySpec;
/**
* Created by mariotaku on 15/2/4.
*/
public class OAuthAuthorization implements Authorization {
public class OAuthAuthorization implements Authorization,OAuthSupport {
private static final String DEFAULT_ENCODING = "UTF-8";
private static final String OAUTH_SIGNATURE_METHOD = "HMAC-SHA1";
private static final String OAUTH_VERSION = "1.0";
SecureRandom secureRandom = new SecureRandom();
private final String consumerKey, consumerSecret;
private final OAuthToken oauthToken;
SecureRandom secureRandom = new SecureRandom();
public OAuthAuthorization(String consumerKey, String consumerSecret) {
this(consumerKey, consumerSecret, null);
@ -65,6 +63,20 @@ public class OAuthAuthorization implements Authorization {
this.oauthToken = oauthToken;
}
@Override
public String getConsumerKey() {
return consumerKey;
}
@Override
public String getConsumerSecret() {
return consumerSecret;
}
public OAuthToken getOauthToken() {
return oauthToken;
}
private String generateOAuthSignature(RestMethod method, String url,
String oauthNonce, long timestamp,
String oauthToken, String oauthTokenSecret,
@ -181,7 +193,6 @@ public class OAuthAuthorization implements Authorization {
return Utils.encode(value, DEFAULT_ENCODING);
}
private String generateOAuthNonce() {
final byte[] input = new byte[32];
secureRandom.nextBytes(input);

View File

@ -0,0 +1,29 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.api.twitter.auth;
/**
* Created by mariotaku on 15/5/7.
*/
public interface OAuthSupport {
String getConsumerKey();
String getConsumerSecret();
}

View File

@ -26,7 +26,7 @@ import org.mariotaku.simplerestapi.http.Endpoint;
/**
* Created by mariotaku on 15/4/19.
*/
public final class XAuthAuthorization implements Authorization {
public final class XAuthAuthorization implements Authorization, OAuthSupport {
@Override
public String getHeader(Endpoint endpoint, RestMethodInfo info) {
@ -37,4 +37,14 @@ public final class XAuthAuthorization implements Authorization {
public boolean hasAuthorization() {
return false;
}
@Override
public String getConsumerKey() {
return null;
}
@Override
public String getConsumerSecret() {
return null;
}
}

View File

@ -36,9 +36,6 @@ public class MediaEntityImpl implements MediaEntity {
@JsonField(name = "id")
long id;
@JsonField(name = "id_str")
String idStr;
@JsonField(name = "indices")
Indices indices;
@ -59,12 +56,8 @@ public class MediaEntityImpl implements MediaEntity {
HashMap<String, Size> sizes;
@JsonField(name = "source_status_id")
long sourceStatusId;
@JsonField(name = "source_status_id_str")
String sourceStatusIdStr;
@JsonField(name = "source_user_id")
long sourceUserId;
@JsonField(name = "source_user_id_str")
String sourceUserIdStr;
@JsonField(name = "video_info")
VideoInfo videoInfo;
@ -137,7 +130,6 @@ public class MediaEntityImpl implements MediaEntity {
public String toString() {
return "MediaEntityImpl{" +
"id=" + id +
", idStr='" + idStr + '\'' +
", indices=" + indices +
", mediaUrl='" + mediaUrl + '\'' +
", mediaUrlHttps='" + mediaUrlHttps + '\'' +
@ -147,9 +139,7 @@ public class MediaEntityImpl implements MediaEntity {
", type=" + type +
", sizes=" + sizes +
", sourceStatusId=" + sourceStatusId +
", sourceStatusIdStr='" + sourceStatusIdStr + '\'' +
", sourceUserId=" + sourceUserId +
", sourceUserIdStr='" + sourceUserIdStr + '\'' +
", videoInfo=" + videoInfo +
", features=" + features +
'}';
@ -200,7 +190,6 @@ public class MediaEntityImpl implements MediaEntity {
@Override
public int getEnd() {
return indices.getEnd();
}

View File

@ -0,0 +1,68 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.api.twitter.model.impl;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.util.Collection;
import twitter4j.PageableResponseList;
/**
* Created by mariotaku on 15/5/7.
*/
public class PageableResponseListImpl<T> extends ResponseListImpl<T> implements PageableResponseList<T> {
long previousCursor;
long nextCursor;
public PageableResponseListImpl(int capacity) {
super(capacity);
}
public PageableResponseListImpl() {
}
public PageableResponseListImpl(Collection<? extends T> collection) {
super(collection);
}
@Override
public long getNextCursor() {
return nextCursor;
}
@Override
public long getPreviousCursor() {
return previousCursor;
}
@Override
public boolean hasNext() {
return nextCursor != 0;
}
@Override
public boolean hasPrevious() {
return previousCursor != 0;
}
}

View File

@ -0,0 +1,100 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.api.twitter.model.impl;
import com.bluelinelabs.logansquare.JsonMapper;
import com.bluelinelabs.logansquare.LoganSquare;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import org.mariotaku.twidere.api.twitter.TwitterConverter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import twitter4j.Status;
import twitter4j.User;
public final class PageableResponseListMapper<T> extends JsonMapper<PageableResponseListImpl<T>> {
private static final Map<Class<?>, PageableResponseListMapper<?>> instanceCache = new HashMap<>();
private final String listField;
private final Class<T> elementType;
public PageableResponseListMapper(String listField, Class<T> elementType) {
this.listField = listField;
this.elementType = elementType;
}
@Override
public PageableResponseListImpl<T> parse(JsonParser jsonParser) throws IOException {
PageableResponseListImpl<T> instance = new PageableResponseListImpl<>();
if (jsonParser.getCurrentToken() == null) {
jsonParser.nextToken();
}
if (jsonParser.getCurrentToken() != JsonToken.START_OBJECT) {
jsonParser.skipChildren();
return null;
}
while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
String fieldName = jsonParser.getCurrentName();
jsonParser.nextToken();
parseField(instance, fieldName, jsonParser);
jsonParser.skipChildren();
}
return instance;
}
public void parseField(PageableResponseListImpl<T> instance, String fieldName, JsonParser jsonParser) throws IOException {
if (listField.equals(fieldName)) {
instance.addAll(LoganSquare.mapperFor(elementType).parseList(jsonParser));
} else if ("previous_cursor".equals(fieldName)) {
instance.previousCursor = jsonParser.getValueAsLong(0);
} else if ("next_cursor".equals(fieldName)) {
instance.previousCursor = jsonParser.getValueAsLong(0);
}
}
@Override
public void serialize(PageableResponseListImpl object, JsonGenerator jsonGenerator, boolean writeStartAndEnd) throws IOException {
throw new UnsupportedOperationException();
}
public synchronized static <C> PageableResponseListMapper<C> get(Class<C> cls) {
@SuppressWarnings("unchecked")
final PageableResponseListMapper<C> cache = (PageableResponseListMapper<C>) instanceCache.get(cls);
if (cache != null) return cache;
final String listField;
if (User.class.isAssignableFrom(cls)) {
listField = "users";
} else if (Status.class.isAssignableFrom(cls)) {
listField = "statuses";
} else {
throw new TwitterConverter.UnsupportedTypeException(cls);
}
final PageableResponseListMapper<C> created = new PageableResponseListMapper<>(listField, cls);
instanceCache.put(cls, created);
return created;
}
}

View File

@ -0,0 +1,63 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.api.twitter.model.impl;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import org.mariotaku.twidere.api.twitter.TwitterConverter;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import twitter4j.PageableResponseList;
import twitter4j.Status;
import twitter4j.User;
/**
* Created by mariotaku on 15/5/7.
*/
@JsonObject
public class PageableResponseListWrapper extends TwitterResponseImpl implements Wrapper<PageableResponseList<?>> {
@JsonField(name = "previous_cursor")
long previousCursor;
@JsonField(name = "next_cursor")
long nextCursor;
@JsonField(name = "users")
ArrayList<User> users;
@JsonField(name = "statuses")
ArrayList<Status> statuses;
@Override
public PageableResponseList<?> getWrapped(Object extra) {
final Type[] typeArgs = (Type[]) extra;
final Class<?> elementType = (Class<?>) typeArgs[0];
if (User.class.isAssignableFrom(elementType)) {
return new PageableResponseListImpl<>(users);
} else if (Status.class.isAssignableFrom(elementType)) {
return new PageableResponseListImpl<>(statuses);
}
throw new TwitterConverter.UnsupportedTypeException(elementType);
}
}

View File

@ -30,7 +30,7 @@ import twitter4j.RateLimitStatus;
* Created by mariotaku on 15/5/7.
*/
@JsonObject
public class PlaceImpl implements Place {
public class PlaceImpl extends TwitterResponseImpl implements Place {
@JsonField(name = "full_name")
String fullName;
@ -105,13 +105,4 @@ public class PlaceImpl implements Place {
return 0;
}
@Override
public int getAccessLevel() {
return 0;
}
@Override
public RateLimitStatus getRateLimitStatus() {
return null;
}
}

View File

@ -0,0 +1,68 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.api.twitter.model.impl;
import java.util.ArrayList;
import twitter4j.QueryResult;
import twitter4j.Status;
/**
* Created by mariotaku on 15/5/7.
*/
public class QueryResultImpl extends ResponseListImpl<Status> implements QueryResult {
private final QueryResultWrapper.SearchMetadata metadata;
@Override
public double getCompletedIn() {
return metadata.completedIn;
}
@Override
public long getMaxId() {
return metadata.maxId;
}
@Override
public String getQuery() {
return metadata.query;
}
@Override
public int getResultsPerPage() {
return metadata.count;
}
@Override
public long getSinceId() {
return metadata.sinceId;
}
@Override
public String getWarning() {
return metadata.warning;
}
public QueryResultImpl(ArrayList<Status> statuses, QueryResultWrapper.SearchMetadata metadata) {
addAll(statuses);
this.metadata = metadata;
}
}

View File

@ -0,0 +1,67 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.api.twitter.model.impl;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import java.util.ArrayList;
import twitter4j.QueryResult;
import twitter4j.Status;
/**
* Created by mariotaku on 15/5/7.
*/
@JsonObject
public class QueryResultWrapper extends TwitterResponseImpl implements Wrapper<QueryResult> {
@JsonField(name = "previous_cursor")
long previousCursor;
@JsonField(name = "next_cursor")
long nextCursor;
@JsonField(name = "search_metadata")
SearchMetadata metadata;
@JsonField(name = "statuses")
ArrayList<Status> statuses;
@Override
public QueryResult getWrapped(Object extra) {
return new QueryResultImpl(statuses, metadata);
}
@JsonObject
static class SearchMetadata {
@JsonField(name = "max_id")
long maxId;
@JsonField(name = "since_id")
long sinceId;
@JsonField(name = "count")
int count;
@JsonField(name = "completed_in")
double completedIn;
@JsonField(name = "query")
String query;
@JsonField(name = "warning")
String warning;
}
}

View File

@ -0,0 +1,188 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.api.twitter.model.impl;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import org.mariotaku.simplerestapi.http.RestResponse;
import twitter4j.RateLimitStatus;
/**
* A data class representing Twitter REST API's rate limit status
*
* @author Yusuke Yamamoto - yusuke at mac.com
* @see <a href="https://dev.twitter.com/docs/rate-limiting">Rate Limiting |
* Twitter Developers</a>
*/
@JsonObject
final class RateLimitStatusJSONImpl implements RateLimitStatus, java.io.Serializable {
private static final long serialVersionUID = 1625565652687304084L;
private final long creationTimeInMillis;
@JsonField(name = "remaining")
int remaining;
@JsonField(name = "limit")
int limit;
@JsonField(name = "reset")
int resetTimeInSeconds;
private RateLimitStatusJSONImpl(final int limit, final int remaining, final int resetTimeInSeconds) {
this();
this.limit = limit;
this.remaining = remaining;
this.resetTimeInSeconds = resetTimeInSeconds;
}
public RateLimitStatusJSONImpl() {
creationTimeInMillis = System.currentTimeMillis();
}
/**
* {@inheritDoc}
*/
@Override
public int getLimit() {
return limit;
}
/**
* {@inheritDoc}
*/
@Override
public int getRemaining() {
return remaining;
}
/**
* {@inheritDoc}
*/
@Override
public int getRemainingHits() {
return getRemaining();
}
/**
* {@inheritDoc}
*/
@Override
public int getResetTimeInSeconds() {
return resetTimeInSeconds;
}
/**
* {@inheritDoc}
*/
@Override
public int getSecondsUntilReset() {
return (int) ((resetTimeInSeconds * 1000L - creationTimeInMillis) / 1000);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
RateLimitStatusJSONImpl that = (RateLimitStatusJSONImpl) o;
if (creationTimeInMillis != that.creationTimeInMillis) return false;
if (remaining != that.remaining) return false;
if (limit != that.limit) return false;
return resetTimeInSeconds == that.resetTimeInSeconds;
}
@Override
public int hashCode() {
int result = (int) (creationTimeInMillis ^ (creationTimeInMillis >>> 32));
result = 31 * result + remaining;
result = 31 * result + limit;
result = 31 * result + resetTimeInSeconds;
return result;
}
@Override
public String toString() {
return "RateLimitStatusJSONImpl{" +
"creationTimeInMillis=" + creationTimeInMillis +
", remaining=" + remaining +
", limit=" + limit +
", resetTimeInSeconds=" + resetTimeInSeconds +
'}';
}
static RateLimitStatus createFromResponseHeader(final RestResponse res) {
if (null == res) return null;
int remainingHits;// "X-Rate-Limit-Remaining"
int limit;// "X-Rate-Limit-Limit"
int resetTimeInSeconds;// not included in the response header. Need to
// be calculated.
final String strLimit = res.getHeader("X-Rate-Limit-Limit");
if (strLimit != null) {
limit = Integer.parseInt(strLimit);
} else
return null;
final String remaining = res.getHeader("X-Rate-Limit-Remaining");
if (remaining != null) {
remainingHits = Integer.parseInt(remaining);
} else
return null;
final String reset = res.getHeader("X-Rate-Limit-Reset");
if (reset != null) {
final long longReset = Long.parseLong(reset);
resetTimeInSeconds = (int) longReset;
} else
return null;
return new RateLimitStatusJSONImpl(limit, remainingHits, resetTimeInSeconds);
}
// static Map<String, RateLimitStatus> createRateLimitStatuses(final HttpResponse res, final Configuration conf)
// throws TwitterException {
// final JSONObject json = res.asJSONObject();
// final Map<String, RateLimitStatus> map = createRateLimitStatuses(json);
// return map;
// }
//
// static Map<String, RateLimitStatus> createRateLimitStatuses(final InputStream stream) throws TwitterException {
// final Map<String, RateLimitStatus> map = new HashMap<String, RateLimitStatus>();
// try {
// final JSONObject resources = json.getJSONObject("resources");
// final Iterator<?> resourceKeys = resources.keys();
// while (resourceKeys.hasNext()) {
// final JSONObject resource = resources.getJSONObject((String) resourceKeys.next());
// final Iterator<?> endpointKeys = resource.keys();
// while (endpointKeys.hasNext()) {
// final String endpoint = (String) endpointKeys.next();
// final JSONObject rateLimitStatusJSON = resource.getJSONObject(endpoint);
// final RateLimitStatus rateLimitStatus = new RateLimitStatusJSONImpl(rateLimitStatusJSON);
// map.put(endpoint, rateLimitStatus);
// }
// }
// return Collections.unmodifiableMap(map);
// } catch (final JSONException jsone) {
// throw new TwitterException(jsone);
// }
// }
}

View File

@ -0,0 +1,156 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.api.twitter.model.impl;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import twitter4j.Relationship;
/**
* Created by mariotaku on 15/5/7.
*/
@JsonObject
public class RelationshipImpl extends TwitterResponseImpl implements Relationship {
@JsonField(name = "source")
Source source;
@JsonField(name = "target")
Target target;
@Override
public boolean isSourceBlockingTarget() {
return source.blocking;
}
@Override
public boolean isTargetFollowingSource() {
return target.following;
}
@Override
public boolean isTargetFollowedBySource() {
return target.followedBy;
}
@Override
public boolean isSourceNotificationsEnabled() {
return false;
}
@Override
public boolean isSourceMutingTarget() {
return source.muting;
}
@Override
public boolean isSourceMarkedTargetAsSpam() {
return false;
}
@Override
public boolean isSourceFollowingTarget() {
return source.following;
}
@Override
public boolean isSourceFollowedByTarget() {
return source.followedBy;
}
@Override
public boolean isSourceBlockedByTarget() {
return source.blockedBy;
}
@Override
public String getTargetUserScreenName() {
return target.screenName;
}
@Override
public long getTargetUserId() {
return target.id;
}
@Override
public String getSourceUserScreenName() {
return source.screenName;
}
@Override
public long getSourceUserId() {
return source.id;
}
@Override
public boolean canSourceMediaTagTarget() {
return false;
}
@Override
public boolean canSourceDMTarget() {
return false;
}
@Override
public boolean isSourceRequestedFollowingTarget() {
return source.followingRequested;
}
@Override
public boolean isTargetRequestedFollowingSource() {
return target.followingRequested;
}
@JsonObject
static class Target {
@JsonField(name = "id")
long id;
@JsonField(name = "screen_name")
public String screenName;
@JsonField(name = "following")
boolean following;
@JsonField(name = "followed_by")
boolean followedBy;
@JsonField(name = "following_requested")
boolean followingRequested;
}
@JsonObject
static class Source {
@JsonField(name = "id")
long id;
@JsonField(name = "screen_name")
public String screenName;
@JsonField(name = "blocked_by")
boolean blockedBy;
@JsonField(name = "blocking")
boolean blocking;
@JsonField(name = "muting")
boolean muting;
@JsonField(name = "following")
boolean following;
@JsonField(name = "followed_by")
boolean followedBy;
@JsonField(name = "following_requested")
boolean followingRequested;
}
}

View File

@ -0,0 +1,40 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.api.twitter.model.impl;
import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject;
import twitter4j.Relationship;
/**
* Created by mariotaku on 15/5/7.
*/
@JsonObject
public class RelationshipWrapper extends TwitterResponseImpl implements Wrapper<Relationship> {
@JsonField(name = "relationship")
RelationshipImpl relationship;
@Override
public Relationship getWrapped(Object extra) {
return relationship;
}
}

View File

@ -19,21 +19,22 @@
package org.mariotaku.twidere.api.twitter.model.impl;
import org.mariotaku.simplerestapi.http.RestResponse;
import java.util.ArrayList;
import java.util.Collection;
import twitter4j.RateLimitStatus;
import twitter4j.ResponseList;
import twitter4j.internal.util.InternalParseUtil;
/**
* Created by mariotaku on 15/5/7.
*/
public class ResponseListImpl<T> extends ArrayList<T> implements ResponseList<T> {
@Override
public int getAccessLevel() {
return 0;
}
private int accessLevel;
private RateLimitStatus rateLimitStatus;
public ResponseListImpl(int capacity) {
super(capacity);
@ -47,7 +48,18 @@ public class ResponseListImpl<T> extends ArrayList<T> implements ResponseList<T>
}
@Override
public RateLimitStatus getRateLimitStatus() {
return null;
public final void processResponseHeader(RestResponse resp) {
rateLimitStatus = RateLimitStatusJSONImpl.createFromResponseHeader(resp);
accessLevel = InternalParseUtil.toAccessLevel(resp);
}
@Override
public final int getAccessLevel() {
return accessLevel;
}
@Override
public final RateLimitStatus getRateLimitStatus() {
return rateLimitStatus;
}
}

View File

@ -35,7 +35,7 @@ import twitter4j.SavedSearch;
* Created by mariotaku on 15/5/7.
*/
@JsonObject
public class SavedSearchImpl implements SavedSearch {
public class SavedSearchImpl extends TwitterResponseImpl implements SavedSearch {
@Override
public int getId() {
@ -82,13 +82,4 @@ public class SavedSearchImpl implements SavedSearch {
return id - another.getId();
}
@Override
public int getAccessLevel() {
return 0;
}
@Override
public RateLimitStatus getRateLimitStatus() {
return null;
}
}

View File

@ -44,7 +44,7 @@ import twitter4j.UserMentionEntity;
* Created by mariotaku on 15/5/5.
*/
@JsonObject
public class StatusImpl implements Status {
public class StatusImpl extends TwitterResponseImpl implements Status {
@JsonField(name = "created_at", typeConverter = TwitterDateConverter.class)
Date createdAt;
@ -295,16 +295,6 @@ public class StatusImpl implements Status {
return (int) delta;
}
@Override
public int getAccessLevel() {
return 0;
}
@Override
public RateLimitStatus getRateLimitStatus() {
return null;
}
@Override
public String toString() {
return "StatusImpl{" +

View File

@ -0,0 +1,51 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.api.twitter.model.impl;
import org.mariotaku.simplerestapi.http.RestResponse;
import twitter4j.RateLimitStatus;
import twitter4j.TwitterResponse;
import twitter4j.internal.util.InternalParseUtil;
/**
* Created by mariotaku on 15/5/7.
*/
public class TwitterResponseImpl implements TwitterResponse {
private int accessLevel;
private RateLimitStatus rateLimitStatus;
@Override
public final void processResponseHeader(RestResponse resp) {
rateLimitStatus = RateLimitStatusJSONImpl.createFromResponseHeader(resp);
accessLevel = InternalParseUtil.toAccessLevel(resp);
}
@Override
public final int getAccessLevel() {
return accessLevel;
}
@Override
public final RateLimitStatus getRateLimitStatus() {
return rateLimitStatus;
}
}

View File

@ -50,6 +50,7 @@ public class TypeConverterMapper<T> implements TypeConverter<T> {
throw new UnsupportedOperationException();
}
@SuppressWarnings({"TryWithIdenticalCatches", "unchecked"})
public static <T> void register(Class<T> cls, Class<? extends T> impl) {
LoganSquare.registerTypeConverter(cls, new TypeConverterMapper<>(impl));
try {

View File

@ -29,7 +29,6 @@ import org.mariotaku.twidere.api.twitter.TwitterDateConverter;
import java.util.Date;
import twitter4j.RateLimitStatus;
import twitter4j.Status;
import twitter4j.UrlEntity;
import twitter4j.User;
@ -38,7 +37,7 @@ import twitter4j.User;
* Created by mariotaku on 15/3/31.
*/
@JsonObject
public class UserImpl implements User {
public class UserImpl extends TwitterResponseImpl implements User {
@JsonField(name = "id")
long id;
@ -477,16 +476,6 @@ public class UserImpl implements User {
return createdAt;
}
@Override
public int getAccessLevel() {
return 0;
}
@Override
public RateLimitStatus getRateLimitStatus() {
return null;
}
@Override
public int compareTo(@NonNull final User that) {
return (int) (id - that.getId());

View File

@ -0,0 +1,31 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.twidere.api.twitter.model.impl;
import twitter4j.TwitterResponse;
/**
* Created by mariotaku on 15/5/7.
*/
public interface Wrapper<T> extends TwitterResponse {
T getWrapped(Object extra);
}

View File

@ -61,10 +61,10 @@ public interface MediaEntity extends UrlEntity, Serializable {
}
interface Size extends Serializable {
Integer THUMB = 0;
Integer SMALL = 1;
Integer MEDIUM = 2;
Integer LARGE = 3;
String THUMB = "thumb";
String SMALL = "small";
String MEDIUM = "medium";
String LARGE = "large";
int FIT = 100;
int CROP = 101;

View File

@ -24,6 +24,6 @@ package twitter4j;
*
* @author Yusuke Yamamoto - yusuke at mac.com
*/
public interface PageableResponseList<T extends TwitterResponse> extends ResponseList<T>, CursorSupport {
public interface PageableResponseList<T > extends ResponseList<T>, CursorSupport {
}

View File

@ -26,12 +26,8 @@ public interface QueryResult extends ResponseList<Status> {
long getMaxId();
int getPage();
String getQuery();
String getRefreshUrl();
int getResultsPerPage();
long getSinceId();

View File

@ -16,15 +16,6 @@
package twitter4j;
/**
* A data interface that has detailed information about a relationship between
* two users
*
* @author Perry Sakkaris - psakkaris at gmail.com
* @see <a href="https://dev.twitter.com/docs/api/1.1/get/friendships/show">GET
* friendships/show | Twitter Developers</a>
* @since Twitter4J 2.1.0
*/
public interface Relationship extends TwitterResponse {
boolean canSourceDMTarget();
@ -109,4 +100,7 @@ public interface Relationship extends TwitterResponse {
*/
boolean isTargetFollowingSource();
boolean isSourceRequestedFollowingTarget();
boolean isTargetRequestedFollowingSource();
}

View File

@ -29,68 +29,4 @@ import twitter4j.conf.Configuration;
*/
public interface TwitterBase extends TwitterOAuth{
/**
* Registers a RateLimitStatusListener for account associated rate limits
*
* @param listener the listener to be added
* @see <a href="https://dev.twitter.com/docs/rate-limiting">Rate Limiting |
* Twitter Developers</a>
* @since Twitter4J 2.1.12
*/
void addRateLimitStatusListener(RateLimitStatusListener listener);
/**
* Returns the authorization scheme for this instance.<br>
* The returned type will be either of BasicAuthorization,
* OAuthAuthorization, or NullAuthorization
*
* @return the authorization scheme for this instance
*/
Authorization getAuthorization();
/**
* Returns the configuration associated with this instance
*
* @return configuration associated with this instance
* @since Twitter4J 2.1.8
*/
Configuration getConfiguration();
/**
* Returns authenticating user's user id.<br>
* This method may internally call verifyCredentials() on the first
* invocation if<br>
* - this instance is authenticated by Basic and email address is supplied
* instead of screen name, or - this instance is authenticated by OAuth.<br>
*
* @return the authenticating user's id
* @throws twitter4j.TwitterException when verifyCredentials threw an exception.
* @throws IllegalStateException if no credentials are supplied. i.e.) this
* is an anonymous Twitter instance
* @since Twitter4J 2.1.1
*/
long getId() throws TwitterException, IllegalStateException;
/**
* Returns authenticating user's screen name.<br>
* This method may internally call verifyCredentials() on the first
* invocation if<br>
* - this instance is authenticated by Basic and email address is supplied
* instead of screen name, or - this instance is authenticated by OAuth.<br>
* Note that this method returns a transiently cached (will be lost upon
* serialization) screen name while it is possible to change a user's screen
* name.<br>
*
* @return the authenticating screen name
* @throws twitter4j.TwitterException when verifyCredentials threw an exception.
* @throws IllegalStateException if no credentials are supplied. i.e.) this
* is an anonymous Twitter instance
* @since Twitter4J 2.1.1
*/
String getScreenName() throws TwitterException, IllegalStateException;
/**
* Shuts down this instance and releases allocated resources.
*/
void shutdown();
}

View File

@ -123,6 +123,11 @@ public class TwitterException extends Exception implements TwitterResponse, Http
|| statusCode == TOO_MANY_REQUESTS; // API 1.1
}
@Override
public void processResponseHeader(RestResponse resp) {
}
/**
* {@inheritDoc}
*/

View File

@ -19,6 +19,8 @@
package twitter4j;
import org.mariotaku.simplerestapi.http.RestResponse;
import java.io.Serializable;
/**
@ -38,22 +40,10 @@ public interface TwitterResponse extends Serializable {
int READ_WRITE = 2;
int READ_WRITE_DIRECTMESSAGES = 3;
/**
* @return application permission model
* @see <a
* href="https://dev.twitter.com/pages/application-permission-model-faq#how-do-we-know-what-the-access-level-of-a-user-token-is">Application
* Permission Model FAQ - How do we know what the access level of a
* user token is?</a>
* @since Twitter4J 2.2.3
*/
void processResponseHeader(RestResponse resp);
int getAccessLevel();
/**
* Returns the current rate limit status if available.
*
* @return current rate limit status
* @since Twitter4J 2.1.0
*/
RateLimitStatus getRateLimitStatus();
}

View File

@ -19,6 +19,9 @@
package twitter4j.api;
import org.mariotaku.simplerestapi.method.GET;
import org.mariotaku.simplerestapi.param.Query;
import twitter4j.Paging;
import twitter4j.ResponseList;
import twitter4j.Status;
@ -28,124 +31,50 @@ import twitter4j.TwitterException;
* @author Joern Huxhorn - jhuxhorn at googlemail.com
*/
public interface FavoritesResources {
/**
* Favorites the status specified in the ID parameter as the authenticating
* user. Returns the favorite status when successful. <br>
* This method calls http://api.twitter.com/1.1/favorites/create/[id].json
*
* @param id the ID of the status to favorite
* @return Status
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/favorites/create/:id">POST
* favorites/create/:id | Twitter Developers</a>
*/
Status createFavorite(long id) throws TwitterException;
/**
* Favorites the status specified in the ID parameter as the authenticating
* user. Returns the favorite status when successful. <br>
* This method calls http://api.twitter.com/1.1/favorites/create/[id].json
*
* @param id the ID of the status to favorite
* @return Status
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/favorites/create/:id">POST
* favorites/create/:id | Twitter Developers</a>
*/
Status createFavorite(long id) throws TwitterException;
/**
* Un-favorites the status specified in the ID parameter as the
* authenticating user. Returns the un-favorited status in the requested
* format when successful. <br>
* This method calls http://api.twitter.com/1.1/favorites/destroy/[id].json
*
* @param id the ID of the status to un-favorite
* @return Status
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/favorites/destroy/:id">POST
* favorites/destroy/:id | Twitter Developers</a>
*/
Status destroyFavorite(long id) throws TwitterException;
/**
* Un-favorites the status specified in the ID parameter as the
* authenticating user. Returns the un-favorited status in the requested
* format when successful. <br>
* This method calls http://api.twitter.com/1.1/favorites/destroy/[id].json
*
* @param id the ID of the status to un-favorite
* @return Status
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/favorites/destroy/:id">POST
* favorites/destroy/:id | Twitter Developers</a>
*/
Status destroyFavorite(long id) throws TwitterException;
/**
* Returns the 20 most recent favorite statuses for the authenticating user
* or user specified by the ID parameter in the requested format. <br>
* This method calls http://api.twitter.com/1.1/favorites/list.json
*
* @return ResponseList&lt;Status&gt;
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/favorites/list">GET
* favorites | Twitter Developers</a>
* @since Twitter4J 2.0.1
*/
ResponseList<Status> getFavorites() throws TwitterException;
@GET("/favorites/list.json")
ResponseList<Status> getFavorites() throws TwitterException;
/**
* Returns the 20 most recent favorite statuses for the authenticating user
* or user specified by the ID parameter in the requested format.
*
* @param userId the ID of the user for whom to request a list of favorite
* statuses
* @return ResponseList&lt;Status&gt;
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/favorites/list">GET
* favorites | Twitter Developers</a>
* @since Twitter4J 2.0.1
*/
ResponseList<Status> getFavorites(long userId) throws TwitterException;
@GET("/favorites/list.json")
ResponseList<Status> getFavorites(@Query("user_id") long userId) throws TwitterException;
/**
* Returns the 20 most recent favorite statuses for the authenticating user
* or user specified by the ID parameter in the requested format.
*
* @param userId the ID of the user for whom to request a list of favorite
* statuses
* @param paging controls pagination. Supports sinceId and page parameters.
* @return ResponseList&lt;Status&gt;
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/favorites/list">GET
* favorites | Twitter Developers</a>
* @since Twitter4J 2.0.1
*/
ResponseList<Status> getFavorites(long userId, Paging paging) throws TwitterException;
@GET("/favorites/list.json")
ResponseList<Status> getFavorites(@Query("user_id") long userId, @Query({"since_id", "max_id", "count"}) Paging paging) throws TwitterException;
/**
* Returns the 20 most recent favorite statuses for the authenticating user
* or user specified by the ID parameter in the requested format. <br>
* This method calls http://api.twitter.com/1.1/favorites/list.json
*
* @param paging controls pagination. Supports sinceId and page parameters.
* @return ResponseList&lt;Status&gt;
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/favorites/list">GET
* favorites | Twitter Developers</a>
* @since Twitter4J 2.2.5
*/
ResponseList<Status> getFavorites(Paging paging) throws TwitterException;
@GET("/favorites/list.json")
ResponseList<Status> getFavorites(@Query({"since_id", "max_id", "count"}) Paging paging) throws TwitterException;
/**
* Returns the 20 most recent favorite statuses for the authenticating user
* or user specified by the ID parameter in the requested format.
*
* @param screenName the screen name of the user for whom to request a list
* of favorite statuses
* @return ResponseList&lt;Status&gt;
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/favorites/list">GET
* favorites | Twitter Developers</a>
* @since Twitter4J 2.0.1
*/
ResponseList<Status> getFavorites(String screenName) throws TwitterException;
@GET("/favorites/list.json")
ResponseList<Status> getFavorites(@Query("screen_name") String screenName) throws TwitterException;
/**
* Returns the 20 most recent favorite statuses for the authenticating user
* or user specified by the ID parameter in the requested format. <br>
* This method calls http://api.twitter.com/1.1/favorites/[id].json
*
* @param screenName the screen name of the user for whom to request a list
* of favorite statuses
* @param paging controls pagination. Supports sinceId and page parameters.
* @return ResponseList&lt;Status&gt;
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/favorites/list">GET
* favorites | Twitter Developers</a>
* @since Twitter4J 2.2.5
*/
ResponseList<Status> getFavorites(String screenName, Paging paging) throws TwitterException;
@GET("/favorites/list.json")
ResponseList<Status> getFavorites(@Query("screen_name") String screenName, @Query({"since_id", "max_id", "count"}) Paging paging) throws TwitterException;
}

View File

@ -19,7 +19,9 @@
package twitter4j.api;
import twitter4j.Paging;
import org.mariotaku.simplerestapi.method.GET;
import org.mariotaku.simplerestapi.param.Query;
import twitter4j.Friendship;
import twitter4j.IDs;
import twitter4j.PageableResponseList;
@ -34,279 +36,61 @@ import twitter4j.User;
*/
public interface FriendsFollowersResources {
/**
* Allows the authenticating users to follow the user specified in the ID
* parameter.<br>
* Returns the befriended user in the requested format when successful.
* Returns a string describing the failure condition when unsuccessful. If
* you are already friends with the user an HTTP 403 will be returned. <br>
* This method calls http://api.twitter.com/1.1/friendships/create/[id].json
*
* @param userId the ID of the user to be befriended
* @return the befriended user
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/friendships/create">POST
* friendships/create | Twitter Developers</a>
* @since Twitter4J 2.1.0
*/
User createFriendship(long userId) throws TwitterException;
User createFriendship(long userId) throws TwitterException;
/**
* Allows the authenticating users to follow the user specified in the ID
* parameter.<br>
* Returns the befriended user in the requested format when successful.
* Returns a string describing the failure condition when unsuccessful. If
* you are already friends with the user an HTTP 403 will be returned. <br>
* This method calls http://api.twitter.com/1.1/friendships/create/[id].json
*
* @param userId the ID of the user to be befriended
* @param follow Enable notifications for the target user in addition to
* becoming friends.
* @return the befriended user
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/friendships/create">POST
* friendships/create | Twitter Developers</a>
* @since Twitter4J 2.1.0
*/
User createFriendship(long userId, boolean follow) throws TwitterException;
User createFriendship(long userId, boolean follow) throws TwitterException;
/**
* Allows the authenticating users to follow the user specified in the ID
* parameter.<br>
* Returns the befriended user in the requested format when successful.
* Returns a string describing the failure condition when unsuccessful. If
* you are already friends with the user an HTTP 403 will be returned. <br>
* This method calls http://api.twitter.com/1.1/friendships/create/[id].json
*
* @param screenName the screen name of the user to be befriended
* @return the befriended user
* @throws twitter4j.TwitterException when Twitter service or network is
* unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/friendships/create">POST
* friendships/create | Twitter Developers</a>
* @since Twitter4J 2.0.1
*/
User createFriendship(String screenName) throws TwitterException;
User createFriendship(String screenName) throws TwitterException;
/**
* Allows the authenticating users to follow the user specified in the ID
* parameter.<br>
* Returns the befriended user in the requested format when successful.
* Returns a string describing the failure condition when unsuccessful. If
* you are already friends with the user an HTTP 403 will be returned. <br>
* This method calls http://api.twitter.com/1.1/friendships/create/[id].json
*
* @param screenName the screen name of the user to be befriended
* @param follow Enable notifications for the target user in addition to
* becoming friends.
* @return the befriended user
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/friendships/create">POST
* friendships/create | Twitter Developers</a>
* @since Twitter4J 2.0.2
*/
User createFriendship(String screenName, boolean follow) throws TwitterException;
User createFriendship(String screenName, boolean follow) throws TwitterException;
/**
* Allows the authenticating users to unfollow the user specified in the ID
* parameter.<br>
* Returns the unfollowed user in the requested format when successful.
* Returns a string describing the failure condition when unsuccessful. <br>
* This method calls
* http://api.twitter.com/1.1/friendships/destroy/[id].json
*
* @param userId the ID of the user for whom to request a list of friends
* @return User
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/friendships/destroy">POST
* friendships/destroy | Twitter Developers</a>
* @since Twitter4J 2.1.0
*/
User destroyFriendship(long userId) throws TwitterException;
User destroyFriendship(long userId) throws TwitterException;
/**
* Allows the authenticating users to unfollow the user specified in the ID
* parameter.<br>
* Returns the unfollowed user in the requested format when successful.
* Returns a string describing the failure condition when unsuccessful. <br>
* This method calls
* http://api.twitter.com/1.1/friendships/destroy/[id].json
*
* @param screenName the screen name of the user for whom to request a list
* of friends
* @return User
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/friendships/destroy">POST
* friendships/destroy | Twitter Developers</a>
* @since Twitter4J 2.0.1
*/
User destroyFriendship(String screenName) throws TwitterException;
User destroyFriendship(String screenName) throws TwitterException;
IDs getFollowersIDs(Paging paging) throws TwitterException;
IDs getFollowersIDs(Paging paging) throws TwitterException;
IDs getFollowersIDs(long userId, Paging paging) throws TwitterException;
IDs getFollowersIDs(long userId, Paging paging) throws TwitterException;
IDs getFollowersIDs(String screenName, Paging paging) throws TwitterException;
IDs getFollowersIDs(String screenName, Paging paging) throws TwitterException;
PageableResponseList<User> getFollowersList(Paging paging) throws TwitterException;
PageableResponseList<User> getFollowersList(Paging paging) throws TwitterException;
PageableResponseList<User> getFollowersList(long userId, Paging paging) throws TwitterException;
PageableResponseList<User> getFollowersList(long userId, Paging paging) throws TwitterException;
PageableResponseList<User> getFollowersList(String screenName, Paging paging) throws TwitterException;
PageableResponseList<User> getFollowersList(String screenName, Paging paging) throws TwitterException;
IDs getFriendsIDs(Paging paging) throws TwitterException;
IDs getFriendsIDs(Paging paging) throws TwitterException;
IDs getFriendsIDs(long userId, Paging paging) throws TwitterException;
IDs getFriendsIDs(long userId, Paging paging) throws TwitterException;
IDs getFriendsIDs(String screenName, Paging paging) throws TwitterException;
IDs getFriendsIDs(String screenName, Paging paging) throws TwitterException;
PageableResponseList<User> getFriendsList(Paging paging) throws TwitterException;
PageableResponseList<User> getFriendsList(Paging paging) throws TwitterException;
PageableResponseList<User> getFriendsList(long userId, Paging paging) throws TwitterException;
PageableResponseList<User> getFriendsList(long userId, Paging paging) throws TwitterException;
PageableResponseList<User> getFriendsList(String screenName, Paging paging) throws TwitterException;
PageableResponseList<User> getFriendsList(String screenName, Paging paging) throws TwitterException;
/**
* Returns an array of numeric IDs for every user who has a pending request
* to follow the authenticating user. <br>
* This method calls http://api.twitter.com/1.1/friendships/incoming.json
*
* @param paging Breaks the results into pages. A single page contains 5000
* identifiers. Provide a value of -1 to begin paging.
* @return an array of numeric IDs for every user who has a pending request
* to follow the authenticating user.
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/friendships/incoming">GET
* friendships/incoming | Twitter Developers</a>
* @since Twitter4J 2.1.2
*/
IDs getIncomingFriendships(Paging paging) throws TwitterException;
IDs getIncomingFriendships(Paging paging) throws TwitterException;
/**
* Returns an array of numeric IDs for every protected user for whom the
* authenticating user has a pending follow request. <br>
* This method calls http://api.twitter.com/1.1/friendships/outgoing.json
*
* @param paging Breaks the results into pages. A single page contains 5000
* identifiers. Provide a value of -1 to begin paging.
* @return an array of numeric IDs for every protected user for whom the
* authenticating user has a pending follow request.
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/friendships/outgoing">GET
* friendships/outgoing | Twitter Developers</a>
* @since Twitter4J 2.1.2
*/
IDs getOutgoingFriendships(Paging paging) throws TwitterException;
IDs getOutgoingFriendships(Paging paging) throws TwitterException;
/**
* Returns the relationship of the authenticating user to the specified
* users. <br>
* This method has not been finalized and the interface is subject to change
* in incompatible ways. <br>
* This method calls http://api.twitter.com/1.1/friendships/lookup.json
*
* @param ids array of the ids to lookup
* @return list of Relationships
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="http://groups.google.com/group/twitter-api-announce/msg/34909da7c399169e">#newtwitter
* and the API - Twitter API Announcements | Google Group</a>
* @since Twitter4J 2.1.9
*/
ResponseList<Friendship> lookupFriendships(long[] ids) throws TwitterException;
ResponseList<Friendship> lookupFriendships(long[] ids) throws TwitterException;
/**
* Returns the relationship of the authenticating user to the specified
* users. <br>
* This method has not been finalized and the interface is subject to change
* in incompatible ways. <br>
* This method calls http://api.twitter.com/1.1/friendships/lookup.json
*
* @param screenNames array of the screen names to lookup
* @return list of Relationships
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="http://groups.google.com/group/twitter-api-announce/msg/34909da7c399169e">#newtwitter
* and the API - Twitter API Announcements | Google Group</a>
* @since Twitter4J 2.1.9
*/
ResponseList<Friendship> lookupFriendships(String[] screenNames) throws TwitterException;
ResponseList<Friendship> lookupFriendships(String[] screenNames) throws TwitterException;
/**
* Returns detailed information about the relationship between two users. <br>
* This method calls http://api.twitter.com/1.1/friendships/show.json
*
* @param sourceId the ID of the source user
* @param targetId the ID of the target user
* @return Relationship
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/friendships/show">GET
* friendships/show | Twitter Developers</a>
* @since Twitter4J 2.1.0
*/
Relationship showFriendship(long sourceId, long targetId) throws TwitterException;
@GET("/friendships/show.json")
Relationship showFriendship(@Query("source_id") long sourceId, @Query("target_id") long targetId) throws TwitterException;
/**
* Returns detailed information about the relationship between two users. <br>
* This method calls http://api.twitter.com/1.1/friendships/show.json
*
* @param sourceScreenName the screen name of the source user
* @param targetScreenName the screen name of the target user
* @return Relationship
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/friendships/show">GET
* friendships/show | Twitter Developers</a>
* @since Twitter4J 2.1.0
*/
Relationship showFriendship(String sourceScreenName, String targetScreenName) throws TwitterException;
@GET("/friendships/show.json")
Relationship showFriendship(@Query("target_id") long targetId) throws TwitterException;
/**
* Allows you to enable or disable retweets and device notifications from
* the specified user. <br>
* This method has not been finalized and the interface is subject to change
* in incompatible ways. <br>
* This method calls http://api.twitter.com/1.1/friendships/update.json
*
* @param userId user id to update
* @param enableDeviceNotification set true to enable device notification
* @param retweets set true to enable retweets
* @return Relationship
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="http://groups.google.com/group/twitter-api-announce/msg/34909da7c399169e">#newtwitter
* and the API - Twitter API Announcements | Google Group</a>
* @since Twitter4J 2.1.9
*/
Relationship updateFriendship(long userId, boolean enableDeviceNotification, boolean retweets)
throws TwitterException;
Relationship showFriendship(String sourceScreenName, String targetScreenName) throws TwitterException;
/**
* Allows you to enable or disable retweets and device notifications from
* the specified user. <br>
* This method has not been finalized and the interface is subject to change
* in incompatible ways. <br>
* This method calls http://api.twitter.com/1.1/friendships/update.json
*
* @param screenName screen name to update
* @param enableDeviceNotification set true to enable device notification
* @param retweets set true to enable retweets
* @return Relationship
* @throws twitter4j.TwitterException when Twitter service or network is unavailable
* @see <a
* href="http://groups.google.com/group/twitter-api-announce/msg/34909da7c399169e">#newtwitter
* and the API - Twitter API Announcements | Google Group</a>
* @since Twitter4J 2.1.9
*/
Relationship updateFriendship(String screenName, boolean enableDeviceNotification, boolean retweets)
throws TwitterException;
Relationship updateFriendship(long userId, boolean enableDeviceNotification, boolean retweets)
throws TwitterException;
Relationship updateFriendship(String screenName, boolean enableDeviceNotification, boolean retweets)
throws TwitterException;
}

View File

@ -1,5 +1,8 @@
package twitter4j.api;
import org.mariotaku.simplerestapi.method.GET;
import org.mariotaku.simplerestapi.param.Query;
import twitter4j.Paging;
import twitter4j.ResponseList;
import twitter4j.Status;
@ -7,15 +10,21 @@ import twitter4j.TwitterException;
public interface PrivateTimelinesResources extends PrivateResources {
@GET("/statuses/media_timeline.json")
ResponseList<Status> getMediaTimeline() throws TwitterException;
ResponseList<Status> getMediaTimeline(long userId) throws TwitterException;
@GET("/statuses/media_timeline.json")
ResponseList<Status> getMediaTimeline(@Query("user_id") long userId) throws TwitterException;
ResponseList<Status> getMediaTimeline(long userId, Paging paging) throws TwitterException;
@GET("/statuses/media_timeline.json")
ResponseList<Status> getMediaTimeline(@Query("user_id") long userId, @Query({"since_id", "max_id", "count", "page"}) Paging paging) throws TwitterException;
ResponseList<Status> getMediaTimeline(Paging paging) throws TwitterException;
@GET("/statuses/media_timeline.json")
ResponseList<Status> getMediaTimeline(@Query({"since_id", "max_id", "count", "page"}) Paging paging) throws TwitterException;
ResponseList<Status> getMediaTimeline(String screenName) throws TwitterException;
@GET("/statuses/media_timeline.json")
ResponseList<Status> getMediaTimeline(@Query("screen_name") String screenName) throws TwitterException;
ResponseList<Status> getMediaTimeline(String screenName, Paging paging) throws TwitterException;
@GET("/statuses/media_timeline.json")
ResponseList<Status> getMediaTimeline(@Query("screen_name") String screenName,@Query({"since_id", "max_id", "count", "page"}) Paging paging) throws TwitterException;
}

View File

@ -1,5 +1,8 @@
package twitter4j.api;
import org.mariotaku.simplerestapi.method.GET;
import org.mariotaku.simplerestapi.param.Query;
import twitter4j.Paging;
import twitter4j.ResponseList;
import twitter4j.Status;
@ -9,13 +12,14 @@ import twitter4j.TwitterException;
public interface PrivateTweetResources extends PrivateResources {
StatusActivitySummary getStatusActivitySummary(long statusId) throws TwitterException;
StatusActivitySummary getStatusActivitySummary(@Query("id") long statusId) throws TwitterException;
StatusActivitySummary getStatusActivitySummary(long statusId, boolean includeUserEntities) throws TwitterException;
StatusActivitySummary getStatusActivitySummary(long statusId, boolean includeUserEntities) throws TwitterException;
ResponseList<Status> showConversation(long statusId) throws TwitterException;
ResponseList<Status> showConversation(@Query("id") long statusId) throws TwitterException;
ResponseList<Status> showConversation(long statusId, Paging paging) throws TwitterException;
@GET("/conversation/show.json")
ResponseList<Status> showConversation(@Query("id") long statusId, @Query({"since_id", "max_id", "count", "page"}) Paging paging) throws TwitterException;
TranslationResult showTranslation(long statusId, String dest) throws TwitterException;
TranslationResult showTranslation(long statusId, String dest) throws TwitterException;
}

View File

@ -19,6 +19,9 @@
package twitter4j.api;
import org.mariotaku.simplerestapi.method.GET;
import org.mariotaku.simplerestapi.param.Query;
import java.io.File;
import java.io.InputStream;
@ -36,139 +39,31 @@ import twitter4j.User;
* @author Joern Huxhorn - jhuxhorn at googlemail.com
*/
public interface UsersResources {
/**
* Blocks the user specified in the ID parameter as the authenticating user.
* Returns the blocked user in the requested format when successful. <br>
* This method calls http://api.twitter.com/1.1/blocks/create/[id].json
*
* @param userId the ID of the user to block
* @return the blocked user
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/blocks/create">POST
* blocks/create | Twitter Developers</a>
* @since Twitter4J 2.1.0
*/
User createBlock(long userId) throws TwitterException;
/**
* Blocks the user specified in the ID parameter as the authenticating user.
* Returns the blocked user in the requested format when successful. <br>
* This method calls http://api.twitter.com/1.1/blocks/create/[id].json
*
* @param screenName the screen_name of the user to block
* @return the blocked user
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/blocks/create">POST
* blocks/create | Twitter Developers</a>
* @since Twitter4J 2.0.1
*/
User createBlock(String screenName) throws TwitterException;
User createMute(long userId) throws TwitterException;
User createMute(String screenName) throws TwitterException;
/**
* Un-blocks the user specified in the ID parameter as the authenticating
* user. Returns the un-blocked user in the requested format when
* successful. <br>
* This method calls http://api.twitter.com/1.1/blocks/destroy/[id].json
*
* @param userId the ID of the user to block
* @return the unblocked user
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/blocks/destroy">POST
* blocks/destroy | Twitter Developers</a>
* @since Twitter4J 2.0.1
*/
User destroyBlock(long userId) throws TwitterException;
/**
* Un-blocks the user specified in the ID parameter as the authenticating
* user. Returns the un-blocked user in the requested format when
* successful. <br>
* This method calls http://api.twitter.com/1.1/blocks/destroy/[id].json
*
* @param screenName the screen name of the user to block
* @return the unblocked user
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/blocks/destroy">POST
* blocks/destroy | Twitter Developers</a>
* @since Twitter4J 2.0.1
*/
User destroyBlock(String screenName) throws TwitterException;
User destroyMute(long userId) throws TwitterException;
User destroyMute(String screenName) throws TwitterException;
/**
* Returns the current trend, geo, language, timezone and sleep time
* information for the authenticating user. <br>
* This method has not been finalized and the interface is subject to change
* in incompatible ways. <br>
* This method calls http://api.twitter.com/1.1/account/settings.json
*
* @return the current trend, geo and sleep time information for the
* authenticating user.
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/account/totals">GET
* account/settings | Twitter Developers</a>
* @since Twitter4J 2.1.9
*/
AccountSettings getAccountSettings() throws TwitterException;
/**
* Returns an array of numeric user ids the authenticating user is blocking. <br>
* This method calls http://api.twitter.com/1.1/blocks/blocks/ids
*
* @return Returns an array of numeric user ids the authenticating user is
* blocking.
* @throws TwitterException when Twitter service or network is unavailable
* @see <a href="https://dev.twitter.com/docs/api/1.1/get/blocks/ids">GET
* blocks/ids | Twitter Developers</a>
* @since Twitter4J 2.0.4
*/
IDs getBlocksIDs() throws TwitterException;
IDs getBlocksIDs(Paging paging) throws TwitterException;
/**
* Returns a list of user objects that the authenticating user is blocking. <br>
* This method calls http://api.twitter.com/1.1/blocks/blocking.json
*
* @return a list of user objects that the authenticating user
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/blocks/blocking">GET
* blocks/blocking | Twitter Developers</a>
* @since Twitter4J 2.0.4
*/
PageableResponseList<User> getBlocksList() throws TwitterException;
PageableResponseList<User> getBlocksList(Paging paging) throws TwitterException;
/**
* Access the users in a given category of the Twitter suggested user list
* and return their most recent status if they are not a protected user. <br>
* This method has not been finalized and the interface is subject to change
* in incompatible ways. <br>
* This method calls
* http://api.twitter.com/1.1/users/suggestions/:slug/members.json
*
* @param categorySlug slug
* @return list of suggested users
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="http://groups.google.com/group/twitter-api-announce/msg/34909da7c399169e">#newtwitter
* and the API - Twitter API Announcements | Google Group</a>
* @since Twitter4J 2.1.9
*/
ResponseList<User> getMemberSuggestions(String categorySlug) throws TwitterException;
IDs getMutesUsersIDs() throws TwitterException;
@ -179,402 +74,50 @@ public interface UsersResources {
PageableResponseList<User> getMutesUsersList(Paging paging) throws TwitterException;
/**
* Access to Twitter's suggested user list. This returns the list of
* suggested user categories. The category can be used in the
* users/suggestions/category endpoint to get the users in that category. <br>
* This method calls http://api.twitter.com/1.1/users/suggestions/:slug.json
*
* @return list of suggested user categories.
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/users/suggestions/:slug">GET
* users/suggestions/:slug | Twitter Developers</a>
* @since Twitter4J 2.1.1
*/
ResponseList<Category> getSuggestedUserCategories() throws TwitterException;
/**
* Access the users in a given category of the Twitter suggested user list.<br>
* It is recommended that end clients cache this data for no more than one
* hour. <br>
* This method calls http://api.twitter.com/1.1/users/suggestions/:slug.json
*
* @param categorySlug slug
* @return list of suggested users
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/users/suggestions/slug">GET
* users/suggestions/slug | Twitter Developers</a>
* @since Twitter4J 2.1.1
*/
ResponseList<User> getUserSuggestions(String categorySlug) throws TwitterException;
/**
* Return up to 100 users worth of extended information, specified by either
* ID, screen name, or combination of the two. The author's most recent
* status (if the authenticating user has permission) will be returned
* inline. <br>
* This method calls http://api.twitter.com/1.1/users/lookup.json
*
* @param ids Specifies the screen names of the users to return.
* @return users
* @throws TwitterException when Twitter service or network is unavailable
* @see <a href="https://dev.twitter.com/docs/api/1.1/get/users/lookup">GET
* users/lookup | Twitter Developers</a>
* @since Twitter4J 2.1.1
*/
ResponseList<User> lookupUsers(long[] ids) throws TwitterException;
/**
* Return up to 100 users worth of extended information, specified by either
* ID, screen name, or combination of the two. The author's most recent
* status (if the authenticating user has permission) will be returned
* inline. <br>
* This method calls http://api.twitter.com/1.1/users/lookup.json
*
* @param screenNames Specifies the screen names of the users to return.
* @return users
* @throws TwitterException when Twitter service or network is unavailable
* @see <a href="https://dev.twitter.com/docs/api/1.1/get/users/lookup">GET
* users/lookup | Twitter Developers</a>
* @since Twitter4J 2.1.1
*/
ResponseList<User> lookupUsers(String[] screenNames) throws TwitterException;
void removeProfileBannerImage() throws TwitterException;
/**
* Run a search for users similar to the Find People button on Twitter.com;
* the same results returned by people search on Twitter.com will be
* returned by using this API.<br>
* Usage note: It is only possible to retrieve the first 1000 matches from
* this API. <br>
* This method calls http://api.twitter.com/1.1/users/search.json
*
* @param query The query to run against people search.
* @param page Specifies the page of results to retrieve. Number of statuses
* per page is fixed to 20.
* @return the list of Users matches the provided
* @throws TwitterException when Twitter service or network is unavailable
* @see <a href="https://dev.twitter.com/docs/api/1.1/get/users/search">GET
* users/search | Twitter Developers</a>
*/
ResponseList<User> searchUsers(String query, int page) throws TwitterException;
/**
* Returns extended information of a given user, specified by ID or screen
* name as per the required id parameter. The author's most recent status
* will be returned inline. <br>
* This method calls http://api.twitter.com/1.1/users/show.json
*
* @param userId the ID of the user for whom to request the detail
* @return users
* @throws TwitterException when Twitter service or network is unavailable
* @see <a href="https://dev.twitter.com/docs/api/1.1/get/users/show">GET
* users/show | Twitter Developers</a>
* @since Twitter4J 2.1.0
*/
User showUser(long userId) throws TwitterException;
/**
* Returns extended information of a given user, specified by ID or screen
* name as per the required id parameter. The author's most recent status
* will be returned inline. <br>
* This method calls http://api.twitter.com/1.1/users/show.json
*
* @param screenName the screen name of the user for whom to request the
* detail
* @return User
* @throws TwitterException when Twitter service or network is unavailable
* @see <a href="https://dev.twitter.com/docs/api/1.1/get/users/show">GET
* users/show | Twitter Developers</a>
*/
User showUser(String screenName) throws TwitterException;
@GET("/users/show.json")
User showUser(@Query("user_id") long userId) throws TwitterException;
@GET("/users/show.json")
User showUser(@Query("screen_name") String screenName) throws TwitterException;
/**
* Updates the current trend, geo, language, timezone and sleep time
* information for the authenticating user. <br>
* This method has not been finalized and the interface is subject to change
* in incompatible ways. <br>
* This method calls http://api.twitter.com/1.1/account/settings.json
*
* @param settingsUpdate Settings to be updated
* @return the current trend, geo and sleep time information for the
* authenticating user.
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/account/settings">POST
* account/settings | Twitter Developers</a>
* @since Twitter4J 2.2.4
*/
AccountSettings updateAccountSettings(SettingsUpdate settingsUpdate) throws TwitterException;
/**
* Sets values that users are able to set under the "Account" tab of their
* settings page. Only the parameters specified(non-null) will be updated. <br>
* This method calls http://api.twitter.com/1.1/account/update_profile.json
*
* @param name Optional. Maximum of 20 characters.
* @param url Optional. Maximum of 100 characters. Will be prepended with
* "http://" if not present.
* @param location Optional. Maximum of 30 characters. The contents are not
* normalized or geocoded in any way.
* @param description Optional. Maximum of 160 characters.
* @return the updated user
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/account/update_profile">POST
* account/update_profile | Twitter Developers</a>
* @since Twitter4J 2.1.8
*/
User updateProfile(String name, String url, String location, String description) throws TwitterException;
/**
* Updates the authenticating user's profile background image. <br>
* This method calls
* http://api.twitter.com/1.1/account/update_profile_background_image.json
*
* @param image Must be a valid GIF, JPG, or PNG image of less than 800
* kilobytes in size. Images with width larger than 2048 pixels
* will be forceably scaled down.
* @param tile If set to true the background image will be displayed tiled.
* The image will not be tiled otherwise.
* @return the updated user
* @throws TwitterException when Twitter service or network is unavailable,
* or when the specified file is not found
* (FileNotFoundException will be nested), or when the specified
* file object in not representing a file (IOException will be
* nested)
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/account/update_profile_background_image">POST
* account/update_profile_background_image | Twitter Developers</a>
* @since Twitter4J 2.1.0
*/
User updateProfileBackgroundImage(File image, boolean tile) throws TwitterException;
/**
* Updates the authenticating user's profile background image. <br>
* This method calls
* http://api.twitter.com/1.1/account/update_profile_background_image.json
*
* @param image Must be a valid GIF, JPG, or PNG image of less than 800
* kilobytes in size. Images with width larger than 2048 pixels
* will be forceably scaled down.
* @param tile If set to true the background image will be displayed tiled.
* The image will not be tiled otherwise.
* @return the updated user
* @throws TwitterException when Twitter service or network is unavailable,
* or when the specified file is not found
* (FileNotFoundException will be nested), or when the specified
* file object in not representing a file (IOException will be
* nested)
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/account/update_profile_background_image">POST
* account/update_profile_background_image | Twitter Developers</a>
* @since Twitter4J 2.1.11
*/
User updateProfileBackgroundImage(InputStream image, boolean tile) throws TwitterException;
/**
* <table border="1" width="50%" align="center" cellpadding="1">
* <thead>
* <tr>
* <th>Code(s)</th>
* <th>Meaning</th>
* </tr>
* </thead>
* <td>200,201,202</td>
* <td>Profile banner image successfully uploaded</td>
* <tr>
* <td>400</td>
* <td>Either an image was not provided or the image data could be processed
* </td>
* </tr>
* <tr>
* <td>422</td>
* <td>The image could not be resized or it too large</td>
* </tr>
* </table>
*
* @throws TwitterException when Twitter service or network is unavailable,
* or when the specified file is not found
* (FileNotFoundException will be nested), or when the specified
* file object in not representing a file (IOException will be
* nested)
*/
void updateProfileBannerImage(File banner) throws TwitterException;
/**
* <table border="1" width="50%" align="center" cellpadding="1">
* <thead>
* <tr>
* <th>Code(s)</th>
* <th>Meaning</th>
* </tr>
* </thead>
* <td>200,201,202</td>
* <td>Profile banner image successfully uploaded</td>
* <tr>
* <td>400</td>
* <td>Either an image was not provided or the image data could be processed
* </td>
* </tr>
* <tr>
* <td>422</td>
* <td>The image could not be resized or it too large</td>
* </tr>
* </table>
*
* @throws TwitterException when Twitter service or network is unavailable,
* or when the specified file is not found
* (FileNotFoundException will be nested), or when the specified
* file object in not representing a file (IOException will be
* nested)
*/
void updateProfileBannerImage(File banner, int width, int height, int offsetLeft, int offsetTop)
throws TwitterException;
/**
* <table border="1" width="50%" align="center" cellpadding="1">
* <thead>
* <tr>
* <th>Code(s)</th>
* <th>Meaning</th>
* </tr>
* </thead>
* <td>200,201,202</td>
* <td>Profile banner image successfully uploaded</td>
* <tr>
* <td>400</td>
* <td>Either an image was not provided or the image data could be processed
* </td>
* </tr>
* <tr>
* <td>422</td>
* <td>The image could not be resized or it too large</td>
* </tr>
* </table>
*
* @throws TwitterException when Twitter service or network is unavailable,
* or when the specified file is not found
* (FileNotFoundException will be nested), or when the specified
* file object in not representing a file (IOException will be
* nested)
*/
void updateProfileBannerImage(InputStream banner) throws TwitterException;
/**
* <table border="1" width="50%" align="center" cellpadding="1">
* <thead>
* <tr>
* <th>Code(s)</th>
* <th>Meaning</th>
* </tr>
* </thead>
* <td>200,201,202</td>
* <td>Profile banner image successfully uploaded</td>
* <tr>
* <td>400</td>
* <td>Either an image was not provided or the image data could be processed
* </td>
* </tr>
* <tr>
* <td>422</td>
* <td>The image could not be resized or it too large</td>
* </tr>
* </table>
*
* @throws TwitterException when Twitter service or network is unavailable,
* or when the specified file is not found
* (FileNotFoundException will be nested), or when the specified
* file object in not representing a file (IOException will be
* nested)
*/
void updateProfileBannerImage(InputStream banner, int width, int height, int offsetLeft, int offsetTop)
throws TwitterException;
/**
* Sets one or more hex values that control the color scheme of the
* authenticating user's profile page on twitter.com. Each parameter's value
* must be a valid hexidecimal value, and may be either three or six
* characters (ex: #fff or #ffffff). <br>
* This method calls
* http://api.twitter.com/1.1/account/update_profile_colors.json
*
* @param profileBackgroundColor optional, can be null
* @param profileTextColor optional, can be null
* @param profileLinkColor optional, can be null
* @param profileSidebarFillColor optional, can be null
* @param profileSidebarBorderColor optional, can be null
* @return the updated user
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/account/update_profile_colors">POST
* account/update_profile_colors | Twitter Developers</a>
* @since Twitter4J 2.0.0
*/
User updateProfileColors(String profileBackgroundColor, String profileTextColor, String profileLinkColor,
String profileSidebarFillColor, String profileSidebarBorderColor) throws TwitterException;
/**
* Updates the authenticating user's profile image. <br>
* This method calls
* http://api.twitter.com/1.1/account/update_profile_image.json
*
* @param image Must be a valid GIF, JPG, or PNG image of less than 700
* kilobytes in size. Images with width larger than 500 pixels
* will be scaled down.
* @return the updated user
* @throws TwitterException when Twitter service or network is unavailable,
* or when the specified file is not found
* (FileNotFoundException will be nested), or when the specified
* file object in not representing a file (IOException will be
* nested)
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/account/update_profile_image">POST
* account/update_profile_image | Twitter Developers</a>
* @since Twitter4J 2.1.0
*/
User updateProfileImage(File image) throws TwitterException;
/**
* Updates the authenticating user's profile image. <br>
* This method calls
* http://api.twitter.com/1.1/account/update_profile_image.json
*
* @param image Must be a valid GIF, JPG, or PNG image of less than 700
* kilobytes in size. Images with width larger than 500 pixels
* will be scaled down.
* @return the updated user
* @throws TwitterException when Twitter service or network is unavailable,
* or when the specified file is not found
* (FileNotFoundException will be nested), or when the specified
* file object in not representing a file (IOException will be
* nested)
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/account/update_profile_image">POST
* account/update_profile_image | Twitter Developers</a>
* @since Twitter4J 2.1.11
*/
User updateProfileImage(InputStream image) throws TwitterException;
/**
* Returns an HTTP 200 OK response code and a representation of the
* requesting user if authentication was successful; returns a 401 status
* code and an error message if not. Use this method to test if supplied
* user credentials are valid. <br>
* This method calls
* http://api.twitter.com/1.1/account/verify_credentials.json
*
* @return user
* @throws twitter4j.TwitterException when Twitter service or network is
* unavailable, or if supplied credential is wrong
* (TwitterException.getStatusCode() == 401)
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/account/verify_credentials">GET
* account/verify_credentials | Twitter Developers</a>
* @since Twitter4J 2.0.0
*/
@GET(" account/verify_credentials.json")
User verifyCredentials() throws TwitterException;
}

View File

@ -559,18 +559,6 @@
<!-- Begin third Party components -->
<service android:name="edu.ucdavis.earlybird.UCDService" />
<receiver
android:name="edu.ucdavis.earlybird.UploadReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.net.wifi.supplicant.CONNECTION_CHANGE" />
<action android:name="android.intent.action.ACTION_POWER_CONNECTED" />
<action android:name="android.intent.action.ACTION_POWER_DISCONNECTED" />
<action android:name="edu.ucdavis.earlybird.UPLOAD_PROFILE" />
</intent-filter>
</receiver>
<!-- SPICE -->
<service android:name="edu.tsinghua.spice.SpiceService" />
<receiver

View File

@ -754,6 +754,7 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
profileTypeView.setVisibility(View.GONE);
}
// TODO Handle source click
final String timeString = Utils.formatToLongTimeString(context, timestamp);
if (!TextUtils.isEmpty(timeString) && !TextUtils.isEmpty(source)) {
timeSourceView.setText(Html.fromHtml(context.getString(R.string.time_source, timeString, source)));
@ -764,7 +765,6 @@ public class StatusFragment extends BaseSupportFragment implements LoaderCallbac
}
timeSourceView.setMovementMethod(null);
textView.setText(Html.fromHtml(status.text_html));
linkify.applyAllLinks(textView, status.account_id, layoutPosition, status.is_possibly_sensitive);
ThemeUtils.applyParagraphSpacing(textView, 1.1f);

View File

@ -1640,7 +1640,7 @@ public class UserFragment extends BaseSupportFragment implements OnClickListener
final Twitter twitter = TwitterAPIUtils.getTwitterInstance(context, account_id, false);
if (twitter == null) return SingleResponse.getInstance();
try {
final Relationship relationship = twitter.showFriendship(account_id, user_id);
final Relationship relationship = twitter.showFriendship(user_id);
if (relationship.isSourceBlockingTarget() || relationship.isSourceBlockedByTarget()) {
Utils.setLastSeen(context, user_id, -1);
} else {

View File

@ -26,6 +26,7 @@ import android.util.Xml;
import com.nostra13.universalimageloader.utils.IoUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.mariotaku.simplerestapi.RestAPIFactory;
import org.mariotaku.simplerestapi.RestClient;
import org.mariotaku.simplerestapi.http.Endpoint;
import org.mariotaku.simplerestapi.http.RestHttpClient;
@ -43,8 +44,6 @@ import org.xmlpull.v1.XmlPullParserFactory;
import java.io.IOException;
import java.io.Reader;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.net.HttpCookie;
import java.util.ArrayList;
import java.util.HashMap;
@ -65,11 +64,10 @@ public class OAuthPasswordAuthenticator implements Constants {
private final Endpoint endpoint;
public OAuthPasswordAuthenticator(final TwitterOAuth oauth) {
final InvocationHandler handler = Proxy.getInvocationHandler(oauth);
if (!(handler instanceof RestClient)) throw new IllegalArgumentException();
final RestClient restClient = RestAPIFactory.getRestClient(oauth);
this.oauth = oauth;
this.client = ((RestClient) handler).getRestClient();
this.endpoint = ((RestClient) handler).getEndpoint();
this.client = restClient.getRestClient();
this.endpoint = restClient.getEndpoint();
}
public OAuthToken getOAuthAccessToken(final String username, final String password) throws AuthenticationException {

View File

@ -47,8 +47,6 @@ import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.User;
import static org.mariotaku.twidere.util.TwitterAPIUtils.getTwitterInstance;
public class TwitterWrapper implements Constants {
public static int clearNotification(final Context context, final int notificationType, final long accountId) {
@ -107,9 +105,10 @@ public class TwitterWrapper implements Constants {
@NonNull
public static User showUser(final Twitter twitter, final long id, final String screenName) throws TwitterException {
if (twitter.getId() == id || twitter.getScreenName().equalsIgnoreCase(screenName)) {
return twitter.verifyCredentials();
} else if (id != -1) {
// if (twitter.getId() == id || twitter.getScreenName().equalsIgnoreCase(screenName)) {
// return twitter.verifyCredentials();
// } else
if (id != -1) {
return twitter.showUser(id);
} else if (screenName != null) {
return twitter.showUser(screenName);
@ -124,7 +123,7 @@ public class TwitterWrapper implements Constants {
if (screenName != null) {
searchScreenName = screenName;
} else if (id != -1) {
searchScreenName = twitter.showFriendship(twitter.getId(), id).getTargetUserScreenName();
searchScreenName = twitter.showFriendship(id).getTargetUserScreenName();
} else
throw new IllegalArgumentException();
final Paging paging = new Paging();

View File

@ -129,8 +129,9 @@ import org.mariotaku.querybuilder.Selectable;
import org.mariotaku.querybuilder.Table;
import org.mariotaku.querybuilder.Tables;
import org.mariotaku.querybuilder.query.SQLSelectQuery;
import org.mariotaku.simplerestapi.RestAPIFactory;
import org.mariotaku.simplerestapi.RestClient;
import org.mariotaku.simplerestapi.http.Authorization;
import org.mariotaku.simplerestapi.http.RestHttpClient;
import org.mariotaku.twidere.BuildConfig;
import org.mariotaku.twidere.Constants;
import org.mariotaku.twidere.R;
@ -141,9 +142,8 @@ import org.mariotaku.twidere.adapter.iface.IBaseAdapter;
import org.mariotaku.twidere.adapter.iface.IBaseCardAdapter;
import org.mariotaku.twidere.api.twitter.auth.BasicAuthorization;
import org.mariotaku.twidere.api.twitter.auth.OAuthAuthorization;
import org.mariotaku.twidere.api.twitter.auth.OAuthSupport;
import org.mariotaku.twidere.api.twitter.auth.OAuthToken;
import org.mariotaku.twidere.api.twitter.auth.XAuthAuthorization;
import org.mariotaku.twidere.app.TwidereApplication;
import org.mariotaku.twidere.fragment.iface.IBaseFragment.SystemWindowsInsetsCallback;
import org.mariotaku.twidere.fragment.support.AccountsManagerFragment;
import org.mariotaku.twidere.fragment.support.AddStatusFilterDialogFragment;
@ -220,7 +220,6 @@ import org.mariotaku.twidere.service.RefreshService;
import org.mariotaku.twidere.util.TwidereLinkify.HighlightStyle;
import org.mariotaku.twidere.util.content.ContentResolverUtils;
import org.mariotaku.twidere.util.menu.TwidereMenuInfo;
import org.mariotaku.twidere.util.net.TwidereHostResolverFactory;
import org.mariotaku.twidere.view.CardMediaContainer.OnMediaClickListener;
import org.mariotaku.twidere.view.CardMediaContainer.PreviewStyle;
import org.mariotaku.twidere.view.ShapedImageView;
@ -265,7 +264,6 @@ import twitter4j.TwitterException;
import twitter4j.UserMentionEntity;
import twitter4j.conf.Configuration;
import twitter4j.conf.ConfigurationBuilder;
import twitter4j.http.HostAddressResolverFactory;
import static android.text.TextUtils.isEmpty;
import static android.text.format.DateUtils.getRelativeTimeSpanString;
@ -2677,11 +2675,12 @@ public final class Utils implements Constants, TwitterConstants {
public static boolean isOfficialTwitterInstance(final Context context, final Twitter twitter) {
if (context == null || twitter == null) return false;
final Configuration conf = twitter.getConfiguration();
final Authorization auth = twitter.getAuthorization();
final boolean isOAuth = auth instanceof OAuthAuthorization || auth instanceof XAuthAuthorization;
final String consumerKey = conf.getOAuthConsumerKey(), consumerSecret = conf.getOAuthConsumerSecret();
return isOAuth && TwitterContentUtils.isOfficialKey(context, consumerKey, consumerSecret);
final RestClient restClient = RestAPIFactory.getRestClient(twitter);
final Authorization auth = restClient.getAuthorization();
if (!(auth instanceof OAuthSupport)) return false;
final String consumerKey = ((OAuthSupport) auth).getConsumerKey();
final String consumerSecret = ((OAuthSupport) auth).getConsumerSecret();
return TwitterContentUtils.isOfficialKey(context, consumerKey, consumerSecret);
}
public static boolean isOnWifi(final Context context) {