Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Twitter api fix #29

Merged
merged 6 commits into from

2 participants

Commits on Nov 19, 2012
  1. @jdappel
Commits on Nov 20, 2012
  1. @jdappel

    Updated deleteDirectMessage

    jdappel authored
  2. @jdappel

    Updated deleteList

    jdappel authored
  3. @jdappel

    Updated deleteSavedSearch

    jdappel authored
  4. @jdappel

    Updated deleteStatus

    jdappel authored
  5. @jdappel
This page is out of date. Refresh to see the latest.
Showing with 75 additions and 40 deletions.
  1. +1 −15 spring-social-twitter/src/main/java/org/springframework/social/twitter/api/impl/BlockTemplate.java
  2. +47 −0 ...ng-social-twitter/src/main/java/org/springframework/social/twitter/api/impl/CursoredTwitterProfileList.java
  3. +4 −2 spring-social-twitter/src/main/java/org/springframework/social/twitter/api/impl/DirectMessageTemplate.java
  4. +3 −1 spring-social-twitter/src/main/java/org/springframework/social/twitter/api/impl/ListTemplate.java
  5. +2 −1  spring-social-twitter/src/main/java/org/springframework/social/twitter/api/impl/SearchTemplate.java
  6. +2 −1  spring-social-twitter/src/main/java/org/springframework/social/twitter/api/impl/TimelineTemplate.java
  7. +1 −1  spring-social-twitter/src/main/java/org/springframework/social/twitter/api/impl/UserTemplate.java
  8. +2 −8 spring-social-twitter/src/test/java/org/springframework/social/twitter/api/impl/BlockTemplateTest.java
  9. +3 −2 spring-social-twitter/src/test/java/org/springframework/social/twitter/api/impl/DirectMessageTemplateTest.java
  10. +3 −2 spring-social-twitter/src/test/java/org/springframework/social/twitter/api/impl/ListsTemplateTest.java
  11. +1 −1  spring-social-twitter/src/test/java/org/springframework/social/twitter/api/impl/SearchTemplateTest.java
  12. +1 −1  spring-social-twitter/src/test/java/org/springframework/social/twitter/api/impl/TimelineTemplateTest.java
  13. +1 −1  spring-social-twitter/src/test/java/org/springframework/social/twitter/api/impl/UserTemplateTest.java
  14. +4 −4 spring-social-twitter/src/test/java/org/springframework/social/twitter/api/impl/list-members.json
