com.jakewharton.trakt
Class TraktApiBuilder<T>

java.lang.Object
  extended by com.jakewharton.apibuilder.ApiBuilder
      extended by com.jakewharton.trakt.TraktApiBuilder<T>
Type Parameters:
T - Native class type of the HTTP method call result.
Direct Known Subclasses:
AccountService.CreateBuilder, AccountService.TestBuilder, CalendarService.PremieresBuilder, CalendarService.ShowsBuilder, FriendsService.AddBuilder, FriendsService.AllBuilder, FriendsService.ApproveBuilder, FriendsService.DeleteBuilder, FriendsService.DenyBuilder, FriendsService.RequestsBuilder, GenreService.MoviesBuilder, GenreService.ShowsBuilder, MovieService.CancelWatchingBuilder, MovieService.LibraryBuilder, MovieService.ScrobbleBuilder, MovieService.SeenBuilder, MovieService.ShoutsBuilder, MovieService.SummaryBuilder, MovieService.TrendingBuilder, MovieService.UnlibraryBuilder, MovieService.UnseenBuilder, MovieService.UnwatchlistBuilder, MovieService.WatchingBuilder, MovieService.WatchingNowBuilder, MovieService.WatchlistBuilder, RateService.EpisodeBuilder, RateService.MovieBuilder, RateService.ShowBuilder, RecommendationsService.DismissMovieBuilder, RecommendationsService.DismissShowBuilder, RecommendationsService.MoviesBuilder, RecommendationsService.ShowsBuilder, SearchService.EpisodesBuilder, SearchService.MoviesBuilder, SearchService.PeopleBuilder, SearchService.ShowsBuilder, SearchService.UsersBuilder, ShoutService.EpisodeBuilder, ShoutService.MovieBuilder, ShoutService.ShowBuilder, ShowService.CancelWatchingBuilder, ShowService.EpisodeLibraryBuilder, ShowService.EpisodeSeenBuilder, ShowService.EpisodeShoutsBuilder, ShowService.EpisodeSummaryBuilder, ShowService.EpisodeUnlibraryBuilder, ShowService.EpisodeUnseenBuilder, ShowService.EpisodeUnwatchlistBuilder, ShowService.EpisodeWatchingNowBuilder, ShowService.EpisodeWatchlistBuilder, ShowService.ScrobbleBuilder, ShowService.SeasonBuilder, ShowService.SeasonsBuilder, ShowService.ShoutsBuilder, ShowService.SummaryBuilder, ShowService.TrendingBuilder, ShowService.UnlibraryBuilder, ShowService.UnwatchlistBuilder, ShowService.WatchingBuilder, ShowService.WatchingNowBuilder, ShowService.WatchlistBuilder, UserService.CalendarShowsBuilder, UserService.FriendsBuilder, UserService.LibraryMoviesAllBuilder, UserService.LibraryMoviesCollectionBuilder, UserService.LibraryMoviesHatedBuilder, UserService.LibraryMoviesLovedBuilder, UserService.LibraryShowsAllBuilder, UserService.LibraryShowsCollectionBuilder, UserService.LibraryShowsHatedBuilder, UserService.LibraryShowsLovedBuilder, UserService.LibraryShowsWatchedBuilder, UserService.ProfileBuilder, UserService.WatchedBuilder, UserService.WatchedEpisodesBuilder, UserService.WatchedMoviesBuilder, UserService.WatchingBuilder, UserService.WatchlistEpisodesBuilder, UserService.WatchlistMoviesBuilder, UserService.WatchlistShowsBuilder

public abstract class TraktApiBuilder<T>
extends com.jakewharton.apibuilder.ApiBuilder

Trakt-specific API builder extension which provides helper methods for adding fields, parameters, and post-parameters commonly used in the API.

Author:
Jake Wharton

Nested Class Summary
protected static class TraktApiBuilder.HttpMethod
          Valid HTTP request methods.
 
Field Summary
protected static String FIELD_API_KEY
          API key field name.
protected static String FIELD_DATE
           
protected static String FIELD_DAYS
           
protected static String FIELD_EPISODE
           
protected static String FIELD_EXTENDED
           
protected static String FIELD_QUERY
           
protected static String FIELD_SEASON
           
protected static String FIELD_TITLE
           
protected static String FIELD_USERNAME
           
 
Fields inherited from class com.jakewharton.apibuilder.ApiBuilder
API_URL_DELIMITER_END, API_URL_DELIMITER_START
 
Constructor Summary
TraktApiBuilder(TraktApiService service, com.google.gson.reflect.TypeToken<T> token, String methodUri)
          Initialize a new builder for an HTTP GET call.
TraktApiBuilder(TraktApiService service, com.google.gson.reflect.TypeToken<T> token, String urlFormat, TraktApiBuilder.HttpMethod method)
          Initialize a new builder for the specified HTTP method call.
 
Method Summary
protected static long dateToUnixTimestamp(Date date)
          Convert a Date to its Unix timestamp equivalent.
protected  com.google.gson.JsonElement execute()
          Execute the remote API method and return the JSON object result.
protected  com.jakewharton.apibuilder.ApiBuilder field(String name, Date date)
          Add a URL field value.
protected
<K extends TraktEnumeration>
com.jakewharton.apibuilder.ApiBuilder
field(String name, K value)
          Add a URL field value.
 T fire()
          Execute remote API method and unmarshall the result to its native type.
protected  boolean hasPostParameter(String name)
           
protected  void includeDebugStrings()
          Mark current builder as Trakt developer method.
protected  com.jakewharton.apibuilder.ApiBuilder parameter(String name, Date value)
          Add a URL parameter value.
