Giter VIP home page Giter VIP logo

trakt-java's Introduction

trakt-java

A Java wrapper around the trakt v2 API using retrofit.

Trakt methods are grouped into service objects which can be centrally managed by a TraktV2 instance. It will act as a factory for all of the services and will automatically initialize them with your API key (OAuth client id) and optionally a given user access token.

Usage

Add the following dependency to your Gradle project:

compile 'com.uwetrottmann:trakt-java:4.3.0'

Or for Maven:

<dependency>
  <groupId>com.uwetrottmann</groupId>
  <artifactId>trakt-java</artifactId>
  <version>4.3.0</version>
</dependency>

Dependencies

If you would rather use the released jar, add dependencies as you see fit. For example for Gradle:

compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp:2.2.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
compile 'org.apache.oltu.oauth2:org.apache.oltu.oauth2.client:1.0.0'
compile 'joda-time:joda-time:2.7'

Or for Maven:

<dependency>
    <groupId>com.squareup.retrofit</groupId>
    <artifactId>retrofit</artifactId>
    <version>1.9.0</version>
</dependency>
<dependency>
  <groupId>com.squareup.okhttp</groupId>
  <artifactId>okhttp</artifactId>
  <version>2.2.0</version>
</dependency>
<dependency>
  <groupId>com.squareup.okhttp</groupId>
  <artifactId>okhttp-urlconnection</artifactId>
  <version>2.2.0</version>
</dependency>
<dependency>
    <groupId>org.apache.oltu.oauth2</groupId>
    <artifactId>org.apache.oltu.oauth2.client</artifactId>
    <version>1.0.0</version>
</dependency>
<dependency>
    <groupId>joda-time</groupId>
    <artifactId>joda-time</artifactId>
    <version>2.7</version>
</dependency>

Calling methods

Calling methods is easy, but make sure to do it on a background thread (there will be network activity). When using methods that require authentication, make sure to set a valid OAuth 2.0 access token obtained from trakt.

TraktV2 provides some helper methods to handle the OAuth 2.0 flow.

You also might want to look at how retrofit works and can be customized.

// Setup service manager
TraktV2 trakt = new TraktV2();
trakt.setApiKey("api_key");
// trakt.setAccessToken("oauth_access_token"); // optional, see docs if required

// Create service instance
Shows traktShows = trakt.shows();

try {
    // Get trending shows
    List<TrendingShow> shows = traktShows.trending(1, 10, Extended.FULLIMAGES);
    for (TrendingShow trending : shows) {
        System.out.println("Title: " + trending.show.title);
    }
} catch (RetrofitError e) {
    // TODO: handle
}

See test cases in src/test/ for more examples.

Original Implementation

License

Copyright 2013-2015 Uwe Trottmann

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

trakt-java's People

Contributors

uwetrottmann avatar jakewharton avatar florianmski avatar samicemalone avatar porzione avatar oprisnik avatar leinad87 avatar

Watchers

James Cloos avatar Thiago avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.