View
16 spring-social-twitter/src/main/java/org/springframework/social/twitter/api/impl/BlockTemplate.java
@@ -15,7 +15,6 @@
*/
package org.springframework.social.twitter.api.impl;
-import java.util.List;
import org.springframework.social.twitter.api.BlockOperations;
import org.springframework.social.twitter.api.CursoredList;
@@ -73,8 +72,7 @@ public TwitterProfile unblock(String screenName) {
requireAuthorization();
LinkedMultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>();
parameters.set("cursor", String.valueOf(cursor));
- CursoredList<Long> blockedUserIds = restTemplate.getForObject(buildUri("blocks/list.json", parameters), CursoredLongList.class).getList();
- return getCursoredProfileList(blockedUserIds, blockedUserIds.getPreviousCursor(), blockedUserIds.getNextCursor());
+ return restTemplate.getForObject(buildUri("blocks/list.json", parameters), CursoredTwitterProfileUsersList.class).getList();
}
public CursoredList<Long> getBlockedUserIds() {
@@ -87,17 +85,5 @@ public TwitterProfile unblock(String screenName) {
parameters.set("cursor", String.valueOf(cursor));
return restTemplate.getForObject(buildUri("blocks/ids.json", parameters), CursoredLongList.class).getList();
}
-
- private CursoredList<TwitterProfile> getCursoredProfileList(List<Long> userIds, long previousCursor, long nextCursor) {
- // TODO: Would be good to figure out how to retrieve profiles in a tighter-than-cursor granularity.
- List<List<Long>> chunks = CursorUtils.chunkList(userIds, 100);
- CursoredList<TwitterProfile> users = new CursoredList<TwitterProfile>(userIds.size(), previousCursor, nextCursor);
- for (List<Long> userIdChunk : chunks) {
- String joinedIds = ArrayUtils.join(userIdChunk.toArray());
- users.addAll(restTemplate.getForObject(buildUri("users/lookup.json", "user_id", joinedIds), TwitterProfileList.class));
- }
- return users;
- }
-
}
View
47 ...social-twitter/src/main/java/org/springframework/social/twitter/api/impl/CursoredTwitterProfileList.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.social.twitter.api.impl;
+
+import java.util.List;
+
+import org.codehaus.jackson.annotate.JsonCreator;
+import org.codehaus.jackson.annotate.JsonIgnore;
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+import org.codehaus.jackson.annotate.JsonProperty;
+import org.springframework.social.twitter.api.CursoredList;
+import org.springframework.social.twitter.api.TwitterProfile;
+
+/**
+ * Holder for list of TwitterProfile objects pulled from a JSON object's "users" property.
+ * @author Jeremy Appel
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+class CursoredTwitterProfileUsersList {
+ private final CursoredList<TwitterProfile> list;
+
+ @JsonCreator
+ public CursoredTwitterProfileUsersList(
+ @JsonProperty("users") List<TwitterProfile> list,
+ @JsonProperty("previous_cursor") long previousCursor,
+ @JsonProperty("next_cursor") long nextCursor) {
+ this.list = new CursoredList<TwitterProfile>(list, previousCursor, nextCursor);
+ }
+
+ @JsonIgnore
+ public CursoredList<TwitterProfile> getList() {
+ return list;
+ }
+}
View
6 spring-social-twitter/src/main/java/org/springframework/social/twitter/api/impl/DirectMessageTemplate.java
@@ -87,7 +87,9 @@ public DirectMessage sendDirectMessage(long toUserId, String text) {
public void deleteDirectMessage(long messageId) {
requireAuthorization();
- restTemplate.delete(buildUri("direct_messages/destroy.json","id",String.valueOf(messageId)));
+ MultiValueMap<String, Object> data = new LinkedMultiValueMap<String, Object>();
+ data.add("id", String.valueOf(messageId));
+ restTemplate.postForObject(buildUri("direct_messages/destroy.json"), data, DirectMessage.class);
}
-
+
}
View
4 spring-social-twitter/src/main/java/org/springframework/social/twitter/api/impl/ListTemplate.java
@@ -113,7 +113,9 @@ public UserList updateList(long listId, String name, String description, boolean
public void deleteList(long listId) {
requireAuthorization();
- restTemplate.delete(buildUri("lists/destroy.json", "list_id", String.valueOf(listId)));
+ MultiValueMap<String, Object> request = new LinkedMultiValueMap<String, Object>();
+ request.set("list_id", String.valueOf(listId));
+ restTemplate.postForObject(buildUri("lists/destroy.json"), request, UserList.class);
}
public List<TwitterProfile> getListMembers(long listId) {
View
3  spring-social-twitter/src/main/java/org/springframework/social/twitter/api/impl/SearchTemplate.java
@@ -79,7 +79,8 @@ public SavedSearch createSavedSearch(String query) {
public void deleteSavedSearch(long searchId) {
requireAuthorization();
- restTemplate.delete(buildUri("saved_searches/destroy/" + searchId + ".json"));
+ MultiValueMap<String, Object> data = new LinkedMultiValueMap<String, Object>();
+ restTemplate.postForObject(buildUri("saved_searches/destroy/" + searchId + ".json"), data, SavedSearch.class);
}
// Trends
View
3  spring-social-twitter/src/main/java/org/springframework/social/twitter/api/impl/TimelineTemplate.java
@@ -149,7 +149,8 @@ public Tweet updateStatus(String message, Resource media, StatusDetails details)
public void deleteStatus(long tweetId) {
requireAuthorization();
- restTemplate.delete(buildUri("statuses/destroy/" + tweetId + ".json"));
+ MultiValueMap<String, Object> data = new LinkedMultiValueMap<String, Object>();
+ restTemplate.postForObject(buildUri("statuses/destroy/" + tweetId + ".json"), data, String.class);
}
public void retweet(long tweetId) {
View
2  spring-social-twitter/src/main/java/org/springframework/social/twitter/api/impl/UserTemplate.java
@@ -100,6 +100,6 @@ public TwitterProfile getUserProfile(long userId) {
public Map<ResourceFamily, List<RateLimitStatus>> getRateLimitStatus(ResourceFamily... resources) {
requireAuthorization();
String joinedResources = ArrayUtils.join(resources);
- return restTemplate.getForObject(buildUri("account/rate_limit_status.json", "resources", joinedResources), RateLimitStatusHolder.class).getRateLimits();
+ return restTemplate.getForObject(buildUri("application/rate_limit_status.json", "resources", joinedResources), RateLimitStatusHolder.class).getRateLimits();
}
}
View
10 spring-social-twitter/src/test/java/org/springframework/social/twitter/api/impl/BlockTemplateTest.java
@@ -100,10 +100,7 @@ public void unblock_screenName_unauthorized() {
public void getBlockedUsers() {
mockServer.expect(requestTo("https://api.twitter.com/1.1/blocks/list.json?cursor=-1"))
.andExpect(method(GET))
- .andRespond(withSuccess(jsonResource("blocked-user-ids"), APPLICATION_JSON));
- mockServer.expect(requestTo("https://api.twitter.com/1.1/users/lookup.json?user_id=14846645%2C14718006"))
- .andExpect(method(GET))
- .andRespond(withSuccess(jsonResource("list-of-profiles"), APPLICATION_JSON));
+ .andRespond(withSuccess(jsonResource("list-members"), APPLICATION_JSON));
CursoredList<TwitterProfile> blockedUsers = twitter.blockOperations().getBlockedUsers();
assertBlockedUsers(blockedUsers);
}
@@ -117,10 +114,7 @@ public void getBlockedUsers_unauthorized() {
public void getBlockedUsersInCursor() {
mockServer.expect(requestTo("https://api.twitter.com/1.1/blocks/list.json?cursor=332211"))
.andExpect(method(GET))
- .andRespond(withSuccess(jsonResource("blocked-user-ids"), APPLICATION_JSON));
- mockServer.expect(requestTo("https://api.twitter.com/1.1/users/lookup.json?user_id=14846645%2C14718006"))
- .andExpect(method(GET))
- .andRespond(withSuccess(jsonResource("list-of-profiles"), APPLICATION_JSON));
+ .andRespond(withSuccess(jsonResource("list-members"), APPLICATION_JSON));
CursoredList<TwitterProfile> blockedUsers = twitter.blockOperations().getBlockedUsersInCursor(332211);
assertBlockedUsers(blockedUsers);
}
View
5 ...-social-twitter/src/test/java/org/springframework/social/twitter/api/impl/DirectMessageTemplateTest.java
@@ -163,8 +163,9 @@ public void sendDirectMessaage_toUserId_unauthorized() {
@Test
public void deleteDirectMessage() {
- mockServer.expect(requestTo("https://api.twitter.com/1.1/direct_messages/destroy.json?id=42"))
- .andExpect(method(DELETE))
+ mockServer.expect(requestTo("https://api.twitter.com/1.1/direct_messages/destroy.json"))
+ .andExpect(method(POST))
+ .andExpect(content().string("id=42"))
.andRespond(withSuccess(jsonResource("directMessage"), APPLICATION_JSON));
twitter.directMessageOperations().deleteDirectMessage(42L);
mockServer.verify();
View
5 spring-social-twitter/src/test/java/org/springframework/social/twitter/api/impl/ListsTemplateTest.java
@@ -122,8 +122,9 @@ public void updateList_unauthorized() {
@Test
public void deleteList_forUserIdByListId() {
- mockServer.expect(requestTo("https://api.twitter.com/1.1/lists/destroy.json?list_id=40841803"))
- .andExpect(method(DELETE))
+ mockServer.expect(requestTo("https://api.twitter.com/1.1/lists/destroy.json"))
+ .andExpect(method(POST))
+ .andExpect(content().string("list_id=40841803"))
.andRespond(withSuccess("{}", APPLICATION_JSON));
twitter.listOperations().deleteList(40841803);
mockServer.verify();
View
2  spring-social-twitter/src/test/java/org/springframework/social/twitter/api/impl/SearchTemplateTest.java
@@ -151,7 +151,7 @@ public void createSavedSearch_unauthorized() {
@Test
public void deleteSavedSearch() {
mockServer.expect(requestTo("https://api.twitter.com/1.1/saved_searches/destroy/26897775.json"))
- .andExpect(method(DELETE))
+ .andExpect(method(POST))
.andRespond(withSuccess("{}", APPLICATION_JSON));
twitter.searchOperations().deleteSavedSearch(26897775);
mockServer.verify();
View
2  spring-social-twitter/src/test/java/org/springframework/social/twitter/api/impl/TimelineTemplateTest.java
@@ -340,7 +340,7 @@ public void updateStatus_forbidden() {
@Test
public void deleteStatus() {
mockServer.expect(requestTo("https://api.twitter.com/1.1/statuses/destroy/12345.json"))
- .andExpect(method(DELETE))
+ .andExpect(method(POST))
.andRespond(withSuccess("{}", APPLICATION_JSON));
twitter.timelineOperations().deleteStatus(12345L);
mockServer.verify();
View
2  spring-social-twitter/src/test/java/org/springframework/social/twitter/api/impl/UserTemplateTest.java
@@ -227,7 +227,7 @@ public void getSuggestions_unauthorized() {
@Test
public void getRateLimit() {
- mockServer.expect(requestTo("https://api.twitter.com/1.1/account/rate_limit_status.json?resources=help%2Csearch"))
+ mockServer.expect(requestTo("https://api.twitter.com/1.1/application/rate_limit_status.json?resources=help%2Csearch"))
.andExpect(method(GET))
.andRespond(withSuccess(jsonResource("rate-limit-status"), APPLICATION_JSON));
View
8 spring-social-twitter/src/test/java/org/springframework/social/twitter/api/impl/list-members.json
@@ -117,9 +117,9 @@
"profile_background_color":"352726"
}
],
- "next_cursor":0,
- "previous_cursor":0,
- "next_cursor_str":"0",
- "previous_cursor_str":"0"
+ "next_cursor":332211,
+ "previous_cursor":112233,
+ "next_cursor_str":"332211",
+ "previous_cursor_str":"112233"
}
Something went wrong with that request. Please try again.