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

Commit 949496d

Browse files
authored
Merge pull request #15 from LucaScorpion/rework-to-2.0
Rework to 2.0
2 parents a599f92 + 53f6a15 commit 949496d

73 files changed

Lines changed: 10972 additions & 1245 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitattributes

Lines changed: 0 additions & 17 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,9 @@
55
# Maven
66
target/*
77

8+
# Java
89
*.class
9-
10-
# Mobile Tools for Java (J2ME)
11-
.mtj.tmp/
12-
13-
# Package Files #
1410
*.jar
15-
*.war
16-
*.ear
1711

1812
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
1913
hs_err_pid*
20-
21-
# =========================
22-
# Operating System Files
23-
# =========================
24-
25-
# OSX
26-
# =========================
27-
28-
.DS_Store
29-
.AppleDouble
30-
.LSOverride
31-
32-
# Thumbnails
33-
._*
34-
35-
# Files that might appear on external disk
36-
.Spotlight-V100
37-
.Trashes
38-
39-
# Directories potentially created on remote AFP share
40-
.AppleDB
41-
.AppleDesktop
42-
Network Trash Folder
43-
Temporary Items
44-
.apdisk
45-
46-
# Windows
47-
# =========================
48-
49-
# Windows image file caches
50-
Thumbs.db
51-
ehthumbs.db
52-
53-
# Folder config file
54-
Desktop.ini
55-
56-
# Recycle Bin used on file shares
57-
$RECYCLE.BIN/
58-
59-
# Windows Installer files
60-
*.cab
61-
*.msi
62-
*.msm
63-
*.msp
64-
65-
# Windows shortcuts
66-
*.lnk

Jenkinsfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
pipeline {
2+
agent any
3+
4+
stages {
5+
stage('Clean') {
6+
steps {
7+
mvn 'clean'
8+
}
9+
}
10+
stage('Build') {
11+
steps {
12+
mvn 'install'
13+
}
14+
}
15+
stage('Results') {
16+
steps {
17+
junit '**/target/*-reports/TEST-*.xml'
18+
}
19+
}
20+
}
21+
}
22+
23+
def mvn(String goals) {
24+
def mvnHome = tool 'Maven 3'
25+
sh "'${mvnHome}/bin/mvn' -Dmaven.test.failure.ignore $goals"
26+
}

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2016 Scorpiac
3+
Copyright (c) 2017 Scorpiac
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 44 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,84 @@
11
# JavaRant
22
A devRant API wrapper for Java.
33

4+
[![Maven Central](https://img.shields.io/maven-central/v/com.scorpiac.javarant/javarant.svg)](https://mvnrepository.com/artifact/com.scorpiac.javarant/javarant)
5+
[![Jenkins](https://img.shields.io/jenkins/s/https/jenkins.scorpiac.com/job/JavaRant/job/rework-to-2.0.svg)]()
6+
[![Jenkins tests](https://img.shields.io/jenkins/t/https/jenkins.scorpiac.com/job/JavaRant/job/rework-to-2.0.svg)]()
7+
48
## Using JavaRant
5-
JavaRant is available on Maven, simply add this dependency to your `pom.xml` file:
9+
JavaRant is available on [Maven](http://mvnrepository.com/artifact/com.scorpiac.javarant/javarant), simply add this dependency to your `pom.xml` file:
610

7-
```
11+
```xml
812
<dependency>
913
<groupId>com.scorpiac.javarant</groupId>
1014
<artifactId>javarant</artifactId>
11-
<version>1.3</version>
15+
<version>2.0.0</version>
1216
</dependency>
1317
```
1418

15-
## Class overview
19+
## Getting started
1620

17-
### DevRant
18-
This is the main class to interact with devRant.
19-
To use it, you first need to create an instance of it.
21+
To access devRant simply create a new `DevRant` object:
2022

2123
```
2224
DevRant devRant = new DevRant();
2325
```
2426

25-
It can then be used to get rants and collabs from the feed or by searching.
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:
2631

2732
```
28-
List<Rant> rants = devRant.getRants(Sort.ALGO, 10, 0);
29-
List<Rant> wtf = devRant.search("wtf");
30-
List<Rant> weekly = devRant.getWeekly(Sort.TOP(Range.ALL), 20, 0);
31-
List<Rant> stories = devRant.getStories(Sort.RECENT, 20, 0);
32-
33-
List<Collab> collabs = devRant.getCollabs(10, 0);
33+
Result<CommentedRant> result = devRant.getRant(832125);
3434
35-
Rant random = devRant.getSurprise();
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+
}
3641
```
3742

38-
It can also be used to get specific items based on an id (or username).
39-
These methods will throw an exception if the specified item does not exist (`NoSuchRantException` for rants and `NoSuchUserException` for users).
40-
Additionally, `getCollab` will also throw a `NotACollabException` if the requested rant is a normal rant instead of a collab.
43+
The `DevRant` class itself can be used to get specific rants and users.
4144

4245
```
43-
Rant rant = devRant.getRant(422850);
44-
Collab collab = devRant.getCollab(420025);
46+
// Get a specific rant.
47+
Result<CommentedRant> rant = devRant.getRant(686001);
4548
46-
User me = devRant.getUser("LucaScorpion");
47-
User me2 = devRant.getUser(102959);
49+
// Get a user by username.
50+
Result<User> me = devRant.getUser("LucaScorpion");
4851
```
4952

50-
To post or vote anything we first need to log in.
51-
This will make a request to get an authentication token, which is stored for later use.
52-
Your username and password will _not_ be stored.
53-
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+
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.
5456

5557
```
56-
devRant.login("username", "password".toCharArray());
57-
```
58+
// Get the 10 latest rants.
59+
Result<List<Rant>> recent = devRant.getFeed().getRants(Sort.RECENT, 10, 0);
5860
59-
Voting on rants and comments can be done by passing the `Rant` or `Comment` object to vote on, or by directly passing the id.
61+
// Get the 10 best stories.
62+
Result<List<Rant>> stories = devRant.getFeed().getStories(Sort.TOP, 0);
6063
64+
// Get 10 collabs.
65+
Result<List<Collab>> collabs = devRant.getFeed().getCollabs(10);
6166
```
62-
devRant.vote(rant, Vote.DOWN(Reason.NOT_FOR_ME));
63-
devRant.vote(comment, Vote.NONE);
6467

65-
devRant.voteRant(429863, Vote.UP);
66-
devRant.voteComment(424558, Vote.UP);
67-
```
68-
69-
To post a rant you simply need the content and tags.
70-
To post a comment you need the text and a `Rant` object, or the id of the rant to comment on.
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.
7170

7271
```
73-
devRant.postRant("Hello world!", "hello, not a rant");
72+
// Log in to devRant.
73+
char[] password = "<password>".toCharArray();
74+
devRant.login("<username>", password);
7475
75-
devRant.postComment(rant, "This is a comment.");
76-
devRant.postComment(424553, "And another one.");
77-
```
76+
// Upvote a rant.
77+
devRant.getAuth().voteRant(832125, Vote.UP);
7878
79-
You can log out to clear the authorization token.
79+
// Clear the vote on a comment.
80+
devRant.getAuth().voteComment(832169, Vote.NONE);
8081
81-
```
82+
// Log out to clear the token.
8283
devRant.logout();
8384
```
84-
85-
### RantContent
86-
This is the base class for rants and comments, which have the following attributes:
87-
88-
- id
89-
- user
90-
- upvotes
91-
- downvotes
92-
- score
93-
- voteState
94-
- content
95-
- image
96-
97-
### Rant
98-
In addition to the `RantContent` attributes, rants also contain:
99-
100-
- tags
101-
- commentCount
102-
- comments
103-
104-
The comments can be accessed by calling `getComments()`.
105-
This will also fetch them if that has not been done yet.
106-
Alternatively you can call `fetchComments()` to fetch the comments, or `fetchComments(force)` to force fetch them (i.e. fetch them again).
107-
108-
### Collab
109-
Collabs are an extension of rants.
110-
Besides the attributes from a rant, collabs contain the following:
111-
112-
- projectType
113-
- description
114-
- techStack
115-
- teamSize
116-
- url
117-
118-
Like with a rant the comments can be fetched or force fetched.
119-
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.
120-
121-
### Comment
122-
A comment only contains the attributes from `RantContent`.
123-
124-
### Image
125-
An image has the following attributes:
126-
127-
- url
128-
- width
129-
- height
130-
131-
### User
132-
Users can be get from rants, comments, by id or username.
133-
When they are get from a rant or comment, only the id, username and score are given.
134-
The other data will be fetched and stored as soon as it's accessed.
135-
Alternatively you can fetch the data by calling `fetchData()`, or `fetchData(force)` to force fetch the data (i.e. fetch it again).
136-
137-
### Sort
138-
These are the different sort options, which are used when getting rants from the feed.
139-
You can pick between `ALGO`, `RECENT` or `TOP`.
140-
141-
### Range
142-
The range is used for the `TOP` sorting method.
143-
The ranges are `DAY`, `WEEK`, `MONTH`, and `ALL`.
144-
145-
### Vote
146-
These are the different vote options, which are used to vote on rants and comments.
147-
The vote options are `UP`, `NONE` and `DOWN`.
148-
149-
### Reason
150-
These are the reasons for a downvote.
151-
The options are `NOT_FOR_ME`, `REPOST` and `OFFENSIVE_SPAM`.

0 commit comments

Comments
 (0)