Skip to content
This repository was archived by the owner on Jan 5, 2019. It is now read-only.

Commit 5230de2

Browse files
committed
Add voting on comments
1 parent 475ab73 commit 5230de2

1 file changed

Lines changed: 31 additions & 6 deletions

File tree

src/main/java/com/scorpiac/javarant/DevRant.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ public class DevRant {
3030

3131
// API endpoints.
3232
static final String API = "/api";
33-
static final String API_RANTS = API + "/devrant/rants";
34-
static final String API_SEARCH = API + "/devrant/search";
33+
static final String API_DEVRANT = API + "/devrant";
34+
static final String API_RANTS = API_DEVRANT + "/rants";
35+
static final String API_SEARCH = API_DEVRANT + "/search";
3536
static final String API_SURPRISE = API_RANTS + "/surprise";
3637
static final String API_USERS = API + "/users";
3738
static final String API_USER_ID = API + "/get-user-id";
38-
static final String API_WEEKLY = API + "/devrant/weekly-rants";
39-
static final String API_COLLABS = API + "/devrant/collabs";
40-
static final String API_STORIES = API + "/devrant/story-rants";
39+
static final String API_WEEKLY = API_DEVRANT + "/weekly-rants";
40+
static final String API_COLLABS = API_DEVRANT + "/collabs";
41+
static final String API_STORIES = API_DEVRANT + "/story-rants";
4142
static final String API_AUTH_TOKEN = API_USERS + "/auth-token";
4243
static final String API_COMMENT = "/comments";
4344
static final String API_VOTE = "/vote";
@@ -259,11 +260,35 @@ public boolean vote(Rant rant, Vote vote) {
259260
* @return Whether the vote was successful.
260261
*/
261262
public boolean voteRant(int id, Vote vote) {
262-
// Rants url, id, vote.
263+
// Rants url, id, vote url.
263264
String url = String.format("%1$s/%2$d%3$s", API_RANTS, id, API_VOTE);
264265
return Util.jsonSuccess(post(url, new BasicNameValuePair("vote", String.valueOf(vote.getValue()))));
265266
}
266267

268+
/**
269+
* Vote on a comment.
270+
*
271+
* @param comment The comment to vote on.
272+
* @param vote The vote.
273+
* @return Whether the vote was successful.
274+
*/
275+
public boolean vote(Comment comment, Vote vote) {
276+
return voteComment(comment.getId(), vote);
277+
}
278+
279+
/**
280+
* Vote on a comment.
281+
*
282+
* @param id The id of the comment.
283+
* @param vote The vote.
284+
* @return Whether the vote was successful.
285+
*/
286+
public boolean voteComment(int id, Vote vote) {
287+
// API url, comments url, id, vote url.
288+
String url = String.format("%1$s%2$s/%3$d%4$s", API, API_COMMENT, id, API_VOTE);
289+
return Util.jsonSuccess(post(url, new BasicNameValuePair("vote", String.valueOf(vote.getValue()))));
290+
}
291+
267292
/**
268293
* Make a POST-request to the devRant server.
269294
*

0 commit comments

Comments
 (0)