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

Commit 466eda9

Browse files
authored
Update readme
1 parent 12314b9 commit 466eda9

1 file changed

Lines changed: 72 additions & 59 deletions

File tree

README.md

Lines changed: 72 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,70 @@ JavaRant is available on Maven, simply add this dependency to your `pom.xml` fil
1515
## Class overview
1616

1717
### DevRant
18-
This is the main class to get rants.
19-
From here you can get a list of rants, get a random rant, or search for rants containing a specific term.
18+
This is the main class to interact with devRant.
19+
To use it, you first need to create an instance of it.
2020

21-
Examples:
21+
```
22+
DevRant devRant = new DevRant();
23+
```
24+
25+
It can then be used to get rants and collabs from the feed or by searching.
26+
27+
```
28+
List<Rant> rants = devRant.rants(Sort.ALGO, 10, 0);
29+
List<Rant> wtf = devRant.search("wtf");
30+
List<Rant> weekly = devRant.weekly();
31+
32+
List<Collab> collabs = devRant.collabs();
33+
34+
Rant random = devRant.surprise();
35+
```
36+
37+
It can also be used to get specific items based on an id (or username).
38+
These methods will throw an exception if the specified item does not exist (`NoSuchRantException` for rants and `NoSuchUserException` for users).
39+
Additionally, `getCollab` will also throw a `NotACollabException` if the requested rant is a normal rant instead of a collab.
40+
41+
```
42+
Rant rant = devRant.getRant(422850);
43+
Collab collab = devRant.getCollab(420025);
44+
45+
User me = devRant.getUser("LucaScorpion");
46+
User me2 = devRant.getUser(102959);
47+
```
48+
49+
To post or vote anything we first need to log in.
50+
This will make a request to get an authentication token, which is stored for later use.
51+
Your username and password will _not_ be stored.
52+
The login method uses `char[]` instead of `String` for the password parameter for security reasons (and most of the times you have a password it should already be in the form of a `char[]`).
53+
54+
```
55+
devRant.login("username", "password".toCharArray());
56+
```
57+
58+
Voting on rants and comments can be done by passing the `Rant` or `Comment` object to vote on, or by directly passing the id.
59+
60+
```
61+
devRant.vote(rant, Vote.DOWN);
62+
devRant.vote(comment, Vote.NONE);
63+
64+
devRant.voteRant(429863, Vote.UP);
65+
devRant.voteComment(424558, Vote.UP);
66+
```
67+
68+
To post a rant you simply need the content and tags.
69+
To post a comment you need the text and a `Rant` object, or the id of the rant to comment on.
2270

2371
```
24-
// Get the first 10 rants.
25-
Rant[] rants = DevRant.getRants(Sort.ALGO, 10, 0);
72+
devRant.postRant("Hello world!", "hello, not a rant");
2673
27-
// Get a random rant.
28-
Rant random = DevRant.surprise();
74+
devRant.postComment(rant, "This is a comment.");
75+
devRant.postComment(424553, "And another one.");
76+
```
2977

30-
// Search for rants containing "wtf".
31-
Rant[] wtf = DevRant.search("wtf");
78+
You can log out to clear the authorization token.
3279

33-
// Get the weekly rants.
34-
Rant[] weekly = DevRant.weekly();
80+
```
81+
devRant.logout();
3582
```
3683

3784
### RantContent
@@ -41,15 +88,12 @@ This is the base class for rants and comments, which have the following attribut
4188
- user
4289
- upvotes
4390
- downvotes
91+
- score
4492
- content
4593
- image
4694

47-
Additionally you can call `getScore()` which calculates the total score.
48-
4995
### Rant
50-
Rants are get through one of the methods in `DevRant`, or by an id (`Rant.byId(id)`).
51-
The latter will throw a `NoSuchRantException` if the id is invalid.
52-
In addition to the `RantContent` attributes, a `Rant` also contains:
96+
In addition to the `RantContent` attributes, rants also contain:
5397

5498
- tags
5599
- commentCount
@@ -59,24 +103,9 @@ The comments can be accessed by calling `getComments()`.
59103
This will also fetch them if that has not been done yet.
60104
Alternatively you can call `fetchComments()` to fetch the comments, or `fetchComments(force)` to force fetch them (i.e. fetch them again).
61105

62-
Examples:
63-
64-
```
65-
// Get a rant by its id.
66-
Rant rant = Rant.byId(136761);
67-
68-
// Fetch and get the comments.
69-
Comment[] comments = rant.getComments();
70-
71-
// Force fetch the comments.
72-
boolean success = rant.fetchComments(true);
73-
```
74-
75106
### Collab
76107
Collabs are an extension of rants.
77-
They are get through `DevRant.collabs()` or by an id (`Collab.byId(id)`).
78-
The latter will throw a `NoSuchRantException` if the id is invalid, or a `NotACollabException` if it is simply a rant instead of a collab.
79-
Besides the attributes from a rant, collabs have the following attributes:
108+
Besides the attributes from a rant, collabs contain the following:
80109

81110
- projectType
82111
- description
@@ -87,42 +116,26 @@ Besides the attributes from a rant, collabs have the following attributes:
87116
Like with a rant the comments can be fetched or force fetched.
88117
There is also more data which needs to be fetched, similar to the comments this is done by calling `fetchData()` or `fetchData(force)` to force fetch it.
89118

90-
Examples:
91-
92-
```
93-
// Get a collab by its id.
94-
Collab collab = Collab.byId(420392);
95-
96-
// Force fetch the data.
97-
boolean success = collab.fetchData(true);
98-
```
99-
100119
### Comment
101120
A comment only contains the attributes from `RantContent`.
102121

103122
### Image
104-
An image contains a link to the image on devRant, and a width and height.
123+
An image has the following attributes:
124+
125+
- url
126+
- width
127+
- height
105128

106129
### User
107-
Users can be get from rants, comments, by id (`User.byId(id)`) or username (`User.byUsername(username)`).
108-
The latter two will throw a `NoSuchUserException` for non-existing users.
130+
Users can be get from rants, comments, by id or username.
109131
When they are get from a rant or comment, only the id, username and score are given.
110132
The other data will be fetched and stored as soon as it's accessed.
111133
Alternatively you can fetch the data by calling `fetchData()`, or `fetchData(force)` to force fetch the data (i.e. fetch it again).
112134

113-
Examples:
114-
115-
```
116-
// Get a user by their id.
117-
User me = User.byId(102959);
118-
119-
// Get a user by their username.
120-
User alsoMe = User.byUsername("LucaScorpion");
121-
122-
// Fetch the data.
123-
boolean success = me.fetchData();
124-
```
125-
126135
### Sort
127-
These are the different sort options which are used by `DevRant.getRants`.
136+
These are the different sort options, which are used when getting rants from the feed.
128137
You can pick between `ALGO`, `RECENT` or `TOP`.
138+
139+
### Vote
140+
These are the different vote options, which are used to vote on rants and comments.
141+
The vote options are `UP`, `NONE` and `DOWN`.

0 commit comments

Comments
 (0)