com.jakewharton.trakt
Class TraktApiService

java.lang.Object
  extended by com.jakewharton.apibuilder.ApiService
      extended by com.jakewharton.trakt.TraktApiService
Direct Known Subclasses:
AccountService, CalendarService, FriendsService, GenreService, MovieService, RateService, RecommendationsService, SearchService, ShoutService, ShowService, UserService

public abstract class TraktApiService
extends com.jakewharton.apibuilder.ApiService

Trakt-specific API service extension which facilitates provides helper methods for performing remote method calls as well as deserializing the corresponding JSON responses.

Author:
Jake Wharton

Field Summary
 
Fields inherited from class com.jakewharton.apibuilder.ApiService
CONTENT_ENCODING
 
Constructor Summary
TraktApiService()
          Create a new Trakt service with our proper default values.
 
Method Summary
 com.google.gson.JsonElement get(String url)
          Execute request using HTTP GET.
 com.google.gson.JsonElement post(String url, String postBody)
          Execute request using HTTP POST.
 void setApiKey(String value)
          Set API key to use for client authentication by Trakt.
 void setAuthentication(String username, String password_sha)
          Set email and password to use for HTTP basic authentication.
 void setMediaCenterDate(String mediaCenterDate)
          Set the media center build date debug string.
 void setMediaCenterVersion(String mediaCenterVersion)
          Set the media center version debug string.
 void setPluginVersion(String pluginVersion)
          Set the plugin version debug string.
 void setUseSsl(boolean useSsl)
          Set whether or not to use the SSL API endpoint.
protected  com.google.gson.JsonElement unmarshall(InputStream jsonContent)
          Read the entirety of an input stream and parse to a JSON object.
protected
<T> T
unmarshall(com.google.gson.reflect.TypeToken<T> typeToken, com.google.gson.JsonElement response)
          Use GSON to deserialize a JSON object to a native class representation.
protected
<T> T
unmarshall(com.google.gson.reflect.TypeToken<T> typeToken, String reponse)
          Use GSON to deserialize a JSON string to a native class representation.
 
Methods inherited from class com.jakewharton.apibuilder.ApiService
acceptGzip, addRequestHeader, closeConnection, closeStream, convertStreamToString, executeDelete, executeDelete, executeGet, executeGet, executeMethod, executePost, executePost, getConnectTimeout, getParametersString, getReadTimeout, getRequestHeader, getRequestHeaderNames, getWrappedInputStream, removeRequestHeader, setConnectTimeout, setReadTimeout
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TraktApiService

public TraktApiService()
Create a new Trakt service with our proper default values.

Method Detail

get

public com.google.gson.JsonElement get(String url)
Execute request using HTTP GET.

Parameters:
url - URL to request.
Returns:
JSON object.

post

public com.google.gson.JsonElement post(String url,
                                        String postBody)
Execute request using HTTP POST.

Parameters:
url - URL to request.
postBody - String to use as the POST body.
Returns:
JSON object.

setAuthentication

public void setAuthentication(String username,
                              String password_sha)
Set email and password to use for HTTP basic authentication.

Parameters:
username - Username.
password_sha - Password SHA1.

setApiKey

public void setApiKey(String value)
Set API key to use for client authentication by Trakt.

Parameters:
value - Value.

setPluginVersion

public void setPluginVersion(String pluginVersion)
Set the plugin version debug string.

Parameters:
pluginVersion - Value.

setMediaCenterVersion

public void setMediaCenterVersion(String mediaCenterVersion)
Set the media center version debug string.

Parameters:
mediaCenterVersion - Value.

setMediaCenterDate

public void setMediaCenterDate(String mediaCenterDate)
Set the media center build date debug string.

Parameters:
mediaCenterDate - Value.

setUseSsl

public void setUseSsl(boolean useSsl)
Set whether or not to use the SSL API endpoint.

Parameters:
useSsl - Value.

unmarshall

protected <T> T unmarshall(com.google.gson.reflect.TypeToken<T> typeToken,
                           com.google.gson.JsonElement response)
Use GSON to deserialize a JSON object to a native class representation.

Type Parameters:
T - Native class type.
Parameters:
typeToken - Native class type wrapper.
response - Serialized JSON object.
Returns:
Deserialized native instance.

unmarshall

protected <T> T unmarshall(com.google.gson.reflect.TypeToken<T> typeToken,
                           String reponse)
Use GSON to deserialize a JSON string to a native class representation.

Type Parameters:
T - Native class type.
Parameters:
typeToken - Native class type wrapper.
reponse - Serialized JSON string.
Returns:
Deserialized native instance.

unmarshall

protected com.google.gson.JsonElement unmarshall(InputStream jsonContent)
Read the entirety of an input stream and parse to a JSON object.

Parameters:
jsonContent - JSON content input stream.
Returns:
Parsed JSON object.


Copyright © 2011 Jake Wharton. All Rights Reserved.