Skip to content

synapticloopltd/getcookie-java-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project requires JVM version of at least 1.8

getcookie-java-api top

A Java API for getcookie.com

Table of Contents top

Usage top

The getcookie java API offers a LIMITED, READ ONLY interface to the 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 ]"));
			}
		}
	}
}

Building the Package top

*NIX/Mac OS X top

From the root of the project, simply run

./gradlew build

Windows top

./gradlew.bat build

This will compile and assemble the artefacts into the build/libs/ directory.

Note that this may also run tests (if applicable see the Testing notes)

Running the Tests top

*NIX/Mac OS X top

From the root of the project, simply run

gradle --info test

if you do not have gradle installed, try:

gradlew --info test

Windows top

From the root of the project, simply run

gradle --info test

if you do not have gradle installed, try:

./gradlew.bat --info test

The --info switch will also output logging for the tests

Artefact Publishing - Github top

This project publishes artefacts to GitHub

Note that the latest version can be found https://github.com/synapticloopltd/getcookie-java-api/releases

As such, this is not a repository, but a location to download files from.

Artefact Publishing - Bintray top

This project publishes artefacts to bintray

Note that the latest version can be found https://bintray.com/synapticloop/maven/getcookie-java-api/view

maven setup top

this comes from the jcenter bintray, to set up your repository:

<?xml version="1.0" encoding="UTF-8" ?>
<settings xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd' xmlns='http://maven.apache.org/SETTINGS/1.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
  <profiles>
    <profile>
      <repositories>
        <repository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central</id>
          <name>bintray</name>
          <url>http://jcenter.bintray.com</url>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>central</id>
          <name>bintray-plugins</name>
          <url>http://jcenter.bintray.com</url>
        </pluginRepository>
      </pluginRepositories>
      <id>bintray</id>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>bintray</activeProfile>
  </activeProfiles>
</settings>

gradle setup top

Repository

repositories {
	maven {
		url  "http://jcenter.bintray.com" 
	}
}

or just

repositories {
	jcenter()
}

Dependencies - Gradle top

dependencies {
	runtime(group: 'synapticloop', name: 'getcookie-java-api', version: '1.2.1', ext: 'jar')

	compile(group: 'synapticloop', name: 'getcookie-java-api', version: '1.2.1', ext: 'jar')
}

or, more simply for versions of gradle greater than 2.1

dependencies {
	runtime 'synapticloop:getcookie-java-api:1.2.1'

	compile 'synapticloop:getcookie-java-api:1.2.1'
}

Dependencies - Maven top

<dependency>
	<groupId>synapticloop</groupId>
	<artifactId>getcookie-java-api</artifactId>
	<version>1.2.1</version>
	<type>jar</type>
</dependency>

Dependencies - Downloads top

You will also need to download the following dependencies:

cobertura dependencies

  • net.sourceforge.cobertura:cobertura:2.1.1: (It may be available on one of: bintray mvn central)

compile dependencies

  • org.apache.logging.log4j:log4j-slf4j-impl:2.8.2: (It may be available on one of: bintray mvn central)
  • org.apache.logging.log4j:log4j-core:2.8.2: (It may be available on one of: bintray mvn central)
  • org.apache.httpcomponents:httpclient:4.5.3: (It may be available on one of: bintray mvn central)
  • commons-io:commons-io:2.5: (It may be available on one of: bintray mvn central)
  • com.fasterxml.jackson.core:jackson-databind:2.8.5: (It may be available on one of: bintray mvn central)
  • org.slf4j:slf4j-api:1.7.13: (It may be available on one of: bintray mvn central)
  • org.apache.commons:commons-lang3:3.5: (It may be available on one of: bintray mvn central)

runtime dependencies

  • org.apache.httpcomponents:httpclient:4.5.3: (It may be available on one of: bintray mvn central)
  • commons-io:commons-io:2.5: (It may be available on one of: bintray mvn central)
  • com.fasterxml.jackson.core:jackson-databind:2.8.5: (It may be available on one of: bintray mvn central)
  • org.slf4j:slf4j-api:1.7.13: (It may be available on one of: bintray mvn central)
  • org.apache.commons:commons-lang3:3.5: (It may be available on one of: bintray mvn central)

testCompile dependencies

testRuntime dependencies

NOTE: You may need to download any dependencies of the above dependencies in turn (i.e. the transitive dependencies)

License top

The MIT License (MIT)

Copyright (c) 2017 synapticloop

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

--

This README.md file was hand-crafted with care utilising synapticlooptemplar->documentr

--

About

A limited Java API for the getcookie.com website

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages