Skip to content
This repository has been archived by the owner on Oct 20, 2022. It is now read-only.

Commit

Permalink
Add reply comment feature
Browse files Browse the repository at this point in the history
  • Loading branch information
vergnesOL committed Feb 29, 2012
1 parent 70012c6 commit 7dadb0d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,9 @@ CursoredList<Comment> getCommentsToMe(long sinceId, long maxId,
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);

}
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,26 @@ public CursoredList<Comment> getMentioningComments(long sinceId,
.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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.