Permalink
Browse files

Add reply comment feature

  • Loading branch information...
vergnesOL committed Feb 29, 2012
1 parent 70012c6 commit 7dadb0db2f7b9267090fa2a60f1a0124d0054fa2
@@ -87,4 +87,9 @@ Comment createComment(long id, String comment,
int pageSize, int pageNumber, AuthorFilterType authorFilterType,
SourceFilterType sourceFilterType);
+ Comment replyComment(long commentId, long statusId, String comment);
+
+ Comment replyComment(long commentId, long statusId, String comment,
+ boolean withoutMention, boolean commentFromExternalSource);
+
}
@@ -273,4 +273,26 @@ public Comment deleteComment(long id) {
.build(), JsonNode.class);
return deserializeCursoredList(dataNode, Comment.class, "comments");
}
+
+ @Override
+ public Comment replyComment(long commentId, long statusId, String comment) {
+ return replyComment(commentId, statusId, comment, false, false);
+ }
+
+ @Override
+ public Comment replyComment(long commentId, long statusId, String comment,
+ boolean withoutMention, boolean commentFromExternalSource) {
+ requireAuthorization();
+ MultiValueMap<String, String> request = new LinkedMultiValueMap<String, String>(
+ 5);
+ request.add("cid", String.valueOf(commentId));
+ request.add("id", String.valueOf(statusId));
+ request.add("comment", comment);
+ request.add("without_mention",
+ StringUtils.booleanToString(withoutMention));
+ request.add("comment_ori",
+ StringUtils.booleanToString(commentFromExternalSource));
+ return restTemplate.postForObject(buildUri("comments/reply.json"),
+ request, Comment.class);
+ }
}
@@ -68,6 +68,20 @@ public void testDeleteComment() {
verifyComment(comment);
}
+ @Test
+ public void testDeleteComments() {
+ mockServer
+ .expect(requestTo("https://api.weibo.com/2/comments/destroy_batch.json"))
+ .andExpect(method(POST))
+ .andExpect(body("cids=1%2C2%2C3%2C4%2C5"))
+ .andRespond(
+ withResponse(jsonResource("comments"), responseHeaders));
+ List<Comment> comments = commentTemplate.deleteComments(Arrays.asList(
+ 1L, 2L, 3L, 4L, 5L));
+ verifyComment(comments.iterator().next());
+ assertEquals(2, comments.size());
+ }
+
@Test
public void testGetCommentsByMe() {
mockServer
@@ -280,25 +294,23 @@ public void testGetMentioningCommentsPaginationFiltered() {
assertEquals(10, comments.getNextCursor());
}
+ @Test
+ public void testReplyComment() {
+ mockServer
+ .expect(requestTo("https://api.weibo.com/2/comments/reply.json"))
+ .andExpect(method(POST))
+ .andExpect(body("cid=1&"))
+ .andRespond(
+ withResponse(jsonResource("comment"), responseHeaders));
+ Comment comment = commentTemplate.replyComment(1L, 99L, "我喜欢你做的");
+ verifyComment(comment);
+ }
+
private void verifyComment(Comment comment) {
assertEquals(12438492184L, comment.getId());
assertEquals(1306860625000L, comment.getCreatedAt().getTime());
assertEquals("我喜欢你做的", comment.getText());
assertNotNull(comment.getUser());
assertNotNull(comment.getStatus());
}
-
- @Test
- public void testDeleteComments() {
- mockServer
- .expect(requestTo("https://api.weibo.com/2/comments/destroy_batch.json"))
- .andExpect(method(POST))
- .andExpect(body("cids=1%2C2%2C3%2C4%2C5"))
- .andRespond(
- withResponse(jsonResource("comments"), responseHeaders));
- List<Comment> comments = commentTemplate.deleteComments(Arrays.asList(
- 1L, 2L, 3L, 4L, 5L));
- verifyComment(comments.iterator().next());
- assertEquals(2, comments.size());
- }
}

0 comments on commit 7dadb0d

Please sign in to comment.