Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

TFJ-629 list manipulation with slug - ListSubscribersMethods

  • Loading branch information...
commit 607cc4ce7775ff3d68125e1a5828247b1a907a70 1 parent 8c1d795
@yusuke authored
View
76 twitter4j-async/src/main/java/twitter4j/AsyncTwitterImpl.java
@@ -1581,6 +1581,25 @@ public void invoke(List<TwitterListener> listeners) throws TwitterException {
* {@inheritDoc}
*/
@Override
+ public void getUserListSubscribers(final long ownerId, final String slug, final long cursor) {
+ getDispatcher().invokeLater(new AsyncTask(LIST_SUBSCRIBERS, listeners) {
+ @Override
+ public void invoke(List<TwitterListener> listeners) throws TwitterException {
+ PagableResponseList<User> users = twitter.getUserListSubscribers(ownerId, slug, cursor);
+ for (TwitterListener listener : listeners) {
+ try {
+ listener.gotUserListSubscribers(users);
+ } catch (Exception ignore) {
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void createUserListSubscription(final int listId) {
getDispatcher().invokeLater(new AsyncTask(SUBSCRIBE_LIST, listeners) {
@Override
@@ -1600,6 +1619,25 @@ public void invoke(List<TwitterListener> listeners) throws TwitterException {
* {@inheritDoc}
*/
@Override
+ public void createUserListSubscription(final long ownerId, final String slug) {
+ getDispatcher().invokeLater(new AsyncTask(SUBSCRIBE_LIST, listeners) {
+ @Override
+ public void invoke(List<TwitterListener> listeners) throws TwitterException {
+ UserList list = twitter.createUserListSubscription(ownerId, slug);
+ for (TwitterListener listener : listeners) {
+ try {
+ listener.subscribedUserList(list);
+ } catch (Exception ignore) {
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void destroyUserListSubscription(final int listId) {
getDispatcher().invokeLater(new AsyncTask(UNSUBSCRIBE_LIST, listeners) {
@Override
@@ -1619,6 +1657,25 @@ public void invoke(List<TwitterListener> listeners) throws TwitterException {
* {@inheritDoc}
*/
@Override
+ public void destroyUserListSubscription(final long ownerId, final String slug) {
+ getDispatcher().invokeLater(new AsyncTask(UNSUBSCRIBE_LIST, listeners) {
+ @Override
+ public void invoke(List<TwitterListener> listeners) throws TwitterException {
+ UserList list = twitter.destroyUserListSubscription(ownerId, slug);
+ for (TwitterListener listener : listeners) {
+ try {
+ listener.unsubscribedUserList(list);
+ } catch (Exception ignore) {
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public void showUserListSubscription(final int listId, final long userId) {
getDispatcher().invokeLater(new AsyncTask(CHECK_LIST_SUBSCRIPTION, listeners) {
@Override
@@ -1634,6 +1691,25 @@ public void invoke(List<TwitterListener> listeners) throws TwitterException {
});
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void showUserListSubscription(final long ownerId, final String slug, final long userId) {
+ getDispatcher().invokeLater(new AsyncTask(CHECK_LIST_SUBSCRIPTION, listeners) {
+ @Override
+ public void invoke(List<TwitterListener> listeners) throws TwitterException {
+ User user = twitter.showUserListSubscription(ownerId, slug, userId);
+ for (TwitterListener listener : listeners) {
+ try {
+ listener.checkedUserListSubscription(user);
+ } catch (Exception ignore) {
+ }
+ }
+ }
+ });
+ }
+
/*Direct Message Methods */
/**
View
48 twitter4j-async/src/main/java/twitter4j/api/ListSubscribersMethodsAsync.java
@@ -16,7 +16,6 @@
package twitter4j.api;
-
/**
* @author Joern Huxhorn - jhuxhorn at googlemail.com
*/
@@ -34,6 +33,18 @@
void getUserListSubscribers(int listId, long cursor);
/**
+ * Returns the subscribers of the specified list.
+ * <br>This method calls http://api.twitter.com/1/lists/subscribers.json
+ *
+ * @param ownerId The user ID of the user who owns the list being requested by a slug.
+ * @param slug slug of the list
+ * @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.
+ * @see <a href="https://dev.twitter.com/docs/api/1/get/lists/subscribers">GET lists/subscribers | Twitter Developers</a>
+ * @since Twitter4J 3.0.0
+ */
+ void getUserListSubscribers(long ownerId, String slug, long cursor);
+
+ /**
* Make the authenticated user follow the specified list.
* <br>This method calls http://api.twitter.com/1/list/subscribers/create.json
*
@@ -44,6 +55,17 @@
void createUserListSubscription(int listId);
/**
+ * Make the authenticated user follow the specified list.
+ * <br>This method calls http://api.twitter.com/1/list/subscribers/create.json
+ *
+ * @param ownerId The user ID of the user who owns the list being requested by a slug.
+ * @param slug slug of the list
+ * @see <a href="https://dev.twitter.com/docs/api/1/post/lists/subscribers/create">POST lists/subscribers/create | Twitter Developers</a>
+ * @since Twitter4J 3.0.0
+ */
+ void createUserListSubscription(long ownerId, String slug);
+
+ /**
* Unsubscribes the authenticated user form the specified list.
* <br>This method calls http://api.twitter.com/1/subscribers/destroy.json
*
@@ -54,6 +76,17 @@
void destroyUserListSubscription(int listId);
/**
+ * Unsubscribes the authenticated user form the specified list.
+ * <br>This method calls http://api.twitter.com/1/subscribers/destroy.json
+ *
+ * @param ownerId The user ID of the user who owns the list being requested by a slug.
+ * @param slug slug of the list
+ * @see <a href="https://dev.twitter.com/docs/api/1/post/lists/subscribers/destroy">POST lists/subscribers/destroy | Twitter Developers</a>
+ * @since Twitter4J 3.0.0
+ */
+ void destroyUserListSubscription(long ownerId, String slug);
+
+ /**
* Check if the specified user is a subscriber of the specified list.
* <br>This method calls http://api.twitter.com/1/lists/subscribers/show.json
*
@@ -64,4 +97,17 @@
* @since Twitter4J 2.2.3
*/
void showUserListSubscription(int listId, long userId);
+
+ /**
+ * Check if the specified user is a subscriber of the specified list.
+ * <br>This method calls http://api.twitter.com/1/lists/subscribers/show.json
+ *
+ * @param ownerId The user ID of the user who owns the list being requested by a slug.
+ * @param slug slug of the list
+ * @param userId The id of the user who you want to know is a member or not of the specified list.
+ * , 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/get/lists/subscribers/show">GET lists/subscribers/show | Twitter Developers</a>
+ * @since Twitter4J 3.0.0
+ */
+ void showUserListSubscription(long ownerId, String slug, long userId);
}
View
46 twitter4j-core/src/main/java/twitter4j/TwitterImpl.java
@@ -916,11 +916,30 @@ public User showUserListMembership(long ownerId, String slug, long userId) throw
* {@inheritDoc}
*/
@Override
+ public PagableResponseList<User> getUserListSubscribers(long ownerId, String slug, long cursor) throws TwitterException {
+ return factory.createPagableUserList(get(conf.getRestBaseURL() + "lists/subscribers.json?owner_id=" + ownerId
+ + "&slug=" + slug + "&cursor=" + cursor));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
public UserList createUserListSubscription(int listId) throws TwitterException {
ensureAuthorizationEnabled();
return factory.createAUserList(post(conf.getRestBaseURL() +
- "lists/subscribers/create.json"
- , new HttpParameter[]{new HttpParameter("list_id", listId)}));
+ "lists/subscribers/create.json", new HttpParameter[]{new HttpParameter("list_id", listId)}));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public UserList createUserListSubscription(long ownerId, String slug) throws TwitterException {
+ ensureAuthorizationEnabled();
+ return factory.createAUserList(post(conf.getRestBaseURL() +
+ "lists/subscribers/create.json", new HttpParameter[]{new HttpParameter("owner_id", ownerId)
+ , new HttpParameter("slug", slug)}));
}
/**
@@ -930,8 +949,17 @@ public UserList createUserListSubscription(int listId) throws TwitterException {
public UserList destroyUserListSubscription(int listId) throws TwitterException {
ensureAuthorizationEnabled();
return factory.createAUserList(post(conf.getRestBaseURL() +
- "lists/subscribers/destroy.json",
- new HttpParameter[]{new HttpParameter("list_id", listId)}));
+ "lists/subscribers/destroy.json", new HttpParameter[]{new HttpParameter("list_id", listId)}));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public UserList destroyUserListSubscription(long ownerId, String slug) throws TwitterException {
+ ensureAuthorizationEnabled();
+ return factory.createAUserList(post(conf.getRestBaseURL() + "lists/subscribers/destroy.json"
+ , new HttpParameter[]{new HttpParameter("owner_id", ownerId), new HttpParameter("slug", slug)}));
}
/**
@@ -944,6 +972,16 @@ public User showUserListSubscription(int listId, long userId) throws TwitterExce
"lists/subscribers/show.json?list_id=" + listId + "&user_id=" + userId));
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public User showUserListSubscription(long ownerId, String slug, long userId) throws TwitterException {
+ ensureAuthorizationEnabled();
+ return factory.createUser(get(conf.getRestBaseURL() +
+ "lists/subscribers/show.json?owner_id=" + ownerId + "&slug=" + slug + "&user_id=" + userId));
+ }
+
/*Direct Message Methods */
/**
View
61 twitter4j-core/src/main/java/twitter4j/api/ListSubscribersMethods.java
@@ -36,8 +36,21 @@
* @see <a href="https://dev.twitter.com/docs/api/1/get/lists/subscribers">GET lists/subscribers | Twitter Developers</a>
* @since Twitter4J 2.2.3
*/
- PagableResponseList<User> getUserListSubscribers(int listId, long cursor)
- throws TwitterException;
+ PagableResponseList<User> getUserListSubscribers(int listId, long cursor) throws TwitterException;
+
+ /**
+ * Returns the subscribers of the specified list.
+ * <br>This method calls http://api.twitter.com/1/lists/subscribers.json
+ *
+ * @param ownerId The user ID of the user who owns the list being requested by a slug.
+ * @param slug slug of the list
+ * @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 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/get/lists/subscribers">GET lists/subscribers | Twitter Developers</a>
+ * @since Twitter4J 3.0.0
+ */
+ PagableResponseList<User> getUserListSubscribers(long ownerId, String slug, long cursor) throws TwitterException;
/**
* Make the authenticated user follow the specified list.
@@ -52,6 +65,19 @@
UserList createUserListSubscription(int listId) throws TwitterException;
/**
+ * Make the authenticated user follow the specified list.
+ * <br>This method calls http://api.twitter.com/1/list/subscribers/create.json
+ *
+ * @param ownerId The user ID of the user who owns the list being requested by a slug.
+ * @param slug slug 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/post/lists/subscribers/create">POST lists/subscribers/create | Twitter Developers</a>
+ * @since Twitter4J 3.0.0
+ */
+ UserList createUserListSubscription(long ownerId, String slug) throws TwitterException;
+
+ /**
* Unsubscribes the authenticated user form the specified list.
* <br>This method calls http://api.twitter.com/1/subscribers/destroy.json
*
@@ -64,6 +90,19 @@
UserList destroyUserListSubscription(int listId) throws TwitterException;
/**
+ * Unsubscribes the authenticated user form the specified list.
+ * <br>This method calls http://api.twitter.com/1/subscribers/destroy.json
+ *
+ * @param ownerId The user ID of the user who owns the list being requested by a slug.
+ * @param slug slug 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/post/lists/subscribers/destroy">POST lists/subscribers/destroy | Twitter Developers</a>
+ * @since Twitter4J 3.0.0
+ */
+ UserList destroyUserListSubscription(long ownerId, String slug) throws TwitterException;
+
+ /**
* Check if the specified user is a subscriber of the specified list.
* <br>This method calls http://api.twitter.com/1/lists/subscribers/show.json
*
@@ -75,6 +114,20 @@
* @see <a href="https://dev.twitter.com/docs/api/1/get/lists/subscribers/show">GET lists/subscribers/show | Twitter Developers</a>
* @since Twitter4J 2.2.3
*/
- User showUserListSubscription(int listId, long userId)
- throws TwitterException;
+ User showUserListSubscription(int 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/lists/subscribers/show.json
+ *
+ * @param ownerId The user ID of the user who owns the list being requested by a slug.
+ * @param slug slug 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/get/lists/subscribers/show">GET lists/subscribers/show | Twitter Developers</a>
+ * @since Twitter4J 3.0.0
+ */
+ User showUserListSubscription(long ownerId, String slug, long userId) throws TwitterException;
}
Please sign in to comment.
Something went wrong with that request. Please try again.