Skip to content
Browse files

Add unfollow topic feature

  • Loading branch information...
1 parent 547502a commit db5564a9adb87c9d45b048b42aa72e270b6f4af9 @vergnesOL vergnesOL committed
View
2 src/main/java/org/springframework/social/weibo/api/TrendOperations.java
@@ -39,4 +39,6 @@
TrendsWrapper getWeeklyTrends(boolean onlyApplicationData);
+ boolean unfollow(long trendId);
+
}
View
11 src/main/java/org/springframework/social/weibo/api/impl/TrendTemplate.java
@@ -124,4 +124,15 @@ public long follow(String trendName) {
.postForObject(buildUri("trends/follow.json"), request,
JsonNode.class).findValue("topicid").asLong();
}
+
+ @Override
+ public boolean unfollow(long trendId) {
+ requireAuthorization();
+ MultiValueMap<String, String> request = new LinkedMultiValueMap<String, String>(
+ 1);
+ request.add("trend_id", String.valueOf(trendId));
+ return restTemplate
+ .postForObject(buildUri("trends/destroy.json"), request,
+ JsonNode.class).findValue("result").asBoolean();
+ }
}
View
10 src/test/java/org/springframework/social/weibo/api/impl/TrendTemplateTest.java
@@ -234,4 +234,14 @@ public void testFollow() {
withResponse("{\"topicid\":1568197}", responseHeaders));
assertEquals(1568197, trendTemplate.follow("苹果"));
}
+
+ @Test
+ public void testUnfollow() {
+ mockServer
+ .expect(requestTo("https://api.weibo.com/2/trends/destroy.json"))
+ .andExpect(method(POST)).andExpect(body("trend_id=1"))
+ .andExpect(header("Authorization", "OAuth2 accessToken"))
+ .andRespond(withResponse("{\"result\":true}", responseHeaders));
+ assertTrue(trendTemplate.unfollow(1));
+ }
}

0 comments on commit db5564a

Please sign in to comment.
Something went wrong with that request. Please try again.