Skip to content
This repository has been archived by the owner on Dec 29, 2021. It is now read-only.

Commit

Permalink
TFJ-628 Fixed
Browse files Browse the repository at this point in the history
Added support for Paging in #getFavorites method. sinceId and paging are supported.
  • Loading branch information
nischal committed Sep 5, 2011
1 parent 5f9c44c commit 31c18fd
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
34 changes: 34 additions & 0 deletions twitter4j-async/src/main/java/twitter4j/AsyncTwitterImpl.java
Expand Up @@ -2273,6 +2273,40 @@ public void invoke(List<TwitterListener> listeners) throws TwitterException {
}
});
}

/**
* {@inheritDoc}
*/
public void getFavorites(final Paging paging) {
getDispatcher().invokeLater(new AsyncTask(FAVORITES, listeners) {
public void invoke(List<TwitterListener> listeners) throws TwitterException {
ResponseList<Status> statuses = twitter.getFavorites(paging);
for (TwitterListener listener : listeners) {
try {
listener.gotFavorites(statuses);
} catch (Exception ignore) {
}
}
}
});
}

/**
* {@inheritDoc}
*/
public void getFavorites(final String id, final Paging paging) {
getDispatcher().invokeLater(new AsyncTask(FAVORITES, listeners) {
public void invoke(List<TwitterListener> listeners) throws TwitterException {
ResponseList<Status> statuses = twitter.getFavorites(id, paging);
for (TwitterListener listener : listeners) {
try {
listener.gotFavorites(statuses);
} catch (Exception ignore) {
}
}
}
});
}

/**
* {@inheritDoc}
Expand Down
Expand Up @@ -16,6 +16,11 @@

package twitter4j.api;

import twitter4j.Paging;
import twitter4j.ResponseList;
import twitter4j.Status;
import twitter4j.TwitterException;

/**
* @author Joern Huxhorn - jhuxhorn at googlemail.com
*/
Expand Down Expand Up @@ -59,6 +64,27 @@ public interface FavoriteMethodsAsync {
* @since Twitter4J 2.0.1
*/
void getFavorites(String id, int page);

/**
* 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/favorites.json
*
* @param paging controls pagination. Supports sinceId and page parameters.
* @see <a href="https://dev.twitter.com/docs/api/1/get/favorites">GET favorites | Twitter Developers</a>
* @since Twitter4J 2.2.5
*/
void getFavorites(Paging paging);

/**
* 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/favorites/[id].json
*
* @param id the ID or screen name of the user for whom to request a list of favorite statuses
* @param paging controls pagination. Supports sinceId and page parameters.
* @see <a href="https://dev.twitter.com/docs/api/1/get/favorites">GET favorites | Twitter Developers</a>
* @since Twitter4J 2.2.5
*/
void getFavorites(String id, Paging paging);

/**
* Favorites the status specified in the ID parameter as the authenticating user. Returns the favorite status when successful.
Expand Down
21 changes: 21 additions & 0 deletions twitter4j-core/src/main/java/twitter4j/TwitterImpl.java
Expand Up @@ -1489,6 +1489,27 @@ public ResponseList<Status> getFavorites(String id, int page) throws TwitterExce
mergeParameters(getParameterArray("page", page)
, INCLUDE_ENTITIES)));
}

/**
* {@inheritDoc}
*/
public ResponseList<Status> getFavorites(Paging paging) throws TwitterException {
ensureAuthorizationEnabled();
return factory.createStatusList(get(conf.getRestBaseURL() + "favorites.json",
mergeParameters(paging.asPostParameterArray()
, INCLUDE_ENTITIES)));
}

/**
* {@inheritDoc}
*/
public ResponseList<Status> getFavorites(String id, Paging paging) throws TwitterException {
ensureAuthorizationEnabled();
return factory.createStatusList(get(conf.getRestBaseURL() + "favorites/"+ id +".json",
mergeParameters(paging.asPostParameterArray()
, INCLUDE_ENTITIES)));
}


/**
* {@inheritDoc}
Expand Down
28 changes: 28 additions & 0 deletions twitter4j-core/src/main/java/twitter4j/api/FavoriteMethods.java
Expand Up @@ -16,6 +16,7 @@

package twitter4j.api;

import twitter4j.Paging;
import twitter4j.ResponseList;
import twitter4j.Status;
import twitter4j.TwitterException;
Expand Down Expand Up @@ -74,6 +75,33 @@ ResponseList<Status> getFavorites(String id)
*/
ResponseList<Status> getFavorites(String id, int page)
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/favorites.json
*
* @param paging controls pagination. Supports sinceId and page parameters.
* @return ResponseList<Status>
* @throws TwitterException when Twitter service or network is unavailable
* @see <a href="https://dev.twitter.com/docs/api/1/get/favorites">GET favorites | Twitter Developers</a>
* @since Twitter4J 2.2.5
*/
ResponseList<Status> getFavorites(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/favorites/[id].json
*
* @param id the ID or 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<Status>
* @throws TwitterException when Twitter service or network is unavailable
* @see <a href="https://dev.twitter.com/docs/api/1/get/favorites">GET favorites | Twitter Developers</a>
* @since Twitter4J 2.2.5
*/
ResponseList<Status> getFavorites(String id, Paging paging)
throws TwitterException;

/**
* Favorites the status specified in the ID parameter as the authenticating user. Returns the favorite status when successful.
Expand Down

0 comments on commit 31c18fd

Please sign in to comment.