diff --git a/spring-social-twitter/src/main/java/org/springframework/social/twitter/api/ListOperations.java b/spring-social-twitter/src/main/java/org/springframework/social/twitter/api/ListOperations.java index 55ab55a6..fa3ee988 100644 --- a/spring-social-twitter/src/main/java/org/springframework/social/twitter/api/ListOperations.java +++ b/spring-social-twitter/src/main/java/org/springframework/social/twitter/api/ListOperations.java @@ -192,11 +192,12 @@ public interface ListOperations { * Supports either user or application authorization. * @param listId the ID of the list. * @param cursor the cursor to use when fetching the list members. + * @param pageSize The number of {@link TwitterProfile}s per page. The default is 20, with a maximum of 5000 per page. * @throws ApiException if there is an error while communicating with Twitter. * @throws MissingAuthorizationException if TwitterTemplate was not created with OAuth credentials or an application access token. * @return a list of {@link TwitterProfile} */ - CursoredList getListMembersInCursor(long listId, long cursor); + CursoredList getListMembersInCursor(long listId, long cursor, int pageSize); /** * Retrieves a list of Twitter profiles whose users are members of the list. @@ -215,11 +216,12 @@ public interface ListOperations { * @param screenName the screen name of the list owner. * @param listSlug the slug of the list. * @param cursor the cursor to use when fetching the list members. + * @param pageSize The number of {@link TwitterProfile}s per page. The default is 20, with a maximum of 5000 per page. * @throws ApiException if there is an error while communicating with Twitter. * @throws MissingAuthorizationException if TwitterTemplate was not created with OAuth credentials or an application access token. * @return a list of {@link TwitterProfile} */ - CursoredList getListMembersInCursor(String screenName, String listSlug, long cursor); + CursoredList getListMembersInCursor(String screenName, String listSlug, long cursor, int pageSize); /** * Adds one or more new members to a user list. @@ -305,7 +307,7 @@ public interface ListOperations { * @throws ApiException if there is an error while communicating with Twitter. * @throws MissingAuthorizationException if TwitterTemplate was not created with OAuth credentials or an application access token. */ - List getListSubscribers(long listId); + CursoredList getListSubscribers(long listId); /** * Retrieves the subscribers to a list. @@ -316,7 +318,32 @@ public interface ListOperations { * @throws ApiException if there is an error while communicating with Twitter. * @throws MissingAuthorizationException if TwitterTemplate was not created with OAuth credentials or an application access token. */ - List getListSubscribers(String screenName, String listSlug); + CursoredList getListSubscribers(String screenName, String listSlug); + + /** + * Retrieves the subscribers to a list. + * Supports either user or application authorization. + * @param listId the ID of the list. + * @param cursor the cursor to use when fetching the list subscribers. + * @param pageSize The number of {@link TwitterProfile}s per page. The default is 20, with a maximum of 5000 per page. + * @return a list of {@link TwitterProfile}s for the list's subscribers. + * @throws ApiException if there is an error while communicating with Twitter. + * @throws MissingAuthorizationException if TwitterTemplate was not created with OAuth credentials or an application access token. + */ + CursoredList getListSubscribersInCursor(long listId, long cursor, int pageSize); + + /** + * Retrieves the subscribers to a list. + * Supports either user or application authorization. + * @param screenName the screen name of the list owner. + * @param listSlug the slug of the list. + * @param cursor the cursor to use when fetching the list subscribers. + * @param pageSize The number of {@link TwitterProfile}s per page. The default is 20, with a maximum of 5000 per page. + * @return a list of {@link TwitterProfile}s for the list's subscribers. + * @throws ApiException if there is an error while communicating with Twitter. + * @throws MissingAuthorizationException if TwitterTemplate was not created with OAuth credentials or an application access token. + */ + CursoredList getListSubscribersInCursor(String screenName, String listSlug, long cursor, int pageSize); /** * Retrieves the lists that a given user is a member of. @@ -343,22 +370,68 @@ public interface ListOperations { * Supports either user or application authorization. * @param userId the user ID * @param cursor the cursor to use when fetching the list memberships. + * @param pageSize The number of {@link UserList}s per page. The default is 20, with a maximum of 1000 per page. * @return a list of {@link UserList}s that the user is a member of. * @throws ApiException if there is an error while communicating with Twitter. * @throws MissingAuthorizationException if TwitterTemplate was not created with OAuth credentials or an application access token. */ - CursoredList getMembershipsInCursor(long userId, long cursor); + CursoredList getMembershipsInCursor(long userId, long cursor, int pageSize); /** * Retrieves the lists that a given user is a member of. * Supports either user or application authorization. * @param screenName the user's screen name * @param cursor the cursor to use when fetching the list memberships. + * @param pageSize The number of {@link UserList}s per page. The default is 20, with a maximum of 1000 per page. * @return a list of {@link UserList}s that the user is a member of. * @throws ApiException if there is an error while communicating with Twitter. * @throws MissingAuthorizationException if TwitterTemplate was not created with OAuth credentials or an application access token. */ - CursoredList getMembershipsInCursor(String screenName, long cursor); + CursoredList getMembershipsInCursor(String screenName, long cursor, int pageSize); + + /** + * Retrieves the lists that a given user is owned by. + * Supports either user or application authorization. + * @param userId the user ID + * @return a list of {@link UserList}s that the user is owned by. + * @throws ApiException if there is an error while communicating with Twitter. + * @throws MissingAuthorizationException if TwitterTemplate was not created with OAuth credentials or an application access token. + */ + CursoredList getOwnerships(long userId); + + /** + * Retrieves the lists that a given user is owned by. + * Supports either user or application authorization. + * @param screenName the user's screen name + * @return a list of {@link UserList}s that the user is owned by. + * @throws ApiException if there is an error while communicating with Twitter. + * @throws MissingAuthorizationException if TwitterTemplate was not created with OAuth credentials or an application access token. + */ + CursoredList getOwnerships(String screenName); + + /** + * Retrieves the lists that a given user is owned by. + * Supports either user or application authorization. + * @param userId the user ID + * @param cursor the cursor to use when fetching the list memberships. + * @param pageSize The number of {@link UserList}s per page. The default is 20, with a maximum of 1000 per page. + * @return a list of {@link UserList}s that the user is owned by. + * @throws ApiException if there is an error while communicating with Twitter. + * @throws MissingAuthorizationException if TwitterTemplate was not created with OAuth credentials or an application access token. + */ + CursoredList getOwnershipsInCursor(long userId, long cursor, int pageSize); + + /** + * Retrieves the lists that a given user is owned by. + * Supports either user or application authorization. + * @param screenName the user's screen name + * @param cursor the cursor to use when fetching the list memberships. + * @param pageSize The number of {@link UserList}s per page. The default is 20, with a maximum of 1000 per page. + * @return a list of {@link UserList}s that the user is owned by. + * @throws ApiException if there is an error while communicating with Twitter. + * @throws MissingAuthorizationException if TwitterTemplate was not created with OAuth credentials or an application access token. + */ + CursoredList getOwnershipsInCursor(String screenName, long cursor, int pageSize); /** * Retrieves the lists that a given user is subscribed to. @@ -385,22 +458,24 @@ public interface ListOperations { * Supports either user or application authorization. * @param userId the user ID * @param cursor the cursor to use when fetching the list subscriptions. + * @param pageSize The number of {@link UserList}s per page. The default is 20, with a maximum of 1000 per page. * @return a list of {@link UserList}s that the user is subscribed to. * @throws ApiException if there is an error while communicating with Twitter. * @throws MissingAuthorizationException if TwitterTemplate was not created with OAuth credentials or an application access token. */ - CursoredList getSubscriptionsInCursor(long userId, long cursor); + CursoredList getSubscriptionsInCursor(long userId, long cursor, int pageSize); /** * Retrieves the lists that a given user is subscribed to. * Supports either user or application authorization. * @param screenName the user's screen name * @param cursor the cursor to use when fetching the list subscriptions. + * @param pageSize The number of {@link UserList}s per page. The default is 20, with a maximum of 1000 per page. * @return a list of {@link UserList}s that the user is subscribed to. * @throws ApiException if there is an error while communicating with Twitter. * @throws MissingAuthorizationException if TwitterTemplate was not created with OAuth credentials or an application access token. */ - CursoredList getSubscriptionsInCursor(String screenName, long cursor); + CursoredList getSubscriptionsInCursor(String screenName, long cursor, int pageSize); /** * Checks to see if a given user is a member of a given list. diff --git a/spring-social-twitter/src/main/java/org/springframework/social/twitter/api/ResourceFamily.java b/spring-social-twitter/src/main/java/org/springframework/social/twitter/api/ResourceFamily.java index 07427f8b..3ed488d3 100644 --- a/spring-social-twitter/src/main/java/org/springframework/social/twitter/api/ResourceFamily.java +++ b/spring-social-twitter/src/main/java/org/springframework/social/twitter/api/ResourceFamily.java @@ -29,6 +29,7 @@ public enum ResourceFamily { APPLICATION("application"), BLOCKS("blocks"), DIRECT_MESSAGES("direct_messages"), + FAVORITES("favorites"), FOLLOWERS("followers"), FRIENDS("friends"), FRIENDSHIPS("friendships"), diff --git a/spring-social-twitter/src/main/java/org/springframework/social/twitter/api/impl/ListTemplate.java b/spring-social-twitter/src/main/java/org/springframework/social/twitter/api/impl/ListTemplate.java index c21f531a..f9fbf16e 100644 --- a/spring-social-twitter/src/main/java/org/springframework/social/twitter/api/impl/ListTemplate.java +++ b/spring-social-twitter/src/main/java/org/springframework/social/twitter/api/impl/ListTemplate.java @@ -34,24 +34,24 @@ * @author Craig Walls */ class ListTemplate extends AbstractTwitterOperations implements ListOperations { - + private final RestTemplate restTemplate; - + public ListTemplate(RestTemplate restTemplate, boolean isAuthorizedForUser, boolean isAuthorizedForApp) { super(isAuthorizedForUser, isAuthorizedForApp); this.restTemplate = restTemplate; } - + public List getLists() { requireUserAuthorization(); return restTemplate.getForObject(buildUri("lists/list.json"), UserSubscriptionList.class); } - + public List getLists(long userId) { requireEitherUserOrAppAuthorization(); return restTemplate.getForObject(buildUri("lists/list.json", "user_id", String.valueOf(userId)), UserSubscriptionList.class); } - + public List getLists(String screenName) { requireEitherUserOrAppAuthorization(); return restTemplate.getForObject(buildUri("lists/list.json", "screen_name", String.valueOf(screenName)), UserSubscriptionList.class); @@ -103,7 +103,7 @@ public List getListStatuses(String screenName, String listSlug, int pageS return restTemplate.getForObject(buildUri("lists/statuses.json", parameters), TweetList.class); } - public UserList createList(String name, String description, boolean isPublic) { + public UserList createList(String name, String description, boolean isPublic) { requireUserAuthorization(); MultiValueMap request = buildListDataMap(name, description, isPublic); return restTemplate.postForObject(buildUri("lists/create.json"), request, UserList.class); @@ -128,11 +128,12 @@ public CursoredList getListMembers(long listId) { return restTemplate.getForObject(buildUri("lists/members.json", "list_id", String.valueOf(listId)), TwitterProfileUsersList.class).getList(); } - public CursoredList getListMembersInCursor(long listId, long cursor) { + public CursoredList getListMembersInCursor(long listId, long cursor, int pageSize) { requireEitherUserOrAppAuthorization(); MultiValueMap request = new LinkedMultiValueMap(); request.set("list_id", String.valueOf(listId)); request.set("cursor", String.valueOf(cursor)); + request.set("count", String.valueOf(pageSize)); return restTemplate.getForObject(buildUri("lists/members.json", request), TwitterProfileUsersList.class).getList(); } @@ -144,12 +145,13 @@ public CursoredList getListMembers(String screenName, String lis return restTemplate.getForObject(buildUri("lists/members.json", parameters), TwitterProfileUsersList.class).getList(); } - public CursoredList getListMembersInCursor(String screenName, String listSlug, long cursor) { + public CursoredList getListMembersInCursor(String screenName, String listSlug, long cursor, int pageSize) { requireEitherUserOrAppAuthorization(); LinkedMultiValueMap parameters = new LinkedMultiValueMap(); parameters.set("owner_screen_name", screenName); parameters.set("slug", listSlug); parameters.set("cursor", String.valueOf(cursor)); + parameters.set("count", String.valueOf(pageSize)); return restTemplate.getForObject(buildUri("lists/members.json", parameters), TwitterProfileUsersList.class).getList(); } @@ -172,7 +174,7 @@ public UserList addToList(long listId, String... newMemberScreenNames) { public void removeFromList(long listId, long memberId) { requireUserAuthorization(); MultiValueMap request = new LinkedMultiValueMap(); - request.set("user_id", String.valueOf(memberId)); + request.set("user_id", String.valueOf(memberId)); request.set("list_id", String.valueOf(listId)); restTemplate.postForObject(buildUri("lists/members/destroy.json"), request, String.class); } @@ -180,24 +182,43 @@ public void removeFromList(long listId, long memberId) { public void removeFromList(long listId, String memberScreenName) { requireUserAuthorization(); MultiValueMap request = new LinkedMultiValueMap(); - request.set("screen_name", String.valueOf(memberScreenName)); + request.set("screen_name", String.valueOf(memberScreenName)); request.set("list_id", String.valueOf(listId)); restTemplate.postForObject(buildUri("lists/members/destroy.json"), request, String.class); } - public List getListSubscribers(long listId) { + public CursoredList getListSubscribers(long listId) { requireEitherUserOrAppAuthorization(); return restTemplate.getForObject(buildUri("lists/subscribers.json", "list_id", String.valueOf(listId)), TwitterProfileUsersList.class).getList(); } - public List getListSubscribers(String screenName, String listSlug) { + public CursoredList getListSubscribers(String screenName, String listSlug) { requireEitherUserOrAppAuthorization(); LinkedMultiValueMap parameters = new LinkedMultiValueMap(); parameters.set("owner_screen_name", screenName); parameters.set("slug", listSlug); return restTemplate.getForObject(buildUri("lists/subscribers.json", parameters), TwitterProfileUsersList.class).getList(); } - + + public CursoredList getListSubscribersInCursor(long listId, long cursor, int pageSize) { + requireEitherUserOrAppAuthorization(); + MultiValueMap request = new LinkedMultiValueMap(); + request.set("list_id", String.valueOf(listId)); + request.set("cursor", String.valueOf(cursor)); + request.set("count", String.valueOf(pageSize)); + return restTemplate.getForObject(buildUri("lists/subscribers.json", request), TwitterProfileUsersList.class).getList(); + } + + public CursoredList getListSubscribersInCursor(String screenName, String listSlug, long cursor, int pageSize){ + requireEitherUserOrAppAuthorization(); + LinkedMultiValueMap parameters = new LinkedMultiValueMap(); + parameters.set("owner_screen_name", screenName); + parameters.set("slug", listSlug); + parameters.set("cursor", String.valueOf(cursor)); + parameters.set("count", String.valueOf(pageSize)); + return restTemplate.getForObject(buildUri("lists/subscribers.json", parameters), TwitterProfileUsersList.class).getList(); + } + public UserList subscribe(long listId) { requireUserAuthorization(); MultiValueMap request = new LinkedMultiValueMap(); @@ -238,22 +259,52 @@ public CursoredList getMemberships(String screenName) { return restTemplate.getForObject(buildUri("lists/memberships.json", "screen_name", screenName), UserListList.class).getList(); } - public CursoredList getMembershipsInCursor(long userId, long cursor) { + public CursoredList getMembershipsInCursor(long userId, long cursor, int pageSize) { requireEitherUserOrAppAuthorization(); MultiValueMap request = new LinkedMultiValueMap(); request.set("user_id", String.valueOf(userId)); request.set("cursor", String.valueOf(cursor)); + request.set("count", String.valueOf(pageSize)); return restTemplate.getForObject(buildUri("lists/memberships.json", request), UserListList.class).getList(); } - public CursoredList getMembershipsInCursor(String screenName, long cursor) { + public CursoredList getMembershipsInCursor(String screenName, long cursor, int pageSize) { requireEitherUserOrAppAuthorization(); MultiValueMap request = new LinkedMultiValueMap(); request.set("screen_name", screenName); request.set("cursor", String.valueOf(cursor)); + request.set("count", String.valueOf(pageSize)); return restTemplate.getForObject(buildUri("lists/memberships.json", request), UserListList.class).getList(); } + public CursoredList getOwnerships(long userId) { + requireEitherUserOrAppAuthorization(); + return restTemplate.getForObject(buildUri("lists/ownerships.json", "user_id", String.valueOf(userId)), UserListList.class).getList(); + } + + public CursoredList getOwnerships(String screenName) { + requireEitherUserOrAppAuthorization(); + return restTemplate.getForObject(buildUri("lists/ownerships.json", "screen_name", screenName), UserListList.class).getList(); + } + + public CursoredList getOwnershipsInCursor(long userId, long cursor, int pageSize) { + requireEitherUserOrAppAuthorization(); + MultiValueMap request = new LinkedMultiValueMap(); + request.set("user_id", String.valueOf(userId)); + request.set("cursor", String.valueOf(cursor)); + request.set("count", String.valueOf(pageSize)); + return restTemplate.getForObject(buildUri("lists/ownerships.json", request), UserListList.class).getList(); + } + + public CursoredList getOwnershipsInCursor(String screenName, long cursor, int pageSize) { + requireEitherUserOrAppAuthorization(); + MultiValueMap request = new LinkedMultiValueMap(); + request.set("screen_name", screenName); + request.set("cursor", String.valueOf(cursor)); + request.set("count", String.valueOf(pageSize)); + return restTemplate.getForObject(buildUri("lists/ownerships.json", request), UserListList.class).getList(); + } + public CursoredList getSubscriptions(long userId) { requireEitherUserOrAppAuthorization(); return restTemplate.getForObject(buildUri("lists/subscriptions.json", "user_id", String.valueOf(userId)), UserListList.class).getList(); @@ -264,19 +315,21 @@ public CursoredList getSubscriptions(String screenName) { return restTemplate.getForObject(buildUri("lists/subscriptions.json", "screen_name", screenName), UserListList.class).getList(); } - public CursoredList getSubscriptionsInCursor(long userId, long cursor) { + public CursoredList getSubscriptionsInCursor(long userId, long cursor, int pageSize) { requireEitherUserOrAppAuthorization(); MultiValueMap request = new LinkedMultiValueMap(); request.set("user_id", String.valueOf(userId)); request.set("cursor", String.valueOf(cursor)); + request.set("count", String.valueOf(pageSize)); return restTemplate.getForObject(buildUri("lists/subscriptions.json", request), UserListList.class).getList(); } - public CursoredList getSubscriptionsInCursor(String screenName, long cursor) { + public CursoredList getSubscriptionsInCursor(String screenName, long cursor, int pageSize) { requireEitherUserOrAppAuthorization(); MultiValueMap request = new LinkedMultiValueMap(); request.set("screen_name", screenName); request.set("cursor", String.valueOf(cursor)); + request.set("count", String.valueOf(pageSize)); return restTemplate.getForObject(buildUri("lists/subscriptions.json", request), UserListList.class).getList(); } diff --git a/spring-social-twitter/src/test/java/org/springframework/social/twitter/api/impl/ListsTemplateTest.java b/spring-social-twitter/src/test/java/org/springframework/social/twitter/api/impl/ListsTemplateTest.java index 1080b751..cbed0f56 100644 --- a/spring-social-twitter/src/test/java/org/springframework/social/twitter/api/impl/ListsTemplateTest.java +++ b/spring-social-twitter/src/test/java/org/springframework/social/twitter/api/impl/ListsTemplateTest.java @@ -159,14 +159,13 @@ public void getListMembers_byListId() { @Test public void getListMembersInCursor_byListId() { - mockServer.expect(requestTo("https://api.twitter.com/1.1/lists/members.json?list_id=40841803&cursor=12345")) + mockServer.expect(requestTo("https://api.twitter.com/1.1/lists/members.json?list_id=40841803&cursor=12345&count=20")) .andExpect(method(GET)) .andRespond(withSuccess(jsonResource("list-members"), APPLICATION_JSON)); - CursoredList listMembers = twitter.listOperations().getListMembersInCursor(40841803, 12345); + CursoredList listMembers = twitter.listOperations().getListMembersInCursor(40841803, 12345, 20); assertListMembers(listMembers); assertEquals(332211, listMembers.getNextCursor()); assertEquals(112233, listMembers.getPreviousCursor()); - } @Test @@ -179,10 +178,10 @@ public void getListMembers_byScreenNameAndListSlug() { @Test public void getListMembersInCursor_byScreenNameAndListSlug() { - mockServer.expect(requestTo("https://api.twitter.com/1.1/lists/members.json?owner_screen_name=habuma&slug=forfun&cursor=12345")) + mockServer.expect(requestTo("https://api.twitter.com/1.1/lists/members.json?owner_screen_name=habuma&slug=forfun&cursor=12345&count=20")) .andExpect(method(GET)) .andRespond(withSuccess(jsonResource("list-members"), APPLICATION_JSON)); - CursoredList listMembers = twitter.listOperations().getListMembersInCursor("habuma", "forfun", 12345); + CursoredList listMembers = twitter.listOperations().getListMembersInCursor("habuma", "forfun", 12345, 20); assertListMembers(listMembers); assertEquals(332211, listMembers.getNextCursor()); assertEquals(112233, listMembers.getPreviousCursor()); @@ -254,7 +253,7 @@ public void getListSubscribers_byListId() { .andRespond(withSuccess(jsonResource("list-members"), APPLICATION_JSON)); assertListMembers(twitter.listOperations().getListSubscribers(40841803)); } - + @Test public void getListSubscribers_byScreenNameAndListSlug() { mockServer.expect(requestTo("https://api.twitter.com/1.1/lists/subscribers.json?owner_screen_name=habuma&slug=forfun")) @@ -263,6 +262,28 @@ public void getListSubscribers_byScreenNameAndListSlug() { assertListMembers(twitter.listOperations().getListSubscribers("habuma", "forfun")); } + @Test + public void getListSubscribersInCursor_byListId() { + mockServer.expect(requestTo("https://api.twitter.com/1.1/lists/subscribers.json?list_id=40841803&cursor=12345&count=20")) + .andExpect(method(GET)) + .andRespond(withSuccess(jsonResource("list-members"), APPLICATION_JSON)); + CursoredList listMembers = twitter.listOperations().getListSubscribersInCursor(40841803, 12345, 20); + assertListMembers(listMembers); + assertEquals(332211, listMembers.getNextCursor()); + assertEquals(112233, listMembers.getPreviousCursor()); + } + + @Test + public void getListSubscribersInCursor_byScreenNameAndListSlug() { + mockServer.expect(requestTo("https://api.twitter.com/1.1/lists/subscribers.json?owner_screen_name=habuma&slug=forfun&cursor=12345&count=20")) + .andExpect(method(GET)) + .andRespond(withSuccess(jsonResource("list-members"), APPLICATION_JSON)); + CursoredList listMembers = twitter.listOperations().getListSubscribersInCursor("habuma", "forfun", 12345, 20); + assertListMembers(listMembers); + assertEquals(332211, listMembers.getNextCursor()); + assertEquals(112233, listMembers.getPreviousCursor()); + } + @Test public void getListSubscribers_byScreenNameAndListSlug_appAuthorization() { appAuthMockServer.expect(requestTo("https://api.twitter.com/1.1/lists/subscribers.json?owner_screen_name=habuma&slug=forfun")) @@ -282,10 +303,10 @@ public void getMemberships_forUserId() { @Test public void getMembershipsInCursor_forUserId() { - mockServer.expect(requestTo("https://api.twitter.com/1.1/lists/memberships.json?user_id=161064614&cursor=12345")) + mockServer.expect(requestTo("https://api.twitter.com/1.1/lists/memberships.json?user_id=161064614&cursor=12345&count=20")) .andExpect(method(GET)) .andRespond(withSuccess(jsonResource("list-of-lists"), APPLICATION_JSON)); - CursoredList memberships = twitter.listOperations().getMembershipsInCursor(161064614, 12345); + CursoredList memberships = twitter.listOperations().getMembershipsInCursor(161064614, 12345, 20); assertListOfLists(memberships); assertEquals(234567, memberships.getNextCursor()); assertEquals(123456, memberships.getPreviousCursor()); @@ -310,10 +331,10 @@ public void getMemberships_forScreenName() { @Test public void getMembershipsInCursor_forScreenName() { - mockServer.expect(requestTo("https://api.twitter.com/1.1/lists/memberships.json?screen_name=habuma&cursor=12345")) + mockServer.expect(requestTo("https://api.twitter.com/1.1/lists/memberships.json?screen_name=habuma&cursor=12345&count=20")) .andExpect(method(GET)) .andRespond(withSuccess(jsonResource("list-of-lists"), APPLICATION_JSON)); - CursoredList memberships = twitter.listOperations().getMembershipsInCursor("habuma", 12345); + CursoredList memberships = twitter.listOperations().getMembershipsInCursor("habuma", 12345, 20); assertListOfLists(memberships); assertEquals(234567, memberships.getNextCursor()); assertEquals(123456, memberships.getPreviousCursor()); @@ -328,6 +349,62 @@ public void getMemberships_forScreenName_appAuthorization() { assertListOfLists(appAuthTwitter.listOperations().getMemberships("habuma")); } +@Test + public void getOwnerships_forUserId() { + mockServer.expect(requestTo("https://api.twitter.com/1.1/lists/ownerships.json?user_id=161064614")) + .andExpect(method(GET)) + .andRespond(withSuccess(jsonResource("list-of-lists"), APPLICATION_JSON)); + assertListOfLists(twitter.listOperations().getOwnerships(161064614)); + } + + @Test + public void getOwnershipsInCursor_forUserId() { + mockServer.expect(requestTo("https://api.twitter.com/1.1/lists/ownerships.json?user_id=161064614&cursor=12345&count=20")) + .andExpect(method(GET)) + .andRespond(withSuccess(jsonResource("list-of-lists"), APPLICATION_JSON)); + CursoredList ownerships = twitter.listOperations().getOwnershipsInCursor(161064614, 12345, 20); + assertListOfLists(ownerships); + assertEquals(234567, ownerships.getNextCursor()); + assertEquals(123456, ownerships.getPreviousCursor()); + } + + @Test + public void getOwnerships_forUserId_appAuthorization() { + appAuthMockServer.expect(requestTo("https://api.twitter.com/1.1/lists/ownerships.json?user_id=161064614")) + .andExpect(method(GET)) + .andExpect(header("Authorization", "Bearer APP_ACCESS_TOKEN")) + .andRespond(withSuccess(jsonResource("list-of-lists"), APPLICATION_JSON)); + assertListOfLists(appAuthTwitter.listOperations().getOwnerships(161064614)); + } + + @Test + public void getOwnerships_forScreenName() { + mockServer.expect(requestTo("https://api.twitter.com/1.1/lists/ownerships.json?screen_name=habuma")) + .andExpect(method(GET)) + .andRespond(withSuccess(jsonResource("list-of-lists"), APPLICATION_JSON)); + assertListOfLists(twitter.listOperations().getOwnerships("habuma")); + } + + @Test + public void getOwnershipsInCursor_forScreenName() { + mockServer.expect(requestTo("https://api.twitter.com/1.1/lists/ownerships.json?screen_name=habuma&cursor=12345&count=20")) + .andExpect(method(GET)) + .andRespond(withSuccess(jsonResource("list-of-lists"), APPLICATION_JSON)); + CursoredList ownerships = twitter.listOperations().getOwnershipsInCursor("habuma", 12345, 20); + assertListOfLists(ownerships); + assertEquals(234567, ownerships.getNextCursor()); + assertEquals(123456, ownerships.getPreviousCursor()); + } + + @Test + public void getOwnerships_forScreenName_appAuthorization() { + appAuthMockServer.expect(requestTo("https://api.twitter.com/1.1/lists/ownerships.json?screen_name=habuma")) + .andExpect(method(GET)) + .andExpect(header("Authorization", "Bearer APP_ACCESS_TOKEN")) + .andRespond(withSuccess(jsonResource("list-of-lists"), APPLICATION_JSON)); + assertListOfLists(appAuthTwitter.listOperations().getOwnerships("habuma")); + } + @Test public void getSubscriptions_forUserId() { mockServer.expect(requestTo("https://api.twitter.com/1.1/lists/subscriptions.json?user_id=161064614")) @@ -338,10 +415,10 @@ public void getSubscriptions_forUserId() { @Test public void getSubscriptionsInCursor_forUserId() { - mockServer.expect(requestTo("https://api.twitter.com/1.1/lists/subscriptions.json?user_id=161064614&cursor=12345")) + mockServer.expect(requestTo("https://api.twitter.com/1.1/lists/subscriptions.json?user_id=161064614&cursor=12345&count=20")) .andExpect(method(GET)) .andRespond(withSuccess(jsonResource("list-of-lists"), APPLICATION_JSON)); - CursoredList subscriptions = twitter.listOperations().getSubscriptionsInCursor(161064614, 12345); + CursoredList subscriptions = twitter.listOperations().getSubscriptionsInCursor(161064614, 12345, 20); assertListOfLists(subscriptions); assertEquals(234567, subscriptions.getNextCursor()); assertEquals(123456, subscriptions.getPreviousCursor()); @@ -366,10 +443,10 @@ public void getSubscriptions_forScreenName() { @Test public void getSubscriptionsInCursor_forScreenName() { - mockServer.expect(requestTo("https://api.twitter.com/1.1/lists/subscriptions.json?screen_name=habuma&cursor=12345")) + mockServer.expect(requestTo("https://api.twitter.com/1.1/lists/subscriptions.json?screen_name=habuma&cursor=12345&count=20")) .andExpect(method(GET)) .andRespond(withSuccess(jsonResource("list-of-lists"), APPLICATION_JSON)); - CursoredList subscriptions = twitter.listOperations().getSubscriptionsInCursor("habuma", 12345); + CursoredList subscriptions = twitter.listOperations().getSubscriptionsInCursor("habuma", 12345, 20); assertListOfLists(subscriptions); assertEquals(234567, subscriptions.getNextCursor()); assertEquals(123456, subscriptions.getPreviousCursor());