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

Commit

Permalink
Add get mentioning comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vergnesOL committed Feb 17, 2012
1 parent 063e2e9 commit 53c44a5
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ CursoredList<Comment> getCommentsByMe(int pageSize, int pageNumber,
CursoredList<Comment> getCommentsByMe(long sinceId, long maxId,
int pageSize, int pageNumber, SourceFilterType sourceFilterType);

CursoredList<Comment> getMentioningComments();

CursoredList<Comment> getMentioningComments(int pageSize, int pageNumber);

CursoredList<Comment> getMentioningComments(int pageSize, int pageNumber,
AuthorFilterType authorFilterType, SourceFilterType sourceFilterType);

CursoredList<Comment> getMentioningComments(long sinceId, long maxId,
int pageSize, int pageNumber, AuthorFilterType authorFilterType,
SourceFilterType sourceFilterType);

CursoredList<Comment> getCommentsOnStatus(long id);

CursoredList<Comment> getCommentsOnStatus(long id, int pageSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,46 @@ public CursoredList<Comment> getCommentsTimeline(long sinceId, long maxId,
.build(), JsonNode.class);
return deserializeCursoredList(dataNode, Comment.class, "comments");
}

@Override
public CursoredList<Comment> getMentioningComments() {
requireAuthorization();
JsonNode dataNode = restTemplate.getForObject(
buildUri("comments/mentions.json"), JsonNode.class);
return deserializeCursoredList(dataNode, Comment.class, "comments");
}

@Override
public CursoredList<Comment> getMentioningComments(int pageSize,
int pageNumber) {
return getMentioningComments(pageSize, pageNumber,
AuthorFilterType.ALL, SourceFilterType.ALL);
}

@Override
public CursoredList<Comment> getMentioningComments(int pageSize,
int pageNumber, AuthorFilterType authorFilterType,
SourceFilterType sourceFilterType) {
return getMentioningComments(0, 0, pageSize, pageNumber,
authorFilterType, sourceFilterType);
}

@Override
public CursoredList<Comment> getMentioningComments(long sinceId,
long maxId, int pageSize, int pageNumber,
AuthorFilterType authorFilterType, SourceFilterType sourceFilterType) {
requireAuthorization();
JsonNode dataNode = restTemplate.getForObject(
uriBuilder("comments/mentions.json")
.queryParam("since_id", String.valueOf(sinceId))
.queryParam("max_id", String.valueOf(maxId))
.queryParam("count", String.valueOf(pageSize))
.queryParam("page", String.valueOf(pageNumber))
.queryParam("filter_by_author",
String.valueOf(authorFilterType.ordinal()))
.queryParam("filter_by_source",
String.valueOf(sourceFilterType.ordinal()))
.build(), JsonNode.class);
return deserializeCursoredList(dataNode, Comment.class, "comments");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,54 @@ public void testGetCommentsToMePaginationFiltered() {
assertEquals(10, comments.getNextCursor());
}

@Test
public void testGetMentioningComments() {
mockServer
.expect(requestTo("https://api.weibo.com/2/comments/mentions.json"))
.andExpect(method(GET))
.andRespond(
withResponse(jsonResource("comments"), responseHeaders));
CursoredList<Comment> comments = commentTemplate
.getMentioningComments();
verifyComment(comments.iterator().next());
assertEquals(2, comments.size());
assertEquals(7, comments.getTotalNumber());
assertEquals(0, comments.getPreviousCursor());
assertEquals(10, comments.getNextCursor());
}

@Test
public void testGetMentioningCommentsPagination() {
mockServer
.expect(requestTo("https://api.weibo.com/2/comments/mentions.json?since_id=0&max_id=0&count=50&page=5&filter_by_author=0&filter_by_source=0"))
.andExpect(method(GET))
.andRespond(
withResponse(jsonResource("comments"), responseHeaders));
CursoredList<Comment> comments = commentTemplate.getMentioningComments(
50, 5);
verifyComment(comments.iterator().next());
assertEquals(2, comments.size());
assertEquals(7, comments.getTotalNumber());
assertEquals(0, comments.getPreviousCursor());
assertEquals(10, comments.getNextCursor());
}

@Test
public void testGetMentioningCommentsPaginationFiltered() {
mockServer
.expect(requestTo("https://api.weibo.com/2/comments/mentions.json?since_id=0&max_id=0&count=50&page=5&filter_by_author=1&filter_by_source=0"))
.andExpect(method(GET))
.andRespond(
withResponse(jsonResource("comments"), responseHeaders));
CursoredList<Comment> comments = commentTemplate.getMentioningComments(
50, 5, AuthorFilterType.FRIENDS, SourceFilterType.ALL);
verifyComment(comments.iterator().next());
assertEquals(2, comments.size());
assertEquals(7, comments.getTotalNumber());
assertEquals(0, comments.getPreviousCursor());
assertEquals(10, comments.getNextCursor());
}

private void verifyComment(Comment comment) {
assertEquals(12438492184L, comment.getId());
assertEquals(1306860625000L, comment.getCreatedAt().getTime());
Expand Down

0 comments on commit 53c44a5

Please sign in to comment.