Skip to content
This repository was archived by the owner on Jan 5, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
fbf5457
Update pom, add properties for version numbers
LucaScorpion Jul 8, 2017
8d9fde8
Remove GSON, add Jackson, ripped out stuff until it compiled again
LucaScorpion Jul 8, 2017
d1e424d
Set up basic injection, request handler
LucaScorpion Jul 8, 2017
9f930cc
Add ObjectMapperService, use URIBuilder, start on request handler
LucaScorpion Jul 8, 2017
b9e0b95
Improve request handler with object mapper response handler
LucaScorpion Jul 8, 2017
f1e360b
Remove DevRantHolder class
LucaScorpion Jul 8, 2017
5d781d4
Use optionals in request handler
LucaScorpion Jul 8, 2017
2cfa3e6
Improve RequestHandler structure
LucaScorpion Jul 11, 2017
0284f4f
Start on object mapping
LucaScorpion Jul 11, 2017
d26b957
Add getRant method to DevRant, add enum for Endpoint
LucaScorpion Jul 13, 2017
eaf5399
Update gitignore, license, pom
LucaScorpion Aug 10, 2017
573fb9c
Fix comments
LucaScorpion Aug 10, 2017
813c6dd
Fix images
LucaScorpion Aug 10, 2017
597cd17
Add testng and wiremock, fix versions
LucaScorpion Aug 31, 2017
d09ca84
Add simple test, fix pom for now
LucaScorpion Aug 31, 2017
7305609
Move test directory to correct location
LucaScorpion Aug 31, 2017
7db5a3f
Improve DevRantIT
LucaScorpion Aug 31, 2017
06c1503
Add MinimalUser for RantContent
LucaScorpion Aug 31, 2017
a4f4c2c
Remove InjectionModule, fix DevRantTest
LucaScorpion Aug 31, 2017
26387b3
Fix all javadoc, add json example for test, redo Sort and Vote
LucaScorpion Aug 31, 2017
2002f92
Make attach-javadocs quiet
LucaScorpion Aug 31, 2017
b3b5682
Add release profile to sign artifacts
LucaScorpion Aug 31, 2017
bac70bd
Also move sources and javadocs plugins to release profile
LucaScorpion Aug 31, 2017
1d4e8c0
Use Wiremock in integration test
LucaScorpion Aug 31, 2017
47799ac
Remove query params from stub url
LucaScorpion Aug 31, 2017
d3a6481
Add getUser from id and username
LucaScorpion Sep 2, 2017
6885720
Move integration tests to verify phase
LucaScorpion Sep 2, 2017
b09b46e
Add rant feed
LucaScorpion Sep 2, 2017
33b3a49
Expose timeout, improve javadoc
LucaScorpion Sep 4, 2017
16b205d
Improve tests, add MinimalRant without comments
LucaScorpion Sep 4, 2017
c87c914
Jenkinsify
LucaScorpion Sep 5, 2017
85d3b34
Simplify readme, add shields
LucaScorpion Sep 5, 2017
0659f06
Add results stage for test reports
LucaScorpion Sep 5, 2017
3f9fb09
Add tests badge to readme
LucaScorpion Sep 5, 2017
4618dca
Update version in readme
LucaScorpion Sep 5, 2017
a1e7dd0
Rename Rant to CommentedRant, MinimalRant to Rant
LucaScorpion Sep 6, 2017
9ed3869
Add search to feed
LucaScorpion Sep 6, 2017
be54068
Add surprise method
LucaScorpion Sep 6, 2017
3d020dc
Simplify responses, add user id invalid test
LucaScorpion Sep 6, 2017
5f3f9a6
Add test for invalid user id
LucaScorpion Sep 6, 2017
f5782ac
Let DevRantFeed use DevRant
LucaScorpion Sep 8, 2017
398bc57
Add test for request with server error
LucaScorpion Sep 8, 2017
3654a62
Add login
LucaScorpion Sep 8, 2017
20cc741
Separate authenticated calls to DevRantAuth
LucaScorpion Sep 9, 2017
16f92ee
Fix request handler, implement login with tests
LucaScorpion Sep 9, 2017
3d46ffe
Rename Endpoint to ApiEndpoint
LucaScorpion Sep 9, 2017
3529f2e
Clean up code
LucaScorpion Sep 9, 2017
093ae2d
Close scanner for response stream
LucaScorpion Sep 15, 2017
2fb6a84
Return Result object instead of Optional for all request methods.
LucaScorpion Sep 15, 2017
43a1b6e
Improve tests to also check for error messages
LucaScorpion Sep 15, 2017
9b2df7b
Add javadoc, small code improvements
LucaScorpion Sep 15, 2017
11597a1
Improve CommentedRantResponse
LucaScorpion Sep 15, 2017
7634e00
Add weekly rants to feed
LucaScorpion Sep 16, 2017
d199b8e
Add stories to feed
LucaScorpion Sep 16, 2017
a5655cd
Add collabs to feed
LucaScorpion Sep 16, 2017
29b0daa
Add test for request handler
LucaScorpion Sep 16, 2017
91bed53
Add getCollab
LucaScorpion Sep 16, 2017
dda89fb
Improve internal response with comments
LucaScorpion Sep 16, 2017
e80e950
Make Vote a class instead of enum, use the Reason
LucaScorpion Sep 16, 2017
fe91af2
Add rant vote method
LucaScorpion Sep 16, 2017
f3db5bf
Add extra test for downvote
LucaScorpion Sep 16, 2017
bcea56b
Add voteComment method
LucaScorpion Sep 16, 2017
b502911
Use string in urlPath matcher in tests instead of api endpoints
LucaScorpion Sep 16, 2017
eefbdc3
Add javadoc
LucaScorpion Sep 16, 2017
53f6a15
Update readme, make error from result not optional
LucaScorpion Sep 16, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 deletions .gitattributes

