Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
A Java wrapper around the Trakt RESTful API and a simple DSL for easy interaction.
tag: 1.1.0

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src
.gitignore
CHANGELOG.md
README.md
pom.xml

README.md

trakt-java

A Java wrapper around the Trakt RESTful API and a simple DSL for easy interaction.

Remote services are grouped into local service objects which can be centrally managed by a ServiceManager instance. The manager will act as a factory for all of the services and will automatically initialize them with your credentials and API key.

Each service contains methods which correspond to a remote method. Each of these methods instantiates a class that will allow for you to build the parameters using the Java builder pattern.

Required remote method parameters will be arguments to the service method and all of the methods in the returned builder are optional.

When fully assembled, you can trigger the remote execution by calling the fire() method. This will return a native object which represents the result of the execution. All returned objects are immutable and should be handled as such.

WARNING: The Trakt API has NO versioning support so be sure to extensively test all API calls!

Usage

Quick example:

ServiceManager manager = new ServiceManager();
manager.setAuthentication("username", "sha1_of_password");
manager.setApiKey("api_key");

//Recently watched
List<MediaEntity> watchedList =
    manager.userService().watched("justin").fire();
for (MediaEntity watched : watchedList) {
    System.out.println("Type: " + watched.getType());
    System.out.println("Date: " + watched.getWatched());

    switch (watched.getType()) {
        case Movie:
            System.out.println("Title: " + watched.getMovie().getTitle());
            break;
        case TvShow:
            System.out.println("Title: " + watched.getShow().getTitle());
            System.out.println("Ep.#: " + watched.getEpisode().getTitle());
            break;
    }
    System.out.println();
}

//Upcoming show episodes
Date apocolypse = new Date(2012, 12, 21);
List<CalendarDate> calendarShows =
    manager.userService().calendarShows("justin").date(apocolypse).days(3).fire();
for (CalendarDate calendarDate : calendarShows) {
    System.out.println(calendarDate.getDate());
    System.out.println("-------------------------");
    for (CalendarTvShowEpisode episode : calendarDate.getEpisodes()) {
        System.out.print(episode.getShow().getTitle());
        System.out.print(" - ");
        System.out.print(episode.getEpisode().getSeason());
        System.out.print("x");
        System.out.print(episode.getEpisode().getNumber());
        System.out.print(" - ");
        System.out.println(episode.getEpisode().getTitle());
    }
    System.out.println();
}

See the test cases for more examples.

Documentation

Questions, comments, and suggestions should be posted on the Google Group for Jake Wharton's projects.

Developed By

Contributors

The overall package and class layout as well as approximately 50% of the code in the Trakt* classes are based on nabeelmukhtar's github-java-sdk library.

License

Copyright 2011 Jake Wharton

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.
Something went wrong with that request. Please try again.