implemented some api

better error handing
This commit is contained in:
Mariotaku Lee 2015-05-08 12:05:05 +08:00
parent a7d314dcc2
commit 3a286bf321
26 changed files with 237 additions and 541 deletions

View File

@ -29,14 +29,10 @@ import com.bluelinelabs.logansquare.annotation.JsonObject;
import org.mariotaku.twidere.util.ParseUtils;
import java.io.Serializable;
import twitter4j.GeoLocation;
@JsonObject
public class ParcelableLocation implements Serializable, Parcelable {
private static final long serialVersionUID = -1690848439775407442L;
public class ParcelableLocation implements Parcelable {
@JsonField(name = "latitude")
public double latitude;

View File

@ -0,0 +1,52 @@
/*
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.mariotaku.simplerestapi.http;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* Created by mariotaku on 15/5/8.
*/
public class SimpleValueMap implements ValueMap {
private final Map<String, Object> internalMap = new HashMap<>();
@Override
public boolean has(String key) {
return internalMap.containsKey(key);
}
@Override
public Object get(String key) {
return internalMap.get(key);
}
protected void put(String key, Object value) {
internalMap.put(key, value);
}
@Override
public String[] keys() {
final Set<String> keySet = internalMap.keySet();
return keySet.toArray(new String[keySet.size()]);
}
}

View File

@ -22,6 +22,7 @@ package org.mariotaku.twidere.api.twitter;
import com.bluelinelabs.logansquare.LoganSquare;
import com.bluelinelabs.logansquare.typeconverters.TypeConverter;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import org.mariotaku.simplerestapi.Converter;
@ -63,6 +64,7 @@ import java.lang.reflect.Type;
import java.nio.charset.Charset;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import twitter4j.CardEntity;
@ -124,14 +126,13 @@ public class TwitterConverter implements Converter {
registerWrapper(PageableResponseList.class, PageableResponseListWrapper.class);
registerWrapper(Relationship.class, RelationshipWrapper.class);
registerWrapper(CardEntity.BindingValue.class, CardEntityImpl.BindingValueWrapper.class);
// TypeConverterMapper.register(DirectMessage.class, DirectMessageImpl.class);
}
@Override
public Object convert(RestResponse response, Type type) throws Exception {
final TypedData body = response.getBody();
if (!response.isSuccessful()) {
throw LoganSquare.parse(body.stream(), TwitterException.class);
throw parseOrThrow(response, body.stream(), TwitterException.class);
}
final ContentType contentType = body.contentType();
final InputStream stream = body.stream();
@ -139,7 +140,7 @@ public class TwitterConverter implements Converter {
final Class<?> cls = (Class<?>) type;
final Class<?> wrapperCls = wrapperMap.get(cls);
if (wrapperCls != null) {
final Wrapper<?> wrapper = (Wrapper<?>) LoganSquare.parse(stream, wrapperCls);
final Wrapper<?> wrapper = (Wrapper<?>) parseOrThrow(response, stream, wrapperCls);
wrapper.processResponseHeader(response);
return wrapper.getWrapped(null);
} else if (OAuthToken.class.isAssignableFrom(cls)) {
@ -155,7 +156,7 @@ public class TwitterConverter implements Converter {
throw new IOException(e);
}
}
final Object object = LoganSquare.parse(stream, cls);
final Object object = parseOrThrow(response, stream, cls);
checkResponse(cls, object, response);
if (object instanceof TwitterResponseImpl) {
((TwitterResponseImpl) object).processResponseHeader(response);
@ -167,12 +168,12 @@ public class TwitterConverter implements Converter {
final Class<?> rawClass = (Class<?>) rawType;
final Class<?> wrapperCls = wrapperMap.get(rawClass);
if (wrapperCls != null) {
final Wrapper<?> wrapper = (Wrapper<?>) LoganSquare.parse(stream, wrapperCls);
final Wrapper<?> wrapper = (Wrapper<?>) parseOrThrow(response, stream, wrapperCls);
wrapper.processResponseHeader(response);
return wrapper.getWrapped(((ParameterizedType) type).getActualTypeArguments());
} else if (ResponseList.class.isAssignableFrom(rawClass)) {
final Type elementType = ((ParameterizedType) type).getActualTypeArguments()[0];
final ResponseListImpl<?> responseList = new ResponseListImpl<>(LoganSquare.parseList(stream, (Class<?>) elementType));
final ResponseListImpl<?> responseList = new ResponseListImpl<>(parseListOrThrow(response, stream, (Class<?>) elementType));
responseList.processResponseHeader(response);
return responseList;
}
@ -181,6 +182,22 @@ public class TwitterConverter implements Converter {
throw new UnsupportedTypeException(type);
}
private static <T> T parseOrThrow(RestResponse resp, InputStream stream, Class<T> cls) throws IOException, TwitterException {
try {
return LoganSquare.parse(stream, cls);
} catch (JsonParseException e) {
throw new TwitterException("Malformed JSON Data", resp);
}
}
private static <T> List<T> parseListOrThrow(RestResponse resp, InputStream stream, Class<T> elementCls) throws IOException, TwitterException {
try {
return LoganSquare.parseList(stream, elementCls);
} catch (JsonParseException e) {
throw new TwitterException("Malformed JSON Data", resp);
}
}
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");

View File

@ -34,9 +34,7 @@ import twitter4j.RateLimitStatus;
* Twitter Developers</a>
*/
@JsonObject
final class RateLimitStatusJSONImpl implements RateLimitStatus, java.io.Serializable {
private static final long serialVersionUID = 1625565652687304084L;
final class RateLimitStatusJSONImpl implements RateLimitStatus {
private final long creationTimeInMillis;

View File

@ -22,7 +22,7 @@ import java.io.Serializable;
* @author Yusuke Yamamoto - yusuke at mac.com
* @since Twitter4J 2.1.9
*/
public interface AccountSettings extends TwitterResponse, Serializable {
public interface AccountSettings extends TwitterResponse {
/**
* Returns the language used to render Twitter's UII for this user.
*

View File

@ -1,37 +1,36 @@
package twitter4j;
import java.io.Serializable;
import java.util.Date;
public interface Activity extends TwitterResponse, Comparable<Activity>, Serializable {
public interface Activity extends TwitterResponse, Comparable<Activity> {
public Action getAction();
Action getAction();
public Date getCreatedAt();
Date getCreatedAt();
public long getMaxPosition();
long getMaxPosition();
public long getMinPosition();
long getMinPosition();
public User[] getSources();
User[] getSources();
public int getSourcesSize();
int getSourcesSize();
public int getTargetObjectsSize();
int getTargetObjectsSize();
public Status[] getTargetObjectStatuses();
Status[] getTargetObjectStatuses();
public UserList[] getTargetObjectUserLists();
UserList[] getTargetObjectUserLists();
public int getTargetsSize();
int getTargetsSize();
public Status[] getTargetStatuses();
Status[] getTargetStatuses();
public UserList[] getTargetUserLists();
UserList[] getTargetUserLists();
public User[] getTargetUsers();
User[] getTargetUsers();
public static enum Action implements Serializable {
enum Action {
FAVORITE(0x1), FOLLOW(0x2), MENTION(0x3), REPLY(0x4), RETWEET(0x5), LIST_MEMBER_ADDED(0x06),
LIST_CREATED(0x07), FAVORITED_RETWEET(0x08), RETWEETED_RETWEET(0x09);

View File

@ -19,13 +19,12 @@
package twitter4j;
import java.io.Serializable;
import java.util.Map;
/**
* Created by mariotaku on 14/12/31.
*/
public interface CardEntity extends Serializable {
public interface CardEntity {
String getName();
@ -37,7 +36,7 @@ public interface CardEntity extends Serializable {
Map<String, BindingValue> getBindingValues();
interface BindingValue extends Serializable {
interface BindingValue {
String TYPE_STRING = "STRING";
String TYPE_IMAGE = "IMAGE";

View File

@ -22,7 +22,7 @@ import java.io.Serializable;
* @author Yusuke Yamamoto - yusuke at mac.com
* @since Twitter4J 2.2.5
*/
public interface EntitySupport extends Serializable {
public interface EntitySupport {
/**
* Returns an array if hashtag mentioned in the tweet, or null if no hashtag
* were mentioned.

View File

@ -24,19 +24,13 @@ import com.fasterxml.jackson.core.JsonParser;
import org.mariotaku.twidere.api.twitter.model.impl.GeoPoint;
import java.io.IOException;
import java.io.Serializable;
/**
* A data class representing geo location.
*
* @author Yusuke Yamamoto - yusuke at mac.com
*/
public class GeoLocation implements Serializable {
/**
*
*/
private static final long serialVersionUID = 4603460402828968366L;
public class GeoLocation {
public static final TypeConverter<GeoLocation> CONVERTER = new TypeConverter<GeoLocation>() {
@Override

View File

@ -24,7 +24,7 @@ import java.io.Serializable;
* @author Yusuke Yamamoto - yusuke at mac.com
* @since Twitter4J 2.1.9
*/
public interface HashtagEntity extends Serializable {
public interface HashtagEntity {
/**
* Returns the index of the end character of the hashtag.
*

View File

@ -6,7 +6,7 @@ import java.io.Serializable;
import java.util.Map;
public interface MediaEntity extends UrlEntity, Serializable {
public interface MediaEntity extends UrlEntity {
long getId();
@ -41,7 +41,7 @@ public interface MediaEntity extends UrlEntity, Serializable {
VideoInfo getVideoInfo();
interface VideoInfo extends Serializable {
interface VideoInfo {
Variant[] getVariants();
@ -49,7 +49,7 @@ public interface MediaEntity extends UrlEntity, Serializable {
long getDuration();
interface Variant extends Serializable {
interface Variant {
String getContentType();
@ -60,7 +60,7 @@ public interface MediaEntity extends UrlEntity, Serializable {
}
interface Size extends Serializable {
interface Size {
String THUMB = "thumb";
String SMALL = "small";
String MEDIUM = "medium";

View File

@ -16,7 +16,6 @@
package twitter4j;
import java.io.Serializable;
import java.util.List;
/**
@ -24,12 +23,12 @@ import java.util.List;
*
* @author Yusuke Yamamoto - yusuke at mac.com
*/
public interface ResponseList<T> extends TwitterResponse, List<T>, Serializable {
public interface ResponseList<T> extends TwitterResponse, List<T> {
/**
* {@inheritDoc}
*/
@Override
public RateLimitStatus getRateLimitStatus();
/**
* {@inheritDoc}
*/
@Override
public RateLimitStatus getRateLimitStatus();
}

View File

@ -38,7 +38,7 @@ public final class SearchQuery implements ValueMap {
private String lang = null;
private String locale = null;
private long maxId = -1l;
private int rpp = -1;
private int count = -1;
private int page = -1;
private String since = null;
private long sinceId = -1;
@ -77,7 +77,7 @@ public final class SearchQuery implements ValueMap {
if (maxId != query1.maxId) return false;
if (page != query1.page) return false;
if (rpp != query1.rpp) return false;
if (count != query1.count) return false;
if (sinceId != query1.sinceId) return false;
if (geocode != null ? !geocode.equals(query1.geocode) : query1.geocode != null)
return false;
@ -180,10 +180,10 @@ public final class SearchQuery implements ValueMap {
/**
* Returns the number of tweets to return per page, up to a max of 100
*
* @return rpp
* @return count
*/
public int getRpp() {
return rpp;
public int getCount() {
return count;
}
/**
@ -222,7 +222,7 @@ public final class SearchQuery implements ValueMap {
result = 31 * result + (lang != null ? lang.hashCode() : 0);
result = 31 * result + (locale != null ? locale.hashCode() : 0);
result = 31 * result + (int) (maxId ^ maxId >>> 32);
result = 31 * result + rpp;
result = 31 * result + count;
result = 31 * result + page;
result = 31 * result + (since != null ? since.hashCode() : 0);
result = 31 * result + (int) (sinceId ^ sinceId >>> 32);
@ -322,7 +322,7 @@ public final class SearchQuery implements ValueMap {
* @since Twitter4J 2.1.0
*/
public SearchQuery rpp(final int rpp) {
setRpp(rpp);
setCount(rpp);
return this;
}
@ -408,10 +408,10 @@ public final class SearchQuery implements ValueMap {
/**
* sets the number of tweets to return per page, up to a max of 100
*
* @param rpp the number of tweets to return per page
* @param count the number of tweets to return per page
*/
public void setRpp(final int rpp) {
this.rpp = rpp;
public void setCount(final int count) {
this.count = count;
}
/**
@ -473,7 +473,7 @@ public final class SearchQuery implements ValueMap {
@Override
public String toString() {
return "Query{" + "query='" + query + '\'' + ", lang='" + lang + '\'' + ", locale='" + locale + '\''
+ ", maxId=" + maxId + ", rpp=" + rpp + ", page=" + page + ", since='" + since + '\'' + ", sinceId="
+ ", maxId=" + maxId + ", count=" + count + ", page=" + page + ", since='" + since + '\'' + ", sinceId="
+ sinceId + ", geocode='" + geocode + '\'' + ", until='" + until + '\'' + ", resultType='" + resultType
+ '\'' + '}';
}
@ -509,8 +509,8 @@ public final class SearchQuery implements ValueMap {
case "since_id": {
return sinceId != -1;
}
case "rpp": {
return rpp != -1;
case "count": {
return count != -1;
}
case "page": {
return page != -1;
@ -551,9 +551,9 @@ public final class SearchQuery implements ValueMap {
if (sinceId == -1) return null;
return String.valueOf(sinceId);
}
case "rpp": {
if (rpp == -1) return null;
return String.valueOf(rpp);
case "count": {
if (count == -1) return null;
return String.valueOf(count);
}
case "page": {
if (page == -1) return null;
@ -577,7 +577,7 @@ public final class SearchQuery implements ValueMap {
@Override
public String[] keys() {
return new String[]{"q", "lang", "locale", "max_id", "since_id", "rpp", "page", "since",
return new String[]{"q", "lang", "locale", "max_id", "since_id", "count", "page", "since",
"until", "geocode", "result_type"};
}

View File

@ -19,76 +19,55 @@
package twitter4j;
import org.mariotaku.simplerestapi.http.ValueMap;
import java.util.HashMap;
import java.util.Set;
import org.mariotaku.simplerestapi.http.SimpleValueMap;
/**
* Created by mariotaku on 15/1/6.
*/
public class SettingsUpdate implements ValueMap {
public class SettingsUpdate extends SimpleValueMap {
private final HashMap<String, String> settingsMap = new HashMap<>();
public void set(String key, boolean value) {
set(key, String.valueOf(value));
public void put(String key, boolean value) {
super.put(key, String.valueOf(value));
}
public void set(String key, int value) {
set(key, String.valueOf(value));
public void put(String key, int value) {
super.put(key, String.valueOf(value));
}
public void set(String key, String value) {
settingsMap.put(key, value);
public void put(String key, String value) {
super.put(key, value);
}
public void setTrendLocationWoeid(int woeid) {
set("trend_location_woeid", woeid);
put("trend_location_woeid", woeid);
}
public void setSleepTimeEnabled(boolean enabled) {
set("sleep_time_enabled", enabled);
put("sleep_time_enabled", enabled);
}
public void setStartSleepTime(int startSleepTime) {
set("start_sleep_time", startSleepTime);
put("start_sleep_time", startSleepTime);
}
public void setEndSleepTime(int endSleepTime) {
set("end_sleep_time", endSleepTime);
put("end_sleep_time", endSleepTime);
}
public void setTimezone(String timezone) {
set("time_zone", timezone);
put("time_zone", timezone);
}
public void setProtected(boolean userProtected) {
set("protected", userProtected);
put("protected", userProtected);
}
public void setLang(String lang) {
set("lang", lang);
put("lang", lang);
}
public void setScreenName(String screenName) {
set("screen_name", screenName);
put("screen_name", screenName);
}
@Override
public boolean has(String key) {
return settingsMap.containsKey(key);
}
@Override
public String get(String key) {
return settingsMap.get(key);
}
@Override
public String[] keys() {
final Set<String> keySet = settingsMap.keySet();
return keySet.toArray(new String[keySet.size()]);
}
}

View File

@ -24,7 +24,7 @@ import java.util.Date;
*
* @author Yusuke Yamamoto - yusuke at mac.com
*/
public interface Status extends Comparable<Status>, TwitterResponse, ExtendedEntitySupport, Serializable {
public interface Status extends Comparable<Status>, TwitterResponse, ExtendedEntitySupport {
/**
* Returns an array of contributors, or null if no contributor is associated

View File

@ -23,7 +23,7 @@ import java.util.Map;
* @author Yusuke Yamamoto - yusuke at mac.com
* @since Twitter4J 2.2.3
*/
public interface TwitterAPIConfiguration extends TwitterResponse, Serializable {
public interface TwitterAPIConfiguration extends TwitterResponse {
int getCharactersReservedPerMedia();
int getMaxMediaPerUpload();

View File

@ -32,7 +32,7 @@ import java.io.Serializable;
* @see twitter4j.Status
* @see User
*/
public interface TwitterResponse extends Serializable {
public interface TwitterResponse {
int NONE = 0;
int READ = 1;

View File

@ -25,7 +25,7 @@ import java.net.URL;
* @author Mocel - mocel at guma.jp
* @since Twitter4J 2.1.9
*/
public interface UrlEntity extends Serializable {
public interface UrlEntity {
/**
* Returns the display URL if mentioned URL is shorten.

View File

@ -24,7 +24,7 @@ import java.util.Date;
*
* @author Yusuke Yamamoto - yusuke at mac.com
*/
public interface User extends Comparable<User>, TwitterResponse, Serializable {
public interface User extends Comparable<User>, TwitterResponse {
Date getCreatedAt();
boolean isDefaultProfile();

View File

@ -16,10 +16,9 @@
package twitter4j;
import java.io.Serializable;
import java.util.Date;
public interface UserList extends Comparable<UserList>, TwitterResponse, Serializable {
public interface UserList extends Comparable<UserList>, TwitterResponse {
Mode getMode();
String getDescription();

View File

@ -1,5 +1,5 @@
/*
* Twidere - Twitter client for Android
* Twidere - Twitter client for Android
*
* Copyright (C) 2012-2015 Mariotaku Lee <mariotaku.lee@gmail.com>
*
@ -19,14 +19,22 @@
package twitter4j;
import org.mariotaku.simplerestapi.http.Authorization;
import twitter4j.conf.Configuration;
import org.mariotaku.simplerestapi.http.SimpleValueMap;
/**
* @author Yusuke Yamamoto - yusuke at mac.com
* @since Twitter4J 2.2.0
* Created by mariotaku on 15/5/8.
*/
public interface TwitterBase extends TwitterOAuth{
public class UserListUpdate extends SimpleValueMap {
public void setDescription(String description) {
put("description", description);
}
public void setName(String name) {
put("name", name);
}
public void setPublic(boolean isPublic) {
put("public", String.valueOf(isPublic));
}
}

View File

@ -16,47 +16,45 @@
package twitter4j;
import java.io.Serializable;
/**
* A data interface representing one single user mention entity.
*
*
* @author Yusuke Yamamoto - yusuke at mac.com
* @since Twitter4J 2.1.9
*/
public interface UserMentionEntity extends Serializable {
/**
* Returns the index of the end character of the user mention.
*
* @return the index of the end character of the user mention
*/
int getEnd();
public interface UserMentionEntity {
/**
* Returns the index of the end character of the user mention.
*
* @return the index of the end character of the user mention
*/
int getEnd();
/**
* Returns the user id mentioned in the status.
*
* @return the user id mentioned in the status
*/
long getId();
/**
* Returns the user id mentioned in the status.
*
* @return the user id mentioned in the status
*/
long getId();
/**
* Returns the name mentioned in the status.
*
* @return the name mentioned in the status
*/
String getName();
/**
* Returns the name mentioned in the status.
*
* @return the name mentioned in the status
*/
String getName();
/**
* Returns the screen name mentioned in the status.
*
* @return the screen name mentioned in the status
*/
String getScreenName();
/**
* Returns the screen name mentioned in the status.
*
* @return the screen name mentioned in the status
*/
String getScreenName();
/**
* Returns the index of the start character of the user mention.
*
* @return the index of the start character of the user mention
*/
int getStart();
/**
* Returns the index of the start character of the user mention.
*
* @return the index of the start character of the user mention
*/
int getStart();
}

View File

@ -19,6 +19,10 @@
package twitter4j.api;
import org.mariotaku.simplerestapi.method.GET;
import org.mariotaku.simplerestapi.param.Form;
import org.mariotaku.simplerestapi.param.Query;
import twitter4j.PageableResponseList;
import twitter4j.Paging;
import twitter4j.ResponseList;
@ -26,116 +30,24 @@ import twitter4j.Status;
import twitter4j.TwitterException;
import twitter4j.User;
import twitter4j.UserList;
import twitter4j.UserListUpdate;
/**
* @author Joern Huxhorn - jhuxhorn at googlemail.com
*/
public interface ListsResources {
/**
* Adds a member to a list. The authenticated user must own the list to be
* able to add members to it. Lists are limited to having 500 members. <br>
* This method calls http://api.twitter.com/1.1/lists/members/create.json
*
* @param listId The id of the list.
* @param userId The id of the user to add as a member of the list.
* @return the updated list
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/lists/members/create">POST
* lists/members/create | Twitter Developers</a>
* @since Twitter4J 2.1.0
*/
UserList addUserListMember(long listId, long userId) throws TwitterException;
UserList addUserListMember(long listId, String userScreenName) throws TwitterException;
/**
* Adds multiple members to a list, by specifying a comma-separated list of
* member ids or screen names. The authenticated user must own the list to
* be able to add members to it. Lists are limited to having 500 members,
* and you are limited to adding up to 100 members to a list at a time with
* this method. <br>
* This method calls
* http://api.twitter.com/1.1/lists/members/create_all.json
*
* @param listId The id of the list.
* @param userIds The array of ids of the user to add as member of the list.
* up to 100 are allowed in a single request.
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/lists/members/create_all">POST
* lists/members/create_all | Twitter Developers</a>
* @since Twitter4J 2.1.7
*/
UserList addUserListMembers(long listId, long[] userIds) throws TwitterException;
/**
* Adds multiple members to a list, by specifying a comma-separated list of
* member ids or screen names. The authenticated user must own the list to
* be able to add members to it. Lists are limited to having 500 members,
* and you are limited to adding up to 100 members to a list at a time with
* this method. <br>
* This method calls
* http://api.twitter.com/1.1/lists/members/create_all.json
*
* @param listId The id of the list.
* @param screenNames The array of screen names of the user to add as member
* of the list. up to 100 are allowed in a single request.
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/lists/members/create_all">POST
* lists/members/create_all | Twitter Developers</a>
* @since Twitter4J 2.1.7
*/
UserList addUserListMembers(long listId, String[] screenNames) throws TwitterException;
/**
* Creates a new list for the authenticated user. Accounts are limited to 20
* lists. <br>
* This method calls http://api.twitter.com/1.1/lists/create.json
*
* @param listName The name of the list you are creating. Required.
* @param isPublicList set true if you wish to make a public list
* @param description The description of the list you are creating.
* Optional.
* @return the list that was created
* @throws twitter4j.TwitterException when Twitter service or network is
* unavailable, or the authenticated user already has 20
* lists(TwitterException.getStatusCode() == 403).
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/lists/create ">POST
* lists/create | Twitter Developers</a>
* @since Twitter4J 2.1.0
*/
UserList createUserList(String listName, boolean isPublicList, String description) throws TwitterException;
/**
* Make the authenticated user follow the specified list. <br>
* This method calls http://api.twitter.com/1.1/list/subscribers/create.json
*
* @param listId The id of the list.
* @return the updated list
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/lists/subscribers/create">POST
* lists/subscribers/create | Twitter Developers</a>
* @since Twitter4J 2.2.3
*/
UserList createUserListSubscription(long listId) throws TwitterException;
/**
* Removes the specified member from the list. The authenticated user must
* be the list's owner to remove members from the list. <br>
* This method calls http://api.twitter.com/1.1/lists/members/destroy.json
*
* @param listId The id of the list.
* @param userId The screen name of the member you wish to remove from the
* list.
* @return the updated list
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/lists/members/destroy">POST
* lists/members/destroy | Twitter Developers</a>
* @since Twitter4J 2.1.0
*/
UserList deleteUserListMember(long listId, long userId) throws TwitterException;
UserList deleteUserListMember(long listId, String screenName) throws TwitterException;
@ -144,49 +56,10 @@ public interface ListsResources {
UserList deleteUserListMembers(long listId, String[] screenNames) throws TwitterException;
/**
* Deletes the specified list. Must be owned by the authenticated user. <br>
* This method calls http://api.twitter.com/1.1/lists/destroy.json
*
* @param listId The id of the list to delete
* @return the deleted list
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/lists/destroy">POST
* lists/destroy | Twitter Developers</a>
* @since Twitter4J 2.1.0
*/
UserList destroyUserList(long listId) throws TwitterException;
/**
* Unsubscribes the authenticated user form the specified list. <br>
* This method calls http://api.twitter.com/1.1/subscribers/destroy.json
*
* @param listId The id of the list.
* @return the updated list
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/lists/subscribers/destroy">POST
* lists/subscribers/destroy | Twitter Developers</a>
* @since Twitter4J 2.2.3
*/
UserList destroyUserListSubscription(long listId) throws TwitterException;
/**
* Returns the members of the specified list. <br>
* This method calls http://api.twitter.com/1.1/lists/members.json
*
* @param listId The id of the list
* @param paging Breaks the results into pages. A single page contains 20
* lists. Provide a value of -1 to begin paging. Provide values
* as returned to in the response body's next_cursor and
* previous_cursor attributes to page back and forth in the list.
* @return the members of the specified list.
* @throws TwitterException when Twitter service or network is unavailable
* @see <a href="https://dev.twitter.com/docs/api/1.1/get/lists/members">GET
* lists/members | Twitter Developers</a>
* @since Twitter4J 2.2.3
*/
PageableResponseList<User> getUserListMembers(long listId, Paging paging) throws TwitterException;
PageableResponseList<User> getUserListMembers(String slug, long ownerId, Paging paging)
@ -195,106 +68,16 @@ public interface ListsResources {
PageableResponseList<User> getUserListMembers(String slug, String ownerScreenName, Paging paging)
throws TwitterException;
/**
* List the lists the authenticating user has been added to. <br>
* This method calls http://api.twitter.com/1.1/lists/memberships.json
*
* @param cursor Breaks the results into pages. A single page contains 20
* lists. Provide a value of -1 to begin paging. Provide values
* as returned to in the response body's next_cursor and
* previous_cursor attributes to page back and forth in the list.
* @return the list of lists
* @throws TwitterException when Twitter service or network is unavailable
* @throws IllegalStateException when authorization is not enabled
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/lists/memberships">GET
* lists/memberships | Twitter Developers</a>
* @since Twitter4J 2.2.4
*/
PageableResponseList<UserList> getUserListMemberships(long cursor) throws TwitterException;
/**
* List the lists the specified user has been added to. <br>
* This method calls http://api.twitter.com/1.1/lists/memberships.json
*
* @param listMemberId The id of the list member
* @param cursor Breaks the results into pages. A single page contains 20
* lists. Provide a value of -1 to begin paging. Provide values
* as returned to in the response body's next_cursor and
* previous_cursor attributes to page back and forth in the list.
* @return the list of lists
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/lists/memberships">GET
* lists/memberships | Twitter Developers</a>
* @since Twitter4J 2.2.4
*/
PageableResponseList<UserList> getUserListMemberships(long listMemberId, long cursor) throws TwitterException;
/**
* List the lists the specified user has been added to. <br>
* This method calls http://api.twitter.com/1.1/lists/memberships.json
*
* @param listMemberId The id of the list member
* @param cursor Breaks the results into pages. A single page contains 20
* lists. Provide a value of -1 to begin paging. Provide values
* as returned to in the response body's next_cursor and
* previous_cursor attributes to page back and forth in the list.
* @param filterToOwnedLists Whether to return just lists the authenticating
* user owns, and the user represented by listMemberId is a
* member of.
* @return the list of lists
* @throws TwitterException when Twitter service or network is unavailable
* @throws IllegalStateException when filerToOwnedLists is true but
* authorization is not enabled
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/lists/memberships">GET
* lists/memberships | Twitter Developers</a>
* @since Twitter4J 2.2.4
*/
PageableResponseList<UserList> getUserListMemberships(long listMemberId, long cursor, boolean filterToOwnedLists)
throws TwitterException;
/**
* List the lists the specified user has been added to. <br>
* This method calls http://api.twitter.com/1.1/lists/memberships.json
*
* @param listMemberScreenName The screen name of the list member
* @param cursor Breaks the results into pages. A single page contains 20
* lists. Provide a value of -1 to begin paging. Provide values
* as returned to in the response body's next_cursor and
* previous_cursor attributes to page back and forth in the list.
* @return the list of lists
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/lists/memberships">GET
* lists/memberships | Twitter Developers</a>
* @since Twitter4J 2.1.0
*/
PageableResponseList<UserList> getUserListMemberships(String listMemberScreenName, long cursor)
throws TwitterException;
/**
* List the lists the specified user has been added to. <br>
* This method calls http://api.twitter.com/1.1/lists/memberships.json
*
* @param listMemberScreenName The screen name of the list member
* @param cursor Breaks the results into pages. A single page contains 20
* lists. Provide a value of -1 to begin paging. Provide values
* as returned to in the response body's next_cursor and
* previous_cursor attributes to page back and forth in the list.
* @param filterToOwnedLists Whether to return just lists the authenticating
* user owns, and the user represented by listMemberScreenName is
* a member of.
* @return the list of lists
* @throws TwitterException when Twitter service or network is unavailable
* @throws IllegalStateException when filerToOwnedLists is true but
* authorization is not enabled
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/lists/memberships">GET
* lists/memberships | Twitter Developers</a>
* @since Twitter4J 2.2.4
*/
PageableResponseList<UserList> getUserListMemberships(String listMemberScreenName, long cursor,
boolean filterToOwnedLists) throws TwitterException;
@ -305,175 +88,51 @@ public interface ListsResources {
PageableResponseList<UserList> getUserListOwnerships(String listMemberScreenName, long cursor)
throws TwitterException;
/**
* List the lists of the specified user. Private lists will be included if
* the authenticated users is the same as the user whose lists are being
* returned. <br>
* This method calls http://api.twitter.com/1.1/lists.json
*
* @param userId The id of the list owner
* @return the list of lists
* @throws TwitterException when Twitter service or network is unavailable
* @see <a href="https://dev.twitter.com/docs/api/1.1/get/lists">GET lists |
* Twitter Developers</a>
* @since Twitter4J 2.2.3
*/
ResponseList<UserList> getUserLists(long userId, boolean reverse) throws TwitterException;
@GET("/lists/list.json")
ResponseList<UserList> getUserLists(@Query("user_id") long userId, @Query("reverse") boolean reverse) throws TwitterException;
/**
* List the lists of the specified user. Private lists will be included if
* the authenticated users is the same as the user whose lists are being
* returned. <br>
* This method calls http://api.twitter.com/1.1/lists.json
*
* @param screenName The screen name of the user
* @return the list of lists
* @throws TwitterException when Twitter service or network is unavailable
* @see <a href="https://dev.twitter.com/docs/api/1.1/get/lists">GET lists |
* Twitter Developers</a>
* @since Twitter4J 2.1.0
*/
ResponseList<UserList> getUserLists(String screenName, boolean reverse) throws TwitterException;
@GET("/lists/list.json")
ResponseList<UserList> getUserLists(@Query("screen_name") String screenName, @Query("reverse") boolean reverse) throws TwitterException;
/**
* Show tweet timeline for members of the specified list. <br>
* http://api.twitter.com/1.1/user/lists/list_id/statuses.json
*
* @param listId The id of the list
* @param paging controls pagination. Supports since_id, max_id, count and
* page parameters.
* @return list of statuses for members of the specified list
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/lists/statuses">GET
* lists/statuses | Twitter Developers</a>
* @since Twitter4J 2.2.3
*/
ResponseList<Status> getUserListStatuses(long listId, Paging paging) throws TwitterException;
@GET("/lists/statuses.json")
ResponseList<Status> getUserListStatuses(@Query("list_id") long listId, @Query Paging paging) throws TwitterException;
ResponseList<Status> getUserListStatuses(String slug, long ownerId, Paging paging) throws TwitterException;
@GET("/lists/statuses.json")
ResponseList<Status> getUserListStatuses(@Query("list_id") String slug, @Query("owner_id") long ownerId, @Query Paging paging) throws TwitterException;
ResponseList<Status> getUserListStatuses(String slug, String ownerScreenName, Paging paging)
@GET("/lists/statuses.json")
ResponseList<Status> getUserListStatuses(@Query("list_id") String slug, @Query("owner_screen_name") String ownerScreenName, @Query Paging paging)
throws TwitterException;
/**
* Returns the subscribers of the specified list. <br>
* This method calls http://api.twitter.com/1.1/lists/subscribers.json
*
* @param listId The id of the list
* @param paging Breaks the results into pages. A single page contains 20
* lists. Provide a value of -1 to begin paging. Provide values
* as returned to in the response body's next_cursor and
* previous_cursor attributes to page back and forth in the list.
* @return the members of the specified list.
* @throws twitter4j.TwitterException when Twitter service or network is
* unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/lists/subscribers">GET
* lists/subscribers | Twitter Developers</a>
* @since Twitter4J 2.2.3
*/
PageableResponseList<User> getUserListSubscribers(long listId, Paging paging) throws TwitterException;
@GET("/lists/subscribers.json")
PageableResponseList<User> getUserListSubscribers(@Query("list_id") long listId, @Query Paging paging) throws TwitterException;
PageableResponseList<User> getUserListSubscribers(String slug, long ownerId, Paging paging)
@GET("/lists/subscribers.json")
PageableResponseList<User> getUserListSubscribers(@Query("list_id") String slug, @Query("owner_id") long ownerId, @Query Paging paging)
throws TwitterException;
PageableResponseList<User> getUserListSubscribers(String slug, String ownerScreenName, Paging paging)
@GET("/lists/subscribers.json")
PageableResponseList<User> getUserListSubscribers(@Query("list_id") String slug, @Query("owner_screen_name") String ownerScreenName, @Query Paging paging)
throws TwitterException;
/**
* List the lists the specified user follows. <br>
* This method calls http://api.twitter.com/1.1/lists/subscriptions.json
*
* @param listOwnerScreenName The screen name of the list owner
* @param cursor Breaks the results into pages. A single page contains 20
* lists. Provide a value of -1 to begin paging. Provide values
* as returned to in the response body's next_cursor and
* previous_cursor attributes to page back and forth in the list.
* @return the list of lists
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/lists/subscriptions">GET
* lists/subscriptions | Twitter Developers</a>
* @since Twitter4J 2.1.0
*/
PageableResponseList<UserList> getUserListSubscriptions(String listOwnerScreenName, long cursor)
@GET("/lists/subscriptions.json")
PageableResponseList<UserList> getUserListSubscriptions(@Query("screen_name") String listOwnerScreenName, long cursor)
throws TwitterException;
@GET("/lists/subscriptions.json")
PageableResponseList<UserList> getUserListSubscriptions(@Query("user_id") long userId, long cursor)
throws TwitterException;
/**
* Show the specified list. Private lists will only be shown if the
* authenticated user owns the specified list. <br>
* This method calls http://api.twitter.com/1.1/lists/show.json
*
* @param listId The id of the list to show
* @return the specified list
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/lists/show">https://dev.twitter.com/docs/api/1.1/get/lists/show | Twitter Developers</a>
* @since Twitter4J 2.2.3
*/
UserList showUserList(long listId) throws TwitterException;
UserList showUserList(String slug, long ownerId) throws TwitterException;
UserList showUserList(String slug, String ownerScreenName) throws TwitterException;
/**
* Check if a user is a member of the specified list.<br>
* <br>
* This method calls http://api.twitter.com/1.1/lists/members/show.json
*
* @param listId The id of the list.
* @param userId The id of the user who you want to know is a member or not
* of the specified list.
* @return the updated list
* @throws TwitterException when Twitter service or network is unavailable ,
* or the user is not a member of the specified
* list(TwitterException.getStatusCode() returns 404 in that
* case.)
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/lists/members/show">GET
* lists/members/show | Twitter Developers</a>
* @since Twitter4J 2.2.3
*/
User showUserListMembership(long listId, long userId) throws TwitterException;
/**
* Check if the specified user is a subscriber of the specified list. <br>
* This method calls http://api.twitter.com/1.1/lists/subscribers/show.json
*
* @param listId The id of the list.
* @param userId The id of the user who you want to know is a member or not
* of the specified list.
* @return the updated list
* @throws TwitterException when Twitter service or network is unavailable ,
* or the user is not a member of the specified
* list(TwitterException.getStatusCode() returns 404 in that
* case.)
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/get/lists/subscribers/show">GET
* lists/subscribers/show | Twitter Developers</a>
* @since Twitter4J 2.2.3
*/
User showUserListSubscription(long listId, long userId) throws TwitterException;
/**
* Updates the specified list. <br>
* This method calls http://api.twitter.com/1.1/lists/update.json
*
* @param listId The id of the list to update.
* @param newListName What you'd like to change the list's name to.
* @param isPublicList Whether your list is public or private. Optional.
* Values can be public or private. Lists are public by default
* if no mode is specified.
* @param newDescription What you'd like to change the list description to.
* @return the updated list
* @throws TwitterException when Twitter service or network is unavailable
* @see <a
* href="https://dev.twitter.com/docs/api/1.1/post/lists/update ">POST
* lists/update | Twitter Developers</a>
* @since Twitter4J 2.1.0
*/
UserList updateUserList(long listId, String newListName, boolean isPublicList, String newDescription)
throws TwitterException;
UserList updateUserList(@Query("list_id") long listId, @Form UserListUpdate update) throws TwitterException;
}

View File

@ -83,6 +83,7 @@ import org.mariotaku.twidere.view.TabPagerIndicator;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.UserList;
import twitter4j.UserListUpdate;
import static org.mariotaku.twidere.util.MenuUtils.setMenuItemAvailability;
import static org.mariotaku.twidere.util.Utils.addIntentToMenu;
@ -474,7 +475,11 @@ public class UserListFragment extends BaseSupportFragment implements OnClickList
mDescription = ParseUtils.parseString(mEditDescription.getText());
mIsPublic = mPublicCheckBox.isChecked();
if (mName == null || mName.length() <= 0) return;
mTwitterWrapper.updateUserListDetails(mAccountId, mListId, mIsPublic, mName, mDescription);
final UserListUpdate update = new UserListUpdate();
update.setPublic(mIsPublic);
update.setName(mName);
update.setDescription(mDescription);
mTwitterWrapper.updateUserListDetails(mAccountId, mListId, update);
break;
}
}

View File

@ -53,7 +53,7 @@ public class TweetSearchLoader extends TwitterAPIStatusesLoader {
@Override
public List<Status> getStatuses(@NonNull final Twitter twitter, final Paging paging) throws TwitterException {
final SearchQuery query = new SearchQuery(processQuery(mQuery));
query.setRpp(paging.getCount());
query.setCount(paging.getCount());
if (paging.getMaxId() > 0) {
query.setMaxId(paging.getMaxId());
}

View File

@ -96,6 +96,7 @@ import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.User;
import twitter4j.UserList;
import twitter4j.UserListUpdate;
import twitter4j.http.HttpResponseCode;
import static org.mariotaku.twidere.provider.TwidereDataStore.STATUSES_URIS;
@ -107,7 +108,6 @@ import static org.mariotaku.twidere.util.Utils.getDefaultAccountId;
import static org.mariotaku.twidere.util.Utils.getNewestMessageIdsFromDatabase;
import static org.mariotaku.twidere.util.Utils.getNewestStatusIdsFromDatabase;
import static org.mariotaku.twidere.util.Utils.getStatusCountInDatabase;
import static org.mariotaku.twidere.util.TwitterAPIUtils.getTwitterInstance;
import static org.mariotaku.twidere.util.Utils.showErrorMessage;
import static org.mariotaku.twidere.util.Utils.showInfoMessage;
import static org.mariotaku.twidere.util.Utils.showOkMessage;
@ -500,10 +500,8 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
return 0;
}
public int updateUserListDetails(final long accountId, final long listId, final boolean isPublic,
final String name, final String description) {
final UpdateUserListDetailsTask task = new UpdateUserListDetailsTask(accountId, listId, isPublic, name,
description);
public int updateUserListDetails(final long accountId, final long listId, final UserListUpdate update) {
final UpdateUserListDetailsTask task = new UpdateUserListDetailsTask(accountId, listId, update);
return mAsyncTaskManager.add(task, true);
}
@ -2522,17 +2520,13 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
private final long accountId;
private final long listId;
private final boolean isPublic;
private final String name, description;
private final UserListUpdate update;
public UpdateUserListDetailsTask(final long accountId, final long listId, final boolean isPublic,
final String name, final String description) {
public UpdateUserListDetailsTask(final long accountId, final long listId, UserListUpdate update) {
super(mContext, mAsyncTaskManager);
this.accountId = accountId;
this.listId = listId;
this.name = name;
this.isPublic = isPublic;
this.description = description;
this.update = update;
}
@Override
@ -2541,7 +2535,7 @@ public class AsyncTwitterWrapper extends TwitterWrapper {
final Twitter twitter = TwitterAPIUtils.getTwitterInstance(mContext, accountId, false);
if (twitter != null) {
try {
final UserList list = twitter.updateUserList(listId, name, isPublic, description);
final UserList list = twitter.updateUserList(listId, update);
return SingleResponse.getInstance(new ParcelableUserList(list, accountId));
} catch (final TwitterException e) {
return SingleResponse.getInstance(e);