protected
<K extends TraktEnumeration>
com.jakewharton.apibuilder.ApiBuilder
parameter(String name, K value)
          Add a URL parameter value.
protected
<K> com.jakewharton.apibuilder.ApiBuilder
parameter(String name, List<K> valueList)
          Add a URL parameter value.
protected  void performValidation()
          Perform any required validation before firing off the request.
protected  void postFireCallback(T result)
          Perform any required actions before returning the request result.
protected  TraktApiBuilder<T> postParameter(String name, int value)
           
protected  TraktApiBuilder<T> postParameter(String name, com.google.gson.JsonElement value)
           
protected
<K extends TraktEnumeration>
TraktApiBuilder<T>
postParameter(String name, K value)
           
protected  TraktApiBuilder<T> postParameter(String name, String value)
           
protected  void preFireCallback()
          Perform any required actions before validating the request.
 void print()
          Print the HTTP request that would be made
 
Methods inherited from class com.jakewharton.apibuilder.ApiBuilder
buildUrl, buildUrl, encodeUrl, field, field, field, field, field, hasField, hasParameter, parameter, parameter, parameter, parameter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIELD_API_KEY

protected static final String FIELD_API_KEY
API key field name.

See Also:
Constant Field Values

FIELD_USERNAME

protected static final String FIELD_USERNAME
See Also:
Constant Field Values

FIELD_DATE

protected static final String FIELD_DATE
See Also:
Constant Field Values

FIELD_DAYS

protected static final String FIELD_DAYS
See Also:
Constant Field Values

FIELD_QUERY

protected static final String FIELD_QUERY
See Also:
Constant Field Values

FIELD_SEASON

protected static final String FIELD_SEASON
See Also:
Constant Field Values

FIELD_TITLE

protected static final String FIELD_TITLE
See Also:
Constant Field Values

FIELD_EPISODE

protected static final String FIELD_EPISODE
See Also:
Constant Field Values

FIELD_EXTENDED

protected static final String FIELD_EXTENDED
See Also:
Constant Field Values
Constructor Detail

TraktApiBuilder

public TraktApiBuilder(TraktApiService service,
                       com.google.gson.reflect.TypeToken<T> token,
                       String methodUri)
Initialize a new builder for an HTTP GET call.

Parameters:
service - Service to bind to.
token - Return type token.
methodUri - URI method format string.

TraktApiBuilder

public TraktApiBuilder(TraktApiService service,
                       com.google.gson.reflect.TypeToken<T> token,
                       String urlFormat,
                       TraktApiBuilder.HttpMethod method)
Initialize a new builder for the specified HTTP method call.

Parameters:
service - Service to bind to.
token - Return type token.
urlFormat - URL format string.
method - HTTP method.
Method Detail

fire

public final T fire()
Execute remote API method and unmarshall the result to its native type.

Returns:
Instance of result type.
Throws:
com.jakewharton.apibuilder.ApiException - if validation fails.

preFireCallback

protected void preFireCallback()
Perform any required actions before validating the request.


performValidation

protected void performValidation()
Perform any required validation before firing off the request.


postFireCallback

protected void postFireCallback(T result)
Perform any required actions before returning the request result.

Parameters:
result - Request result.

includeDebugStrings

protected final void includeDebugStrings()
Mark current builder as Trakt developer method. This will automatically add the debug fields to the post body.


execute

protected final com.google.gson.JsonElement execute()

Execute the remote API method and return the JSON object result.

This method can be overridden to select a specific subset of the JSON object. The overriding implementation should still call 'super.execute()' and then perform the filtering from there.

Returns:
JSON object instance.

print

public final void print()
Print the HTTP request that would be made


parameter

protected final com.jakewharton.apibuilder.ApiBuilder parameter(String name,
                                                                Date value)
Add a URL parameter value.

Parameters:
name - Name.
value - Value.
Returns:
Current instance for builder pattern.

parameter

protected final <K extends TraktEnumeration> com.jakewharton.apibuilder.ApiBuilder parameter(String name,
                                                                                             K value)
Add a URL parameter value.

Parameters:
name - Name.
value - Value.
Returns:
Current instance for builder pattern.

parameter

protected final <K> com.jakewharton.apibuilder.ApiBuilder parameter(String name,
                                                                    List<K> valueList)
Add a URL parameter value.

Parameters:
name - Name.
valueList - List of values.
Returns:
Current instance for builder pattern.

field

protected final com.jakewharton.apibuilder.ApiBuilder field(String name,
                                                            Date date)
Add a URL field value.

Parameters:
name - Name.
date - Value.
Returns:
Current instance for builder pattern.

field

protected final <K extends TraktEnumeration> com.jakewharton.apibuilder.ApiBuilder field(String name,
                                                                                         K value)
Add a URL field value.

Parameters:
name - Name.
value - Value.
Returns:
Current instance for builder pattern.

hasPostParameter

protected final boolean hasPostParameter(String name)

postParameter

protected final TraktApiBuilder<T> postParameter(String name,
                                                 String value)

postParameter

protected final TraktApiBuilder<T> postParameter(String name,
                                                 int value)

postParameter

protected final <K extends TraktEnumeration> TraktApiBuilder<T> postParameter(String name,
                                                                              K value)

postParameter

protected final TraktApiBuilder<T> postParameter(String name,
                                                 com.google.gson.JsonElement value)

dateToUnixTimestamp

protected static final long dateToUnixTimestamp(Date date)
Convert a Date to its Unix timestamp equivalent.

Parameters:
date - Date value.
Returns:
Unix timestamp value.


Copyright © 2011 Jake Wharton. All Rights Reserved.