oprisnik / trakt-java

A Java wrapper around the trakt.tv API using retrofit.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.0.3'

Or for Maven:

<dependency>
  <groupId>com.uwetrottmann</groupId>
  <artifactId>trakt-java</artifactId>
  <version>4.0.3</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.8.0'
compile 'com.squareup.okhttp:okhttp:2.1.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.1.0'

Or for Maven:

<dependency>
    <groupId>com.squareup.retrofit</groupId>
    <artifactId>retrofit</artifactId>
    <version>1.8.0</version>
</dependency>
<dependency>
  <groupId>com.squareup.okhttp</groupId>
  <artifactId>okhttp</artifactId>
  <version>2.1.0</version>
</dependency>
<dependency>
  <groupId>com.squareup.okhttp</groupId>
  <artifactId>okhttp-urlconnection</artifactId>
  <version>2.1.0</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.

About

A Java wrapper around the trakt.tv API using retrofit.


Languages

Language:Java 99.8%Language:PowerShell 0.2%