Giter VIP home page Giter VIP logo

trakt-java's Introduction

trakt-java

A Java wrapper around the trakt v2 API using retrofit 2.

Pull requests are welcome.

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

Available on Maven Central

Add the following dependency to your Gradle project:

implementation 'com.uwetrottmann.trakt5:trakt-java:6.4.0'

Or for Maven:

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

Android

This library ships Java 8 bytecode. This requires Android Gradle Plugin 3.2.x or newer.

This library depends on threetenbp. To avoid issues on Android you should exclude this dependency and include ThreeTenABP instead:

implementation ('com.uwetrottmann.trakt5:trakt-java:<latest-version>') {
  exclude group: 'org.threeten', module: 'threetenbp'
}
implementation 'com.jakewharton.threetenabp:threetenabp:<latest-version>'

Example

Use like any other retrofit2 based service. You only need to supply your OAuth 2.0 credentials and optional user OAuth access token obtained from trakt.

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

TraktV2 trakt = new TraktV2("api_key");
Shows traktShows = trakt.shows();
try {
    // Get trending shows
    Response<List<TrendingShow>> response = traktShows.trending(1, null, Extended.FULL).execute();
    if (response.isSuccessful()) {
        List<TrendingShow> shows = response.body();
        for (TrendingShow trending : shows) {
            System.out.println("Title: " + trending.show.title);
        }
    } else {
        if (response.code() == 401) {
            // authorization required, supply a valid OAuth access token
        } else {
            // the request failed for some other reason
        }
    }
} catch (Exception e) {
    // see execute() javadoc 
}

See test cases in src/test/ for more examples and the retrofit website for configuration options.

Use Proguard!

You likely will not use every method in this library, so it is probably useful to strip unused ones with Proguard. Just apply the Proguard rules for retrofit.

License

Created by Uwe Trottmann.

See full list of contributors.

Except where noted otherwise, released into the public domain. Do not just copy, make it better.

trakt-java's People

Contributors

albodelu avatar courville avatar florianmski avatar hrk avatar jakewharton avatar kilianb avatar larsg310 avatar leinad87 avatar mattkranzler5 avatar mlaggner avatar mmarco94 avatar oprisnik avatar porzione avatar samicemalone avatar uwetrottmann avatar yacsrk avatar

Watchers

 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.