This file was deleted.

55 changes: 1 addition & 54 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,62 +5,9 @@
# Maven
target/*

# Java
*.class

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# =========================
# Operating System Files
# =========================

# OSX
# =========================

.DS_Store
.AppleDouble
.LSOverride

# Thumbnails
._*

# Files that might appear on external disk
.Spotlight-V100
.Trashes

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# Windows
# =========================

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk
26 changes: 26 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
pipeline {
agent any

stages {
stage('Clean') {
steps {
mvn 'clean'
}
}
stage('Build') {
steps {
mvn 'install'
}
}
stage('Results') {
steps {
junit '**/target/*-reports/TEST-*.xml'
}
}
}
}

def mvn(String goals) {
def mvnHome = tool 'Maven 3'
sh "'${mvnHome}/bin/mvn' -Dmaven.test.failure.ignore $goals"
}
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 Scorpiac
Copyright (c) 2017 Scorpiac

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
155 changes: 44 additions & 111 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,151 +1,84 @@
# JavaRant
A devRant API wrapper for Java.

[![Maven Central](https://img.shields.io/maven-central/v/com.scorpiac.javarant/javarant.svg)](https://mvnrepository.com/artifact/com.scorpiac.javarant/javarant)
[![Jenkins](https://img.shields.io/jenkins/s/https/jenkins.scorpiac.com/job/JavaRant/job/rework-to-2.0.svg)]()
[![Jenkins tests](https://img.shields.io/jenkins/t/https/jenkins.scorpiac.com/job/JavaRant/job/rework-to-2.0.svg)]()

## Using JavaRant
JavaRant is available on Maven, simply add this dependency to your `pom.xml` file:
JavaRant is available on [Maven](http://mvnrepository.com/artifact/com.scorpiac.javarant/javarant), simply add this dependency to your `pom.xml` file:

```
```xml
<dependency>
<groupId>com.scorpiac.javarant</groupId>
<artifactId>javarant</artifactId>
<version>1.3</version>
<version>2.0.0</version>
</dependency>
```

## Class overview
## Getting started

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

```
DevRant devRant = new DevRant();
```

It can then be used to get rants and collabs from the feed or by searching.
Most object that are returned from `DevRant` are wrapped in a `Result` object.
This will contain an optional result value, along with an error message.
If the optional result is empty, then an error occurred and the error message will be set.
For example:

```
List<Rant> rants = devRant.getRants(Sort.ALGO, 10, 0);
List<Rant> wtf = devRant.search("wtf");
List<Rant> weekly = devRant.getWeekly(Sort.TOP(Range.ALL), 20, 0);
List<Rant> stories = devRant.getStories(Sort.RECENT, 20, 0);

List<Collab> collabs = devRant.getCollabs(10, 0);
Result<CommentedRant> result = devRant.getRant(832125);

Rant random = devRant.getSurprise();
if (!result.getValue().isPresent()) {
System.out.println("An error occurred: " + result.getError());
} else {
CommentedRant rant = result.getValue().get();
System.out.println(rant.getUser().getUsername() + '\n' + rant.getText());
}
```

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

```
Rant rant = devRant.getRant(422850);
Collab collab = devRant.getCollab(420025);
// Get a specific rant.
Result<CommentedRant> rant = devRant.getRant(686001);

User me = devRant.getUser("LucaScorpion");
User me2 = devRant.getUser(102959);
// Get a user by username.
Result<User> me = devRant.getUser("LucaScorpion");
```

To post or vote anything we first need to log in.
This will make a request to get an authentication token, which is stored for later use.
Your username and password will _not_ be stored.
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[]`).
The `DevRant` class contains 2 methods for getting to specific parts of the api.
First, `getFeed()` which returns a `DevRantFeed` object.
This is used to access the rant and collab feeds.

```
devRant.login("username", "password".toCharArray());
```
// Get the 10 latest rants.
Result<List<Rant>> recent = devRant.getFeed().getRants(Sort.RECENT, 10, 0);

Voting on rants and comments can be done by passing the `Rant` or `Comment` object to vote on, or by directly passing the id.
// Get the 10 best stories.
Result<List<Rant>> stories = devRant.getFeed().getStories(Sort.TOP, 0);

// Get 10 collabs.
Result<List<Collab>> collabs = devRant.getFeed().getCollabs(10);
```
devRant.vote(rant, Vote.DOWN(Reason.NOT_FOR_ME));
devRant.vote(comment, Vote.NONE);

devRant.voteRant(429863, Vote.UP);
devRant.voteComment(424558, Vote.UP);
```

To post a rant you simply need the content and tags.
To post a comment you need the text and a `Rant` object, or the id of the rant to comment on.
Second, `getAuth()` which returns a `DevRantAuth` object, which is used to access user functionality.
Note that a user needs to be logged in before this can be accessed.

```
devRant.postRant("Hello world!", "hello, not a rant");
// Log in to devRant.
char[] password = "<password>".toCharArray();
devRant.login("<username>", password);

devRant.postComment(rant, "This is a comment.");
devRant.postComment(424553, "And another one.");
```
// Upvote a rant.
devRant.getAuth().voteRant(832125, Vote.UP);

You can log out to clear the authorization token.
// Clear the vote on a comment.
devRant.getAuth().voteComment(832169, Vote.NONE);

```
// Log out to clear the token.
devRant.logout();
```

### RantContent
This is the base class for rants and comments, which have the following attributes:

- id
- user
- upvotes
- downvotes
- score
- voteState
- content
- image

### Rant
In addition to the `RantContent` attributes, rants also contain:

- tags
- commentCount
- comments

The comments can be accessed by calling `getComments()`.
This will also fetch them if that has not been done yet.
Alternatively you can call `fetchComments()` to fetch the comments, or `fetchComments(force)` to force fetch them (i.e. fetch them again).

### Collab
Collabs are an extension of rants.
Besides the attributes from a rant, collabs contain the following:

- projectType
- description
- techStack
- teamSize
- url

Like with a rant the comments can be fetched or force fetched.
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.

### Comment
A comment only contains the attributes from `RantContent`.

### Image
An image has the following attributes:

- url
- width
- height

### User
Users can be get from rants, comments, by id or username.
When they are get from a rant or comment, only the id, username and score are given.
The other data will be fetched and stored as soon as it's accessed.
Alternatively you can fetch the data by calling `fetchData()`, or `fetchData(force)` to force fetch the data (i.e. fetch it again).

### Sort
These are the different sort options, which are used when getting rants from the feed.
You can pick between `ALGO`, `RECENT` or `TOP`.

### Range
The range is used for the `TOP` sorting method.
The ranges are `DAY`, `WEEK`, `MONTH`, and `ALL`.

### Vote
These are the different vote options, which are used to vote on rants and comments.
The vote options are `UP`, `NONE` and `DOWN`.

### Reason
These are the reasons for a downvote.
The options are `NOT_FOR_ME`, `REPOST` and `OFFENSIVE_SPAM`.
Loading