Skip to content

Commit

Permalink
updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
synapticloop committed Feb 3, 2017
1 parent 841fa09 commit 7fe8fd9
Show file tree
Hide file tree
Showing 7 changed files with 211 additions and 78 deletions.
149 changes: 116 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,117 @@

- [getcookie-java-api](#documentr_heading_0)
- [Table of Contents](#documentr_heading_1)
- [Building the Package](#documentr_heading_2)
- [*NIX/Mac OS X](#documentr_heading_3)
- [Windows](#documentr_heading_4)
- [Running the Tests](#documentr_heading_5)
- [*NIX/Mac OS X](#documentr_heading_6)
- [Windows](#documentr_heading_7)
- [Artefact Publishing - Github](#documentr_heading_8)
- [Artefact Publishing - Bintray](#documentr_heading_9)
- [maven setup](#documentr_heading_10)
- [gradle setup](#documentr_heading_11)
- [Dependencies - Gradle](#documentr_heading_12)
- [Dependencies - Maven](#documentr_heading_13)
- [Dependencies - Downloads](#documentr_heading_14)
- [License](#documentr_heading_19)

- [Usage](#documentr_heading_2)
- [Building the Package](#documentr_heading_3)
- [*NIX/Mac OS X](#documentr_heading_4)
- [Windows](#documentr_heading_5)
- [Running the Tests](#documentr_heading_6)
- [*NIX/Mac OS X](#documentr_heading_7)
- [Windows](#documentr_heading_8)
- [Artefact Publishing - Github](#documentr_heading_9)
- [Artefact Publishing - Bintray](#documentr_heading_10)
- [maven setup](#documentr_heading_11)
- [gradle setup](#documentr_heading_12)
- [Dependencies - Gradle](#documentr_heading_13)
- [Dependencies - Maven](#documentr_heading_14)
- [Dependencies - Downloads](#documentr_heading_15)
- [License](#documentr_heading_20)





<a name="documentr_heading_2"></a>

# Building the Package <sup><sup>[top](documentr_top)</sup></sup>
# Usage <sup><sup>[top](documentr_top)</sup></sup>

The getcookie java API offers a **LIMITED, READ ONLY** interface to the
[https://getcookie.com/](https://getcookie.com/) website. You can retrieve:

- Posts (and comments) from a specific group
- Posts (and comments) from a specific user

An example is below:




```
package synapticloop.getcookie.api.example;
import java.util.List;
import synapticloop.getcookie.api.GetCookieApiClient;
import synapticloop.getcookie.api.exception.GetCookieApiException;
import synapticloop.getcookie.api.model.Group;
import synapticloop.getcookie.api.model.Owner;
import synapticloop.getcookie.api.model.Post;
import synapticloop.getcookie.api.model.User;
import synapticloop.getcookie.api.response.GroupPostsResponse;
import synapticloop.getcookie.api.response.UserPostsResponse;
public class QuickTest {
public static void main(String[] args) throws GetCookieApiException {
GetCookieApiClient getCookieApiClient = new GetCookieApiClient();
// get the posts for the 'shower-thoughts' group
GroupPostsResponse groupPosts = getCookieApiClient.getGroupPosts("shower-thoughts");
// due to the JSON data structure - there is an array of groups - which
// only ever has one entry in the array
List<Group> groups = groupPosts.getData().getGroups();
// get the group
Group group = groups.get(0);
// now get the posts
List<Post> posts = group.getPosts();
for (Post post : posts) {
// now we can retrieve the information from the post
String title = post.getTitle();
System.out.println(String.format("[ POST ] title: %s", title));
// we can also retrieve who posted it
Owner owner = post.getOwner();
String username = owner.getUsername();
// anonymous posts don't have much information
if(!"anonymous".equals(username)) {
System.out.println(String.format(" [ USER ] name: %s", username));
System.out.println(String.format(" [ USER ] from: %s", owner.getCountryName()));
// and get the posts that they have done
UserPostsResponse userPosts = getCookieApiClient.getUserPosts(username);
List<User> users = userPosts.getData().getUsers();
// once again - there is only one user in the array
User user = users.get(0);
List<Post> postsFromUser = user.getPosts();
for (Post postFromUser : postsFromUser) {
System.out.println(String.format(" [ USER_POST ] title: %s", postFromUser.getTitle()));
}
} else {
System.out.println(String.format(" [ USER ] [ anonymous ]"));
}
}
}
}
```






<a name="documentr_heading_3"></a>

# Building the Package <sup><sup>[top](documentr_top)</sup></sup>



<a name="documentr_heading_4"></a>

## *NIX/Mac OS X <sup><sup>[top](documentr_top)</sup></sup>

From the root of the project, simply run
Expand All @@ -65,7 +148,7 @@ From the root of the project, simply run



<a name="documentr_heading_4"></a>
<a name="documentr_heading_5"></a>

## Windows <sup><sup>[top](documentr_top)</sup></sup>

Expand All @@ -78,13 +161,13 @@ Note that this may also run tests (if applicable see the Testing notes)



<a name="documentr_heading_5"></a>
<a name="documentr_heading_6"></a>

# Running the Tests <sup><sup>[top](documentr_top)</sup></sup>



<a name="documentr_heading_6"></a>
<a name="documentr_heading_7"></a>

## *NIX/Mac OS X <sup><sup>[top](documentr_top)</sup></sup>

Expand All @@ -98,7 +181,7 @@ if you do not have gradle installed, try:



<a name="documentr_heading_7"></a>
<a name="documentr_heading_8"></a>

## Windows <sup><sup>[top](documentr_top)</sup></sup>

Expand All @@ -115,7 +198,7 @@ The `--info` switch will also output logging for the tests



<a name="documentr_heading_8"></a>
<a name="documentr_heading_9"></a>

# Artefact Publishing - Github <sup><sup>[top](documentr_top)</sup></sup>

Expand All @@ -127,7 +210,7 @@ As such, this is not a repository, but a location to download files from.



<a name="documentr_heading_9"></a>
<a name="documentr_heading_10"></a>

# Artefact Publishing - Bintray <sup><sup>[top](documentr_top)</sup></sup>

Expand All @@ -137,7 +220,7 @@ This project publishes artefacts to [bintray](https://bintray.com/)


<a name="documentr_heading_10"></a>
<a name="documentr_heading_11"></a>

## maven setup <sup><sup>[top](documentr_top)</sup></sup>

Expand Down Expand Up @@ -183,7 +266,7 @@ this comes from the jcenter bintray, to set up your repository:



<a name="documentr_heading_11"></a>
<a name="documentr_heading_12"></a>

## gradle setup <sup><sup>[top](documentr_top)</sup></sup>

Expand Down Expand Up @@ -215,17 +298,17 @@ repositories {



<a name="documentr_heading_12"></a>
<a name="documentr_heading_13"></a>

## Dependencies - Gradle <sup><sup>[top](documentr_top)</sup></sup>



```
dependencies {
runtime(group: 'synapticloop', name: 'getcookie-java-api', version: '1.0.0', ext: 'jar')
runtime(group: 'synapticloop', name: 'getcookie-java-api', version: '1.0.1', ext: 'jar')
compile(group: 'synapticloop', name: 'getcookie-java-api', version: '1.0.0', ext: 'jar')
compile(group: 'synapticloop', name: 'getcookie-java-api', version: '1.0.1', ext: 'jar')
}
```

Expand All @@ -237,17 +320,17 @@ or, more simply for versions of gradle greater than 2.1

```
dependencies {
runtime 'synapticloop:getcookie-java-api:1.0.0'
runtime 'synapticloop:getcookie-java-api:1.0.1'
compile 'synapticloop:getcookie-java-api:1.0.0'
compile 'synapticloop:getcookie-java-api:1.0.1'
}
```





<a name="documentr_heading_13"></a>
<a name="documentr_heading_14"></a>

## Dependencies - Maven <sup><sup>[top](documentr_top)</sup></sup>

Expand All @@ -257,7 +340,7 @@ dependencies {
<dependency>
<groupId>synapticloop</groupId>
<artifactId>getcookie-java-api</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<type>jar</type>
</dependency>
```
Expand All @@ -266,7 +349,7 @@ dependencies {



<a name="documentr_heading_14"></a>
<a name="documentr_heading_15"></a>

## Dependencies - Downloads <sup><sup>[top](documentr_top)</sup></sup>

Expand Down Expand Up @@ -310,7 +393,7 @@ You will also need to download the following dependencies:



<a name="documentr_heading_19"></a>
<a name="documentr_heading_20"></a>

# License <sup><sup>[top](documentr_top)</sup></sup>

Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {
id 'eclipse'
id 'maven-publish'
id 'co.riiid.gradle' version '0.4.2'
id 'com.jfrog.bintray' version '1.6'
id "com.jfrog.bintray" version "1.7.3"

id 'synapticloop.copyrightr' version '1.1.2'
id 'synapticloop.documentr' version '2.8.2'
Expand All @@ -24,7 +24,7 @@ group = 'synapticloop'
archivesBaseName = 'getcookie-java-api'
description = """A Java API for getcookie.com"""

version = '1.0.0'
version = '1.0.1'

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down Expand Up @@ -130,7 +130,7 @@ publishing {


github {
owner = group
owner = 'synapticloopltd'
repo = archivesBaseName
if(System.getenv('GITHUB_TOKEN')) {
token = System.getenv('GITHUB_TOKEN')
Expand All @@ -155,4 +155,4 @@ bintray {
repo = 'maven'
name = 'getcookie-java-api'
}
}
}
6 changes: 6 additions & 0 deletions documentr.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
{ "type": "toplink", "value": " <a name=\"#documentr_top\"></a>" },
{ "type": "tocbacktotop", "value": " <sup><sup>[top](documentr_top)</sup></sup>" },

{ "type":"file", "value":"src/docs/usage-001.md" },

{ "type": "markup", "value":"\n```\n" },
{ "type": "file", "value":"src/test/java/synapticloop/getcookie/api/example/QuickTest.java" },
{ "type": "markup", "value":"\n```\n" },

{ "type":"inbuilt", "value":"gradle-build" },
{ "type":"inbuilt", "value":"gradle-test" },

Expand Down
11 changes: 11 additions & 0 deletions src/docs/usage-001.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

# Usage

The getcookie java API offers a **LIMITED, READ ONLY** interface to the
[https://getcookie.com/](https://getcookie.com/) website. You can retrieve:

- Posts (and comments) from a specific group
- Posts (and comments) from a specific user

An example is below:

21 changes: 15 additions & 6 deletions src/main/java/synapticloop/getcookie/api/GetCookieApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

/*
* Copyright (c) 2017 Synapticloop.
Expand Down Expand Up @@ -137,11 +138,15 @@ public GroupPostsResponse getGroupPosts(String group, Long offset) throws GetCoo
* @throws GetCookieApiException if there was an error with the API call.
*/
public PostResponse getPost(String postId) throws GetCookieApiException {
return(execute(Constants.HTTP_METHOD_GET,
Constants.URL_GETCOOKIE_DOT_COM,
String.format(Constants.PATH_GET_POST, postId),
200,
PostResponse.class));
try {
return(execute(Constants.HTTP_METHOD_GET,
Constants.URL_GETCOOKIE_DOT_COM,
String.format(Constants.PATH_GET_POST, postId),
200,
PostResponse.class));
} catch(GetCookieApiException ex) {
throw(ex);
}
}

/**
Expand Down Expand Up @@ -176,7 +181,11 @@ private <T> T execute(String httpMethod, String url, String path, int allowableS
LOGGER.debug("Status code received: {}, wanted: {}.", statusCode, allowableStatusCode);
if(null != returnClass) {
try {
return parseResponse(response, returnClass);
T parseResponse = parseResponse(response, returnClass);
if( response.getEntity() != null ) {
EntityUtils.consume(response.getEntity());
}
return parseResponse;
} catch (IOException ex) {
throw new GetCookieApiException(ex);
}
Expand Down
Loading

0 comments on commit 7fe8fd9

Please sign in to comment.