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

Commit 475ab73

Browse files
committed
Add voting on rants
1 parent 1908850 commit 475ab73

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,30 @@ public User getUser(int id) {
240240
return new User(this, id);
241241
}
242242

243+
/**
244+
* Vote on a rant.
245+
*
246+
* @param rant The rant to vote on.
247+
* @param vote The vote.
248+
* @return Whether the vote was successful.
249+
*/
250+
public boolean vote(Rant rant, Vote vote) {
251+
return voteRant(rant.getId(), vote);
252+
}
253+
254+
/**
255+
* Vote on a rant.
256+
*
257+
* @param id The id of the rant.
258+
* @param vote The vote.
259+
* @return Whether the vote was successful.
260+
*/
261+
public boolean voteRant(int id, Vote vote) {
262+
// Rants url, id, vote.
263+
String url = String.format("%1$s/%2$d%3$s", API_RANTS, id, API_VOTE);
264+
return Util.jsonSuccess(post(url, new BasicNameValuePair("vote", String.valueOf(vote.getValue()))));
265+
}
266+
243267
/**
244268
* Make a POST-request to the devRant server.
245269
*
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.scorpiac.javarant;
2+
3+
public enum Vote {
4+
UP(1),
5+
NONE(0),
6+
DOWN(-1);
7+
8+
private final int value;
9+
10+
private Vote(int value) {
11+
this.value = value;
12+
}
13+
14+
public int getValue() {
15+
return value;
16+
}
17+
}

0 commit comments

Comments
 (0)