Skip to content

Commit

Permalink
Add method for to get comment’s replies
Browse files Browse the repository at this point in the history
  • Loading branch information
roundrop committed Nov 13, 2015
1 parent e6a2d05 commit 91660f9
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 0 deletions.
9 changes: 9 additions & 0 deletions facebook4j-core/src/main/java/facebook4j/FacebookImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,15 @@ public Comment getComment(String commentId, Reading reading) throws FacebookExce
return factory.createComment(get(buildEndpoint(commentId, reading)));
}

public ResponseList<Comment> getCommentReplies(String commentId) throws FacebookException {
return getCommentReplies(commentId, null);
}

public ResponseList<Comment> getCommentReplies(String commentId, Reading reading) throws FacebookException {
ensureAuthorizationEnabled();
return factory.createCommentList(get(buildEndpoint(commentId, "comments", reading)));
}

public boolean deleteComment(String commentId) throws FacebookException {
ensureAuthorizationEnabled();
HttpResponse res = delete(buildEndpoint(commentId));
Expand Down
19 changes: 19 additions & 0 deletions facebook4j-core/src/main/java/facebook4j/api/CommentMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,25 @@ public interface CommentMethods {
*/
Comment getComment(String commentId, Reading reading) throws FacebookException;

/**
* Returns the replies on a comment.
* @param commentId the ID of a comment
* @return replies
* @throws FacebookException when Facebook service or network is unavailable
* @see <a href="https://developers.facebook.com/docs/reference/api/Comment/">Comment - Facebook Developers</a>
*/
ResponseList<Comment> getCommentReplies(String commentId) throws FacebookException;

/**
* Returns the replies on a comment.
* @param commentId the ID of a comment
* @param reading optional reading parameters. see <a href="https://developers.facebook.com/docs/reference/api/#reading">Graph API#reading - Facebook Developers</a>
* @return replies
* @throws FacebookException when Facebook service or network is unavailable
* @see <a href="https://developers.facebook.com/docs/reference/api/Comment/">Comment - Facebook Developers</a>
*/
ResponseList<Comment> getCommentReplies(String commentId, Reading reading) throws FacebookException;

/**
* Deletes the comment.
* @param commentId the ID of a comment
Expand Down
35 changes: 35 additions & 0 deletions facebook4j-core/src/test/java/facebook4j/CommentMethodsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,41 @@ public void attachment_link() throws Exception {
}
}

public static class getCommentReplies extends MockFacebookTestBase {
@Test
public void id() throws Exception {
facebook.setMockJSON("mock_json/comment/replies.json");
ResponseList<Comment> actual = facebook.getCommentReplies("100000000000001_50000001");
assertThat(facebook.getHttpMethod(), is(RequestMethod.GET));
assertThat(facebook.getEndpointURL(), is(pathOf("/100000000000001_50000001/comments")));

assertThat(actual.size(), is(1));
assertThat(actual.get(0).getId(), is("100000000000001_50000001"));
assertThat(actual.get(0).canRemove(), is(true));
assertThat(actual.get(0).getFrom().getId(), is("100001568838021"));
assertThat(actual.get(0).getFrom().getName(), is("Ryuji Yamashita"));
assertThat(actual.get(0).getLikeCount(), is(0));
assertThat(actual.get(0).getMessage(), is("reply"));
}

@Test
public void reading() throws Exception {
facebook.setMockJSON("mock_json/comment/replies.json");
ResponseList<Comment> actual = facebook.getCommentReplies("100000000000001_50000001", new Reading().limit(1));
assertThat(facebook.getHttpMethod(), is(RequestMethod.GET));
assertThat(facebook.getEndpointURL(), is(pathOf("/100000000000001_50000001/comments")));
assertThat(facebook.getEndpointURL(), hasParameter("limit", "1"));

assertThat(actual.size(), is(1));
assertThat(actual.get(0).getId(), is("100000000000001_50000001"));
assertThat(actual.get(0).canRemove(), is(true));
assertThat(actual.get(0).getFrom().getId(), is("100001568838021"));
assertThat(actual.get(0).getFrom().getName(), is("Ryuji Yamashita"));
assertThat(actual.get(0).getLikeCount(), is(0));
assertThat(actual.get(0).getMessage(), is("reply"));
}
}

public static class deleteComment extends MockFacebookTestBase {
@Test
public void delete() throws Exception {
Expand Down
18 changes: 18 additions & 0 deletions facebook4j-core/src/test/resources/mock_json/comment/replies.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"data": [{
"can_remove": true,
"created_time": "2015-10-26T11:13:13+0000",
"from": {
"id": "100001568838021",
"name": "Ryuji Yamashita"
},
"id": "100000000000001_50000001",
"like_count": 0,
"message": "reply",
"user_likes": false
}],
"paging": {"cursors": {
"after": "WTI5dGJXVnVkRjlqZAFhKemIzSTZANVEF5TURBMU56TTRORGN5TXpJeE16b3hORFExT0RVM09Ua3oZD",
"before": "WTI5dGJXVnVkRjlqZAFhKemIzSTZANVEF5TURBMU56TTRORGN5TXpJeE16b3hORFExT0RVM09Ua3oZD"
}}
}

0 comments on commit 91660f9

Please sign in to comment.