Update to CloseableHttpClient

master
Stuart Boston 11 years ago
parent 6722019db8
commit ba0c8bc564

@ -120,7 +120,7 @@
<dependency>
<groupId>org.yamj</groupId>
<artifactId>api-common</artifactId>
<version>1.3-SNAPSHOT</version>
<version>1.3</version>
</dependency>
</dependencies>

@ -19,24 +19,6 @@
*/
package com.omertron.themoviedbapi;
import static com.omertron.themoviedbapi.tools.ApiUrl.*;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.HttpGet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yamj.api.common.http.CommonHttpClient;
import org.yamj.api.common.http.DigestedResponse;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.omertron.themoviedbapi.model.Account;
@ -67,11 +49,23 @@ import com.omertron.themoviedbapi.model.StatusCode;
import com.omertron.themoviedbapi.model.TmdbConfiguration;
import com.omertron.themoviedbapi.model.TokenAuthorisation;
import com.omertron.themoviedbapi.model.TokenSession;
import com.omertron.themoviedbapi.model.Trailer;
import com.omertron.themoviedbapi.model.Translation;
import com.omertron.themoviedbapi.model.Video;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import com.omertron.themoviedbapi.results.TmdbResultsMap;
import com.omertron.themoviedbapi.tools.ApiUrl;
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_ADULT;
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_COUNTRY;
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_END_DATE;
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_ID;
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_INCLUDE_ALL_MOVIES;
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_LANGUAGE;
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_PAGE;
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_QUERY;
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_SESSION;
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_START_DATE;
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_TOKEN;
import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_YEAR;
import com.omertron.themoviedbapi.tools.WebBrowser;
import com.omertron.themoviedbapi.wrapper.WrapperAlternativeTitles;
import com.omertron.themoviedbapi.wrapper.WrapperChanges;
@ -95,14 +89,32 @@ import com.omertron.themoviedbapi.wrapper.WrapperPersonCredits;
import com.omertron.themoviedbapi.wrapper.WrapperPersonList;
import com.omertron.themoviedbapi.wrapper.WrapperReleaseInfo;
import com.omertron.themoviedbapi.wrapper.WrapperReviews;
import com.omertron.themoviedbapi.wrapper.WrapperTrailers;
import com.omertron.themoviedbapi.wrapper.WrapperTranslations;
import com.omertron.themoviedbapi.wrapper.WrapperVideos;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yamj.api.common.exception.ApiExceptionType;
import org.yamj.api.common.http.DigestedResponse;
import org.yamj.api.common.http.DigestedResponseReader;
import org.yamj.api.common.http.SimpleHttpClientBuilder;
/**
* The MovieDb API
* <p>
* This is for version 3 of the API as specified here: http://help.themoviedb.org/kb/api/about-3
* This is for version 3 of the API as specified here:
* http://help.themoviedb.org/kb/api/about-3
*
* @author stuart.boston
*/
@ -110,8 +122,10 @@ public class TheMovieDbApi {
private static final Logger LOG = LoggerFactory.getLogger(TheMovieDbApi.class);
private String apiKey;
private CommonHttpClient httpClient;
private CloseableHttpClient httpClient;
private TmdbConfiguration tmdbConfig;
private static final String DEFAULT_CHARSET = "UTF-8";
private final Charset charset = Charset.forName(DEFAULT_CHARSET);
// API Methods
private static final String BASE_MOVIE = "movie/";
private static final String BASE_PERSON = "person/";
@ -144,7 +158,7 @@ public class TheMovieDbApi {
* @throws MovieDbException
*/
public TheMovieDbApi(String apiKey) throws MovieDbException {
this(apiKey, null);
this(apiKey, new SimpleHttpClientBuilder().build());
}
/**
@ -154,7 +168,7 @@ public class TheMovieDbApi {
* @param httpClient The httpClient to use for web requests.
* @throws MovieDbException
*/
public TheMovieDbApi(String apiKey, CommonHttpClient httpClient) throws MovieDbException {
public TheMovieDbApi(String apiKey, CloseableHttpClient httpClient) throws MovieDbException {
this.apiKey = apiKey;
this.httpClient = httpClient;
@ -208,7 +222,7 @@ public class TheMovieDbApi {
throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Unable to proces delete request", url);
}
final DigestedResponse response = httpClient.requestContent(httpGet);
final DigestedResponse response = DigestedResponseReader.requestContent(httpClient, httpGet, charset);
if (response.getStatusCode() >= HTTP_STATUS_500) {
throw new MovieDbException(ApiExceptionType.HTTP_503_ERROR, response.getContent(), response.getStatusCode(), url, null);
@ -229,42 +243,6 @@ public class TheMovieDbApi {
return webpage;
}
/**
* Set the proxy information
*
* @param host
* @param port
* @param username
* @param password
*/
public void setProxy(String host, int port, String username, String password) {
// should be set in HTTP client already
if (httpClient != null) {
return;
}
WebBrowser.setProxyHost(host);
WebBrowser.setProxyPort(port);
WebBrowser.setProxyUsername(username);
WebBrowser.setProxyPassword(password);
}
/**
* Set the connection and read time out values
*
* @param connect
* @param read
*/
public void setTimeout(int connect, int read) {
// should be set in HTTP client already
if (httpClient != null) {
return;
}
WebBrowser.setWebTimeoutConnect(connect);
WebBrowser.setWebTimeoutRead(read);
}
/**
* Compare the MovieDB object with a title & year
*
@ -283,7 +261,8 @@ public class TheMovieDbApi {
* @param moviedb The moviedb object to compare too
* @param title The title of the movie to compare
* @param year The year of the movie to compare
* @param maxDistance The Levenshtein Distance between the two titles. 0 = exact match
* @param maxDistance The Levenshtein Distance between the two titles. 0 =
* exact match
* @param caseSensitive true if the comparison is to be case sensitive
* @return True if there is a match, False otherwise.
*/
@ -399,13 +378,16 @@ public class TheMovieDbApi {
//<editor-fold defaultstate="collapsed" desc="Authentication Functions">
/**
* This method is used to generate a valid request token for user based authentication.
* This method is used to generate a valid request token for user based
* authentication.
*
* A request token is required in order to request a session id.
*
* You can generate any number of request tokens but they will expire after 60 minutes.
* You can generate any number of request tokens but they will expire after
* 60 minutes.
*
* As soon as a valid session id has been created the token will be destroyed.
* As soon as a valid session id has been created the token will be
* destroyed.
*
* @return
* @throws MovieDbException
@ -425,7 +407,8 @@ public class TheMovieDbApi {
}
/**
* This method is used to generate a session id for user based authentication.
* This method is used to generate a session id for user based
* authentication.
*
* A session id is required in order to use any of the write methods.
*
@ -456,14 +439,18 @@ public class TheMovieDbApi {
/**
* This method is used to generate a guest session id.
*
* A guest session can be used to rate movies without having a registered TMDb user account.
* A guest session can be used to rate movies without having a registered
* TMDb user account.
*
* You should only generate a single guest session per user (or device) as you will be able to attach the ratings to a TMDb user
* account in the future.
* You should only generate a single guest session per user (or device) as
* you will be able to attach the ratings to a TMDb user account in the
* future.
*
* There are also IP limits in place so you should always make sure it's the end user doing the guest session actions.
* There are also IP limits in place so you should always make sure it's the
* end user doing the guest session actions.
*
* If a guest session is not used for the first time within 24 hours, it will be automatically discarded.
* If a guest session is not used for the first time within 24 hours, it
* will be automatically discarded.
*
* @return
* @throws MovieDbException
@ -483,7 +470,8 @@ public class TheMovieDbApi {
}
/**
* Get the basic information for an account. You will need to have a valid session id.
* Get the basic information for an account. You will need to have a valid
* session id.
*
* @param sessionId
* @return
@ -595,7 +583,8 @@ public class TheMovieDbApi {
*
* It will return the single highest rated poster and backdrop.
*
* ApiExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies found.
* ApiExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies
* found.
*
* @param movieId
* @param language
@ -634,7 +623,8 @@ public class TheMovieDbApi {
*
* It will return the single highest rated poster and backdrop.
*
* ApiExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies found.
* ApiExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies
* found.
*
* @param imdbId
* @param language
@ -669,7 +659,8 @@ public class TheMovieDbApi {
}
/**
* This method is used to retrieve all of the alternative titles we have for a particular movie.
* This method is used to retrieve all of the alternative titles we have for
* a particular movie.
*
* @param movieId
* @param country
@ -731,7 +722,8 @@ public class TheMovieDbApi {
}
/**
* This method should be used when youre wanting to retrieve all of the images for a particular movie.
* This method should be used when youre wanting to retrieve all of the
* images for a particular movie.
*
* @param movieId
* @param language
@ -764,7 +756,8 @@ public class TheMovieDbApi {
}
/**
* This method is used to retrieve all of the keywords that have been added to a particular movie.
* This method is used to retrieve all of the keywords that have been added
* to a particular movie.
*
* Currently, only English keywords exist.
*
@ -794,7 +787,8 @@ public class TheMovieDbApi {
}
/**
* This method is used to retrieve all of the release and certification data we have for a specific movie.
* This method is used to retrieve all of the release and certification data
* we have for a specific movie.
*
* @param movieId
* @param language
@ -824,7 +818,8 @@ public class TheMovieDbApi {
}
/**
* This method is used to retrieve all of the trailers for a particular movie.
* This method is used to retrieve all of the trailers for a particular
* movie.
*
* Supported sites are YouTube and QuickTime.
*
@ -834,7 +829,7 @@ public class TheMovieDbApi {
* @return
* @throws MovieDbException
*/
public TmdbResultsList<Trailer> getMovieTrailers(int movieId, String language, String... appendToResponse) throws MovieDbException {
public TmdbResultsList<Video> getMovieTrailers(int movieId, String language, String... appendToResponse) throws MovieDbException {
ApiUrl apiUrl = new ApiUrl(apiKey, BASE_MOVIE, "/videos");
apiUrl.addArgument(PARAM_ID, movieId);
@ -848,8 +843,8 @@ public class TheMovieDbApi {
String webpage = requestWebPage(url);
try {
WrapperTrailers wrapper = mapper.readValue(webpage, WrapperTrailers.class);
TmdbResultsList<Trailer> results = new TmdbResultsList<Trailer>(wrapper.getTrailers());
WrapperVideos wrapper = mapper.readValue(webpage, WrapperVideos.class);
TmdbResultsList<Video> results = new TmdbResultsList<Video>(wrapper.getTrailers());
results.copyWrapper(wrapper);
return results;
} catch (IOException ex) {
@ -859,7 +854,8 @@ public class TheMovieDbApi {
}
/**
* This method is used to retrieve a list of the available translations for a specific movie.
* This method is used to retrieve a list of the available translations for
* a specific movie.
*
* @param movieId
* @param appendToResponse
@ -887,9 +883,11 @@ public class TheMovieDbApi {
}
/**
* The similar movies method will let you retrieve the similar movies for a particular movie.
* The similar movies method will let you retrieve the similar movies for a
* particular movie.
*
* This data is created dynamically but with the help of users votes on TMDb.
* This data is created dynamically but with the help of users votes on
* TMDb.
*
* The data is much better with movies that have more keywords
*
@ -1001,11 +999,13 @@ public class TheMovieDbApi {
*
* By default, only the last 24 hours of changes are returned.
*
* The maximum number of days that can be returned in a single request is 14.
* The maximum number of days that can be returned in a single request is
* 14.
*
* The language is present on fields that are translatable.
*
* TODO: DOES NOT WORK AT THE MOMENT. This is due to the "value" item changing type in the ChangeItem
* TODO: DOES NOT WORK AT THE MOMENT. This is due to the "value" item
* changing type in the ChangeItem
*
* @param movieId
* @param startDate the start date of the changes, optional
@ -1103,7 +1103,8 @@ public class TheMovieDbApi {
/**
* This method is used to retrieve the movies currently in theatres.
*
* This is a curated list that will normally contain 100 movies. The default response will return 20 movies.
* This is a curated list that will normally contain 100 movies. The default
* response will return 20 movies.
*
* TODO: Implement more than 20 movies
*
@ -1175,7 +1176,8 @@ public class TheMovieDbApi {
}
/**
* This method is used to retrieve the top rated movies that have over 10 votes on TMDb.
* This method is used to retrieve the top rated movies that have over 10
* votes on TMDb.
*
* The default response will return 20 movies.
*
@ -1273,9 +1275,11 @@ public class TheMovieDbApi {
//<editor-fold defaultstate="collapsed" desc="Collection Functions">
/**
* This method is used to retrieve all of the basic information about a movie collection.
* This method is used to retrieve all of the basic information about a
* movie collection.
*
* You can get the ID needed for this method by making a getMovieInfo request for the belongs_to_collection.
* You can get the ID needed for this method by making a getMovieInfo
* request for the belongs_to_collection.
*
* @param collectionId
* @param language
@ -1361,7 +1365,8 @@ public class TheMovieDbApi {
}
/**
* This method is used to retrieve all of the cast & crew information for the person.
* This method is used to retrieve all of the cast & crew information for
* the person.
*
* It will return the single highest rated poster for each movie record.
*
@ -1423,7 +1428,8 @@ public class TheMovieDbApi {
*
* By default, only the last 24 hours of changes are returned.
*
* The maximum number of days that can be returned in a single request is 14.
* The maximum number of days that can be returned in a single request is
* 14.
*
* The language is present on fields that are translatable.
*
@ -1501,7 +1507,8 @@ public class TheMovieDbApi {
//<editor-fold defaultstate="collapsed" desc="Company Functions">
/**
* This method is used to retrieve the basic information about a production company on TMDb.
* This method is used to retrieve the basic information about a production
* company on TMDb.
*
* @param companyId
* @return
@ -1526,7 +1533,8 @@ public class TheMovieDbApi {
/**
* This method is used to retrieve the movies associated with a company.
*
* These movies are returned in order of most recently released to oldest. The default response will return 20 movies per page.
* These movies are returned in order of most recently released to oldest.
* The default response will return 20 movies per page.
*
* TODO: Implement more than 20 movies
*
@ -1595,9 +1603,11 @@ public class TheMovieDbApi {
/**
* Get a list of movies per genre.
*
* It is important to understand that only movies with more than 10 votes get listed.
* It is important to understand that only movies with more than 10 votes
* get listed.
*
* This prevents movies from 1 10/10 rating from being listed first and for the first 5 pages.
* This prevents movies from 1 10/10 rating from being listed first and for
* the first 5 pages.
*
* @param genreId
* @param language
@ -1637,13 +1647,16 @@ public class TheMovieDbApi {
//<editor-fold defaultstate="collapsed" desc="Search Functions">
/**
* Search Movies This is a good starting point to start finding movies on TMDb.
* Search Movies This is a good starting point to start finding movies on
* TMDb.
*
* @param movieName
* @param searchYear Limit the search to the provided year. Zero (0) will get all years
* @param searchYear Limit the search to the provided year. Zero (0) will
* get all years
* @param language The language to include. Can be blank/null.
* @param includeAdult true or false to include adult titles in the search
* @param page The page of results to return. 0 to get the default (first page)
* @param page The page of results to return. 0 to get the default (first
* page)
* @return
* @throws MovieDbException
*/
@ -1723,7 +1736,8 @@ public class TheMovieDbApi {
/**
* This is a good starting point to start finding people on TMDb.
*
* The idea is to be a quick and light method so you can iterate through people quickly.
* The idea is to be a quick and light method so you can iterate through
* people quickly.
*
* @param personName
* @param includeAdult
@ -1795,8 +1809,8 @@ public class TheMovieDbApi {
/**
* Search Companies.
*
* You can use this method to search for production companies that are part of TMDb. The company IDs will map to those returned
* on movie calls.
* You can use this method to search for production companies that are part
* of TMDb. The company IDs will map to those returned on movie calls.
*
* http://help.themoviedb.org/kb/api/search-companies
*
@ -1960,7 +1974,8 @@ public class TheMovieDbApi {
}
/**
* This method lets users add new movies to a list that they created. A valid session id is required.
* This method lets users add new movies to a list that they created. A
* valid session id is required.
*
* @param sessionId
* @param listId
@ -1973,7 +1988,8 @@ public class TheMovieDbApi {
}
/**
* This method lets users remove movies from a list that they created. A valid session id is required.
* This method lets users remove movies from a list that they created. A
* valid session id is required.
*
* @param sessionId
* @param listId
@ -2027,7 +2043,8 @@ public class TheMovieDbApi {
}
/**
* This method lets users delete a list that they created. A valid session id is required.
* This method lets users delete a list that they created. A valid session
* id is required.
*
* @param sessionId
* @param listId
@ -2114,10 +2131,12 @@ public class TheMovieDbApi {
//<editor-fold defaultstate="collapsed" desc="Changes Functions">
/**
* Get a list of movie ids that have been edited. By default we show the last 24 hours and only 100 items per page. The maximum
* number of days that can be returned in a single request is 14. You can then use the movie changes API to get the actual data
* that has been changed. Please note that the change log system to support this was changed on October 5, 2012 and will only
* show movies that have been edited since.
* Get a list of movie ids that have been edited. By default we show the
* last 24 hours and only 100 items per page. The maximum number of days
* that can be returned in a single request is 14. You can then use the
* movie changes API to get the actual data that has been changed. Please
* note that the change log system to support this was changed on October 5,
* 2012 and will only show movies that have been edited since.
*
* @param page
* @param startDate the start date of the changes, optional
@ -2181,30 +2200,42 @@ public class TheMovieDbApi {
//<editor-fold defaultstate="collapsed" desc="Discover">
/**
* Discover movies by different types of data like average rating, number of votes, genres and certifications.
* Discover movies by different types of data like average rating, number of
* votes, genres and certifications.
*
* You can alternatively create a "discover" object and pass it to this method to cut out the requirement for all of these
* parameters
* You can alternatively create a "discover" object and pass it to this
* method to cut out the requirement for all of these parameters
*
* @param page Minimum value is 1
* @param language ISO 639-1 code.
* @param sortBy Available options are vote_average.desc, vote_average.asc, release_date.desc, release_date.asc,
* popularity.desc, popularity.asc
* @param sortBy Available options are vote_average.desc, vote_average.asc,
* release_date.desc, release_date.asc, popularity.desc, popularity.asc
* @param includeAdult Toggle the inclusion of adult titles
* @param year Filter the results release dates to matches that include this value
* @param primaryReleaseYear Filter the results so that only the primary release date year has this value
* @param voteCountGte Only include movies that are equal to, or have a vote count higher than this value
* @param voteAverageGte Only include movies that are equal to, or have a higher average rating than this value
* @param withGenres Only include movies with the specified genres. Expected value is an integer (the id of a genre). Multiple
* values can be specified. Comma separated indicates an 'AND' query, while a pipe (|) separated value indicates an 'OR'.
* @param releaseDateGte The minimum release to include. Expected format is YYYY-MM-DD
* @param releaseDateLte The maximum release to include. Expected format is YYYY-MM-DD
* @param certificationCountry Only include movies with certifications for a specific country. When this value is specified,
* 'certificationLte' is required. A ISO 3166-1 is expected.
* @param certificationLte Only include movies with this certification and lower. Expected value is a valid certification for
* the specified 'certificationCountry'.
* @param withCompanies Filter movies to include a specific company. Expected value is an integer (the id of a company). They
* can be comma separated to indicate an 'AND' query.
* @param year Filter the results release dates to matches that include this
* value
* @param primaryReleaseYear Filter the results so that only the primary
* release date year has this value
* @param voteCountGte Only include movies that are equal to, or have a vote
* count higher than this value
* @param voteAverageGte Only include movies that are equal to, or have a
* higher average rating than this value
* @param withGenres Only include movies with the specified genres. Expected
* value is an integer (the id of a genre). Multiple values can be
* specified. Comma separated indicates an 'AND' query, while a pipe (|)
* separated value indicates an 'OR'.
* @param releaseDateGte The minimum release to include. Expected format is
* YYYY-MM-DD
* @param releaseDateLte The maximum release to include. Expected format is
* YYYY-MM-DD
* @param certificationCountry Only include movies with certifications for a
* specific country. When this value is specified, 'certificationLte' is
* required. A ISO 3166-1 is expected.
* @param certificationLte Only include movies with this certification and
* lower. Expected value is a valid certification for the specified
* 'certificationCountry'.
* @param withCompanies Filter movies to include a specific company.
* Expected value is an integer (the id of a company). They can be comma
* separated to indicate an 'AND' query.
* @return
* @throws MovieDbException
*/
@ -2232,7 +2263,8 @@ public class TheMovieDbApi {
}
/**
* Discover movies by different types of data like average rating, number of votes, genres and certifications.
* Discover movies by different types of data like average rating, number of
* votes, genres and certifications.
*
* @param discover A discover object containing the search criteria required
* @return

@ -70,6 +70,8 @@ public class MovieDb extends AbstractJsonMapping {
private long revenue;
@JsonProperty("runtime")
private int runtime;
@JsonProperty("original_language")
private String originalLanguage;
@JsonProperty("spoken_languages")
private List<Language> spokenLanguages;
@JsonProperty("tagline")
@ -93,8 +95,8 @@ public class MovieDb extends AbstractJsonMapping {
private WrapperMovieKeywords keywords;
@JsonProperty("releases")
private WrapperReleaseInfo releases;
@JsonProperty("videos")
private WrapperTrailers trailers;
@JsonProperty("trailers")
private WrapperVideos trailers;
@JsonProperty("translations")
private WrapperTranslations translations;
@JsonProperty("similar_movies")
@ -206,6 +208,10 @@ public class MovieDb extends AbstractJsonMapping {
public Boolean getVideo() {
return video;
}
public String getOriginalLanguage() {
return originalLanguage;
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Setter methods">
@ -308,8 +314,12 @@ public class MovieDb extends AbstractJsonMapping {
public void setVideo(Boolean video) {
this.video = video;
}
public void setOriginalLanguage(String originalLanguage) {
this.originalLanguage = originalLanguage;
}
// </editor-fold>
//<editor-fold defaultstate="collapsed" desc="AppendToResponse Getters">
public List<AlternativeTitle> getAlternativeTitles() {
return alternativeTitles.getTitles();
@ -335,7 +345,7 @@ public class MovieDb extends AbstractJsonMapping {
return releases.getCountries();
}
public List<Trailer> getTrailers() {
public List<Video> getTrailers() {
return trailers.getTrailers();
}
@ -377,7 +387,7 @@ public class MovieDb extends AbstractJsonMapping {
this.releases = releases;
}
public void setTrailers(WrapperTrailers trailers) {
public void setTrailers(WrapperVideos trailers) {
this.trailers = trailers;
}

@ -24,85 +24,53 @@ import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
/**
* Trailer specific information from the "Append to Response" method
*
* @author Stuart
*/
public class Trailer extends AbstractJsonMapping {
private static final long serialVersionUID = 1L;
/*
* Website sources
*/
public static final String WEBSITE_YOUTUBE = "youtube";
public static final String WEBSITE_QUICKTIME = "quicktime";
/*
* Properties
*/
private String id;
@JsonProperty("name")
private String name;
@JsonProperty("size")
private String size;
private String key;
// The website of the trailer
private String site;
@JsonProperty("source")
private String source;
@JsonProperty("type")
private String type;
@JsonProperty("iso_639_1")
private String language;
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getSize() {
return size;
}
public String getKey() {
return key;
}
public String getSite() {
return site;
}
public String getType() {
return type;
}
public String getLanguage() {
return language;
}
public void setId(String id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public String getSize() {
return size;
}
public void setSize(String size) {
this.size = size;
}
public void setKey(String key) {
this.key = key;
public String getSource() {
return source;
}
public void setSite(String site) {
this.site = site;
public void setSource(String source) {
this.source = source;
}
public void setType(String type) {
this.type = type;
public String getType() {
return type;
}
public void setLanguage(String language) {
this.language = language;
public void setType(String type) {
this.type = type;
}
@Override
@ -110,11 +78,10 @@ public class Trailer extends AbstractJsonMapping {
if (obj instanceof Trailer) {
final Trailer other = (Trailer) obj;
return new EqualsBuilder()
.append(id, other.id)
.append(name, other.name)
.append(size, other.size)
.append(key, other.key)
.append(language, other.language)
.append(source, other.source)
.append(type, other.type)
.isEquals();
} else {
return false;
@ -124,12 +91,10 @@ public class Trailer extends AbstractJsonMapping {
@Override
public int hashCode() {
return new HashCodeBuilder()
.append(id)
.append(name)
.append(size)
.append(key)
.append(site)
.append(language)
.append(source)
.append(type)
.toHashCode();
}
}

@ -0,0 +1,133 @@
/*
* Copyright (c) 2004-2015 Stuart Boston
*
* This file is part of TheMovieDB API.
*
* TheMovieDB API is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* TheMovieDB API is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with TheMovieDB API. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.model;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
/**
* Video specific information
*
* @author Stuart
*/
public class Video extends AbstractJsonMapping {
private static final long serialVersionUID = 1L;
@JsonProperty("id")
private String id;
@JsonProperty("iso_639_1")
private String language;
@JsonProperty("key")
private String key;
@JsonProperty("name")
private String name;
@JsonProperty("site")
private String site;
@JsonProperty("size")
private String size;
@JsonProperty("type")
private String type;
public String getId() {
return id;
}
public String getName() {
return name;
}
public String getSize() {
return size;
}
public String getKey() {
return key;
}
public String getSite() {
return site;
}
public String getType() {
return type;
}
public String getLanguage() {
return language;
}
public void setId(String id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setSize(String size) {
this.size = size;
}
public void setKey(String key) {
this.key = key;
}
public void setSite(String site) {
this.site = site;
}
public void setType(String type) {
this.type = type;
}
public void setLanguage(String language) {
this.language = language;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof Video) {
final Video other = (Video) obj;
return new EqualsBuilder()
.append(id, other.id)
.append(name, other.name)
.append(size, other.size)
.append(key, other.key)
.append(language, other.language)
.isEquals();
} else {
return false;
}
}
@Override
public int hashCode() {
return new HashCodeBuilder()
.append(id)
.append(name)
.append(size)
.append(key)
.append(site)
.append(language)
.toHashCode();
}
}

@ -1,46 +0,0 @@
/*
* Copyright (c) 2004-2015 Stuart Boston
*
* This file is part of TheMovieDB API.
*
* TheMovieDB API is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* TheMovieDB API is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with TheMovieDB API. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.wrapper;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.omertron.themoviedbapi.model.Trailer;
import java.io.Serializable;
import java.util.List;
/**
*
* @author Stuart
*/
public class WrapperTrailers extends AbstractWrapperId implements Serializable {
private static final long serialVersionUID = 1L;
@JsonProperty("results")
private List<Trailer> trailers;
public List<Trailer> getTrailers() {
return trailers;
}
public void setTrailers(List<Trailer> trailers) {
this.trailers = trailers;
}
}

@ -0,0 +1,87 @@
/*
* Copyright (c) 2004-2015 Stuart Boston
*
* This file is part of TheMovieDB API.
*
* TheMovieDB API is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* TheMovieDB API is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with TheMovieDB API. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.wrapper;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.omertron.themoviedbapi.model.Trailer;
import com.omertron.themoviedbapi.model.Video;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Stuart
*/
public class WrapperVideos extends AbstractWrapperId implements Serializable {
private static final long serialVersionUID = 1L;
private List<Video> videos = null;
public List<Video> getTrailers() {
return videos;
}
@JsonSetter("results")
public void setTrailers(List<Video> trailers) {
this.videos = trailers;
}
@JsonSetter("quicktime")
public void setQuickTime(List<Trailer> trailers) {
if (trailers == null) {
this.videos = new ArrayList<Video>();
}
for (Trailer t : trailers) {
System.out.println(t.toString());
System.out.println(convertTrailer(t, "quicktime"));
}
}
@JsonSetter("youtube")
public void setYouTube(List<Trailer> trailers) {
if (trailers == null) {
this.videos = new ArrayList<Video>();
}
for (Trailer t : trailers) {
System.out.println(t.toString());
Video v = convertTrailer(t, "youtube");
System.out.println(v.toString());
videos.add(v);
}
}
private Video convertTrailer(final Trailer trailer, final String site) {
Video video = new Video();
video.setId("");
video.setLanguage("");
video.setSize("");
video.setName(trailer.getName());
video.setKey(trailer.getSource());
video.setType(trailer.getType());
video.setSite(site);
return video;
}
}
Loading…
Cancel
Save