@@ -8,7 +8,7 @@ A devRant API wrapper for Java.
88## Using JavaRant
99JavaRant is available on [ Maven] ( http://mvnrepository.com/artifact/com.scorpiac.javarant/javarant ) , simply add this dependency to your ` pom.xml ` file:
1010
11- ```
11+ ``` xml
1212<dependency >
1313 <groupId >com.scorpiac.javarant</groupId >
1414 <artifactId >javarant</artifactId >
@@ -24,15 +24,61 @@ To access devRant simply create a new `DevRant` object:
2424DevRant devRant = new DevRant();
2525```
2626
27- You can then use it to get specific rants and users, or access the feed:
27+ Most object that are returned from ` DevRant ` are wrapped in a ` Result ` object.
28+ This will contain an optional result value, along with an error message.
29+ If the optional result is empty, then an error occurred and the error message will be set.
30+ For example:
31+
32+ ```
33+ Result<CommentedRant> result = devRant.getRant(832125);
34+
35+ if (!result.getValue().isPresent()) {
36+ System.out.println("An error occurred: " + result.getError());
37+ } else {
38+ CommentedRant rant = result.getValue().get();
39+ System.out.println(rant.getUser().getUsername() + '\n' + rant.getText());
40+ }
41+ ```
42+
43+ The ` DevRant ` class itself can be used to get specific rants and users.
2844
2945```
3046// Get a specific rant.
31- Optional <CommentedRant> rant = devRant.getRant(686001);
47+ Result <CommentedRant> rant = devRant.getRant(686001);
3248
3349// Get a user by username.
34- Optional<User> me = devRant.getUser("LucaScorpion");
50+ Result<User> me = devRant.getUser("LucaScorpion");
51+ ```
52+
53+ The ` DevRant ` class contains 2 methods for getting to specific parts of the api.
54+ First, ` getFeed() ` which returns a ` DevRantFeed ` object.
55+ This is used to access the rant and collab feeds.
56+
57+ ```
58+ // Get the 10 latest rants.
59+ Result<List<Rant>> recent = devRant.getFeed().getRants(Sort.RECENT, 10, 0);
60+
61+ // Get the 10 best stories.
62+ Result<List<Rant>> stories = devRant.getFeed().getStories(Sort.TOP, 0);
63+
64+ // Get 10 collabs.
65+ Result<List<Collab>> collabs = devRant.getFeed().getCollabs(10);
66+ ```
67+
68+ Second, ` getAuth() ` which returns a ` DevRantAuth ` object, which is used to access user functionality.
69+ Note that a user needs to be logged in before this can be accessed.
70+
71+ ```
72+ // Log in to devRant.
73+ char[] password = "<password>".toCharArray();
74+ devRant.login("<username>", password);
75+
76+ // Upvote a rant.
77+ devRant.getAuth().voteRant(832125, Vote.UP);
78+
79+ // Clear the vote on a comment.
80+ devRant.getAuth().voteComment(832169, Vote.NONE);
3581
36- // Get the 10 newest rants .
37- Optional<List<Rant>> recent = devRant.getFeed().getRants(Sort.RECENT );
82+ // Log out to clear the token .
83+ devRant.logout( );
3884```
0 commit comments