From bbda0eec727b26d04a1e834150b2e45181854654 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 16 Feb 2015 08:50:11 +0000 Subject: [PATCH 001/100] Inital commit for release 4.0 Signed-off-by: Stuart Boston --- .../omertron/themoviedbapi/TheMovieDbApi.java | 938 +++++++++--------- .../themoviedbapi/enumeration/MediaType.java | 37 + .../themoviedbapi/methods/AbstractMethod.java | 73 ++ .../themoviedbapi/methods/TmdbAccount.java | 289 ++++++ .../methods/TmdbAuthentication.java | 166 ++++ .../methods/TmdbCertifications.java | 93 ++ .../themoviedbapi/methods/TmdbChanges.java | 131 +++ .../methods/TmdbCollections.java | 40 + .../themoviedbapi/methods/TmdbCompanies.java | 40 + .../methods/TmdbConfiguration.java | 40 + .../themoviedbapi/methods/TmdbCredits.java | 40 + .../themoviedbapi/methods/TmdbDiscover.java | 40 + .../themoviedbapi/methods/TmdbFind.java | 40 + .../themoviedbapi/methods/TmdbGenres.java | 40 + .../themoviedbapi/methods/TmdbJobs.java | 40 + .../themoviedbapi/methods/TmdbKeywords.java | 40 + .../themoviedbapi/methods/TmdbLists.java | 40 + .../themoviedbapi/methods/TmdbMovies.java | 40 + .../themoviedbapi/methods/TmdbNetworks.java | 40 + .../themoviedbapi/methods/TmdbPeople.java | 40 + .../themoviedbapi/methods/TmdbReviews.java | 40 + .../themoviedbapi/methods/TmdbSearch.java | 40 + .../themoviedbapi/methods/TmdbTv.java | 40 + .../themoviedbapi/model/AbstractIdName.java | 3 - .../themoviedbapi/model/Certification.java | 60 ++ .../themoviedbapi/model/ChangedMedia.java | 48 + .../themoviedbapi/model/Configuration.java | 183 ++++ .../themoviedbapi/tools/MethodBase.java | 4 +- .../themoviedbapi/tools/MethodSub.java | 8 +- .../themoviedbapi/wrapper/WrapperConfig.java | 8 +- .../wrapper/WrapperMediaChanges.java | 39 + .../omertron/themoviedbapi/TestAccounts.java | 6 +- .../themoviedbapi/TheMovieDbApiTest.java | 8 +- 33 files changed, 2249 insertions(+), 485 deletions(-) create mode 100644 src/main/java/com/omertron/themoviedbapi/enumeration/MediaType.java create mode 100644 src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java create mode 100644 src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java create mode 100644 src/main/java/com/omertron/themoviedbapi/methods/TmdbAuthentication.java create mode 100644 src/main/java/com/omertron/themoviedbapi/methods/TmdbCertifications.java create mode 100644 src/main/java/com/omertron/themoviedbapi/methods/TmdbChanges.java create mode 100644 src/main/java/com/omertron/themoviedbapi/methods/TmdbCollections.java create mode 100644 src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java create mode 100644 src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java create mode 100644 src/main/java/com/omertron/themoviedbapi/methods/TmdbCredits.java create mode 100644 src/main/java/com/omertron/themoviedbapi/methods/TmdbDiscover.java create mode 100644 src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java create mode 100644 src/main/java/com/omertron/themoviedbapi/methods/TmdbGenres.java create mode 100644 src/main/java/com/omertron/themoviedbapi/methods/TmdbJobs.java create mode 100644 src/main/java/com/omertron/themoviedbapi/methods/TmdbKeywords.java create mode 100644 src/main/java/com/omertron/themoviedbapi/methods/TmdbLists.java create mode 100644 src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java create mode 100644 src/main/java/com/omertron/themoviedbapi/methods/TmdbNetworks.java create mode 100644 src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java create mode 100644 src/main/java/com/omertron/themoviedbapi/methods/TmdbReviews.java create mode 100644 src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java create mode 100644 src/main/java/com/omertron/themoviedbapi/methods/TmdbTv.java create mode 100644 src/main/java/com/omertron/themoviedbapi/model/Certification.java create mode 100644 src/main/java/com/omertron/themoviedbapi/model/ChangedMedia.java create mode 100644 src/main/java/com/omertron/themoviedbapi/model/Configuration.java create mode 100644 src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMediaChanges.java diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 9a7a9d5eb..1b4c6c7b4 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -21,6 +21,27 @@ package com.omertron.themoviedbapi; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.omertron.themoviedbapi.enumeration.MediaType; +import com.omertron.themoviedbapi.methods.TmdbAccount; +import com.omertron.themoviedbapi.methods.TmdbAuthentication; +import com.omertron.themoviedbapi.methods.TmdbCertifications; +import com.omertron.themoviedbapi.methods.TmdbChanges; +import com.omertron.themoviedbapi.methods.TmdbCollections; +import com.omertron.themoviedbapi.methods.TmdbCompanies; +import com.omertron.themoviedbapi.methods.TmdbConfiguration; +import com.omertron.themoviedbapi.methods.TmdbCredits; +import com.omertron.themoviedbapi.methods.TmdbDiscover; +import com.omertron.themoviedbapi.methods.TmdbFind; +import com.omertron.themoviedbapi.methods.TmdbGenres; +import com.omertron.themoviedbapi.methods.TmdbJobs; +import com.omertron.themoviedbapi.methods.TmdbKeywords; +import com.omertron.themoviedbapi.methods.TmdbLists; +import com.omertron.themoviedbapi.methods.TmdbMovies; +import com.omertron.themoviedbapi.methods.TmdbNetworks; +import com.omertron.themoviedbapi.methods.TmdbPeople; +import com.omertron.themoviedbapi.methods.TmdbReviews; +import com.omertron.themoviedbapi.methods.TmdbSearch; +import com.omertron.themoviedbapi.methods.TmdbTV; import com.omertron.themoviedbapi.model.*; import com.omertron.themoviedbapi.results.TmdbResultsList; import com.omertron.themoviedbapi.results.TmdbResultsMap; @@ -56,15 +77,36 @@ public class TheMovieDbApi { private static final Logger LOG = LoggerFactory.getLogger(TheMovieDbApi.class); private String apiKey; - private TmdbConfiguration tmdbConfig; + private Configuration tmdbConfig; private HttpTools httpTools; // Jackson JSON configuration - private static ObjectMapper mapper = new ObjectMapper(); + private static final ObjectMapper MAPPER = new ObjectMapper(); // Constants private static final String MOVIE_ID = "movie_id"; private static final int YEAR_LENGTH = 4; private static final int RATING_MAX = 10; private static final int POST_SUCCESS_STATUS_CODE = 12; + // Sub-methods + private static TmdbAccount tmdbAccount; + private static TmdbAuthentication tmdbAuth; + private static TmdbCertifications tmdbCertifications; + private static TmdbChanges tmdbChanges; + private static TmdbCollections tmdbCollections; + private static TmdbCompanies tmdbCompany; + private static TmdbConfiguration tmdbConfiguration; + private static TmdbCredits tmdbCredits; + private static TmdbDiscover tmdbDiscover; + private static TmdbFind tmdbFind; + private static TmdbGenres tmdbGenre; + private static TmdbJobs tmdbJobs; + private static TmdbKeywords tmdbKeyword; + private static TmdbLists tmdbList; + private static TmdbMovies tmdbMovies; + private static TmdbNetworks tmdbNetworks; + private static TmdbPeople tmdbPeople; + private static TmdbReviews tmdbReviews; + private static TmdbSearch tmdbSearch; + private static TmdbTV tmdbTv; /** * API for The Movie Db. @@ -91,13 +133,42 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(configUrl); try { - WrapperConfig wc = mapper.readValue(webpage, WrapperConfig.class); + WrapperConfig wc = MAPPER.readValue(webpage, WrapperConfig.class); tmdbConfig = wc.getTmdbConfiguration(); } catch (IOException ex) { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to read configuration", configUrl, ex); } } + /** + * Initialise the sub-classes once the API key and http client are known + * + * @param apiKey + * @param httpTools + */ + private void initialise(String apiKey, HttpTools httpTools) { + tmdbAccount = new TmdbAccount(apiKey, httpTools); + tmdbAuth = new TmdbAuthentication(apiKey, httpTools); + tmdbCertifications = new TmdbCertifications(apiKey, httpTools); + tmdbChanges = new TmdbChanges(apiKey, httpTools); + tmdbCollections = new TmdbCollections(apiKey, httpTools); + tmdbCompany = new TmdbCompanies(apiKey, httpTools); + tmdbConfiguration = new TmdbConfiguration(apiKey, httpTools); + tmdbCredits = new TmdbCredits(apiKey, httpTools); + tmdbDiscover = new TmdbDiscover(apiKey, httpTools); + tmdbFind = new TmdbFind(apiKey, httpTools); + tmdbGenre = new TmdbGenres(apiKey, httpTools); + tmdbJobs = new TmdbJobs(apiKey, httpTools); + tmdbKeyword = new TmdbKeywords(apiKey, httpTools); + tmdbList = new TmdbLists(apiKey, httpTools); + tmdbMovies = new TmdbMovies(apiKey, httpTools); + tmdbNetworks = new TmdbNetworks(apiKey, httpTools); + tmdbPeople = new TmdbPeople(apiKey, httpTools); + tmdbReviews = new TmdbReviews(apiKey, httpTools); + tmdbSearch = new TmdbSearch(apiKey, httpTools); + tmdbTv = new TmdbTV(apiKey, httpTools); + } + /** * Compare the MovieDB object with a title & year * @@ -195,13 +266,12 @@ public class TheMovieDbApi { return StringUtils.isNotBlank(year) && !"UNKNOWN".equals(year); } - // /** * Get the configuration information * * @return */ - public TmdbConfiguration getConfiguration() { + public Configuration getConfiguration() { return tmdbConfig; } @@ -228,238 +298,7 @@ public class TheMovieDbApi { throw new MovieDbException(ApiExceptionType.INVALID_URL, sb.toString(), "", ex); } } - // - // - /** - * 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. - * - * As soon as a valid session id has been created the token will be destroyed. - * - * @return - * @throws MovieDbException - */ - public TokenAuthorisation getAuthorisationToken() throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - URL url = new ApiUrl(apiKey, MethodBase.AUTH).setSubMethod(MethodSub.TOKEN_NEW).buildUrl(parameters); - - String webpage = httpTools.getRequest(url); - - try { - return mapper.readValue(webpage, TokenAuthorisation.class); - } catch (IOException ex) { - LOG.warn("Failed to get Authorisation Token: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.AUTH_FAILURE, webpage, url, ex); - } - } - - /** - * 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. - * - * @param token - * @return - * @throws MovieDbException - */ - public TokenSession getSessionToken(TokenAuthorisation token) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - - if (!token.getSuccess()) { - LOG.warn("Session token was not successful!"); - throw new MovieDbException(ApiExceptionType.AUTH_FAILURE, "Authorisation token was not successful!"); - } - - parameters.add(Param.TOKEN, token.getRequestToken()); - URL url = new ApiUrl(apiKey, MethodBase.AUTH).setSubMethod(MethodSub.SESSION_NEW).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - return mapper.readValue(webpage, TokenSession.class); - } catch (IOException ex) { - LOG.warn("Failed to get Session Token: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * This method is used to generate a session id for user based authentication. User must provide their username and password - * - * A session id is required in order to use any of the write methods. - * - * @param token Session token - * @param username User's username - * @param password User's password - * @return - * @throws MovieDbException - */ - public TokenAuthorisation getSessionTokenLogin(TokenAuthorisation token, String username, String password) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - - if (!token.getSuccess()) { - LOG.warn("Session token was not successful!"); - throw new MovieDbException(ApiExceptionType.AUTH_FAILURE, "Authorisation token was not successful!"); - } - - parameters.add(Param.TOKEN, token.getRequestToken()); - parameters.add(Param.USERNAME, username); - parameters.add(Param.PASSWORD, password); - - URL url = new ApiUrl(apiKey, MethodBase.AUTH).setSubMethod(MethodSub.TOKEN_VALIDATE).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - return mapper.readValue(webpage, TokenAuthorisation.class); - } catch (IOException ex) { - LOG.warn("Failed to get Session Token: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * 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. - * - * 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. - * - * If a guest session is not used for the first time within 24 hours, it will be automatically discarded. - * - * @return - * @throws MovieDbException - */ - public TokenSession getGuestSessionToken() throws MovieDbException { - URL url = new ApiUrl(apiKey, MethodBase.AUTH).setSubMethod(MethodSub.GUEST_SESSION).buildUrl(); - String webpage = httpTools.getRequest(url); - - try { - return mapper.readValue(webpage, TokenSession.class); - } catch (IOException ex) { - LOG.warn("Failed to get Guest Session Token: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * Get the basic information for an account. You will need to have a valid session id. - * - * @param sessionId - * @return - * @throws MovieDbException - */ - public Account getAccount(String sessionId) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.SESSION, sessionId); - - URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - return mapper.readValue(webpage, Account.class); - } catch (IOException ex) { - LOG.warn("Failed to get Account: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * Get the account favourite movies - * - * @param sessionId - * @param accountId - * @return - * @throws MovieDbException - */ - public List getFavoriteMovies(String sessionId, int accountId) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.SESSION, sessionId); - - URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(accountId, MethodSub.FAVORITE_MOVIES).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - return mapper.readValue(webpage, WrapperMovie.class).getMovies(); - } catch (IOException ex) { - LOG.warn("Failed to get favorite movies: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - public StatusCode changeFavoriteStatus(String sessionId, int accountId, Integer movieId, boolean isFavorite) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.SESSION, sessionId); - - Map body = new HashMap(); - body.put(MOVIE_ID, movieId); - body.put("favorite", isFavorite); - String jsonBody = convertToJson(body); - - URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(accountId, MethodSub.FAVORITE).buildUrl(parameters); - String webpage = httpTools.postRequest(url, jsonBody); - - try { - return mapper.readValue(webpage, StatusCode.class); - } catch (IOException ex) { - LOG.warn("Failed to get favorite status: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * Add a movie to an accounts watch list. - * - * @param sessionId - * @param accountId - * @param movieId - * @return - * @throws MovieDbException - */ - public StatusCode addToWatchList(String sessionId, int accountId, Integer movieId) throws MovieDbException { - return modifyWatchList(sessionId, accountId, movieId, true); - } - - /** - * Remove a movie from an accounts watch list. - * - * @param sessionId - * @param accountId - * @param movieId - * @return - * @throws MovieDbException - */ - public StatusCode removeFromWatchList(String sessionId, int accountId, Integer movieId) throws MovieDbException { - return modifyWatchList(sessionId, accountId, movieId, false); - } - - private StatusCode modifyWatchList(String sessionId, int accountId, Integer movieId, boolean add) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.SESSION, sessionId); - - Map body = new HashMap(); - body.put(MOVIE_ID, movieId); - body.put("movie_watchlist", add); - String jsonBody = convertToJson(body); - - URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(accountId, MethodSub.MOVIE_WATCHLIST).buildUrl(parameters); - String webpage = httpTools.postRequest(url, jsonBody); - - try { - return mapper.readValue(webpage, StatusCode.class); - } catch (IOException ex) { - LOG.warn("Failed to modify watch list: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - // - - // /** * This method is used to retrieve all of the basic movie information. * @@ -482,7 +321,7 @@ public class TheMovieDbApi { URL url = new ApiUrl(apiKey, MethodBase.MOVIE).buildUrl(parameters); String webpage = httpTools.getRequest(url); try { - MovieDb movie = mapper.readValue(webpage, MovieDb.class); + MovieDb movie = MAPPER.readValue(webpage, MovieDb.class); if (movie == null || movie.getId() == 0) { LOG.warn("No movie found for ID '{}'", movieId); throw new MovieDbException(ApiExceptionType.ID_NOT_FOUND, "No movie found for ID: " + movieId, url); @@ -517,7 +356,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - MovieDb movie = mapper.readValue(webpage, MovieDb.class); + MovieDb movie = MAPPER.readValue(webpage, MovieDb.class); if (movie == null || movie.getId() == 0) { LOG.warn("No movie found for IMDB ID: '{}'", imdbId); throw new MovieDbException(ApiExceptionType.ID_NOT_FOUND, "No movie found for IMDB ID: " + imdbId, url); @@ -547,7 +386,7 @@ public class TheMovieDbApi { URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.ALT_TITLES).buildUrl(parameters); String webpage = httpTools.getRequest(url); try { - WrapperAlternativeTitles wrapper = mapper.readValue(webpage, WrapperAlternativeTitles.class); + WrapperAlternativeTitles wrapper = MAPPER.readValue(webpage, WrapperAlternativeTitles.class); TmdbResultsList results = new TmdbResultsList(wrapper.getTitles()); results.copyWrapper(wrapper); return results; @@ -576,7 +415,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - WrapperMovieCasts wrapper = mapper.readValue(webpage, WrapperMovieCasts.class); + WrapperMovieCasts wrapper = MAPPER.readValue(webpage, WrapperMovieCasts.class); TmdbResultsList results = new TmdbResultsList(wrapper.getAll()); results.copyWrapper(wrapper); return results; @@ -605,7 +444,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - WrapperImages wrapper = mapper.readValue(webpage, WrapperImages.class); + WrapperImages wrapper = MAPPER.readValue(webpage, WrapperImages.class); TmdbResultsList results = new TmdbResultsList(wrapper.getAll()); results.copyWrapper(wrapper); return results; @@ -634,7 +473,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - WrapperMovieKeywords wrapper = mapper.readValue(webpage, WrapperMovieKeywords.class); + WrapperMovieKeywords wrapper = MAPPER.readValue(webpage, WrapperMovieKeywords.class); TmdbResultsList results = new TmdbResultsList(wrapper.getKeywords()); results.copyWrapper(wrapper); return results; @@ -663,7 +502,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - WrapperReleaseInfo wrapper = mapper.readValue(webpage, WrapperReleaseInfo.class); + WrapperReleaseInfo wrapper = MAPPER.readValue(webpage, WrapperReleaseInfo.class); TmdbResultsList results = new TmdbResultsList(wrapper.getCountries()); results.copyWrapper(wrapper); return results; @@ -694,7 +533,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - WrapperVideos wrapper = mapper.readValue(webpage, WrapperVideos.class); + WrapperVideos wrapper = MAPPER.readValue(webpage, WrapperVideos.class); TmdbResultsList - // /** * This method is used to retrieve all of the basic information about a movie collection. * @@ -1083,7 +854,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - return mapper.readValue(webpage, CollectionInfo.class); + return MAPPER.readValue(webpage, CollectionInfo.class); } catch (IOException ex) { LOG.warn("Failed to get collection information: {}", ex.getMessage(), ex); throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); @@ -1107,7 +878,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - WrapperImages wrapper = mapper.readValue(webpage, WrapperImages.class); + WrapperImages wrapper = MAPPER.readValue(webpage, WrapperImages.class); TmdbResultsList results = new TmdbResultsList(wrapper.getAll(ArtworkType.POSTER, ArtworkType.BACKDROP)); results.copyWrapper(wrapper); return results; @@ -1116,9 +887,7 @@ public class TheMovieDbApi { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); } } - // - // /** * This method is used to retrieve all of the basic person information. * @@ -1138,7 +907,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - return mapper.readValue(webpage, Person.class); + return MAPPER.readValue(webpage, Person.class); } catch (IOException ex) { LOG.warn("Failed to get person info: {}", ex.getMessage(), ex); throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); @@ -1164,7 +933,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - WrapperPersonCredits wrapper = mapper.readValue(webpage, WrapperPersonCredits.class); + WrapperPersonCredits wrapper = MAPPER.readValue(webpage, WrapperPersonCredits.class); TmdbResultsList results = new TmdbResultsList(wrapper.getAll()); results.copyWrapper(wrapper); return results; @@ -1189,7 +958,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - WrapperImages wrapper = mapper.readValue(webpage, WrapperImages.class); + WrapperImages wrapper = MAPPER.readValue(webpage, WrapperImages.class); TmdbResultsList results = new TmdbResultsList(wrapper.getAll(ArtworkType.PROFILE)); results.copyWrapper(wrapper); return results; @@ -1199,27 +968,6 @@ public class TheMovieDbApi { } } - /** - * Get the changes for a specific person id. - * - * Changes are grouped by key, and ordered by date in descending order. - * - * 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 language is present on fields that are translatable. - * - * @param personId - * @param startDate - * @param endDate - * @throws MovieDbException - */ - public void getPersonChanges(int personId, String startDate, String endDate) throws MovieDbException { - LOG.trace("getPersonChanges: id: {}, start: {}, end: {}", personId, startDate, endDate); - throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not implemented yet", ""); - } - /** * Get the list of popular people on The Movie Database. * @@ -1249,7 +997,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - WrapperPersonList wrapper = mapper.readValue(webpage, WrapperPersonList.class); + WrapperPersonList wrapper = MAPPER.readValue(webpage, WrapperPersonList.class); TmdbResultsList results = new TmdbResultsList(wrapper.getPersonList()); results.copyWrapper(wrapper); return results; @@ -1270,15 +1018,13 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - return mapper.readValue(webpage, Person.class); + return MAPPER.readValue(webpage, Person.class); } catch (IOException ex) { LOG.warn("Failed to get latest person: {}", ex.getMessage(), ex); throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); } } - // - // /** * This method is used to retrieve the basic information about a production company on TMDb. * @@ -1294,7 +1040,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - return mapper.readValue(webpage, Company.class); + return MAPPER.readValue(webpage, Company.class); } catch (IOException ex) { LOG.warn("Failed to get company information: {}", ex.getMessage(), ex); throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); @@ -1324,7 +1070,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - WrapperCompanyMovies wrapper = mapper.readValue(webpage, WrapperCompanyMovies.class); + WrapperCompanyMovies wrapper = MAPPER.readValue(webpage, WrapperCompanyMovies.class); TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); results.copyWrapper(wrapper); return results; @@ -1333,9 +1079,7 @@ public class TheMovieDbApi { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); } } - // - // /** * You can use this method to retrieve the list of genres used on TMDb. * @@ -1353,7 +1097,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - WrapperGenres wrapper = mapper.readValue(webpage, WrapperGenres.class); + WrapperGenres wrapper = MAPPER.readValue(webpage, WrapperGenres.class); TmdbResultsList results = new TmdbResultsList(wrapper.getGenres()); results.copyWrapper(wrapper); return results; @@ -1388,7 +1132,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - WrapperMovie wrapper = mapper.readValue(webpage, WrapperMovie.class); + WrapperMovie wrapper = MAPPER.readValue(webpage, WrapperMovie.class); TmdbResultsList results = new TmdbResultsList(wrapper.getMovies()); results.copyWrapper(wrapper); return results; @@ -1397,9 +1141,7 @@ public class TheMovieDbApi { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); } } - // - // /** * Search Movies This is a good starting point to start finding movies on TMDb. * @@ -1423,7 +1165,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - WrapperMovie wrapper = mapper.readValue(webpage, WrapperMovie.class); + WrapperMovie wrapper = MAPPER.readValue(webpage, WrapperMovie.class); TmdbResultsList results = new TmdbResultsList(wrapper.getMovies()); results.copyWrapper(wrapper); return results; @@ -1453,7 +1195,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - WrapperCollection wrapper = mapper.readValue(webpage, WrapperCollection.class); + WrapperCollection wrapper = MAPPER.readValue(webpage, WrapperCollection.class); TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); results.copyWrapper(wrapper); return results; @@ -1484,7 +1226,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - WrapperPerson wrapper = mapper.readValue(webpage, WrapperPerson.class); + WrapperPerson wrapper = MAPPER.readValue(webpage, WrapperPerson.class); TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); results.copyWrapper(wrapper); return results; @@ -1513,7 +1255,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - WrapperMovieList wrapper = mapper.readValue(webpage, WrapperMovieList.class); + WrapperMovieList wrapper = MAPPER.readValue(webpage, WrapperMovieList.class); TmdbResultsList results = new TmdbResultsList(wrapper.getMovieList()); results.copyWrapper(wrapper); return results; @@ -1545,7 +1287,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - WrapperCompany wrapper = mapper.readValue(webpage, WrapperCompany.class); + WrapperCompany wrapper = MAPPER.readValue(webpage, WrapperCompany.class); TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); results.copyWrapper(wrapper); return results; @@ -1572,7 +1314,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - WrapperKeywords wrapper = mapper.readValue(webpage, WrapperKeywords.class); + WrapperKeywords wrapper = MAPPER.readValue(webpage, WrapperKeywords.class); TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); results.copyWrapper(wrapper); return results; @@ -1581,9 +1323,7 @@ public class TheMovieDbApi { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); } } - // - // /** * Get a list by its ID * @@ -1599,36 +1339,13 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - return mapper.readValue(webpage, MovieDbList.class); + return MAPPER.readValue(webpage, MovieDbList.class); } catch (IOException ex) { LOG.warn("Failed to get list: {}", ex.getMessage(), ex); throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); } } - /** - * Get all lists of a given user - * - * @param sessionId - * @param accountID - * @return The lists - * @throws MovieDbException - */ - public List getUserLists(String sessionId, int accountID) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.SESSION, sessionId); - - URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(accountID, MethodSub.LISTS).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - return mapper.readValue(webpage, WrapperMovieDbList.class).getLists(); - } catch (IOException ex) { - LOG.warn("Failed to get user list: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - /** * This method lets users create a new list. A valid session id is required. * @@ -1651,7 +1368,7 @@ public class TheMovieDbApi { String webpage = httpTools.postRequest(url, jsonBody); try { - return mapper.readValue(webpage, MovieDbListStatus.class).getListId(); + return MAPPER.readValue(webpage, MovieDbListStatus.class).getListId(); } catch (IOException ex) { LOG.warn("Failed to create list: {}", ex.getMessage(), ex); throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); @@ -1674,7 +1391,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - return mapper.readValue(webpage, ListItemStatus.class).isItemPresent(); + return MAPPER.readValue(webpage, ListItemStatus.class).isItemPresent(); } catch (IOException ex) { LOG.warn("Failed to get item status: {}", ex.getMessage(), ex); throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); @@ -1717,36 +1434,13 @@ public class TheMovieDbApi { String webpage = httpTools.postRequest(url, jsonBody); try { - return mapper.readValue(webpage, StatusCode.class); + return MAPPER.readValue(webpage, StatusCode.class); } catch (IOException ex) { LOG.warn("Failed to remove movie from list: {}", ex.getMessage(), ex); throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); } } - /** - * Get the list of movies on an accounts watchlist. - * - * @param sessionId - * @param accountId - * @return The watchlist of the user - * @throws MovieDbException - */ - public List getWatchList(String sessionId, int accountId) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.SESSION, sessionId); - - URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(accountId, MethodSub.MOVIE_WATCHLIST).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - return mapper.readValue(webpage, WrapperMovie.class).getMovies(); - } catch (IOException ex) { - LOG.warn("Failed to get watch list: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - /** * This method lets users delete a list that they created. A valid session id is required. * @@ -1764,15 +1458,13 @@ public class TheMovieDbApi { String webpage = httpTools.deleteRequest(url); try { - return mapper.readValue(webpage, StatusCode.class); + return MAPPER.readValue(webpage, StatusCode.class); } catch (IOException ex) { LOG.warn("Failed to delete movie list: {}", ex.getMessage(), ex); throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); } } - // - // /** * Get the basic information for a specific keyword id. * @@ -1788,7 +1480,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - return mapper.readValue(webpage, Keyword.class); + return MAPPER.readValue(webpage, Keyword.class); } catch (IOException ex) { LOG.warn("Failed to get keyword: {}", ex.getMessage(), ex); throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); @@ -1815,7 +1507,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - WrapperKeywordMovies wrapper = mapper.readValue(webpage, WrapperKeywordMovies.class); + WrapperKeywordMovies wrapper = MAPPER.readValue(webpage, WrapperKeywordMovies.class); TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); results.copyWrapper(wrapper); return results; @@ -1825,55 +1517,18 @@ public class TheMovieDbApi { } } - // - - // - /** - * 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 - * @param endDate the end date of the changes, optional - * @return List of changed movie - * @throws MovieDbException - */ - public TmdbResultsList getMovieChangesList(int page, String startDate, String endDate) throws MovieDbException { - TmdbParameters params = new TmdbParameters(); - params.add(Param.PAGE, page); - params.add(Param.START_DATE, startDate); - params.add(Param.END_DATE, endDate); - - URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.CHANGES).buildUrl(params); - String webpage = httpTools.getRequest(url); - - try { - WrapperMovieChanges wrapper = mapper.readValue(webpage, WrapperMovieChanges.class); - - TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - LOG.warn("Failed to get movie changes: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } public void getPersonChangesList(int page, String startDate, String endDate) throws MovieDbException { LOG.trace("getPersonChangesList: page: {}, start: {}, end: {}", page, startDate, endDate); throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not implemented yet", ""); } - // - // public TmdbResultsList getJobs() throws MovieDbException { URL url = new ApiUrl(apiKey, MethodBase.JOB).setSubMethod(MethodSub.LIST).buildUrl(); String webpage = httpTools.getRequest(url); try { - WrapperJobList wrapper = mapper.readValue(webpage, WrapperJobList.class); + WrapperJobList wrapper = MAPPER.readValue(webpage, WrapperJobList.class); TmdbResultsList results = new TmdbResultsList(wrapper.getJobs()); results.copyWrapper(wrapper); return results; @@ -1882,9 +1537,7 @@ public class TheMovieDbApi { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); } } - // - // /** * Discover movies by different types of data like average rating, number of votes, genres and certifications. * @@ -1948,7 +1601,7 @@ public class TheMovieDbApi { String webpage = httpTools.getRequest(url); try { - WrapperMovie wrapper = mapper.readValue(webpage, WrapperMovie.class); + WrapperMovie wrapper = MAPPER.readValue(webpage, WrapperMovie.class); TmdbResultsList results = new TmdbResultsList(wrapper.getMovies()); results.copyWrapper(wrapper); return results; @@ -1957,7 +1610,6 @@ public class TheMovieDbApi { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); } } - // /** * Use Jackson to convert Map to JSON string. @@ -1968,9 +1620,359 @@ public class TheMovieDbApi { */ public static String convertToJson(Map map) throws MovieDbException { try { - return mapper.writeValueAsString(map); + return MAPPER.writeValueAsString(map); } catch (JsonProcessingException jpe) { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "JSON conversion failed", "", jpe); } } + + // + /** + * Get the basic information for an account. You will need to have a valid session id. + * + * @param sessionId + * @return + * @throws MovieDbException + */ + public Account getAccount(String sessionId) throws MovieDbException { + return tmdbAccount.getAccount(sessionId); + } + + /** + * Get all lists of a given user + * + * @param sessionId + * @param accountId + * @return The lists + * @throws MovieDbException + */ + public List getUserLists(String sessionId, int accountId) throws MovieDbException { + return tmdbAccount.getUserLists(sessionId, accountId); + } + + /** + * Get the account favourite movies + * + * @param sessionId + * @param accountId + * @return + * @throws MovieDbException + */ + public List getFavoriteMovies(String sessionId, int accountId) throws MovieDbException { + return tmdbAccount.getFavoriteMovies(sessionId, accountId); + } + + /** + * Add or remove a movie to an accounts favourite list. + * + * @param sessionId + * @param accountId + * @param mediaId + * @param mediaType + * @param isFavorite + * @return + * @throws MovieDbException + */ + public StatusCode changeFavoriteStatus(String sessionId, int accountId, Integer mediaId, MediaType mediaType, boolean isFavorite) throws MovieDbException { + return tmdbAccount.changeFavoriteStatus(sessionId, accountId, mediaId, mediaType, isFavorite); + } + + /** + * Get the list of rated movies (and associated rating) for an account. + * + * @param sessionId + * @param accountId + * @return + * @throws MovieDbException + */ + public List getRatedMovies(String sessionId, int accountId) throws MovieDbException { + return tmdbAccount.getRatedMovies(sessionId, accountId); + } + + /** + * Get the list of rated TV shows (and associated rating) for an account. + * + * @param sessionId + * @param accountId + * @return + * @throws MovieDbException + */ + public List getRatedTV(String sessionId, int accountId) throws MovieDbException { + return tmdbAccount.getRatedTV(sessionId, accountId); + } + + /** + * Get the list of movies on an accounts watchlist. + * + * @param sessionId + * @param accountId + * @return The watchlist of the user + * @throws MovieDbException + */ + public List getWatchListMovie(String sessionId, int accountId) throws MovieDbException { + return tmdbAccount.getWatchListMovie(sessionId, accountId); + } + + /** + * Get the list of movies on an accounts watchlist. + * + * @param sessionId + * @param accountId + * @return The watchlist of the user + * @throws MovieDbException + */ + public List getWatchListTV(String sessionId, int accountId) throws MovieDbException { + return tmdbAccount.getWatchListTV(sessionId, accountId); + } + + /** + * Add a movie to an accounts watch list. + * + * @param sessionId + * @param accountId + * @param mediaId + * @param mediaType + * @return + * @throws MovieDbException + */ + public StatusCode addToWatchList(String sessionId, int accountId, Integer mediaId, MediaType mediaType) throws MovieDbException { + return tmdbAccount.modifyWatchList(sessionId, accountId, mediaId, mediaType, true); + } + + /** + * Remove a movie from an accounts watch list. + * + * @param sessionId + * @param accountId + * @param mediaId + * @param mediaType + * @return + * @throws MovieDbException + */ + public StatusCode removeFromWatchList(String sessionId, int accountId, Integer mediaId, MediaType mediaType) throws MovieDbException { + return tmdbAccount.modifyWatchList(sessionId, accountId, mediaId, mediaType, false); + } + + /** + * Get the list of favorite TV series for an account. + * + * @param sessionId + * @param accountId + * @return + * @throws MovieDbException + */ + public List getFavoriteTv(String sessionId, int accountId) throws MovieDbException { + return tmdbAccount.getFavoriteTv(sessionId, accountId); + } + // + + // + /** + * 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. + * + * As soon as a valid session id has been created the token will be destroyed. + * + * @return + * @throws MovieDbException + */ + public TokenAuthorisation getAuthorisationToken() throws MovieDbException { + return tmdbAuth.getAuthorisationToken(); + } + + /** + * 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. + * + * @param token + * @return + * @throws MovieDbException + */ + public TokenSession getSessionToken(TokenAuthorisation token) throws MovieDbException { + return tmdbAuth.getSessionToken(token); + } + + /** + * This method is used to generate a session id for user based authentication. User must provide their username and password + * + * A session id is required in order to use any of the write methods. + * + * @param token Session token + * @param username User's username + * @param password User's password + * @return + * @throws MovieDbException + */ + public TokenAuthorisation getSessionTokenLogin(TokenAuthorisation token, String username, String password) throws MovieDbException { + return tmdbAuth.getSessionTokenLogin(token, username, password); + } + + /** + * 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. + * + * 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. + * + * If a guest session is not used for the first time within 24 hours, it will be automatically discarded. + * + * @return + * @throws MovieDbException + */ + public TokenSession getGuestSessionToken() throws MovieDbException { + return tmdbAuth.getGuestSessionToken(); + } + // + + // + /** + * Get a list of movies certification. + * + * @return + * @throws MovieDbException + */ + public TmdbResultsMap> getMoviesCertification() throws MovieDbException { + return tmdbCertifications.getMoviesCertification(); + } + + /** + * Get a list of tv certification. + * + * @return + * @throws MovieDbException + */ + public TmdbResultsMap> getTvCertification() throws MovieDbException { + return tmdbCertifications.getTvCertification(); + } + // + + // + /** + * Get the changes for a specific movie id. + * + * Changes are grouped by key, and ordered by date in descending order. + * + * 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 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 + * + * @param movieId + * @param startDate the start date of the changes, optional + * @param endDate the end date of the changes, optional + * @return + * @throws MovieDbException + */ + public TmdbResultsMap> getMovieChanges(int movieId, String startDate, String endDate) throws MovieDbException { + return tmdbChanges.getMovieChanges(movieId, startDate, endDate); + } + + /** + * Get the changes for a specific person id. + * + * Changes are grouped by key, and ordered by date in descending order. + * + * 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 language is present on fields that are translatable. + * + * @param personId + * @param startDate + * @param endDate + * @throws MovieDbException + */ + public void getPersonChanges(int personId, String startDate, String endDate) throws MovieDbException { + tmdbChanges.getPersonChanges(personId, startDate, endDate); + } + + /** + * Get a list of Movie IDs that have been edited. + * + * You can then use the movie changes API to get the actual data that has been changed. + * + * @param page + * @param startDate the start date of the changes, optional + * @param endDate the end date of the changes, optional + * @return List of changed movie + * @throws MovieDbException + */ + public TmdbResultsList getMovieChangeList(int page, String startDate, String endDate) throws MovieDbException { + return tmdbChanges.getChangeList(MethodBase.MOVIE, page, startDate, endDate); + } + + /** + * Get a list of TV IDs that have been edited. + * + * You can then use the TV changes API to get the actual data that has been changed. + * + * @param page + * @param startDate the start date of the changes, optional + * @param endDate the end date of the changes, optional + * @return List of changed movie + * @throws MovieDbException + */ + public TmdbResultsList getTvChangeList(int page, String startDate, String endDate) throws MovieDbException { + return tmdbChanges.getChangeList(MethodBase.TV, page, startDate, endDate); + } + + /** + * Get a list of Person IDs that have been edited. + * + * You can then use the person changes API to get the actual data that has been changed. + * + * @param page + * @param startDate the start date of the changes, optional + * @param endDate the end date of the changes, optional + * @return List of changed movie + * @throws MovieDbException + */ + public TmdbResultsList getPersonChangeList(int page, String startDate, String endDate) throws MovieDbException { + return tmdbChanges.getChangeList(MethodBase.PERSON, page, startDate, endDate); + } + // + + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // + // } diff --git a/src/main/java/com/omertron/themoviedbapi/enumeration/MediaType.java b/src/main/java/com/omertron/themoviedbapi/enumeration/MediaType.java new file mode 100644 index 000000000..015ec5e2b --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/enumeration/MediaType.java @@ -0,0 +1,37 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.enumeration; + +/** + * Media type options + * + * @author Stuart + */ +public enum MediaType { + + /** + * Movie media type + */ + MOVIE, + /** + * TV Show media type + */ + TV; +} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java new file mode 100644 index 000000000..f554e2e97 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java @@ -0,0 +1,73 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.tools.HttpTools; +import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yamj.api.common.exception.ApiExceptionType; + +/** + * Abstract methods + * + * @author Stuart + */ +public class AbstractMethod { + + // The API key to be used + protected final String apiKey; + // The HttpTools to use + protected final HttpTools httpTools; + // Jackson JSON configuration + protected static final ObjectMapper MAPPER = new ObjectMapper(); + // Logger + protected static final Logger LOG = LoggerFactory.getLogger(TmdbAccount.class); + + /** + * Default constructor for the methods + * + * @param apiKey + * @param httpTools + */ + public AbstractMethod(String apiKey, HttpTools httpTools) { + this.apiKey = apiKey; + this.httpTools = httpTools; + } + + /** + * Use Jackson to convert Map to JSON string. + * + * @param map + * @return + * @throws MovieDbException + */ + protected static String convertToJson(Map map) throws MovieDbException { + try { + return MAPPER.writeValueAsString(map); + } catch (JsonProcessingException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "JSON conversion failed", "", ex); + } + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java new file mode 100644 index 000000000..1341fb27b --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java @@ -0,0 +1,289 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.enumeration.MediaType; +import com.omertron.themoviedbapi.model.Account; +import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.model.MovieDbList; +import com.omertron.themoviedbapi.model.StatusCode; +import com.omertron.themoviedbapi.tools.ApiUrl; +import com.omertron.themoviedbapi.tools.HttpTools; +import com.omertron.themoviedbapi.tools.MethodBase; +import com.omertron.themoviedbapi.tools.MethodSub; +import com.omertron.themoviedbapi.tools.Param; +import com.omertron.themoviedbapi.tools.TmdbParameters; +import com.omertron.themoviedbapi.wrapper.WrapperMovie; +import com.omertron.themoviedbapi.wrapper.WrapperMovieDbList; +import java.io.IOException; +import java.net.URL; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.yamj.api.common.exception.ApiExceptionType; + +/** + * Class to hold the Account Methods + * + * @author stuart.boston + */ +public class TmdbAccount extends AbstractMethod { + + private static final String MEDIA_ID = "media_id"; + private static final String MEDIA_TYPE = "media_type"; + private static final String FAVORITE = "favorite"; + private static final String WATCHLIST = "watchlist"; + + /** + * Constructor + * + * @param apiKey + * @param httpTools + */ + public TmdbAccount(String apiKey, HttpTools httpTools) { + super(apiKey, httpTools); + } + + /** + * Get the basic information for an account. You will need to have a valid session id. + * + * @param sessionId + * @return + * @throws MovieDbException + */ + public Account getAccount(String sessionId) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.SESSION, sessionId); + + URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, Account.class); + } catch (IOException ex) { + LOG.warn("Failed to get Account: {}", ex.getMessage(), ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + } + } + + /** + * Get all lists of a given user + * + * @param sessionId + * @param accountId + * @return The lists + * @throws MovieDbException + */ + public List getUserLists(String sessionId, int accountId) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.SESSION, sessionId); + + URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(accountId, MethodSub.LISTS).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, WrapperMovieDbList.class).getLists(); + } catch (IOException ex) { + LOG.warn("Failed to get user list: {}", ex.getMessage(), ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + } + } + + /** + * Get the list of favorite movies for an account. + * + * @param sessionId + * @param accountId + * @return + * @throws MovieDbException + */ + public List getFavoriteMovies(String sessionId, int accountId) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.SESSION, sessionId); + + URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(accountId, MethodSub.FAVORITE_MOVIES).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, WrapperMovie.class).getMovies(); + } catch (IOException ex) { + LOG.warn("Failed to get favorite movies: {}", ex.getMessage(), ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + } + } + + /** + * Get the list of favorite TV series for an account. + * + * @param sessionId + * @param accountId + * @return + * @throws MovieDbException + */ + public List getFavoriteTv(String sessionId, int accountId) throws MovieDbException { + throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not implemented yet"); + } + + /** + * Add or remove a movie to an accounts favorite list. + * + * @param sessionId + * @param accountId + * @param mediaType + * @param mediaId + * @param isFavorite + * @return + * @throws MovieDbException + */ + public StatusCode changeFavoriteStatus(String sessionId, int accountId, Integer mediaId, MediaType mediaType, boolean isFavorite) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.SESSION, sessionId); + + Map body = new HashMap(); + body.put(MEDIA_TYPE, mediaType.toString().toLowerCase()); + body.put(MEDIA_ID, mediaId); + body.put(FAVORITE, isFavorite); + String jsonBody = convertToJson(body); + + URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(accountId, MethodSub.FAVORITE).buildUrl(parameters); + String webpage = httpTools.postRequest(url, jsonBody); + + try { + return MAPPER.readValue(webpage, StatusCode.class); + } catch (IOException ex) { + LOG.warn("Failed to get favorite status: {}", ex.getMessage(), ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + } + } + + /** + * Get the list of rated movies (and associated rating) for an account. + * + * @param sessionId + * @param accountId + * @return + * @throws MovieDbException + */ + public List getRatedMovies(String sessionId, int accountId) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.SESSION, sessionId); + + URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(accountId, MethodSub.RATED_MOVIES).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, WrapperMovie.class).getMovies(); + } catch (IOException ex) { + LOG.warn("Failed to get rated movies: {}", ex.getMessage(), ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + } + } + + /** + * Get the list of rated TV shows (and associated rating) for an account. + * + * @param sessionId + * @param accountId + * @return + * @throws MovieDbException + */ + public List getRatedTV(String sessionId, int accountId) throws MovieDbException { + throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not implemented yet"); + } + + /** + * Get the list of movies on an accounts watch list. + * + * @param sessionId + * @param accountId + * @return The watch list of the user + * @throws MovieDbException + */ + public List getWatchListMovie(String sessionId, int accountId) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.SESSION, sessionId); + + URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(accountId, MethodSub.WATCHLIST_MOVIES).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, WrapperMovie.class).getMovies(); + } catch (IOException ex) { + LOG.warn("Failed to get Movie watch list: {}", ex.getMessage(), ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + } + } + + /** + * Get the list of movies on an accounts watch list. + * + * @param sessionId + * @param accountId + * @return The watch list of the user + * @throws MovieDbException + */ + public List getWatchListTV(String sessionId, int accountId) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.SESSION, sessionId); + + URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(accountId, MethodSub.WATCHLIST_TV).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, WrapperMovie.class).getMovies(); + } catch (IOException ex) { + LOG.warn("Failed to get TV watch list: {}", ex.getMessage(), ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + } + } + + /** + * Add or remove a movie to an accounts watch list. + * + * @param sessionId + * @param accountId + * @param movieId + * @param mediaType + * @param addToWatchlist + * @return + * @throws MovieDbException + */ + public StatusCode modifyWatchList(String sessionId, int accountId, Integer movieId, MediaType mediaType, boolean addToWatchlist) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.SESSION, sessionId); + + Map body = new HashMap(); + body.put(MEDIA_TYPE, mediaType.toString().toLowerCase()); + body.put(MEDIA_ID, movieId); + body.put(WATCHLIST, addToWatchlist); + String jsonBody = convertToJson(body); + + URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(accountId, MethodSub.WATCHLIST).buildUrl(parameters); + String webpage = httpTools.postRequest(url, jsonBody); + + try { + return MAPPER.readValue(webpage, StatusCode.class); + } catch (IOException ex) { + LOG.warn("Failed to modify watch list: {}", ex.getMessage(), ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + } + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAuthentication.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAuthentication.java new file mode 100644 index 000000000..788d87fc8 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAuthentication.java @@ -0,0 +1,166 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.model.TokenAuthorisation; +import com.omertron.themoviedbapi.model.TokenSession; +import com.omertron.themoviedbapi.tools.ApiUrl; +import com.omertron.themoviedbapi.tools.HttpTools; +import com.omertron.themoviedbapi.tools.MethodBase; +import com.omertron.themoviedbapi.tools.MethodSub; +import com.omertron.themoviedbapi.tools.Param; +import com.omertron.themoviedbapi.tools.TmdbParameters; +import java.io.IOException; +import java.net.URL; +import org.yamj.api.common.exception.ApiExceptionType; + +/** + * Class to hold the Authentication Methods + * + * @author stuart.boston + */ +public class TmdbAuthentication extends AbstractMethod { + + /** + * Constructor + * + * @param apiKey + * @param httpTools + */ + public TmdbAuthentication(String apiKey, HttpTools httpTools) { + super(apiKey, httpTools); + } + + /** + * 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. + * + * As soon as a valid session id has been created the token will be destroyed. + * + * @return + * @throws MovieDbException + */ + public TokenAuthorisation getAuthorisationToken() throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + URL url = new ApiUrl(apiKey, MethodBase.AUTH).setSubMethod(MethodSub.TOKEN_NEW).buildUrl(parameters); + + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, TokenAuthorisation.class); + } catch (IOException ex) { + LOG.warn("Failed to get Authorisation Token: {}", ex.getMessage(), ex); + throw new MovieDbException(ApiExceptionType.AUTH_FAILURE, webpage, url, ex); + } + } + + /** + * 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. + * + * @param token + * @return + * @throws MovieDbException + */ + public TokenSession getSessionToken(TokenAuthorisation token) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + + if (!token.getSuccess()) { + LOG.warn("Session token was not successful!"); + throw new MovieDbException(ApiExceptionType.AUTH_FAILURE, "Authorisation token was not successful!"); + } + + parameters.add(Param.TOKEN, token.getRequestToken()); + URL url = new ApiUrl(apiKey, MethodBase.AUTH).setSubMethod(MethodSub.SESSION_NEW).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, TokenSession.class); + } catch (IOException ex) { + LOG.warn("Failed to get Session Token: {}", ex.getMessage(), ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + } + } + + /** + * This method is used to generate a session id for user based authentication. User must provide their username and password + * + * A session id is required in order to use any of the write methods. + * + * @param token Session token + * @param username User's username + * @param password User's password + * @return + * @throws MovieDbException + */ + public TokenAuthorisation getSessionTokenLogin(TokenAuthorisation token, String username, String password) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + + if (!token.getSuccess()) { + LOG.warn("Session token was not successful!"); + throw new MovieDbException(ApiExceptionType.AUTH_FAILURE, "Authorisation token was not successful!"); + } + + parameters.add(Param.TOKEN, token.getRequestToken()); + parameters.add(Param.USERNAME, username); + parameters.add(Param.PASSWORD, password); + + URL url = new ApiUrl(apiKey, MethodBase.AUTH).setSubMethod(MethodSub.TOKEN_VALIDATE).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, TokenAuthorisation.class); + } catch (IOException ex) { + LOG.warn("Failed to get Session Token: {}", ex.getMessage(), ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + } + } + + /** + * 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. + * + * 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. + * + * If a guest session is not used for the first time within 24 hours, it will be automatically discarded. + * + * @return + * @throws MovieDbException + */ + public TokenSession getGuestSessionToken() throws MovieDbException { + URL url = new ApiUrl(apiKey, MethodBase.AUTH).setSubMethod(MethodSub.GUEST_SESSION).buildUrl(); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, TokenSession.class); + } catch (IOException ex) { + LOG.warn("Failed to get Guest Session Token: {}", ex.getMessage(), ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + } + }} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCertifications.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCertifications.java new file mode 100644 index 000000000..f17ab64ee --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCertifications.java @@ -0,0 +1,93 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.results.TmdbResultsMap; +import com.omertron.themoviedbapi.tools.HttpTools; +import java.util.List; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.JsonNode; +import com.omertron.themoviedbapi.model.Certification; +import com.omertron.themoviedbapi.tools.ApiUrl; +import com.omertron.themoviedbapi.tools.MethodBase; +import com.omertron.themoviedbapi.tools.MethodSub; +import java.io.IOException; +import java.net.URL; +import java.util.Map; +import org.yamj.api.common.exception.ApiExceptionType; + +/** + * Class to hold the Certification Methods + * + * @author stuart.boston + */ +public class TmdbCertifications extends AbstractMethod { + + /** + * Constructor + * + * @param apiKey + * @param httpTools + */ + public TmdbCertifications(String apiKey, HttpTools httpTools) { + super(apiKey, httpTools); + } + + /** + * Get a list of movies certification. + * + * @return + * @throws MovieDbException + */ + public TmdbResultsMap> getMoviesCertification() throws MovieDbException { + URL url = new ApiUrl(apiKey, MethodBase.CERTIFICATION).setSubMethod(MethodSub.MOVIE_LIST).buildUrl(); + String webpage = httpTools.getRequest(url); + + try { + JsonNode node = MAPPER.readTree(webpage); + Map> results = MAPPER.readValue(node.elements().next().traverse(), new TypeReference>>() { + }); + return new TmdbResultsMap>(results); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get movie certifications", url, ex); + } + } + + /** + * Get a list of tv certification. + * + * @return + * @throws MovieDbException + */ + public TmdbResultsMap> getTvCertification() throws MovieDbException { + URL url = new ApiUrl(apiKey, MethodBase.CERTIFICATION).setSubMethod(MethodSub.TV_LIST).buildUrl(); + String webpage = httpTools.getRequest(url); + + try { + JsonNode node = MAPPER.readTree(webpage); + Map> results = MAPPER.readValue(node.elements().next().traverse(), new TypeReference>>() { + }); + return new TmdbResultsMap>(results); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get TV certifications", url, ex); + } + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbChanges.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbChanges.java new file mode 100644 index 000000000..e93232883 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbChanges.java @@ -0,0 +1,131 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.model.ChangedItem; +import com.omertron.themoviedbapi.model.ChangedMedia; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import com.omertron.themoviedbapi.results.TmdbResultsMap; +import com.omertron.themoviedbapi.tools.ApiUrl; +import com.omertron.themoviedbapi.tools.HttpTools; +import com.omertron.themoviedbapi.tools.MethodBase; +import com.omertron.themoviedbapi.tools.MethodSub; +import com.omertron.themoviedbapi.tools.Param; +import com.omertron.themoviedbapi.tools.TmdbParameters; +import com.omertron.themoviedbapi.wrapper.WrapperMediaChanges; +import java.io.IOException; +import java.net.URL; +import java.util.List; +import org.yamj.api.common.exception.ApiExceptionType; + +/** + * Class to hold the Change Methods + * + * @author stuart.boston + */ +public class TmdbChanges extends AbstractMethod { + + /** + * Constructor + * + * @param apiKey + * @param httpTools + */ + public TmdbChanges(String apiKey, HttpTools httpTools) { + super(apiKey, httpTools); + } + + /** + * Get the changes for a specific movie id. + * + * Changes are grouped by key, and ordered by date in descending order. + * + * 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 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 + * + * @param movieId + * @param startDate the start date of the changes, optional + * @param endDate the end date of the changes, optional + * @return + * @throws MovieDbException + */ + public TmdbResultsMap> getMovieChanges(int movieId, String startDate, String endDate) throws MovieDbException { + return null; + } + + /** + * Get the changes for a specific person id. + * + * Changes are grouped by key, and ordered by date in descending order. + * + * 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 language is present on fields that are translatable. + * + * @param personId + * @param startDate + * @param endDate + * @throws MovieDbException + */ + public void getPersonChanges(int personId, String startDate, String endDate) throws MovieDbException { + LOG.trace("getPersonChanges: id: {}, start: {}, end: {}", personId, startDate, endDate); + throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not implemented yet", ""); + } + + /** + * Get a list of Media IDs that have been edited. + * + * You can then use the movie/TV/person changes API to get the actual data that has been changed. + * + * @param method The method base to get + * @param page + * @param startDate the start date of the changes, optional + * @param endDate the end date of the changes, optional + * @return List of changed movie + * @throws MovieDbException + */ + public TmdbResultsList getChangeList(MethodBase method, int page, String startDate, String endDate) throws MovieDbException { + TmdbParameters params = new TmdbParameters(); + params.add(Param.PAGE, page); + params.add(Param.START_DATE, startDate); + params.add(Param.END_DATE, endDate); + + URL url = new ApiUrl(apiKey, method).setSubMethod(MethodSub.CHANGES).buildUrl(params); + String webpage = httpTools.getRequest(url); + + try { + WrapperMediaChanges wrapper = MAPPER.readValue(webpage, WrapperMediaChanges.class); + + TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get changes", url, ex); + } + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCollections.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCollections.java new file mode 100644 index 000000000..fca09eb07 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCollections.java @@ -0,0 +1,40 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.tools.HttpTools; + +/** + * Class to hold the Collections Methods + * + * @author stuart.boston + */ +public class TmdbCollections extends AbstractMethod { + + /** + * Constructor + * + * @param apiKey + * @param httpTools + */ + public TmdbCollections(String apiKey, HttpTools httpTools) { + super(apiKey, httpTools); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java new file mode 100644 index 000000000..5da4a6260 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java @@ -0,0 +1,40 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.tools.HttpTools; + +/** + * Class to hold the Company Methods + * + * @author stuart.boston + */ +public class TmdbCompanies extends AbstractMethod { + + /** + * Constructor + * + * @param apiKey + * @param httpTools + */ + public TmdbCompanies(String apiKey, HttpTools httpTools) { + super(apiKey, httpTools); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java new file mode 100644 index 000000000..6f93c425f --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java @@ -0,0 +1,40 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.tools.HttpTools; + +/** + * Class to hold the Configuration Methods + * + * @author stuart.boston + */ +public class TmdbConfiguration extends AbstractMethod { + + /** + * Constructor + * + * @param apiKey + * @param httpTools + */ + public TmdbConfiguration(String apiKey, HttpTools httpTools) { + super(apiKey, httpTools); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCredits.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCredits.java new file mode 100644 index 000000000..48c3b8f6e --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCredits.java @@ -0,0 +1,40 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.tools.HttpTools; + +/** + * Class to hold the Credit Methods + * + * @author stuart.boston + */ +public class TmdbCredits extends AbstractMethod { + + /** + * Constructor + * + * @param apiKey + * @param httpTools + */ + public TmdbCredits(String apiKey, HttpTools httpTools) { + super(apiKey, httpTools); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbDiscover.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbDiscover.java new file mode 100644 index 000000000..aa77d5c89 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbDiscover.java @@ -0,0 +1,40 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.tools.HttpTools; + +/** + * Class to hold the Discover Methods + * + * @author stuart.boston + */ +public class TmdbDiscover extends AbstractMethod { + + /** + * Constructor + * + * @param apiKey + * @param httpTools + */ + public TmdbDiscover(String apiKey, HttpTools httpTools) { + super(apiKey, httpTools); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java new file mode 100644 index 000000000..6eb42f762 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java @@ -0,0 +1,40 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.tools.HttpTools; + +/** + * Class to hold the Find Methods + * + * @author stuart.boston + */ +public class TmdbFind extends AbstractMethod { + + /** + * Constructor + * + * @param apiKey + * @param httpTools + */ + public TmdbFind(String apiKey, HttpTools httpTools) { + super(apiKey, httpTools); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbGenres.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbGenres.java new file mode 100644 index 000000000..9ce23dfcc --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbGenres.java @@ -0,0 +1,40 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.tools.HttpTools; + +/** + * Class to hold the Genre Methods + * + * @author stuart.boston + */ +public class TmdbGenres extends AbstractMethod { + + /** + * Constructor + * + * @param apiKey + * @param httpTools + */ + public TmdbGenres(String apiKey, HttpTools httpTools) { + super(apiKey, httpTools); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbJobs.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbJobs.java new file mode 100644 index 000000000..de588c3a9 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbJobs.java @@ -0,0 +1,40 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.tools.HttpTools; + +/** + * Class to hold the Job Methods + * + * @author stuart.boston + */ +public class TmdbJobs extends AbstractMethod { + + /** + * Constructor + * + * @param apiKey + * @param httpTools + */ + public TmdbJobs(String apiKey, HttpTools httpTools) { + super(apiKey, httpTools); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbKeywords.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbKeywords.java new file mode 100644 index 000000000..e467f4f2b --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbKeywords.java @@ -0,0 +1,40 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.tools.HttpTools; + +/** + * Class to hold the Keyword Methods + * + * @author stuart.boston + */ +public class TmdbKeywords extends AbstractMethod { + + /** + * Constructor + * + * @param apiKey + * @param httpTools + */ + public TmdbKeywords(String apiKey, HttpTools httpTools) { + super(apiKey, httpTools); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbLists.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbLists.java new file mode 100644 index 000000000..07d4aa13c --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbLists.java @@ -0,0 +1,40 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.tools.HttpTools; + +/** + * Class to hold the List Methods + * + * @author stuart.boston + */ +public class TmdbLists extends AbstractMethod { + + /** + * Constructor + * + * @param apiKey + * @param httpTools + */ + public TmdbLists(String apiKey, HttpTools httpTools) { + super(apiKey, httpTools); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java new file mode 100644 index 000000000..a505c8fa1 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java @@ -0,0 +1,40 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.tools.HttpTools; + +/** + * Class to hold the Movie Methods + * + * @author stuart.boston + */ +public class TmdbMovies extends AbstractMethod { + + /** + * Constructor + * + * @param apiKey + * @param httpTools + */ + public TmdbMovies(String apiKey, HttpTools httpTools) { + super(apiKey, httpTools); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbNetworks.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbNetworks.java new file mode 100644 index 000000000..0e95f2ed6 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbNetworks.java @@ -0,0 +1,40 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.tools.HttpTools; + +/** + * Class to hold the Network Methods + * + * @author stuart.boston + */ +public class TmdbNetworks extends AbstractMethod { + + /** + * Constructor + * + * @param apiKey + * @param httpTools + */ + public TmdbNetworks(String apiKey, HttpTools httpTools) { + super(apiKey, httpTools); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java new file mode 100644 index 000000000..59bdd1937 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java @@ -0,0 +1,40 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.tools.HttpTools; + +/** + * Class to hold the People Methods + * + * @author stuart.boston + */ +public class TmdbPeople extends AbstractMethod { + + /** + * Constructor + * + * @param apiKey + * @param httpTools + */ + public TmdbPeople(String apiKey, HttpTools httpTools) { + super(apiKey, httpTools); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbReviews.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbReviews.java new file mode 100644 index 000000000..a6c3e16bd --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbReviews.java @@ -0,0 +1,40 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.tools.HttpTools; + +/** + * Class to hold the Review Methods + * + * @author stuart.boston + */ +public class TmdbReviews extends AbstractMethod { + + /** + * Constructor + * + * @param apiKey + * @param httpTools + */ + public TmdbReviews(String apiKey, HttpTools httpTools) { + super(apiKey, httpTools); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java new file mode 100644 index 000000000..991063667 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java @@ -0,0 +1,40 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.tools.HttpTools; + +/** + * Class to hold the Search Methods + * + * @author stuart.boston + */ +public class TmdbSearch extends AbstractMethod { + + /** + * Constructor + * + * @param apiKey + * @param httpTools + */ + public TmdbSearch(String apiKey, HttpTools httpTools) { + super(apiKey, httpTools); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbTv.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbTv.java new file mode 100644 index 000000000..fea8a10b4 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbTv.java @@ -0,0 +1,40 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.tools.HttpTools; + +/** + * Class to hold the TV Methods + * + * @author stuart.boston + */ +public class TmdbTV extends AbstractMethod { + + /** + * Constructor + * + * @param apiKey + * @param httpTools + */ + public TmdbTV(String apiKey, HttpTools httpTools) { + super(apiKey, httpTools); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/AbstractIdName.java b/src/main/java/com/omertron/themoviedbapi/model/AbstractIdName.java index 505d90b22..13ed73235 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/AbstractIdName.java +++ b/src/main/java/com/omertron/themoviedbapi/model/AbstractIdName.java @@ -31,9 +31,6 @@ public class AbstractIdName extends AbstractJsonMapping { private static final long serialVersionUID = 2L; - /* - * Properties - */ @JsonProperty("id") private int id; @JsonProperty("name") diff --git a/src/main/java/com/omertron/themoviedbapi/model/Certification.java b/src/main/java/com/omertron/themoviedbapi/model/Certification.java new file mode 100644 index 000000000..64bb68e33 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/Certification.java @@ -0,0 +1,60 @@ +/* + * 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;private either version 3 of the License;private or + * any later version. + * + * TheMovieDB API is distributed in the hope that it will be useful;private + * 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;private see . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonRootName; + +@JsonRootName("certification") +public class Certification extends AbstractJsonMapping { + + private static final long serialVersionUID = 1L; + // Properties + @JsonProperty("certification") + private String certification; + @JsonProperty("meaning") + private String meaning; + @JsonProperty("order") + private int order; + + public String getCertification() { + return certification; + } + + public void setCertification(String certification) { + this.certification = certification; + } + + public String getMeaning() { + return meaning; + } + + public void setMeaning(String meaning) { + this.meaning = meaning; + } + + public int getOrder() { + return order; + } + + public void setOrder(int order) { + this.order = order; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/ChangedMedia.java b/src/main/java/com/omertron/themoviedbapi/model/ChangedMedia.java new file mode 100644 index 000000000..318f550ca --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/ChangedMedia.java @@ -0,0 +1,48 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ChangedMedia extends AbstractJsonMapping { + + private static final long serialVersionUID = 1L; + + @JsonProperty("id") + private String id; + @JsonProperty("adult") + private boolean adult; + + public String getId() { + return id; + } + + public boolean isAdult() { + return adult; + } + + public void setId(String id) { + this.id = id; + } + + public void setAdult(boolean adult) { + this.adult = adult; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/Configuration.java b/src/main/java/com/omertron/themoviedbapi/model/Configuration.java new file mode 100644 index 000000000..9e21dfe31 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/Configuration.java @@ -0,0 +1,183 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; +import org.apache.commons.lang3.StringUtils; + +/** + * @author stuart.boston + */ +public class Configuration extends AbstractJsonMapping { + + private static final long serialVersionUID = 1L; + /* + * Properties + */ + @JsonProperty("base_url") + private String baseUrl; + @JsonProperty("secure_base_url") + private String secureBaseUrl; + @JsonProperty("poster_sizes") + private List posterSizes; + @JsonProperty("backdrop_sizes") + private List backdropSizes; + @JsonProperty("profile_sizes") + private List profileSizes; + @JsonProperty("logo_sizes") + private List logoSizes; + @JsonProperty("still_sizes") + private List stillSizes; + + public List getBackdropSizes() { + return backdropSizes; + } + + public String getBaseUrl() { + return baseUrl; + } + + public List getPosterSizes() { + return posterSizes; + } + + public List getProfileSizes() { + return profileSizes; + } + + public List getLogoSizes() { + return logoSizes; + } + + public String getSecureBaseUrl() { + return secureBaseUrl; + } + + public List getStillSizes() { + return stillSizes; + } + + public void setBackdropSizes(List backdropSizes) { + this.backdropSizes = backdropSizes; + } + + public void setBaseUrl(String baseUrl) { + this.baseUrl = baseUrl; + } + + public void setPosterSizes(List posterSizes) { + this.posterSizes = posterSizes; + } + + public void setProfileSizes(List profileSizes) { + this.profileSizes = profileSizes; + } + + public void setLogoSizes(List logoSizes) { + this.logoSizes = logoSizes; + } + + public void setSecureBaseUrl(String secureBaseUrl) { + this.secureBaseUrl = secureBaseUrl; + } + + public void setStillSizes(List stillSizes) { + this.stillSizes = stillSizes; + } + + /** + * Copy the data from the passed object to this one + * + * @param config + */ + public void clone(Configuration config) { + backdropSizes = config.getBackdropSizes(); + baseUrl = config.getBaseUrl(); + posterSizes = config.getPosterSizes(); + profileSizes = config.getProfileSizes(); + logoSizes = config.getLogoSizes(); + } + + /** + * Check that the poster size is valid + * + * @param posterSize + * @return + */ + public boolean isValidPosterSize(String posterSize) { + if (StringUtils.isBlank(posterSize) || posterSizes.isEmpty()) { + return false; + } + return posterSizes.contains(posterSize); + } + + /** + * Check that the backdrop size is valid + * + * @param backdropSize + * @return + */ + public boolean isValidBackdropSize(String backdropSize) { + if (StringUtils.isBlank(backdropSize) || backdropSizes.isEmpty()) { + return false; + } + return backdropSizes.contains(backdropSize); + } + + /** + * Check that the profile size is valid + * + * @param profileSize + * @return + */ + public boolean isValidProfileSize(String profileSize) { + if (StringUtils.isBlank(profileSize) || profileSizes.isEmpty()) { + return false; + } + return profileSizes.contains(profileSize); + } + + /** + * Check that the logo size is valid + * + * @param logoSize + * @return + */ + public boolean isValidLogoSize(String logoSize) { + if (StringUtils.isBlank(logoSize) || logoSizes.isEmpty()) { + return false; + } + return logoSizes.contains(logoSize); + } + + /** + * Check to see if the size is valid for any of the images types + * + * @param sizeToCheck + * @return + */ + public boolean isValidSize(String sizeToCheck) { + return isValidPosterSize(sizeToCheck) + || isValidBackdropSize(sizeToCheck) + || isValidProfileSize(sizeToCheck) + || isValidLogoSize(sizeToCheck); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java b/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java index 2f8b1e6ed..198960765 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java @@ -26,6 +26,7 @@ public enum MethodBase { ACCOUNT("account"), AUTH("authentication"), + CERTIFICATION("certification"), COLLECTION("collection"), COMPANY("company"), CONFIGURATION("configuration"), @@ -36,7 +37,8 @@ public enum MethodBase { LIST("list"), MOVIE("movie"), PERSON("person"), - SEARCH("search"); + SEARCH("search"), + TV("tv"); private final String value; diff --git a/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java b/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java index 8e54a1746..5afe05bdf 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java @@ -42,7 +42,9 @@ public enum MethodSub { LISTS("lists"), MOVIE("movie"), MOVIES("movies"), - MOVIE_WATCHLIST("movie_watchlist"), + WATCHLIST("watchlist"), + WATCHLIST_MOVIES("watchlist/movies"), + WATCHLIST_TV("watchlist/tv"), NOW_PLAYING("now-playing"), PERSON("person"), POPULAR("popular"), @@ -59,7 +61,9 @@ public enum MethodSub { UPCOMING("upcoming"), VIDEOS("videos"), ADD_ITEM("add_item"), - REMOVE_ITEM("remove_item"); + REMOVE_ITEM("remove_item"), + MOVIE_LIST("movie/list"), + TV_LIST("tv/list"); private final String value; diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperConfig.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperConfig.java index 1fa55210a..107a7e0c1 100644 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperConfig.java +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperConfig.java @@ -20,7 +20,7 @@ package com.omertron.themoviedbapi.wrapper; import com.fasterxml.jackson.annotation.JsonProperty; -import com.omertron.themoviedbapi.model.TmdbConfiguration; +import com.omertron.themoviedbapi.model.Configuration; import java.util.Collections; import java.util.List; @@ -31,15 +31,15 @@ import java.util.List; public class WrapperConfig extends AbstractWrapper { @JsonProperty("images") - private TmdbConfiguration tmdbConfiguration; + private Configuration tmdbConfiguration; @JsonProperty("change_keys") private List changeKeys = Collections.emptyList(); - public TmdbConfiguration getTmdbConfiguration() { + public Configuration getTmdbConfiguration() { return tmdbConfiguration; } - public void setTmdbConfiguration(TmdbConfiguration tmdbConfiguration) { + public void setTmdbConfiguration(Configuration tmdbConfiguration) { this.tmdbConfiguration = tmdbConfiguration; } diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMediaChanges.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMediaChanges.java new file mode 100644 index 000000000..df246b8a4 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMediaChanges.java @@ -0,0 +1,39 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.ChangedMedia; + +public class WrapperMediaChanges extends AbstractWrapperAll { + + @JsonProperty("results") + private List results; + + public List getResults() { + return results; + } + + public void setResults(List results) { + this.results = results; + } +} diff --git a/src/test/java/com/omertron/themoviedbapi/TestAccounts.java b/src/test/java/com/omertron/themoviedbapi/TestAccounts.java index 37fffcd91..ffdca8c55 100644 --- a/src/test/java/com/omertron/themoviedbapi/TestAccounts.java +++ b/src/test/java/com/omertron/themoviedbapi/TestAccounts.java @@ -151,19 +151,19 @@ public class TestAccounts { } // make sure it's empty (because it's just a test account - Assert.assertTrue(tmdb.getWatchList(tokenSession.getSessionId(), account.getId()).isEmpty()); + Assert.assertTrue(tmdb.getWatchListMovie(tokenSession.getSessionId(), account.getId()).isEmpty()); // add a movie tmdb.addToWatchList(tokenSession.getSessionId(), account.getId(), 550); - List watchList = tmdb.getWatchList(tokenSession.getSessionId(), account.getId()); + List watchList = tmdb.getWatchListMovie(tokenSession.getSessionId(), account.getId()); assertNotNull("Empty watch list returned", watchList); assertEquals("Watchlist wrong size", 1, watchList.size()); // clean up again tmdb.removeFromWatchList(tokenSession.getSessionId(), account.getId(), 550); - Assert.assertTrue(tmdb.getWatchList(tokenSession.getSessionId(), account.getId()).isEmpty()); + Assert.assertTrue(tmdb.getWatchListMovie(tokenSession.getSessionId(), account.getId()).isEmpty()); } @Test diff --git a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java index cfd7bd895..27832ef81 100644 --- a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java +++ b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java @@ -22,7 +22,7 @@ package com.omertron.themoviedbapi; import com.omertron.themoviedbapi.model.AlternativeTitle; import com.omertron.themoviedbapi.model.Artwork; import com.omertron.themoviedbapi.model.ChangedItem; -import com.omertron.themoviedbapi.model.ChangedMovie; +import com.omertron.themoviedbapi.model.ChangedMedia; import com.omertron.themoviedbapi.model.Collection; import com.omertron.themoviedbapi.model.CollectionInfo; import com.omertron.themoviedbapi.model.Company; @@ -38,7 +38,7 @@ import com.omertron.themoviedbapi.model.Person; import com.omertron.themoviedbapi.model.PersonCredit; import com.omertron.themoviedbapi.model.ReleaseInfo; import com.omertron.themoviedbapi.model.Reviews; -import com.omertron.themoviedbapi.model.TmdbConfiguration; +import com.omertron.themoviedbapi.model.Configuration; import com.omertron.themoviedbapi.model.TokenAuthorisation; import com.omertron.themoviedbapi.model.TokenSession; import com.omertron.themoviedbapi.model.Translation; @@ -138,7 +138,7 @@ public class TheMovieDbApiTest { public void testConfiguration() { LOG.info("Test Configuration"); - TmdbConfiguration tmdbConfig = tmdb.getConfiguration(); + Configuration tmdbConfig = tmdb.getConfiguration(); assertNotNull("Configuration failed", tmdbConfig); assertTrue("No base URL", StringUtils.isNotBlank(tmdbConfig.getBaseUrl())); assertTrue("No backdrop sizes", tmdbConfig.getBackdropSizes().size() > 0); @@ -750,7 +750,7 @@ public class TheMovieDbApiTest { int page = 0; String startDate = ""; String endDate = ""; - TmdbResultsList result = tmdb.getMovieChangesList(page, startDate, endDate); + TmdbResultsList result = tmdb.getMovieChangesList(page, startDate, endDate); assertFalse("No movie changes.", result.getResults().isEmpty()); } From 97f3313d8c596cbd064b33df7cdea00a76cc5bf2 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 16 Feb 2015 13:06:10 +0000 Subject: [PATCH 002/100] Updated --- .../omertron/themoviedbapi/TheMovieDbApi.java | 1009 ++++++++--------- .../themoviedbapi/methods/AbstractMethod.java | 19 - .../themoviedbapi/methods/TmdbAccount.java | 53 +- .../themoviedbapi/methods/TmdbChanges.java | 92 +- .../methods/TmdbCollections.java | 67 ++ .../themoviedbapi/methods/TmdbCompanies.java | 69 ++ .../methods/TmdbConfiguration.java | 87 ++ .../themoviedbapi/methods/TmdbCredits.java | 44 + .../themoviedbapi/methods/TmdbDiscover.java | 46 + .../themoviedbapi/methods/TmdbFind.java | 31 + .../themoviedbapi/methods/TmdbGenres.java | 76 ++ .../themoviedbapi/methods/TmdbKeywords.java | 66 ++ .../themoviedbapi/methods/TmdbLists.java | 139 +++ .../model/TBD_ExternalSource.java | 44 + .../TBD_FindResults.java} | 30 +- .../model/TBD_PersonCredits.java | 44 + .../themoviedbapi/tools/MethodBase.java | 1 + .../themoviedbapi/tools/MethodSub.java | 3 +- .../themoviedbapi/tools/PostBody.java | 50 + .../themoviedbapi/tools/PostTools.java | 71 ++ 20 files changed, 1371 insertions(+), 670 deletions(-) create mode 100644 src/main/java/com/omertron/themoviedbapi/model/TBD_ExternalSource.java rename src/main/java/com/omertron/themoviedbapi/{methods/TmdbJobs.java => model/TBD_FindResults.java} (64%) create mode 100644 src/main/java/com/omertron/themoviedbapi/model/TBD_PersonCredits.java create mode 100644 src/main/java/com/omertron/themoviedbapi/tools/PostBody.java create mode 100644 src/main/java/com/omertron/themoviedbapi/tools/PostTools.java diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 1b4c6c7b4..91f62df72 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -33,7 +33,6 @@ import com.omertron.themoviedbapi.methods.TmdbCredits; import com.omertron.themoviedbapi.methods.TmdbDiscover; import com.omertron.themoviedbapi.methods.TmdbFind; import com.omertron.themoviedbapi.methods.TmdbGenres; -import com.omertron.themoviedbapi.methods.TmdbJobs; import com.omertron.themoviedbapi.methods.TmdbKeywords; import com.omertron.themoviedbapi.methods.TmdbLists; import com.omertron.themoviedbapi.methods.TmdbMovies; @@ -42,7 +41,36 @@ import com.omertron.themoviedbapi.methods.TmdbPeople; import com.omertron.themoviedbapi.methods.TmdbReviews; import com.omertron.themoviedbapi.methods.TmdbSearch; import com.omertron.themoviedbapi.methods.TmdbTV; -import com.omertron.themoviedbapi.model.*; +import com.omertron.themoviedbapi.model.Account; +import com.omertron.themoviedbapi.model.AlternativeTitle; +import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model.ArtworkType; +import com.omertron.themoviedbapi.model.Certification; +import com.omertron.themoviedbapi.model.ChangedMedia; +import com.omertron.themoviedbapi.model.Collection; +import com.omertron.themoviedbapi.model.CollectionInfo; +import com.omertron.themoviedbapi.model.Company; +import com.omertron.themoviedbapi.model.Configuration; +import com.omertron.themoviedbapi.model.Discover; +import com.omertron.themoviedbapi.model.Genre; +import com.omertron.themoviedbapi.model.JobDepartment; +import com.omertron.themoviedbapi.model.Keyword; +import com.omertron.themoviedbapi.model.KeywordMovie; +import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.model.MovieDbList; +import com.omertron.themoviedbapi.model.MovieList; +import com.omertron.themoviedbapi.model.Person; +import com.omertron.themoviedbapi.model.PersonCredit; +import com.omertron.themoviedbapi.model.ReleaseInfo; +import com.omertron.themoviedbapi.model.Reviews; +import com.omertron.themoviedbapi.model.StatusCode; +import com.omertron.themoviedbapi.model.TBD_ExternalSource; +import com.omertron.themoviedbapi.model.TBD_FindResults; +import com.omertron.themoviedbapi.model.TBD_PersonCredits; +import com.omertron.themoviedbapi.model.TokenAuthorisation; +import com.omertron.themoviedbapi.model.TokenSession; +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; @@ -51,12 +79,25 @@ import com.omertron.themoviedbapi.tools.MethodBase; import com.omertron.themoviedbapi.tools.MethodSub; import com.omertron.themoviedbapi.tools.Param; import com.omertron.themoviedbapi.tools.TmdbParameters; -import com.omertron.themoviedbapi.wrapper.*; +import com.omertron.themoviedbapi.wrapper.WrapperAlternativeTitles; +import com.omertron.themoviedbapi.wrapper.WrapperCollection; +import com.omertron.themoviedbapi.wrapper.WrapperCompany; +import com.omertron.themoviedbapi.wrapper.WrapperImages; +import com.omertron.themoviedbapi.wrapper.WrapperKeywords; +import com.omertron.themoviedbapi.wrapper.WrapperMovie; +import com.omertron.themoviedbapi.wrapper.WrapperMovieCasts; +import com.omertron.themoviedbapi.wrapper.WrapperMovieKeywords; +import com.omertron.themoviedbapi.wrapper.WrapperMovieList; +import com.omertron.themoviedbapi.wrapper.WrapperPerson; +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.WrapperTranslations; +import com.omertron.themoviedbapi.wrapper.WrapperVideos; import java.io.IOException; -import java.net.MalformedURLException; 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; @@ -69,7 +110,8 @@ import org.yamj.api.common.http.SimpleHttpClientBuilder; /** * The MovieDb API *

- * 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 */ @@ -77,12 +119,10 @@ public class TheMovieDbApi { private static final Logger LOG = LoggerFactory.getLogger(TheMovieDbApi.class); private String apiKey; - private Configuration tmdbConfig; private HttpTools httpTools; // Jackson JSON configuration private static final ObjectMapper MAPPER = new ObjectMapper(); // Constants - private static final String MOVIE_ID = "movie_id"; private static final int YEAR_LENGTH = 4; private static final int RATING_MAX = 10; private static final int POST_SUCCESS_STATUS_CODE = 12; @@ -98,8 +138,7 @@ public class TheMovieDbApi { private static TmdbDiscover tmdbDiscover; private static TmdbFind tmdbFind; private static TmdbGenres tmdbGenre; - private static TmdbJobs tmdbJobs; - private static TmdbKeywords tmdbKeyword; + private static TmdbKeywords tmdbKeywords; private static TmdbLists tmdbList; private static TmdbMovies tmdbMovies; private static TmdbNetworks tmdbNetworks; @@ -128,16 +167,7 @@ public class TheMovieDbApi { public TheMovieDbApi(String apiKey, CloseableHttpClient httpClient) throws MovieDbException { this.apiKey = apiKey; this.httpTools = new HttpTools(httpClient); - - URL configUrl = new ApiUrl(apiKey, MethodBase.CONFIGURATION).buildUrl(); - String webpage = httpTools.getRequest(configUrl); - - try { - WrapperConfig wc = MAPPER.readValue(webpage, WrapperConfig.class); - tmdbConfig = wc.getTmdbConfiguration(); - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to read configuration", configUrl, ex); - } + initialise(apiKey, httpTools); } /** @@ -158,8 +188,7 @@ public class TheMovieDbApi { tmdbDiscover = new TmdbDiscover(apiKey, httpTools); tmdbFind = new TmdbFind(apiKey, httpTools); tmdbGenre = new TmdbGenres(apiKey, httpTools); - tmdbJobs = new TmdbJobs(apiKey, httpTools); - tmdbKeyword = new TmdbKeywords(apiKey, httpTools); + tmdbKeywords = new TmdbKeywords(apiKey, httpTools); tmdbList = new TmdbLists(apiKey, httpTools); tmdbMovies = new TmdbMovies(apiKey, httpTools); tmdbNetworks = new TmdbNetworks(apiKey, httpTools); @@ -187,7 +216,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. */ @@ -266,45 +296,13 @@ public class TheMovieDbApi { return StringUtils.isNotBlank(year) && !"UNKNOWN".equals(year); } - /** - * Get the configuration information - * - * @return - */ - public Configuration getConfiguration() { - return tmdbConfig; - } - - /** - * Generate the full image URL from the size and image path - * - * @param imagePath - * @param requiredSize - * @return - * @throws MovieDbException - */ - public URL createImageUrl(String imagePath, String requiredSize) throws MovieDbException { - if (!tmdbConfig.isValidSize(requiredSize)) { - throw new MovieDbException(ApiExceptionType.INVALID_IMAGE, requiredSize); - } - - StringBuilder sb = new StringBuilder(tmdbConfig.getBaseUrl()); - sb.append(requiredSize); - sb.append(imagePath); - try { - return new URL(sb.toString()); - } catch (MalformedURLException ex) { - LOG.warn("Failed to create image URL: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.INVALID_URL, sb.toString(), "", ex); - } - } - /** * This method is used to retrieve all of the basic movie information. * * 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 @@ -338,7 +336,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 @@ -369,7 +368,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 @@ -426,7 +426,8 @@ public class TheMovieDbApi { } /** - * This method should be used when you’re wanting to retrieve all of the images for a particular movie. + * This method should be used when you’re wanting to retrieve all of the + * images for a particular movie. * * @param movieId * @param language @@ -455,7 +456,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. * @@ -484,7 +486,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 @@ -513,7 +516,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. * @@ -544,7 +548,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 @@ -571,9 +576,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 * @@ -710,7 +717,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 * @@ -770,7 +778,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. * @@ -835,59 +844,6 @@ public class TheMovieDbApi { } } - /** - * 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. - * - * @param collectionId - * @param language - * @return - * @throws MovieDbException - */ - public CollectionInfo getCollectionInfo(int collectionId, String language) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, collectionId); - parameters.add(Param.LANGUAGE, language); - - URL url = new ApiUrl(apiKey, MethodBase.COLLECTION).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - return MAPPER.readValue(webpage, CollectionInfo.class); - } catch (IOException ex) { - LOG.warn("Failed to get collection information: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * Get all of the images for a particular collection by collection id. - * - * @param collectionId - * @param language - * @return - * @throws MovieDbException - */ - public TmdbResultsList getCollectionImages(int collectionId, String language) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, collectionId); - parameters.add(Param.LANGUAGE, language); - - URL url = new ApiUrl(apiKey, MethodBase.COLLECTION).setSubMethod(MethodSub.IMAGES).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperImages wrapper = MAPPER.readValue(webpage, WrapperImages.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getAll(ArtworkType.POSTER, ArtworkType.BACKDROP)); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - LOG.warn("Failed to get collection images: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - /** * This method is used to retrieve all of the basic person information. * @@ -915,7 +871,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. * @@ -1026,130 +983,16 @@ public class TheMovieDbApi { } /** - * This method is used to retrieve the basic information about a production company on TMDb. - * - * @param companyId - * @return - * @throws MovieDbException - */ - public Company getCompanyInfo(int companyId) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, companyId); - - URL url = new ApiUrl(apiKey, MethodBase.COMPANY).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - return MAPPER.readValue(webpage, Company.class); - } catch (IOException ex) { - LOG.warn("Failed to get company information: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * 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. - * - * TODO: Implement more than 20 movies - * - * @param companyId - * @param language - * @param page - * @return - * @throws MovieDbException - */ - public TmdbResultsList getCompanyMovies(int companyId, String language, int page) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, companyId); - parameters.add(Param.LANGUAGE, language); - parameters.add(Param.PAGE, page); - - URL url = new ApiUrl(apiKey, MethodBase.COMPANY).setSubMethod(MethodSub.MOVIES).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperCompanyMovies wrapper = MAPPER.readValue(webpage, WrapperCompanyMovies.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - LOG.warn("Failed to get company movies: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * You can use this method to retrieve the list of genres used on TMDb. - * - * These IDs will correspond to those found in movie calls. - * - * @param language - * @return - * @throws MovieDbException - */ - public TmdbResultsList getGenreList(String language) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.LANGUAGE, language); - - URL url = new ApiUrl(apiKey, MethodBase.GENRE).setSubMethod(MethodSub.LIST).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperGenres wrapper = MAPPER.readValue(webpage, WrapperGenres.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getGenres()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - LOG.warn("Failed to get genre list: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * Get a list of movies per genre. - * - * 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. - * - * @param genreId - * @param language - * @param page - * @param includeAllMovies - * @return - * @throws MovieDbException - */ - public TmdbResultsList getGenreMovies(int genreId, String language, int page, boolean includeAllMovies) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, genreId); - parameters.add(Param.LANGUAGE, language); - parameters.add(Param.PAGE, page); - parameters.add(Param.INCLUDE_ALL_MOVIES, includeAllMovies); - - URL url = new ApiUrl(apiKey, MethodBase.GENRE).setSubMethod(MethodSub.MOVIES).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperMovie wrapper = MAPPER.readValue(webpage, WrapperMovie.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getMovies()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - LOG.warn("Failed to get genre movie list: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * 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 */ @@ -1208,7 +1051,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 @@ -1268,8 +1112,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 * @@ -1324,293 +1168,6 @@ public class TheMovieDbApi { } } - /** - * Get a list by its ID - * - * @param listId - * @return The list and its items - * @throws MovieDbException - */ - public MovieDbList getList(String listId) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, listId); - - URL url = new ApiUrl(apiKey, MethodBase.LIST).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - return MAPPER.readValue(webpage, MovieDbList.class); - } catch (IOException ex) { - LOG.warn("Failed to get list: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * This method lets users create a new list. A valid session id is required. - * - * @param sessionId - * @param name - * @param description - * @return The list id - * @throws MovieDbException - */ - public String createList(String sessionId, String name, String description) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.SESSION, sessionId); - - Map body = new HashMap(); - body.put("name", StringUtils.trimToEmpty(name)); - body.put("description", StringUtils.trimToEmpty(description)); - String jsonBody = convertToJson(body); - - URL url = new ApiUrl(apiKey, MethodBase.LIST).buildUrl(parameters); - String webpage = httpTools.postRequest(url, jsonBody); - - try { - return MAPPER.readValue(webpage, MovieDbListStatus.class).getListId(); - } catch (IOException ex) { - LOG.warn("Failed to create list: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * Check to see if a movie ID is already added to a list. - * - * @param listId - * @param movieId - * @return true if the movie is on the list - * @throws MovieDbException - */ - public boolean isMovieOnList(String listId, Integer movieId) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, movieId); - - URL url = new ApiUrl(apiKey, MethodBase.LIST).setSubMethod(listId, MethodSub.ITEM_STATUS).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - return MAPPER.readValue(webpage, ListItemStatus.class).isItemPresent(); - } catch (IOException ex) { - LOG.warn("Failed to get item status: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * This method lets users add new movies to a list that they created. A valid session id is required. - * - * @param sessionId - * @param listId - * @param movieId - * @return true if the movie is on the list - * @throws MovieDbException - */ - public StatusCode addMovieToList(String sessionId, String listId, Integer movieId) throws MovieDbException { - return modifyMovieList(sessionId, listId, movieId, MethodSub.ADD_ITEM); - } - - /** - * This method lets users remove movies from a list that they created. A valid session id is required. - * - * @param sessionId - * @param listId - * @param movieId - * @return true if the movie is on the list - * @throws MovieDbException - */ - public StatusCode removeMovieFromList(String sessionId, String listId, Integer movieId) throws MovieDbException { - return modifyMovieList(sessionId, listId, movieId, MethodSub.REMOVE_ITEM); - } - - private StatusCode modifyMovieList(String sessionId, String listId, Integer movieId, MethodSub operation) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.SESSION, sessionId); - - String jsonBody = convertToJson(Collections.singletonMap("media_id", String.valueOf(movieId))); - - URL url = new ApiUrl(apiKey, MethodBase.LIST).setSubMethod(listId, operation).buildUrl(parameters); - String webpage = httpTools.postRequest(url, jsonBody); - - try { - return MAPPER.readValue(webpage, StatusCode.class); - } catch (IOException ex) { - LOG.warn("Failed to remove movie from list: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * This method lets users delete a list that they created. A valid session id is required. - * - * @param sessionId - * @param listId - * @return - * @throws MovieDbException - */ - public StatusCode deleteMovieList(String sessionId, String listId) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, listId); - parameters.add(Param.SESSION, sessionId); - - URL url = new ApiUrl(apiKey, MethodBase.LIST).buildUrl(parameters); - String webpage = httpTools.deleteRequest(url); - - try { - return MAPPER.readValue(webpage, StatusCode.class); - } catch (IOException ex) { - LOG.warn("Failed to delete movie list: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * Get the basic information for a specific keyword id. - * - * @param keywordId - * @return - * @throws MovieDbException - */ - public Keyword getKeyword(String keywordId) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, keywordId); - - URL url = new ApiUrl(apiKey, MethodBase.KEYWORD).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - return MAPPER.readValue(webpage, Keyword.class); - } catch (IOException ex) { - LOG.warn("Failed to get keyword: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - - } - - /** - * Get the list of movies for a particular keyword by id. - * - * @param keywordId - * @param language - * @param page - * @return List of movies with the keyword - * @throws MovieDbException - */ - public TmdbResultsList getKeywordMovies(String keywordId, String language, int page) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, keywordId); - parameters.add(Param.LANGUAGE, language); - parameters.add(Param.PAGE, page); - - URL url = new ApiUrl(apiKey, MethodBase.KEYWORD).setSubMethod(MethodSub.MOVIES).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperKeywordMovies wrapper = MAPPER.readValue(webpage, WrapperKeywordMovies.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - LOG.warn("Failed to get keyword movies: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - - } - - public void getPersonChangesList(int page, String startDate, String endDate) throws MovieDbException { - LOG.trace("getPersonChangesList: page: {}, start: {}, end: {}", page, startDate, endDate); - throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not implemented yet", ""); - } - - public TmdbResultsList getJobs() throws MovieDbException { - URL url = new ApiUrl(apiKey, MethodBase.JOB).setSubMethod(MethodSub.LIST).buildUrl(); - String webpage = httpTools.getRequest(url); - - try { - WrapperJobList wrapper = MAPPER.readValue(webpage, WrapperJobList.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getJobs()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - LOG.warn("Failed to get job list: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * 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 - * - * @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 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. - * @return - * @throws MovieDbException - */ - public TmdbResultsList getDiscover(int page, String language, String sortBy, boolean includeAdult, int year, - int primaryReleaseYear, int voteCountGte, float voteAverageGte, String withGenres, String releaseDateGte, - String releaseDateLte, String certificationCountry, String certificationLte, String withCompanies) throws MovieDbException { - - Discover discover = new Discover(); - discover.page(page) - .language(language) - .sortBy(sortBy) - .includeAdult(includeAdult) - .year(year) - .primaryReleaseYear(primaryReleaseYear) - .voteCountGte(voteCountGte) - .voteAverageGte(voteAverageGte) - .withGenres(withGenres) - .releaseDateGte(releaseDateGte) - .releaseDateLte(releaseDateLte) - .certificationCountry(certificationCountry) - .certificationLte(certificationLte) - .withCompanies(withCompanies); - - return getDiscover(discover); - } - - /** - * 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 - * @throws MovieDbException - */ - public TmdbResultsList getDiscover(Discover discover) throws MovieDbException { - URL url = new ApiUrl(apiKey, MethodBase.DISCOVER).setSubMethod(MethodSub.MOVIE).buildUrl(discover.getParams()); - String webpage = httpTools.getRequest(url); - - try { - WrapperMovie wrapper = MAPPER.readValue(webpage, WrapperMovie.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getMovies()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - LOG.warn("Failed to get discover list: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - /** * Use Jackson to convert Map to JSON string. * @@ -1628,7 +1185,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 @@ -1768,13 +1326,16 @@ public class TheMovieDbApi { // /** - * 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 @@ -1784,7 +1345,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. * @@ -1797,7 +1359,8 @@ public class TheMovieDbApi { } /** - * This method is used to generate a session id for user based authentication. User must provide their username and password + * This method is used to generate a session id for user based + * authentication. User must provide their username and password * * A session id is required in order to use any of the write methods. * @@ -1814,14 +1377,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 @@ -1861,20 +1428,47 @@ 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 id * @param startDate the start date of the changes, optional * @param endDate the end date of the changes, optional * @return * @throws MovieDbException */ - public TmdbResultsMap> getMovieChanges(int movieId, String startDate, String endDate) throws MovieDbException { - return tmdbChanges.getMovieChanges(movieId, startDate, endDate); + public TmdbResultsList getMovieChanges(int id, String startDate, String endDate) throws MovieDbException { + return tmdbChanges.getMovieChanges(id, startDate, endDate); + } + + /** + * Get the changes for a specific TV id. + * + * Changes are grouped by key, and ordered by date in descending order. + * + * 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 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 + * + * @param id + * @param startDate the start date of the changes, optional + * @param endDate the end date of the changes, optional + * @return + * @throws MovieDbException + */ + public TmdbResultsList getTVChanges(int id, String startDate, String endDate) throws MovieDbException { + return tmdbChanges.getMovieChanges(id, startDate, endDate); } /** @@ -1884,23 +1478,26 @@ 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. * - * @param personId + * @param id * @param startDate * @param endDate + * @return * @throws MovieDbException */ - public void getPersonChanges(int personId, String startDate, String endDate) throws MovieDbException { - tmdbChanges.getPersonChanges(personId, startDate, endDate); + public TmdbResultsList getPersonChanges(int id, String startDate, String endDate) throws MovieDbException { + return tmdbChanges.getPersonChanges(id, startDate, endDate); } /** * Get a list of Movie IDs that have been edited. * - * You can then use the movie changes API to get the actual data that has been changed. + * You can then use the movie changes API to get the actual data that has + * been changed. * * @param page * @param startDate the start date of the changes, optional @@ -1915,7 +1512,8 @@ public class TheMovieDbApi { /** * Get a list of TV IDs that have been edited. * - * You can then use the TV changes API to get the actual data that has been changed. + * You can then use the TV changes API to get the actual data that has been + * changed. * * @param page * @param startDate the start date of the changes, optional @@ -1930,7 +1528,8 @@ public class TheMovieDbApi { /** * Get a list of Person IDs that have been edited. * - * You can then use the person changes API to get the actual data that has been changed. + * You can then use the person changes API to get the actual data that has + * been changed. * * @param page * @param startDate the start date of the changes, optional @@ -1944,25 +1543,321 @@ public class TheMovieDbApi { // // + /** + * 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. + * + * @param collectionId + * @param language + * @return + * @throws MovieDbException + */ + public CollectionInfo getCollectionInfo(int collectionId, String language) throws MovieDbException { + return tmdbCollections.getCollectionInfo(collectionId, language); + } + + /** + * Get all of the images for a particular collection by collection id. + * + * @param collectionId + * @param language + * @return + * @throws MovieDbException + */ + public TmdbResultsList getCollectionImages(int collectionId, String language) throws MovieDbException { + return tmdbCollections.getCollectionImages(collectionId, language); + } // + // + /** + * This method is used to retrieve the basic information about a production + * company on TMDb. + * + * @param companyId + * @return + * @throws MovieDbException + */ + public Company getCompanyInfo(int companyId) throws MovieDbException { + return tmdbCompany.getCompanyInfo(companyId); + } + + /** + * 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. + * + * TODO: Implement more than 20 movies + * + * @param companyId + * @param language + * @param page + * @return + * @throws MovieDbException + */ + public TmdbResultsList getCompanyMovies(int companyId, String language, int page) throws MovieDbException { + return tmdbCompany.getCompanyMovies(companyId, language, page); + } // + // + /** + * Get the configuration information + * + * @return + * @throws com.omertron.themoviedbapi.MovieDbException + */ + public Configuration getConfiguration() throws MovieDbException { + return tmdbConfiguration.getConfig(); + } + + /** + * Generate the full image URL from the size and image path + * + * @param imagePath + * @param requiredSize + * @return + * @throws MovieDbException + */ + public URL createImageUrl(String imagePath, String requiredSize) throws MovieDbException { + return tmdbConfiguration.createImageUrl(imagePath, requiredSize); + } + + /** + * Get a list of valid jobs + * + * @return + * @throws MovieDbException + */ + public TmdbResultsList getJobs() throws MovieDbException { + return tmdbConfiguration.getJobs(); + } // + // + /** + * Get the detailed information about a particular credit record. + *

+ * This is currently only supported with the new credit model found in TV. + *
+ * These IDs can be found from any TV credit response as well as the + * TV_credits and combined_credits methods for people.
+ * The episodes object returns a list of episodes and are generally going to + * be guest stars.
+ * The season array will return a list of season numbers.
+ * Season credits are credits that were marked with the "add to every + * season" option in the editing interface and are assumed to be "season + * regulars". + * + * @param creditId + * @param language + * @return + * @throws MovieDbException + */ + public TBD_PersonCredits getCreditInfo(String creditId, String language) throws MovieDbException { + return tmdbCredits.getCreditInfo(creditId, language); + } // + // + /** + * 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 + * @throws MovieDbException + */ + public TmdbResultsList getDiscoverMovies(Discover discover) throws MovieDbException { + return tmdbDiscover.getDiscoverMovies(discover); + } + + /** + * 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 + * @throws MovieDbException + */ + public TmdbResultsList getDiscoverTV(Discover discover) throws MovieDbException { + return tmdbDiscover.getDiscoverTV(discover); + } // + // + /** + * You con use this method to find movies, tv series or persons using + * external ids. + * + * Supported query ids are + *

    + *
  • Movies: imdb_id
  • + *
  • People: imdb_id, freebase_mid, freebase_id, tvrage_id
  • + *
  • TV Series: imdb_id, freebase_mid, freebase_id, tvdb_id, + * tvrage_id
  • + *
  • TV Seasons: freebase_mid, freebase_id, tvdb_id, tvrage_id
  • + *
  • TV Episodes: imdb_id, freebase_mid, freebase_id, tvdb_id, + * tvrage_idimdb_id, freebase_mid, freebase_id, tvrage_id, tvdb_id. + *
+ * + * For details see http://docs.themoviedb.apiary.io/#find + * + * @param id the external id + * @param externalSource one of {@link ExternalSource}. + * @param language the language + * @return + * @throws MovieDbException + */ + public TBD_FindResults find(String id, TBD_ExternalSource externalSource, String language) throws MovieDbException { + return tmdbFind.find(id, externalSource, language); + } // + // + /** + * You can use this method to retrieve the list of genres used on TMDb. + * + * These IDs will correspond to those found in movie calls. + * + * @param language + * @return + * @throws MovieDbException + */ + public TmdbResultsList getGenreList(String language) throws MovieDbException { + return tmdbGenre.getGenreList(language); + } + + /** + * Get a list of movies per genre. + * + * 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. + * + * @param genreId + * @param language + * @param page + * @param includeAllMovies + * @return + * @throws MovieDbException + */ + public TmdbResultsList getGenreMovies(int genreId, String language, int page, boolean includeAllMovies) throws MovieDbException { + return tmdbGenre.getGenreMovies(genreId, language, page, includeAllMovies); + } // - // - // + // + /** + * Get the basic information for a specific keyword id. + * + * @param keywordId + * @return + * @throws MovieDbException + */ + public Keyword getKeyword(String keywordId) throws MovieDbException { + return tmdbKeywords.getKeyword(keywordId); + } + + /** + * Get the list of movies for a particular keyword by id. + * + * @param keywordId + * @param language + * @param page + * @return List of movies with the keyword + * @throws MovieDbException + */ + public TmdbResultsList getKeywordMovies(String keywordId, String language, int page) throws MovieDbException { + return tmdbKeywords.getKeywordMovies(keywordId, language, page); + } // + // + /** + * Get a list by its ID + * + * @param listId + * @return The list and its items + * @throws MovieDbException + */ + public MovieDbList getList(String listId) throws MovieDbException { + return tmdbList.getList(listId); + } + + /** + * This method lets users create a new list. A valid session id is required. + * + * @param sessionId + * @param name + * @param description + * @return The list id + * @throws MovieDbException + */ + public String createList(String sessionId, String name, String description) throws MovieDbException { + return tmdbList.createList(sessionId, name, description); + } + + /** + * Check to see if a movie ID is already added to a list. + * + * @param listId + * @param movieId + * @return true if the movie is on the list + * @throws MovieDbException + */ + public boolean isMovieOnList(String listId, Integer movieId) throws MovieDbException { + return tmdbList.isMovieOnList(listId, movieId); + } + + /** + * This method lets users add new movies to a list that they created. A + * valid session id is required. + * + * @param sessionId + * @param listId + * @param movieId + * @return true if the movie is on the list + * @throws MovieDbException + */ + public StatusCode addMovieToList(String sessionId, String listId, Integer movieId) throws MovieDbException { + return tmdbList.modifyMovieList(sessionId, listId, movieId, MethodSub.ADD_ITEM); + } + + /** + * This method lets users remove movies from a list that they created. A + * valid session id is required. + * + * @param sessionId + * @param listId + * @param movieId + * @return true if the movie is on the list + * @throws MovieDbException + */ + public StatusCode removeMovieFromList(String sessionId, String listId, Integer movieId) throws MovieDbException { + return tmdbList.modifyMovieList(sessionId, listId, movieId, MethodSub.REMOVE_ITEM); + } + + /** + * This method lets users delete a list that they created. A valid session + * id is required. + * + * @param sessionId + * @param listId + * @return + * @throws MovieDbException + */ + public StatusCode deleteMovieList(String sessionId, String listId) throws MovieDbException { + return tmdbList.deleteMovieList(sessionId, listId); + } // + // // // diff --git a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java index f554e2e97..010b90f36 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java @@ -19,14 +19,10 @@ */ package com.omertron.themoviedbapi.methods; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.tools.HttpTools; -import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.yamj.api.common.exception.ApiExceptionType; /** * Abstract methods @@ -55,19 +51,4 @@ public class AbstractMethod { this.httpTools = httpTools; } - /** - * Use Jackson to convert Map to JSON string. - * - * @param map - * @return - * @throws MovieDbException - */ - protected static String convertToJson(Map map) throws MovieDbException { - try { - return MAPPER.writeValueAsString(map); - } catch (JsonProcessingException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "JSON conversion failed", "", ex); - } - } - } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java index 1341fb27b..2516f26f6 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java @@ -30,14 +30,14 @@ import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; import com.omertron.themoviedbapi.tools.MethodSub; import com.omertron.themoviedbapi.tools.Param; +import com.omertron.themoviedbapi.tools.PostBody; +import com.omertron.themoviedbapi.tools.PostTools; import com.omertron.themoviedbapi.tools.TmdbParameters; import com.omertron.themoviedbapi.wrapper.WrapperMovie; import com.omertron.themoviedbapi.wrapper.WrapperMovieDbList; import java.io.IOException; import java.net.URL; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.yamj.api.common.exception.ApiExceptionType; /** @@ -47,11 +47,6 @@ import org.yamj.api.common.exception.ApiExceptionType; */ public class TmdbAccount extends AbstractMethod { - private static final String MEDIA_ID = "media_id"; - private static final String MEDIA_TYPE = "media_type"; - private static final String FAVORITE = "favorite"; - private static final String WATCHLIST = "watchlist"; - /** * Constructor * @@ -63,7 +58,8 @@ public class TmdbAccount extends AbstractMethod { } /** - * 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 @@ -79,8 +75,7 @@ public class TmdbAccount extends AbstractMethod { try { return MAPPER.readValue(webpage, Account.class); } catch (IOException ex) { - LOG.warn("Failed to get Account: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get Account", url, ex); } } @@ -102,8 +97,7 @@ public class TmdbAccount extends AbstractMethod { try { return MAPPER.readValue(webpage, WrapperMovieDbList.class).getLists(); } catch (IOException ex) { - LOG.warn("Failed to get user list: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get user list", url, ex); } } @@ -125,8 +119,7 @@ public class TmdbAccount extends AbstractMethod { try { return MAPPER.readValue(webpage, WrapperMovie.class).getMovies(); } catch (IOException ex) { - LOG.warn("Failed to get favorite movies: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get favorite movies", url, ex); } } @@ -157,11 +150,11 @@ public class TmdbAccount extends AbstractMethod { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.SESSION, sessionId); - Map body = new HashMap(); - body.put(MEDIA_TYPE, mediaType.toString().toLowerCase()); - body.put(MEDIA_ID, mediaId); - body.put(FAVORITE, isFavorite); - String jsonBody = convertToJson(body); + String jsonBody = new PostTools() + .add(PostBody.MEDIA_TYPE, mediaType.toString().toLowerCase()) + .add(PostBody.MEDIA_ID, mediaId) + .add(PostBody.FAVORITE, isFavorite) + .build(); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(accountId, MethodSub.FAVORITE).buildUrl(parameters); String webpage = httpTools.postRequest(url, jsonBody); @@ -169,8 +162,7 @@ public class TmdbAccount extends AbstractMethod { try { return MAPPER.readValue(webpage, StatusCode.class); } catch (IOException ex) { - LOG.warn("Failed to get favorite status: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get favorite status", url, ex); } } @@ -192,8 +184,7 @@ public class TmdbAccount extends AbstractMethod { try { return MAPPER.readValue(webpage, WrapperMovie.class).getMovies(); } catch (IOException ex) { - LOG.warn("Failed to get rated movies: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get rated movies", url, ex); } } @@ -227,8 +218,7 @@ public class TmdbAccount extends AbstractMethod { try { return MAPPER.readValue(webpage, WrapperMovie.class).getMovies(); } catch (IOException ex) { - LOG.warn("Failed to get Movie watch list: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get Movie watch list", url, ex); } } @@ -250,8 +240,7 @@ public class TmdbAccount extends AbstractMethod { try { return MAPPER.readValue(webpage, WrapperMovie.class).getMovies(); } catch (IOException ex) { - LOG.warn("Failed to get TV watch list: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get TV watch list", url, ex); } } @@ -270,11 +259,11 @@ public class TmdbAccount extends AbstractMethod { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.SESSION, sessionId); - Map body = new HashMap(); - body.put(MEDIA_TYPE, mediaType.toString().toLowerCase()); - body.put(MEDIA_ID, movieId); - body.put(WATCHLIST, addToWatchlist); - String jsonBody = convertToJson(body); + String jsonBody = new PostTools() + .add(PostBody.MEDIA_TYPE, mediaType.toString().toLowerCase()) + .add(PostBody.MEDIA_ID, movieId) + .add(PostBody.WATCHLIST, addToWatchlist) + .build(); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(accountId, MethodSub.WATCHLIST).buildUrl(parameters); String webpage = httpTools.postRequest(url, jsonBody); diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbChanges.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbChanges.java index e93232883..cb3a8e692 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbChanges.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbChanges.java @@ -20,10 +20,8 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.ChangedItem; import com.omertron.themoviedbapi.model.ChangedMedia; import com.omertron.themoviedbapi.results.TmdbResultsList; -import com.omertron.themoviedbapi.results.TmdbResultsMap; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; @@ -33,7 +31,6 @@ import com.omertron.themoviedbapi.tools.TmdbParameters; import com.omertron.themoviedbapi.wrapper.WrapperMediaChanges; import java.io.IOException; import java.net.URL; -import java.util.List; import org.yamj.api.common.exception.ApiExceptionType; /** @@ -53,54 +50,11 @@ public class TmdbChanges extends AbstractMethod { super(apiKey, httpTools); } - /** - * Get the changes for a specific movie id. - * - * Changes are grouped by key, and ordered by date in descending order. - * - * 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 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 - * - * @param movieId - * @param startDate the start date of the changes, optional - * @param endDate the end date of the changes, optional - * @return - * @throws MovieDbException - */ - public TmdbResultsMap> getMovieChanges(int movieId, String startDate, String endDate) throws MovieDbException { - return null; - } - - /** - * Get the changes for a specific person id. - * - * Changes are grouped by key, and ordered by date in descending order. - * - * 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 language is present on fields that are translatable. - * - * @param personId - * @param startDate - * @param endDate - * @throws MovieDbException - */ - public void getPersonChanges(int personId, String startDate, String endDate) throws MovieDbException { - LOG.trace("getPersonChanges: id: {}, start: {}, end: {}", personId, startDate, endDate); - throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not implemented yet", ""); - } - /** * Get a list of Media IDs that have been edited. * - * You can then use the movie/TV/person changes API to get the actual data that has been changed. + * You can then use the movie/TV/person changes API to get the actual data + * that has been changed. * * @param method The method base to get * @param page @@ -128,4 +82,46 @@ public class TmdbChanges extends AbstractMethod { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get changes", url, ex); } } + + /** + * Get the changes for a specific movie id. + * + * @param id + * @param startDate the start date of the changes, optional + * @param endDate the end date of the changes, optional + * @return + * @throws MovieDbException + */ + public TmdbResultsList getMovieChanges(int id, String startDate, String endDate) throws MovieDbException { + LOG.trace("Movie Changes: id: {}, start: {}, end: {}", id, startDate, endDate); + throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not implemented yet"); + } + + /** + * Get the changes for a specific TV Show + * + * @param id + * @param startDate + * @param endDate + * @return + * @throws MovieDbException + */ + public TmdbResultsList getTvChanges(int id, String startDate, String endDate) throws MovieDbException { + LOG.trace("TV Changes: id: {}, start: {}, end: {}", id, startDate, endDate); + throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not implemented yet"); + } + + /** + * Get the changes for a specific person id. + * + * @param id + * @param startDate + * @param endDate + * @return + * @throws MovieDbException + */ + public TmdbResultsList getPersonChanges(int id, String startDate, String endDate) throws MovieDbException { + LOG.trace("Person Changes: id: {}, start: {}, end: {}", id, startDate, endDate); + throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not implemented yet", ""); + } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCollections.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCollections.java index fca09eb07..2c4308443 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCollections.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCollections.java @@ -19,7 +19,21 @@ */ package com.omertron.themoviedbapi.methods; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model.ArtworkType; +import com.omertron.themoviedbapi.model.CollectionInfo; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; +import com.omertron.themoviedbapi.tools.MethodBase; +import com.omertron.themoviedbapi.tools.MethodSub; +import com.omertron.themoviedbapi.tools.Param; +import com.omertron.themoviedbapi.tools.TmdbParameters; +import com.omertron.themoviedbapi.wrapper.WrapperImages; +import java.io.IOException; +import java.net.URL; +import org.yamj.api.common.exception.ApiExceptionType; /** * Class to hold the Collections Methods @@ -37,4 +51,57 @@ public class TmdbCollections extends AbstractMethod { public TmdbCollections(String apiKey, HttpTools httpTools) { super(apiKey, httpTools); } + + /** + * 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. + * + * @param collectionId + * @param language + * @return + * @throws MovieDbException + */ + public CollectionInfo getCollectionInfo(int collectionId, String language) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, collectionId); + parameters.add(Param.LANGUAGE, language); + + URL url = new ApiUrl(apiKey, MethodBase.COLLECTION).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, CollectionInfo.class); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get collection information", url, ex); + } + } + + /** + * Get all of the images for a particular collection by collection id. + * + * @param collectionId + * @param language + * @return + * @throws MovieDbException + */ + public TmdbResultsList getCollectionImages(int collectionId, String language) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, collectionId); + parameters.add(Param.LANGUAGE, language); + + URL url = new ApiUrl(apiKey, MethodBase.COLLECTION).setSubMethod(MethodSub.IMAGES).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + WrapperImages wrapper = MAPPER.readValue(webpage, WrapperImages.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getAll(ArtworkType.POSTER, ArtworkType.BACKDROP)); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get collection images", url, ex); + } + } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java index 5da4a6260..64eb74dea 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java @@ -19,7 +19,20 @@ */ package com.omertron.themoviedbapi.methods; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.model.Company; +import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; +import com.omertron.themoviedbapi.tools.MethodBase; +import com.omertron.themoviedbapi.tools.MethodSub; +import com.omertron.themoviedbapi.tools.Param; +import com.omertron.themoviedbapi.tools.TmdbParameters; +import com.omertron.themoviedbapi.wrapper.WrapperCompanyMovies; +import java.io.IOException; +import java.net.URL; +import org.yamj.api.common.exception.ApiExceptionType; /** * Class to hold the Company Methods @@ -37,4 +50,60 @@ public class TmdbCompanies extends AbstractMethod { public TmdbCompanies(String apiKey, HttpTools httpTools) { super(apiKey, httpTools); } + + /** + * This method is used to retrieve the basic information about a production + * company on TMDb. + * + * @param companyId + * @return + * @throws MovieDbException + */ + public Company getCompanyInfo(int companyId) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, companyId); + + URL url = new ApiUrl(apiKey, MethodBase.COMPANY).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, Company.class); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get company information", url, ex); + } + } + + /** + * 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. + * + * TODO: Implement more than 20 movies + * + * @param companyId + * @param language + * @param page + * @return + * @throws MovieDbException + */ + public TmdbResultsList getCompanyMovies(int companyId, String language, int page) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, companyId); + parameters.add(Param.LANGUAGE, language); + parameters.add(Param.PAGE, page); + + URL url = new ApiUrl(apiKey, MethodBase.COMPANY).setSubMethod(MethodSub.MOVIES).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + WrapperCompanyMovies wrapper = MAPPER.readValue(webpage, WrapperCompanyMovies.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get company movies", url, ex); + } + } + } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java index 6f93c425f..5e6218a5f 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java @@ -19,7 +19,21 @@ */ package com.omertron.themoviedbapi.methods; +import com.omertron.themoviedbapi.MovieDbException; +import static com.omertron.themoviedbapi.methods.AbstractMethod.MAPPER; +import com.omertron.themoviedbapi.model.Configuration; +import com.omertron.themoviedbapi.model.JobDepartment; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; +import com.omertron.themoviedbapi.tools.MethodBase; +import com.omertron.themoviedbapi.tools.MethodSub; +import com.omertron.themoviedbapi.wrapper.WrapperConfig; +import com.omertron.themoviedbapi.wrapper.WrapperJobList; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import org.yamj.api.common.exception.ApiExceptionType; /** * Class to hold the Configuration Methods @@ -28,6 +42,12 @@ import com.omertron.themoviedbapi.tools.HttpTools; */ public class TmdbConfiguration extends AbstractMethod { + /** + * Cache the configuration in memory
+ * It rarely changes, so this should be safe. + */ + private static Configuration config = null; + /** * Constructor * @@ -37,4 +57,71 @@ public class TmdbConfiguration extends AbstractMethod { public TmdbConfiguration(String apiKey, HttpTools httpTools) { super(apiKey, httpTools); } + + /** + * Get the configuration
+ * If the configuration has been previously retrieved, use that instead + * + * @return + * @throws MovieDbException + */ + public Configuration getConfig() throws MovieDbException { + if (config == null) { + URL configUrl = new ApiUrl(apiKey, MethodBase.CONFIGURATION).buildUrl(); + String webpage = httpTools.getRequest(configUrl); + + try { + WrapperConfig wc = MAPPER.readValue(webpage, WrapperConfig.class); + config = wc.getTmdbConfiguration(); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to read configuration", configUrl, ex); + } + } + return config; + } + + /** + * Generate the full image URL from the size and image path + * + * @param imagePath + * @param requiredSize + * @return + * @throws MovieDbException + */ + public URL createImageUrl(String imagePath, String requiredSize) throws MovieDbException { + if (!config.isValidSize(requiredSize)) { + throw new MovieDbException(ApiExceptionType.INVALID_IMAGE, "Required size '" + requiredSize + "' is not valid"); + } + + StringBuilder sb = new StringBuilder(config.getBaseUrl()); + sb.append(requiredSize); + sb.append(imagePath); + try { + return new URL(sb.toString()); + } catch (MalformedURLException ex) { + throw new MovieDbException(ApiExceptionType.INVALID_URL, "Failed to create image URL", sb.toString(), ex); + } + } + + /** + * Get a list of valid jobs + * + * @return + * @throws MovieDbException + */ + public TmdbResultsList getJobs() throws MovieDbException { + URL url = new ApiUrl(apiKey, MethodBase.JOB).setSubMethod(MethodSub.LIST).buildUrl(); + String webpage = httpTools.getRequest(url); + + try { + WrapperJobList wrapper = MAPPER.readValue(webpage, WrapperJobList.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getJobs()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + LOG.warn("Failed to get job list: {}", ex.getMessage(), ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + } + } + } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCredits.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCredits.java index 48c3b8f6e..2873f028d 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCredits.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCredits.java @@ -19,7 +19,16 @@ */ package com.omertron.themoviedbapi.methods; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.model.TBD_PersonCredits; +import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; +import com.omertron.themoviedbapi.tools.MethodBase; +import com.omertron.themoviedbapi.tools.Param; +import com.omertron.themoviedbapi.tools.TmdbParameters; +import java.io.IOException; +import java.net.URL; +import org.yamj.api.common.exception.ApiExceptionType; /** * Class to hold the Credit Methods @@ -37,4 +46,39 @@ public class TmdbCredits extends AbstractMethod { public TmdbCredits(String apiKey, HttpTools httpTools) { super(apiKey, httpTools); } + + /** + * Get the detailed information about a particular credit record. + *

+ * This is currently only supported with the new credit model found in TV. + *
+ * These IDs can be found from any TV credit response as well as the + * TV_credits and combined_credits methods for people.
+ * The episodes object returns a list of episodes and are generally going to + * be guest stars.
+ * The season array will return a list of season numbers.
+ * Season credits are credits that were marked with the "add to every + * season" option in the editing interface and are assumed to be "season + * regulars". + * + * @param creditId + * @param language + * @return + * @throws MovieDbException + */ + public TBD_PersonCredits getCreditInfo(String creditId, String language) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, creditId); + parameters.add(Param.LANGUAGE, language); + + URL url = new ApiUrl(apiKey, MethodBase.CREDIT).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, TBD_PersonCredits.class); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get credit info", url, ex); + } + } + } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbDiscover.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbDiscover.java index aa77d5c89..1ab00a66b 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbDiscover.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbDiscover.java @@ -19,7 +19,18 @@ */ package com.omertron.themoviedbapi.methods; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.model.Discover; +import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; +import com.omertron.themoviedbapi.tools.MethodBase; +import com.omertron.themoviedbapi.tools.MethodSub; +import com.omertron.themoviedbapi.wrapper.WrapperMovie; +import java.io.IOException; +import java.net.URL; +import org.yamj.api.common.exception.ApiExceptionType; /** * Class to hold the Discover Methods @@ -37,4 +48,39 @@ public class TmdbDiscover extends AbstractMethod { public TmdbDiscover(String apiKey, HttpTools httpTools) { super(apiKey, httpTools); } + + /** + * 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 + * @throws MovieDbException + */ + public TmdbResultsList getDiscoverMovies(Discover discover) throws MovieDbException { + URL url = new ApiUrl(apiKey, MethodBase.DISCOVER).setSubMethod(MethodSub.MOVIE).buildUrl(discover.getParams()); + String webpage = httpTools.getRequest(url); + + try { + WrapperMovie wrapper = MAPPER.readValue(webpage, WrapperMovie.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getMovies()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get movie discover list", url, ex); + } + } + + /** + * 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 + * @throws MovieDbException + */ + public TmdbResultsList getDiscoverTV(Discover discover) throws MovieDbException { + URL url = new ApiUrl(apiKey, MethodBase.DISCOVER).setSubMethod(MethodSub.TV).buildUrl(discover.getParams()); + throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not implemented yet"); + } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java index 6eb42f762..26a9ba28e 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java @@ -19,7 +19,11 @@ */ package com.omertron.themoviedbapi.methods; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.model.TBD_ExternalSource; +import com.omertron.themoviedbapi.model.TBD_FindResults; import com.omertron.themoviedbapi.tools.HttpTools; +import org.yamj.api.common.exception.ApiExceptionType; /** * Class to hold the Find Methods @@ -37,4 +41,31 @@ public class TmdbFind extends AbstractMethod { public TmdbFind(String apiKey, HttpTools httpTools) { super(apiKey, httpTools); } + + /** + * You con use this method to find movies, tv series or persons using + * external ids. + * + * Supported query ids are + *

    + *
  • Movies: imdb_id
  • + *
  • People: imdb_id, freebase_mid, freebase_id, tvrage_id
  • + *
  • TV Series: imdb_id, freebase_mid, freebase_id, tvdb_id, + * tvrage_id
  • + *
  • TV Seasons: freebase_mid, freebase_id, tvdb_id, tvrage_id
  • + *
  • TV Episodes: imdb_id, freebase_mid, freebase_id, tvdb_id, + * tvrage_idimdb_id, freebase_mid, freebase_id, tvrage_id, tvdb_id. + *
+ * + * For details see http://docs.themoviedb.apiary.io/#find + * + * @param id the external id + * @param externalSource one of {@link ExternalSource}. + * @param language the language + * @return + * @throws MovieDbException + */ + public TBD_FindResults find(String id, TBD_ExternalSource externalSource, String language) throws MovieDbException { + throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "not implemented yet"); + } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbGenres.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbGenres.java index 9ce23dfcc..d714ef499 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbGenres.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbGenres.java @@ -19,7 +19,21 @@ */ package com.omertron.themoviedbapi.methods; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.model.Genre; +import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; +import com.omertron.themoviedbapi.tools.MethodBase; +import com.omertron.themoviedbapi.tools.MethodSub; +import com.omertron.themoviedbapi.tools.Param; +import com.omertron.themoviedbapi.tools.TmdbParameters; +import com.omertron.themoviedbapi.wrapper.WrapperGenres; +import com.omertron.themoviedbapi.wrapper.WrapperMovie; +import java.io.IOException; +import java.net.URL; +import org.yamj.api.common.exception.ApiExceptionType; /** * Class to hold the Genre Methods @@ -37,4 +51,66 @@ public class TmdbGenres extends AbstractMethod { public TmdbGenres(String apiKey, HttpTools httpTools) { super(apiKey, httpTools); } + + /** + * You can use this method to retrieve the list of genres used on TMDb. + * + * These IDs will correspond to those found in movie calls. + * + * @param language + * @return + * @throws MovieDbException + */ + public TmdbResultsList getGenreList(String language) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.LANGUAGE, language); + + URL url = new ApiUrl(apiKey, MethodBase.GENRE).setSubMethod(MethodSub.LIST).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + WrapperGenres wrapper = MAPPER.readValue(webpage, WrapperGenres.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getGenres()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get genre list", url, ex); + } + } + + /** + * Get a list of movies per genre. + * + * 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. + * + * @param genreId + * @param language + * @param page + * @param includeAllMovies + * @return + * @throws MovieDbException + */ + public TmdbResultsList getGenreMovies(int genreId, String language, int page, boolean includeAllMovies) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, genreId); + parameters.add(Param.LANGUAGE, language); + parameters.add(Param.PAGE, page); + parameters.add(Param.INCLUDE_ALL_MOVIES, includeAllMovies); + + URL url = new ApiUrl(apiKey, MethodBase.GENRE).setSubMethod(MethodSub.MOVIES).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + WrapperMovie wrapper = MAPPER.readValue(webpage, WrapperMovie.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getMovies()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get genre movie list", url, ex); + } + } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbKeywords.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbKeywords.java index e467f4f2b..0dfa70df1 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbKeywords.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbKeywords.java @@ -19,7 +19,20 @@ */ package com.omertron.themoviedbapi.methods; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.model.Keyword; +import com.omertron.themoviedbapi.model.KeywordMovie; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; +import com.omertron.themoviedbapi.tools.MethodBase; +import com.omertron.themoviedbapi.tools.MethodSub; +import com.omertron.themoviedbapi.tools.Param; +import com.omertron.themoviedbapi.tools.TmdbParameters; +import com.omertron.themoviedbapi.wrapper.WrapperKeywordMovies; +import java.io.IOException; +import java.net.URL; +import org.yamj.api.common.exception.ApiExceptionType; /** * Class to hold the Keyword Methods @@ -37,4 +50,57 @@ public class TmdbKeywords extends AbstractMethod { public TmdbKeywords(String apiKey, HttpTools httpTools) { super(apiKey, httpTools); } + + /** + * Get the basic information for a specific keyword id. + * + * @param keywordId + * @return + * @throws MovieDbException + */ + public Keyword getKeyword(String keywordId) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, keywordId); + + URL url = new ApiUrl(apiKey, MethodBase.KEYWORD).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, Keyword.class); + } catch (IOException ex) { + LOG.warn("Failed to get keyword: {}", ex.getMessage(), ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + } + + } + + /** + * Get the list of movies for a particular keyword by id. + * + * @param keywordId + * @param language + * @param page + * @return List of movies with the keyword + * @throws MovieDbException + */ + public TmdbResultsList getKeywordMovies(String keywordId, String language, int page) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, keywordId); + parameters.add(Param.LANGUAGE, language); + parameters.add(Param.PAGE, page); + + URL url = new ApiUrl(apiKey, MethodBase.KEYWORD).setSubMethod(MethodSub.MOVIES).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + WrapperKeywordMovies wrapper = MAPPER.readValue(webpage, WrapperKeywordMovies.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + LOG.warn("Failed to get keyword movies: {}", ex.getMessage(), ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + } + } + } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbLists.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbLists.java index 07d4aa13c..c86b754f2 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbLists.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbLists.java @@ -19,7 +19,23 @@ */ package com.omertron.themoviedbapi.methods; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.model.ListItemStatus; +import com.omertron.themoviedbapi.model.MovieDbList; +import com.omertron.themoviedbapi.model.MovieDbListStatus; +import com.omertron.themoviedbapi.model.StatusCode; +import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; +import com.omertron.themoviedbapi.tools.MethodBase; +import com.omertron.themoviedbapi.tools.MethodSub; +import com.omertron.themoviedbapi.tools.Param; +import com.omertron.themoviedbapi.tools.PostBody; +import com.omertron.themoviedbapi.tools.PostTools; +import com.omertron.themoviedbapi.tools.TmdbParameters; +import java.io.IOException; +import java.net.URL; +import org.apache.commons.lang3.StringUtils; +import org.yamj.api.common.exception.ApiExceptionType; /** * Class to hold the List Methods @@ -37,4 +53,127 @@ public class TmdbLists extends AbstractMethod { public TmdbLists(String apiKey, HttpTools httpTools) { super(apiKey, httpTools); } + + /** + * Get a list by its ID + * + * @param listId + * @return The list and its items + * @throws MovieDbException + */ + public MovieDbList getList(String listId) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, listId); + + URL url = new ApiUrl(apiKey, MethodBase.LIST).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, MovieDbList.class); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get list", url, ex); + } + } + + /** + * This method lets users create a new list. A valid session id is required. + * + * @param sessionId + * @param name + * @param description + * @return The list id + * @throws MovieDbException + */ + public String createList(String sessionId, String name, String description) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.SESSION, sessionId); + + String jsonBody = new PostTools() + .add(PostBody.NAME, StringUtils.trimToEmpty(name)) + .add(PostBody.DESCRIPTION, StringUtils.trimToEmpty(description)) + .build(); + + URL url = new ApiUrl(apiKey, MethodBase.LIST).buildUrl(parameters); + String webpage = httpTools.postRequest(url, jsonBody); + + try { + return MAPPER.readValue(webpage, MovieDbListStatus.class).getListId(); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to create list", url, ex); + } + } + + /** + * Check to see if a movie ID is already added to a list. + * + * @param listId + * @param movieId + * @return true if the movie is on the list + * @throws MovieDbException + */ + public boolean isMovieOnList(String listId, Integer movieId) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, movieId); + + URL url = new ApiUrl(apiKey, MethodBase.LIST).setSubMethod(listId, MethodSub.ITEM_STATUS).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, ListItemStatus.class).isItemPresent(); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get media status", url, ex); + } + } + + /** + * Modify a list + * + * @param sessionId + * @param listId + * @param movieId + * @param operation + * @return + * @throws MovieDbException + */ + public StatusCode modifyMovieList(String sessionId, String listId, Integer movieId, MethodSub operation) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.SESSION, sessionId); + + String jsonBody = new PostTools() + .add(PostBody.MEDIA_ID, movieId) + .build(); + + URL url = new ApiUrl(apiKey, MethodBase.LIST).setSubMethod(listId, operation).buildUrl(parameters); + String webpage = httpTools.postRequest(url, jsonBody); + + try { + return MAPPER.readValue(webpage, StatusCode.class); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to remove movie from list", url, ex); + } + } + + /** + * This method lets users delete a list that they created. A valid session + * id is required. + * + * @param sessionId + * @param listId + * @return + * @throws MovieDbException + */ + public StatusCode deleteMovieList(String sessionId, String listId) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, listId); + parameters.add(Param.SESSION, sessionId); + + URL url = new ApiUrl(apiKey, MethodBase.LIST).buildUrl(parameters); + String webpage = httpTools.deleteRequest(url); + + try { + return MAPPER.readValue(webpage, StatusCode.class); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to delete movie list", url, ex); + } + } } diff --git a/src/main/java/com/omertron/themoviedbapi/model/TBD_ExternalSource.java b/src/main/java/com/omertron/themoviedbapi/model/TBD_ExternalSource.java new file mode 100644 index 000000000..57b7c5c34 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/TBD_ExternalSource.java @@ -0,0 +1,44 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonRootName; + +/** + * @author stuart.boston + */ +@JsonRootName("???") +public class TBD_ExternalSource extends AbstractJsonMapping { + + private static final long serialVersionUID = 1L; + + // Properties + @JsonProperty("id") + private int id; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbJobs.java b/src/main/java/com/omertron/themoviedbapi/model/TBD_FindResults.java similarity index 64% rename from src/main/java/com/omertron/themoviedbapi/methods/TmdbJobs.java rename to src/main/java/com/omertron/themoviedbapi/model/TBD_FindResults.java index de588c3a9..5b0ffbcd3 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbJobs.java +++ b/src/main/java/com/omertron/themoviedbapi/model/TBD_FindResults.java @@ -17,24 +17,28 @@ * along with TheMovieDB API. If not, see . * */ -package com.omertron.themoviedbapi.methods; +package com.omertron.themoviedbapi.model; -import com.omertron.themoviedbapi.tools.HttpTools; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonRootName; /** - * Class to hold the Job Methods - * * @author stuart.boston */ -public class TmdbJobs extends AbstractMethod { +@JsonRootName("???") +public class TBD_FindResults extends AbstractJsonMapping { - /** - * Constructor - * - * @param apiKey - * @param httpTools - */ - public TmdbJobs(String apiKey, HttpTools httpTools) { - super(apiKey, httpTools); + private static final long serialVersionUID = 1L; + + // Properties + @JsonProperty("id") + private int id; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; } } diff --git a/src/main/java/com/omertron/themoviedbapi/model/TBD_PersonCredits.java b/src/main/java/com/omertron/themoviedbapi/model/TBD_PersonCredits.java new file mode 100644 index 000000000..f2d77b628 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/TBD_PersonCredits.java @@ -0,0 +1,44 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonRootName; + +/** + * @author stuart.boston + */ +@JsonRootName("???") +public class TBD_PersonCredits extends AbstractJsonMapping { + + private static final long serialVersionUID = 1L; + + // Properties + @JsonProperty("id") + private int id; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java b/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java index 198960765..275e0b251 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java @@ -30,6 +30,7 @@ public enum MethodBase { COLLECTION("collection"), COMPANY("company"), CONFIGURATION("configuration"), + CREDIT("credit"), DISCOVER("discover"), GENRE("genre"), JOB("job"), diff --git a/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java b/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java index 5afe05bdf..9b5df95f6 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java @@ -63,7 +63,8 @@ public enum MethodSub { ADD_ITEM("add_item"), REMOVE_ITEM("remove_item"), MOVIE_LIST("movie/list"), - TV_LIST("tv/list"); + TV_LIST("tv/list"), + TV("tv"); private final String value; diff --git a/src/main/java/com/omertron/themoviedbapi/tools/PostBody.java b/src/main/java/com/omertron/themoviedbapi/tools/PostBody.java new file mode 100644 index 000000000..f16eb3b5e --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/tools/PostBody.java @@ -0,0 +1,50 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.tools; + +/** + * List of values to use for the POST requests + * + * @author Stuart.Boston + */ +public enum PostBody { + + MEDIA_ID("media_id"), + MEDIA_TYPE("media_type"), + FAVORITE("favorite"), + WATCHLIST("watchlist"), + NAME("name"), + DESCRIPTION("description"); + + private final String value; + + private PostBody(String value) { + this.value = value; + } + + /** + * Get the URL parameter to use + * + * @return + */ + public String getValue() { + return this.value; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/tools/PostTools.java b/src/main/java/com/omertron/themoviedbapi/tools/PostTools.java new file mode 100644 index 000000000..c917f5d6b --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/tools/PostTools.java @@ -0,0 +1,71 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.tools; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.omertron.themoviedbapi.MovieDbException; +import java.util.HashMap; +import java.util.Map; +import org.yamj.api.common.exception.ApiExceptionType; + +/** + * + * @author Stuart.Boston + */ +public class PostTools { + + // Jackson JSON configuration + protected static final ObjectMapper MAPPER = new ObjectMapper(); + + private final Map values = new HashMap(); + + public PostTools() { + } + + public PostTools add(PostBody key, Object value) { + values.put(key.getValue(), value); + return this; + } + + public PostTools add(String key, Object value) { + values.put(key, value); + return this; + } + + public String build() throws MovieDbException { + return convertToJson(values); + } + + /** + * Use Jackson to convert Map to JSON string. + * + * @param map + * @return + * @throws MovieDbException + */ + private String convertToJson(Map map) throws MovieDbException { + try { + return MAPPER.writeValueAsString(map); + } catch (JsonProcessingException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "JSON conversion failed", "", ex); + } + } +} From 4b9580784567f328ec77da096c73a0a01c57a30c Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 16 Feb 2015 15:46:42 +0000 Subject: [PATCH 003/100] Updated --- .../themoviedbapi/model/TBD_Network.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/main/java/com/omertron/themoviedbapi/model/TBD_Network.java diff --git a/src/main/java/com/omertron/themoviedbapi/model/TBD_Network.java b/src/main/java/com/omertron/themoviedbapi/model/TBD_Network.java new file mode 100644 index 000000000..5b0ffbcd3 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/TBD_Network.java @@ -0,0 +1,44 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonRootName; + +/** + * @author stuart.boston + */ +@JsonRootName("???") +public class TBD_FindResults extends AbstractJsonMapping { + + private static final long serialVersionUID = 1L; + + // Properties + @JsonProperty("id") + private int id; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } +} From 9d396d32e581cc0bc4c58c274a056976db4ed467 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 16 Feb 2015 15:47:01 +0000 Subject: [PATCH 004/100] Updated --- .../omertron/themoviedbapi/TheMovieDbApi.java | 837 ++++++------------ .../themoviedbapi/methods/TmdbMovies.java | 567 ++++++++++++ .../themoviedbapi/methods/TmdbNetworks.java | 33 + .../themoviedbapi/model/TBD_Network.java | 2 +- .../themoviedbapi/tools/MethodBase.java | 1 + 5 files changed, 881 insertions(+), 559 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 91f62df72..3128da369 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -66,6 +66,7 @@ import com.omertron.themoviedbapi.model.Reviews; import com.omertron.themoviedbapi.model.StatusCode; import com.omertron.themoviedbapi.model.TBD_ExternalSource; import com.omertron.themoviedbapi.model.TBD_FindResults; +import com.omertron.themoviedbapi.model.TBD_Network; import com.omertron.themoviedbapi.model.TBD_PersonCredits; import com.omertron.themoviedbapi.model.TokenAuthorisation; import com.omertron.themoviedbapi.model.TokenSession; @@ -79,25 +80,17 @@ import com.omertron.themoviedbapi.tools.MethodBase; import com.omertron.themoviedbapi.tools.MethodSub; import com.omertron.themoviedbapi.tools.Param; import com.omertron.themoviedbapi.tools.TmdbParameters; -import com.omertron.themoviedbapi.wrapper.WrapperAlternativeTitles; import com.omertron.themoviedbapi.wrapper.WrapperCollection; import com.omertron.themoviedbapi.wrapper.WrapperCompany; import com.omertron.themoviedbapi.wrapper.WrapperImages; import com.omertron.themoviedbapi.wrapper.WrapperKeywords; import com.omertron.themoviedbapi.wrapper.WrapperMovie; -import com.omertron.themoviedbapi.wrapper.WrapperMovieCasts; -import com.omertron.themoviedbapi.wrapper.WrapperMovieKeywords; import com.omertron.themoviedbapi.wrapper.WrapperMovieList; import com.omertron.themoviedbapi.wrapper.WrapperPerson; 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.WrapperTranslations; -import com.omertron.themoviedbapi.wrapper.WrapperVideos; import java.io.IOException; import java.net.URL; -import java.util.Collections; import java.util.List; import java.util.Map; import org.apache.commons.lang3.StringUtils; @@ -124,8 +117,6 @@ public class TheMovieDbApi { private static final ObjectMapper MAPPER = new ObjectMapper(); // Constants private static final int YEAR_LENGTH = 4; - private static final int RATING_MAX = 10; - private static final int POST_SUCCESS_STATUS_CODE = 12; // Sub-methods private static TmdbAccount tmdbAccount; private static TmdbAuthentication tmdbAuth; @@ -296,554 +287,6 @@ public class TheMovieDbApi { return StringUtils.isNotBlank(year) && !"UNKNOWN".equals(year); } - /** - * This method is used to retrieve all of the basic movie information. - * - * It will return the single highest rated poster and backdrop. - * - * ApiExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies - * found. - * - * @param movieId - * @param language - * @param appendToResponse - * @return - * @throws MovieDbException - */ - public MovieDb getMovieInfo(int movieId, String language, String... appendToResponse) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, movieId); - parameters.add(Param.LANGUAGE, language); - parameters.add(Param.APPEND, appendToResponse); - - URL url = new ApiUrl(apiKey, MethodBase.MOVIE).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - try { - MovieDb movie = MAPPER.readValue(webpage, MovieDb.class); - if (movie == null || movie.getId() == 0) { - LOG.warn("No movie found for ID '{}'", movieId); - throw new MovieDbException(ApiExceptionType.ID_NOT_FOUND, "No movie found for ID: " + movieId, url); - } - return movie; - } catch (IOException ex) { - LOG.warn("Failed to get movie info: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * This method is used to retrieve all of the basic movie information. - * - * It will return the single highest rated poster and backdrop. - * - * ApiExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies - * found. - * - * @param imdbId - * @param language - * @param appendToResponse - * @return - * @throws MovieDbException - */ - public MovieDb getMovieInfoImdb(String imdbId, String language, String... appendToResponse) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, imdbId); - parameters.add(Param.LANGUAGE, language); - parameters.add(Param.APPEND, appendToResponse); - - URL url = new ApiUrl(apiKey, MethodBase.MOVIE).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - MovieDb movie = MAPPER.readValue(webpage, MovieDb.class); - if (movie == null || movie.getId() == 0) { - LOG.warn("No movie found for IMDB ID: '{}'", imdbId); - throw new MovieDbException(ApiExceptionType.ID_NOT_FOUND, "No movie found for IMDB ID: " + imdbId, url); - } - return movie; - } catch (IOException ex) { - LOG.warn("Failed to get movie info: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get movie info", url, ex); - } - } - - /** - * This method is used to retrieve all of the alternative titles we have for - * a particular movie. - * - * @param movieId - * @param country - * @param appendToResponse - * @return - * @throws MovieDbException - */ - public TmdbResultsList getMovieAlternativeTitles(int movieId, String country, String... appendToResponse) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, movieId); - parameters.add(Param.COUNTRY, country); - parameters.add(Param.APPEND, appendToResponse); - - URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.ALT_TITLES).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - try { - WrapperAlternativeTitles wrapper = MAPPER.readValue(webpage, WrapperAlternativeTitles.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getTitles()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - LOG.warn("Failed to get movie alternative titles: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * Get the cast information for a specific movie id. - * - * TODO: Add a function to enrich the data with the people methods - * - * @param movieId - * @param appendToResponse - * @return - * @throws MovieDbException - */ - public TmdbResultsList getMovieCasts(int movieId, String... appendToResponse) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, movieId); - parameters.add(Param.APPEND, appendToResponse); - - URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.CASTS).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperMovieCasts wrapper = MAPPER.readValue(webpage, WrapperMovieCasts.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getAll()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - LOG.warn("Failed to get movie casts: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * This method should be used when you’re wanting to retrieve all of the - * images for a particular movie. - * - * @param movieId - * @param language - * @param appendToResponse - * @return - * @throws MovieDbException - */ - public TmdbResultsList getMovieImages(int movieId, String language, String... appendToResponse) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, movieId); - parameters.add(Param.LANGUAGE, language); - parameters.add(Param.APPEND, appendToResponse); - - URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.IMAGES).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperImages wrapper = MAPPER.readValue(webpage, WrapperImages.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getAll()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - LOG.warn("Failed to get movie images: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * This method is used to retrieve all of the keywords that have been added - * to a particular movie. - * - * Currently, only English keywords exist. - * - * @param movieId - * @param appendToResponse - * @return - * @throws MovieDbException - */ - public TmdbResultsList getMovieKeywords(int movieId, String... appendToResponse) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, movieId); - parameters.add(Param.APPEND, appendToResponse); - - URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.KEYWORDS).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperMovieKeywords wrapper = MAPPER.readValue(webpage, WrapperMovieKeywords.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getKeywords()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - LOG.warn("Failed to get movie keywords: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * This method is used to retrieve all of the release and certification data - * we have for a specific movie. - * - * @param movieId - * @param language - * @param appendToResponse - * @return - * @throws MovieDbException - */ - public TmdbResultsList getMovieReleaseInfo(int movieId, String language, String... appendToResponse) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, movieId); - parameters.add(Param.LANGUAGE, language); - parameters.add(Param.APPEND, appendToResponse); - - URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.RELEASES).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperReleaseInfo wrapper = MAPPER.readValue(webpage, WrapperReleaseInfo.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getCountries()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - LOG.warn("Failed to get movie release information: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * This method is used to retrieve all of the trailers for a particular - * movie. - * - * Supported sites are YouTube and QuickTime. - * - * @param movieId - * @param language - * @param appendToResponse - * @return - * @throws MovieDbException - */ - public TmdbResultsList
// + /** + * This method is used to retrieve all of the basic movie information. + * + * It will return the single highest rated poster and backdrop. + * + * ApiExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies + * found. + * + * @param movieId + * @param language + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public MovieDb getMovieInfo(int movieId, String language, String... appendToResponse) throws MovieDbException { + return tmdbMovies.getMovieInfo(movieId, language, appendToResponse); + } + + /** + * This method is used to retrieve all of the basic movie information. + * + * It will return the single highest rated poster and backdrop. + * + * ApiExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies + * found. + * + * @param imdbId + * @param language + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public MovieDb getMovieInfoImdb(String imdbId, String language, String... appendToResponse) throws MovieDbException { + return tmdbMovies.getMovieInfoImdb(imdbId, language, appendToResponse); + } + + /** + * This method is used to retrieve all of the alternative titles we have for + * a particular movie. + * + * @param movieId + * @param country + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public TmdbResultsList getMovieAlternativeTitles(int movieId, String country, String... appendToResponse) throws MovieDbException { + return tmdbMovies.getMovieAlternativeTitles(movieId, country, appendToResponse); + } + + /** + * Get the cast information for a specific movie id. + * + * TODO: Add a function to enrich the data with the people methods + * + * @param movieId + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public TmdbResultsList getMovieCasts(int movieId, String... appendToResponse) throws MovieDbException { + return tmdbMovies.getMovieCasts(movieId, appendToResponse); + } + + /** + * This method should be used when you’re wanting to retrieve all of the + * images for a particular movie. + * + * @param movieId + * @param language + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public TmdbResultsList getMovieImages(int movieId, String language, String... appendToResponse) throws MovieDbException { + return tmdbMovies.getMovieImages(movieId, language, appendToResponse); + } + + /** + * This method is used to retrieve all of the keywords that have been added + * to a particular movie. + * + * Currently, only English keywords exist. + * + * @param movieId + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public TmdbResultsList getMovieKeywords(int movieId, String... appendToResponse) throws MovieDbException { + return tmdbMovies.getMovieKeywords(movieId, appendToResponse); + } + + /** + * This method is used to retrieve all of the release and certification data + * we have for a specific movie. + * + * @param movieId + * @param language + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public TmdbResultsList getMovieReleaseInfo(int movieId, String language, String... appendToResponse) throws MovieDbException { + return tmdbMovies.getMovieReleaseInfo(movieId, language, appendToResponse); + } + + /** + * This method is used to retrieve all of the trailers for a particular + * movie. + * + * Supported sites are YouTube and QuickTime. + * + * @param movieId + * @param language + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public TmdbResultsList + // + /** + * This method is used to retrieve the basic information about a TV network. + *

+ * You can use this ID to search for TV shows with the discover method. + * + * @param networkId + * @return + * @throws MovieDbException + */ + public TBD_Network getNetworkInfo(int networkId) throws MovieDbException { + return tmdbNetworks.getNetworkInfo(networkId); + } // + // // // diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java index a505c8fa1..54cd7b9d8 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java @@ -19,7 +19,40 @@ */ package com.omertron.themoviedbapi.methods; +import com.omertron.themoviedbapi.MovieDbException; +import static com.omertron.themoviedbapi.TheMovieDbApi.convertToJson; +import com.omertron.themoviedbapi.model.AlternativeTitle; +import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model.Keyword; +import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.model.MovieList; +import com.omertron.themoviedbapi.model.Person; +import com.omertron.themoviedbapi.model.ReleaseInfo; +import com.omertron.themoviedbapi.model.Reviews; +import com.omertron.themoviedbapi.model.StatusCode; +import com.omertron.themoviedbapi.model.Translation; +import com.omertron.themoviedbapi.model.Video; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; +import com.omertron.themoviedbapi.tools.MethodBase; +import com.omertron.themoviedbapi.tools.MethodSub; +import com.omertron.themoviedbapi.tools.Param; +import com.omertron.themoviedbapi.tools.TmdbParameters; +import com.omertron.themoviedbapi.wrapper.WrapperAlternativeTitles; +import com.omertron.themoviedbapi.wrapper.WrapperImages; +import com.omertron.themoviedbapi.wrapper.WrapperMovie; +import com.omertron.themoviedbapi.wrapper.WrapperMovieCasts; +import com.omertron.themoviedbapi.wrapper.WrapperMovieKeywords; +import com.omertron.themoviedbapi.wrapper.WrapperMovieList; +import com.omertron.themoviedbapi.wrapper.WrapperReleaseInfo; +import com.omertron.themoviedbapi.wrapper.WrapperReviews; +import com.omertron.themoviedbapi.wrapper.WrapperTranslations; +import com.omertron.themoviedbapi.wrapper.WrapperVideos; +import java.io.IOException; +import java.net.URL; +import java.util.Collections; +import org.yamj.api.common.exception.ApiExceptionType; /** * Class to hold the Movie Methods @@ -28,6 +61,9 @@ import com.omertron.themoviedbapi.tools.HttpTools; */ public class TmdbMovies extends AbstractMethod { + private static final int RATING_MAX = 10; + private static final int POST_SUCCESS_STATUS_CODE = 12; + /** * Constructor * @@ -37,4 +73,535 @@ public class TmdbMovies extends AbstractMethod { public TmdbMovies(String apiKey, HttpTools httpTools) { super(apiKey, httpTools); } + + /** + * This method is used to retrieve all of the basic movie information. + * + * It will return the single highest rated poster and backdrop. + * + * ApiExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies + * found. + * + * @param movieId + * @param language + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public MovieDb getMovieInfo(int movieId, String language, String... appendToResponse) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, movieId); + parameters.add(Param.LANGUAGE, language); + parameters.add(Param.APPEND, appendToResponse); + + URL url = new ApiUrl(apiKey, MethodBase.MOVIE).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + try { + MovieDb movie = MAPPER.readValue(webpage, MovieDb.class); + if (movie == null || movie.getId() == 0) { + LOG.warn("No movie found for ID '{}'", movieId); + throw new MovieDbException(ApiExceptionType.ID_NOT_FOUND, "No movie found for ID: " + movieId, url); + } + return movie; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get movie info", url, ex); + } + } + + /** + * This method is used to retrieve all of the basic movie information. + * + * It will return the single highest rated poster and backdrop. + * + * ApiExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies + * found. + * + * @param imdbId + * @param language + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public MovieDb getMovieInfoImdb(String imdbId, String language, String... appendToResponse) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, imdbId); + parameters.add(Param.LANGUAGE, language); + parameters.add(Param.APPEND, appendToResponse); + + URL url = new ApiUrl(apiKey, MethodBase.MOVIE).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + MovieDb movie = MAPPER.readValue(webpage, MovieDb.class); + if (movie == null || movie.getId() == 0) { + throw new MovieDbException(ApiExceptionType.ID_NOT_FOUND, "No movie found for IMDB ID: " + imdbId, url); + } + return movie; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get movie info", url, ex); + } + } + + /** + * This method is used to retrieve all of the alternative titles we have for + * a particular movie. + * + * @param movieId + * @param country + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public TmdbResultsList getMovieAlternativeTitles(int movieId, String country, String... appendToResponse) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, movieId); + parameters.add(Param.COUNTRY, country); + parameters.add(Param.APPEND, appendToResponse); + + URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.ALT_TITLES).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + try { + WrapperAlternativeTitles wrapper = MAPPER.readValue(webpage, WrapperAlternativeTitles.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getTitles()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get movie alternative titles", url, ex); + } + } + + /** + * Get the cast information for a specific movie id. + * + * TODO: Add a function to enrich the data with the people methods + * + * @param movieId + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public TmdbResultsList getMovieCasts(int movieId, String... appendToResponse) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, movieId); + parameters.add(Param.APPEND, appendToResponse); + + URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.CASTS).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + WrapperMovieCasts wrapper = MAPPER.readValue(webpage, WrapperMovieCasts.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getAll()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get movie casts", url, ex); + } + } + + /** + * This method should be used when you’re wanting to retrieve all of the + * images for a particular movie. + * + * @param movieId + * @param language + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public TmdbResultsList getMovieImages(int movieId, String language, String... appendToResponse) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, movieId); + parameters.add(Param.LANGUAGE, language); + parameters.add(Param.APPEND, appendToResponse); + + URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.IMAGES).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + WrapperImages wrapper = MAPPER.readValue(webpage, WrapperImages.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getAll()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get movie images", url, ex); + } + } + + /** + * This method is used to retrieve all of the keywords that have been added + * to a particular movie. + * + * Currently, only English keywords exist. + * + * @param movieId + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public TmdbResultsList getMovieKeywords(int movieId, String... appendToResponse) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, movieId); + parameters.add(Param.APPEND, appendToResponse); + + URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.KEYWORDS).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + WrapperMovieKeywords wrapper = MAPPER.readValue(webpage, WrapperMovieKeywords.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getKeywords()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get movie keywords", url, ex); + } + } + + /** + * This method is used to retrieve all of the release and certification data + * we have for a specific movie. + * + * @param movieId + * @param language + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public TmdbResultsList getMovieReleaseInfo(int movieId, String language, String... appendToResponse) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, movieId); + parameters.add(Param.LANGUAGE, language); + parameters.add(Param.APPEND, appendToResponse); + + URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.RELEASES).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + WrapperReleaseInfo wrapper = MAPPER.readValue(webpage, WrapperReleaseInfo.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getCountries()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get movie release information", url, ex); + } + } + + /** + * This method is used to retrieve all of the trailers for a particular + * movie. + * + * Supported sites are YouTube and QuickTime. + * + * @param movieId + * @param language + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public TmdbResultsList

+ * You can use this ID to search for TV shows with the discover method. + * + * @param networkId + * @return + * @throws MovieDbException + */ + public TBD_Network getNetworkInfo(int networkId) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, networkId); + + URL url = new ApiUrl(apiKey, MethodBase.NETWORK).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, TBD_Network.class); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get network information", url, ex); + } + } + } diff --git a/src/main/java/com/omertron/themoviedbapi/model/TBD_Network.java b/src/main/java/com/omertron/themoviedbapi/model/TBD_Network.java index 5b0ffbcd3..540df4792 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/TBD_Network.java +++ b/src/main/java/com/omertron/themoviedbapi/model/TBD_Network.java @@ -26,7 +26,7 @@ import com.fasterxml.jackson.annotation.JsonRootName; * @author stuart.boston */ @JsonRootName("???") -public class TBD_FindResults extends AbstractJsonMapping { +public class TBD_Network extends AbstractJsonMapping { private static final long serialVersionUID = 1L; diff --git a/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java b/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java index 275e0b251..a1f7a27a3 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java @@ -37,6 +37,7 @@ public enum MethodBase { KEYWORD("keyword"), LIST("list"), MOVIE("movie"), + NETWORK("network"), PERSON("person"), SEARCH("search"), TV("tv"); From c3edbc2aad6a8567977ad229e1a3de610cee6239 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 16 Feb 2015 17:18:05 +0000 Subject: [PATCH 005/100] Update exception messages --- .../omertron/themoviedbapi/TheMovieDbApi.java | 19 +------- .../themoviedbapi/methods/TmdbAccount.java | 3 +- .../methods/TmdbAuthentication.java | 14 ++---- .../methods/TmdbConfiguration.java | 3 +- .../themoviedbapi/methods/TmdbKeywords.java | 6 +-- .../themoviedbapi/methods/TmdbMovies.java | 48 +++++++------------ .../themoviedbapi/tools/PostBody.java | 3 +- 7 files changed, 30 insertions(+), 66 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 3128da369..2fb1b6952 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -19,7 +19,6 @@ */ package com.omertron.themoviedbapi; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.omertron.themoviedbapi.enumeration.MediaType; import com.omertron.themoviedbapi.methods.TmdbAccount; @@ -92,7 +91,6 @@ import com.omertron.themoviedbapi.wrapper.WrapperPersonList; import java.io.IOException; import java.net.URL; import java.util.List; -import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.apache.http.impl.client.CloseableHttpClient; import org.slf4j.Logger; @@ -611,21 +609,6 @@ public class TheMovieDbApi { } } - /** - * Use Jackson to convert Map to JSON string. - * - * @param map - * @return - * @throws MovieDbException - */ - public static String convertToJson(Map map) throws MovieDbException { - try { - return MAPPER.writeValueAsString(map); - } catch (JsonProcessingException jpe) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "JSON conversion failed", "", jpe); - } - } - // /** * Get the basic information for an account. You will need to have a valid @@ -1584,7 +1567,9 @@ public class TheMovieDbApi { // // + // + // // // diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java index 2516f26f6..cf9bf2b6d 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java @@ -271,8 +271,7 @@ public class TmdbAccount extends AbstractMethod { try { return MAPPER.readValue(webpage, StatusCode.class); } catch (IOException ex) { - LOG.warn("Failed to modify watch list: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to modify watch list", url, ex); } } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAuthentication.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAuthentication.java index 788d87fc8..f378bc7c1 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAuthentication.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAuthentication.java @@ -70,8 +70,7 @@ public class TmdbAuthentication extends AbstractMethod { try { return MAPPER.readValue(webpage, TokenAuthorisation.class); } catch (IOException ex) { - LOG.warn("Failed to get Authorisation Token: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.AUTH_FAILURE, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.AUTH_FAILURE, "Failed to get Authorisation Token", url, ex); } } @@ -88,7 +87,6 @@ public class TmdbAuthentication extends AbstractMethod { TmdbParameters parameters = new TmdbParameters(); if (!token.getSuccess()) { - LOG.warn("Session token was not successful!"); throw new MovieDbException(ApiExceptionType.AUTH_FAILURE, "Authorisation token was not successful!"); } @@ -99,8 +97,7 @@ public class TmdbAuthentication extends AbstractMethod { try { return MAPPER.readValue(webpage, TokenSession.class); } catch (IOException ex) { - LOG.warn("Failed to get Session Token: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get Session Token", url, ex); } } @@ -119,7 +116,6 @@ public class TmdbAuthentication extends AbstractMethod { TmdbParameters parameters = new TmdbParameters(); if (!token.getSuccess()) { - LOG.warn("Session token was not successful!"); throw new MovieDbException(ApiExceptionType.AUTH_FAILURE, "Authorisation token was not successful!"); } @@ -133,8 +129,7 @@ public class TmdbAuthentication extends AbstractMethod { try { return MAPPER.readValue(webpage, TokenAuthorisation.class); } catch (IOException ex) { - LOG.warn("Failed to get Session Token: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get Session Token", url, ex); } } @@ -160,7 +155,6 @@ public class TmdbAuthentication extends AbstractMethod { try { return MAPPER.readValue(webpage, TokenSession.class); } catch (IOException ex) { - LOG.warn("Failed to get Guest Session Token: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get Guest Session Token", url, ex); } }} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java index 5e6218a5f..81b7f5ce5 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java @@ -119,8 +119,7 @@ public class TmdbConfiguration extends AbstractMethod { results.copyWrapper(wrapper); return results; } catch (IOException ex) { - LOG.warn("Failed to get job list: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get job list", url, ex); } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbKeywords.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbKeywords.java index 0dfa70df1..7b5ca4e0b 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbKeywords.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbKeywords.java @@ -68,8 +68,7 @@ public class TmdbKeywords extends AbstractMethod { try { return MAPPER.readValue(webpage, Keyword.class); } catch (IOException ex) { - LOG.warn("Failed to get keyword: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get keyword " + keywordId, url, ex); } } @@ -98,8 +97,7 @@ public class TmdbKeywords extends AbstractMethod { results.copyWrapper(wrapper); return results; } catch (IOException ex) { - LOG.warn("Failed to get keyword movies: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get keyword movies", url, ex); } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java index 54cd7b9d8..ee6e1d8f9 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java @@ -20,7 +20,6 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; -import static com.omertron.themoviedbapi.TheMovieDbApi.convertToJson; import com.omertron.themoviedbapi.model.AlternativeTitle; import com.omertron.themoviedbapi.model.Artwork; import com.omertron.themoviedbapi.model.Keyword; @@ -38,6 +37,8 @@ import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; import com.omertron.themoviedbapi.tools.MethodSub; import com.omertron.themoviedbapi.tools.Param; +import com.omertron.themoviedbapi.tools.PostBody; +import com.omertron.themoviedbapi.tools.PostTools; import com.omertron.themoviedbapi.tools.TmdbParameters; import com.omertron.themoviedbapi.wrapper.WrapperAlternativeTitles; import com.omertron.themoviedbapi.wrapper.WrapperImages; @@ -51,7 +52,6 @@ import com.omertron.themoviedbapi.wrapper.WrapperTranslations; import com.omertron.themoviedbapi.wrapper.WrapperVideos; import java.io.IOException; import java.net.URL; -import java.util.Collections; import org.yamj.api.common.exception.ApiExceptionType; /** @@ -79,8 +79,7 @@ public class TmdbMovies extends AbstractMethod { * * 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 @@ -99,7 +98,6 @@ public class TmdbMovies extends AbstractMethod { try { MovieDb movie = MAPPER.readValue(webpage, MovieDb.class); if (movie == null || movie.getId() == 0) { - LOG.warn("No movie found for ID '{}'", movieId); throw new MovieDbException(ApiExceptionType.ID_NOT_FOUND, "No movie found for ID: " + movieId, url); } return movie; @@ -113,8 +111,7 @@ public class TmdbMovies extends AbstractMethod { * * 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 @@ -143,8 +140,7 @@ public class TmdbMovies extends AbstractMethod { } /** - * 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 @@ -199,8 +195,7 @@ public class TmdbMovies extends AbstractMethod { } /** - * This method should be used when you’re wanting to retrieve all of the - * images for a particular movie. + * This method should be used when you’re wanting to retrieve all of the images for a particular movie. * * @param movieId * @param language @@ -228,8 +223,7 @@ public class TmdbMovies extends AbstractMethod { } /** - * 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. * @@ -257,8 +251,7 @@ public class TmdbMovies extends AbstractMethod { } /** - * 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 @@ -286,8 +279,7 @@ public class TmdbMovies extends AbstractMethod { } /** - * 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. * @@ -317,8 +309,7 @@ public class TmdbMovies extends AbstractMethod { } /** - * 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 @@ -344,11 +335,9 @@ public class TmdbMovies extends AbstractMethod { } /** - * 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 * @@ -480,8 +469,7 @@ public class TmdbMovies extends AbstractMethod { /** * 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 * @@ -539,8 +527,7 @@ public class TmdbMovies extends AbstractMethod { } /** - * 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. * @@ -590,7 +577,9 @@ public class TmdbMovies extends AbstractMethod { URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(movieId, MethodSub.RATING).buildUrl(parameters); - String jsonBody = convertToJson(Collections.singletonMap("value", rating)); + String jsonBody = new PostTools() + .add(PostBody.VALUE, rating) + .build(); String webpage = httpTools.postRequest(url, jsonBody); try { @@ -599,8 +588,7 @@ public class TmdbMovies extends AbstractMethod { int code = status.getStatusCode(); return code == POST_SUCCESS_STATUS_CODE; } catch (IOException ex) { - LOG.warn("Failed to post movie rating: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to post movie rating", url, ex); } } diff --git a/src/main/java/com/omertron/themoviedbapi/tools/PostBody.java b/src/main/java/com/omertron/themoviedbapi/tools/PostBody.java index f16eb3b5e..e567de720 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/PostBody.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/PostBody.java @@ -31,7 +31,8 @@ public enum PostBody { FAVORITE("favorite"), WATCHLIST("watchlist"), NAME("name"), - DESCRIPTION("description"); + DESCRIPTION("description"), + VALUE("value"); private final String value; From 1e01a4e7df703d2b27762c23f7645ca5d3af2058 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 16 Feb 2015 18:14:22 +0000 Subject: [PATCH 006/100] Add People --- .../omertron/themoviedbapi/TheMovieDbApi.java | 384 ++++++------------ .../themoviedbapi/methods/TmdbPeople.java | 138 +++++++ 2 files changed, 269 insertions(+), 253 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 2fb1b6952..491944c49 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -43,7 +43,6 @@ import com.omertron.themoviedbapi.methods.TmdbTV; import com.omertron.themoviedbapi.model.Account; import com.omertron.themoviedbapi.model.AlternativeTitle; import com.omertron.themoviedbapi.model.Artwork; -import com.omertron.themoviedbapi.model.ArtworkType; import com.omertron.themoviedbapi.model.Certification; import com.omertron.themoviedbapi.model.ChangedMedia; import com.omertron.themoviedbapi.model.Collection; @@ -81,13 +80,10 @@ import com.omertron.themoviedbapi.tools.Param; import com.omertron.themoviedbapi.tools.TmdbParameters; import com.omertron.themoviedbapi.wrapper.WrapperCollection; import com.omertron.themoviedbapi.wrapper.WrapperCompany; -import com.omertron.themoviedbapi.wrapper.WrapperImages; import com.omertron.themoviedbapi.wrapper.WrapperKeywords; import com.omertron.themoviedbapi.wrapper.WrapperMovie; import com.omertron.themoviedbapi.wrapper.WrapperMovieList; import com.omertron.themoviedbapi.wrapper.WrapperPerson; -import com.omertron.themoviedbapi.wrapper.WrapperPersonCredits; -import com.omertron.themoviedbapi.wrapper.WrapperPersonList; import java.io.IOException; import java.net.URL; import java.util.List; @@ -101,8 +97,7 @@ import org.yamj.api.common.http.SimpleHttpClientBuilder; /** * The MovieDb API *

- * 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 */ @@ -205,8 +200,7 @@ 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. */ @@ -286,154 +280,13 @@ public class TheMovieDbApi { } /** - * This method is used to retrieve all of the basic person information. - * - * It will return the single highest rated profile image. - * - * @param personId - * @param appendToResponse - * @return - * @throws MovieDbException - */ - public Person getPersonInfo(int personId, String... appendToResponse) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, personId); - parameters.add(Param.APPEND, appendToResponse); - - URL url = new ApiUrl(apiKey, MethodBase.PERSON).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - return MAPPER.readValue(webpage, Person.class); - } catch (IOException ex) { - LOG.warn("Failed to get person info: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * 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. - * - * @param personId - * @param appendToResponse - * @return - * @throws MovieDbException - */ - public TmdbResultsList getPersonCredits(int personId, String... appendToResponse) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, personId); - parameters.add(Param.APPEND, appendToResponse); - - URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.CREDITS).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperPersonCredits wrapper = MAPPER.readValue(webpage, WrapperPersonCredits.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getAll()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - LOG.warn("Failed to get person credits: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * This method is used to retrieve all of the profile images for a person. - * - * @param personId - * @return - * @throws MovieDbException - */ - public TmdbResultsList getPersonImages(int personId) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, personId); - - URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.IMAGES).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperImages wrapper = MAPPER.readValue(webpage, WrapperImages.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getAll(ArtworkType.PROFILE)); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - LOG.warn("Failed to get person images: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * Get the list of popular people on The Movie Database. - * - * This list refreshes every day. - * - * @return - * @throws MovieDbException - */ - public TmdbResultsList getPersonPopular() throws MovieDbException { - return getPersonPopular(0); - } - - /** - * Get the list of popular people on The Movie Database. - * - * This list refreshes every day. - * - * @param page - * @return - * @throws MovieDbException - */ - public TmdbResultsList getPersonPopular(int page) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.PAGE, page); - - URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.POPULAR).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperPersonList wrapper = MAPPER.readValue(webpage, WrapperPersonList.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getPersonList()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - LOG.warn("Failed to get popular person: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * Get the latest person id. - * - * @return - * @throws MovieDbException - */ - public Person getPersonLatest() throws MovieDbException { - URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.LATEST).buildUrl(); - String webpage = httpTools.getRequest(url); - - try { - return MAPPER.readValue(webpage, Person.class); - } catch (IOException ex) { - LOG.warn("Failed to get latest person: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * 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 */ @@ -492,8 +345,7 @@ 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 @@ -553,8 +405,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 * @@ -611,8 +463,7 @@ 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 @@ -752,16 +603,13 @@ public class TheMovieDbApi { // /** - * 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 @@ -771,8 +619,7 @@ 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. * @@ -785,8 +632,7 @@ public class TheMovieDbApi { } /** - * This method is used to generate a session id for user based - * authentication. User must provide their username and password + * This method is used to generate a session id for user based authentication. User must provide their username and password * * A session id is required in order to use any of the write methods. * @@ -803,18 +649,14 @@ 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 @@ -854,13 +696,11 @@ 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 id * @param startDate the start date of the changes, optional @@ -879,13 +719,11 @@ 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 id * @param startDate the start date of the changes, optional @@ -904,8 +742,7 @@ 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. * @@ -922,8 +759,7 @@ public class TheMovieDbApi { /** * Get a list of Movie IDs that have been edited. * - * You can then use the movie changes API to get the actual data that has - * been changed. + * You can then use the movie changes API to get the actual data that has been changed. * * @param page * @param startDate the start date of the changes, optional @@ -938,8 +774,7 @@ public class TheMovieDbApi { /** * Get a list of TV IDs that have been edited. * - * You can then use the TV changes API to get the actual data that has been - * changed. + * You can then use the TV changes API to get the actual data that has been changed. * * @param page * @param startDate the start date of the changes, optional @@ -954,8 +789,7 @@ public class TheMovieDbApi { /** * Get a list of Person IDs that have been edited. * - * You can then use the person changes API to get the actual data that has - * been changed. + * You can then use the person changes API to get the actual data that has been changed. * * @param page * @param startDate the start date of the changes, optional @@ -970,11 +804,9 @@ public class TheMovieDbApi { // /** - * 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 @@ -1000,8 +832,7 @@ public class TheMovieDbApi { // /** - * 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 @@ -1014,8 +845,7 @@ 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 * @@ -1070,14 +900,11 @@ public class TheMovieDbApi { *

* This is currently only supported with the new credit model found in TV. *
- * These IDs can be found from any TV credit response as well as the - * TV_credits and combined_credits methods for people.
- * The episodes object returns a list of episodes and are generally going to - * be guest stars.
+ * These IDs can be found from any TV credit response as well as the TV_credits and combined_credits methods for people.
+ * The episodes object returns a list of episodes and are generally going to be guest stars.
* The season array will return a list of season numbers.
- * Season credits are credits that were marked with the "add to every - * season" option in the editing interface and are assumed to be "season - * regulars". + * Season credits are credits that were marked with the "add to every season" option in the editing interface and are assumed to + * be "season regulars". * * @param creditId * @param language @@ -1091,8 +918,7 @@ 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 @@ -1103,8 +929,7 @@ 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 @@ -1117,18 +942,16 @@ public class TheMovieDbApi { // /** - * You con use this method to find movies, tv series or persons using - * external ids. + * You con use this method to find movies, tv series or persons using external ids. * * Supported query ids are *

    *
  • Movies: imdb_id
  • *
  • People: imdb_id, freebase_mid, freebase_id, tvrage_id
  • - *
  • TV Series: imdb_id, freebase_mid, freebase_id, tvdb_id, - * tvrage_id
  • + *
  • TV Series: imdb_id, freebase_mid, freebase_id, tvdb_id, tvrage_id
  • *
  • TV Seasons: freebase_mid, freebase_id, tvdb_id, tvrage_id
  • - *
  • TV Episodes: imdb_id, freebase_mid, freebase_id, tvdb_id, - * tvrage_idimdb_id, freebase_mid, freebase_id, tvrage_id, tvdb_id. + *
  • TV Episodes: imdb_id, freebase_mid, freebase_id, tvdb_id, tvrage_idimdb_id, freebase_mid, freebase_id, tvrage_id, + * tvdb_id. *
* * For details see http://docs.themoviedb.apiary.io/#find @@ -1161,11 +984,9 @@ 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 @@ -1243,8 +1064,7 @@ 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 @@ -1257,8 +1077,7 @@ 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 @@ -1271,8 +1090,7 @@ 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 @@ -1290,8 +1108,7 @@ 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 @@ -1308,8 +1125,7 @@ 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 @@ -1322,8 +1138,7 @@ 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 @@ -1350,8 +1165,7 @@ public class TheMovieDbApi { } /** - * This method should be used when you’re wanting to retrieve all of the - * images for a particular movie. + * This method should be used when you’re wanting to retrieve all of the images for a particular movie. * * @param movieId * @param language @@ -1364,8 +1178,7 @@ 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. * @@ -1379,8 +1192,7 @@ 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 @@ -1393,8 +1205,7 @@ 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. * @@ -1409,8 +1220,7 @@ 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 @@ -1422,11 +1232,9 @@ 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 * @@ -1488,8 +1296,7 @@ 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 * @@ -1519,8 +1326,7 @@ 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. * @@ -1567,9 +1373,81 @@ public class TheMovieDbApi { //
// + /** + * This method is used to retrieve all of the basic person information. + * + * It will return the single highest rated profile image. + * + * @param personId + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public Person getPersonInfo(int personId, String... appendToResponse) throws MovieDbException { + return tmdbPeople.getPersonInfo(personId, appendToResponse); + } + /** + * 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. + * + * @param personId + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public TmdbResultsList getPersonCredits(int personId, String... appendToResponse) throws MovieDbException { + return tmdbPeople.getPersonCredits(personId, appendToResponse); + } + + /** + * This method is used to retrieve all of the profile images for a person. + * + * @param personId + * @return + * @throws MovieDbException + */ + public TmdbResultsList getPersonImages(int personId) throws MovieDbException { + return tmdbPeople.getPersonImages(personId); + } + + /** + * Get the list of popular people on The Movie Database. + * + * This list refreshes every day. + * + * @return + * @throws MovieDbException + */ + public TmdbResultsList getPersonPopular() throws MovieDbException { + return tmdbPeople.getPersonPopular(0); + } + + /** + * Get the list of popular people on The Movie Database. + * + * This list refreshes every day. + * + * @param page + * @return + * @throws MovieDbException + */ + public TmdbResultsList getPersonPopular(int page) throws MovieDbException { + return tmdbPeople.getPersonPopular(page); + } + + /** + * Get the latest person id. + * + * @return + * @throws MovieDbException + */ + public Person getPersonLatest() throws MovieDbException { + return tmdbPeople.getPersonLatest(); + } // - + // // // diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java index 59bdd1937..431151b81 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java @@ -19,7 +19,24 @@ */ package com.omertron.themoviedbapi.methods; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model.ArtworkType; +import com.omertron.themoviedbapi.model.Person; +import com.omertron.themoviedbapi.model.PersonCredit; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; +import com.omertron.themoviedbapi.tools.MethodBase; +import com.omertron.themoviedbapi.tools.MethodSub; +import com.omertron.themoviedbapi.tools.Param; +import com.omertron.themoviedbapi.tools.TmdbParameters; +import com.omertron.themoviedbapi.wrapper.WrapperImages; +import com.omertron.themoviedbapi.wrapper.WrapperPersonCredits; +import com.omertron.themoviedbapi.wrapper.WrapperPersonList; +import java.io.IOException; +import java.net.URL; +import org.yamj.api.common.exception.ApiExceptionType; /** * Class to hold the People Methods @@ -37,4 +54,125 @@ public class TmdbPeople extends AbstractMethod { public TmdbPeople(String apiKey, HttpTools httpTools) { super(apiKey, httpTools); } + + /** + * This method is used to retrieve all of the basic person information. + * + * It will return the single highest rated profile image. + * + * @param personId + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public Person getPersonInfo(int personId, String... appendToResponse) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, personId); + parameters.add(Param.APPEND, appendToResponse); + + URL url = new ApiUrl(apiKey, MethodBase.PERSON).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, Person.class); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person info", url, ex); + } + } + + /** + * 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. + * + * @param personId + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public TmdbResultsList getPersonCredits(int personId, String... appendToResponse) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, personId); + parameters.add(Param.APPEND, appendToResponse); + + URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.CREDITS).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + WrapperPersonCredits wrapper = MAPPER.readValue(webpage, WrapperPersonCredits.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getAll()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person credits", url, ex); + } + } + + /** + * This method is used to retrieve all of the profile images for a person. + * + * @param personId + * @return + * @throws MovieDbException + */ + public TmdbResultsList getPersonImages(int personId) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, personId); + + URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.IMAGES).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + WrapperImages wrapper = MAPPER.readValue(webpage, WrapperImages.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getAll(ArtworkType.PROFILE)); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person images", url, ex); + } + } + + /** + * Get the list of popular people on The Movie Database. + * + * This list refreshes every day. + * + * @param page + * @return + * @throws MovieDbException + */ + public TmdbResultsList getPersonPopular(int page) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.PAGE, page); + + URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.POPULAR).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + WrapperPersonList wrapper = MAPPER.readValue(webpage, WrapperPersonList.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getPersonList()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get popular person", url, ex); + } + } + + /** + * Get the latest person id. + * + * @return + * @throws MovieDbException + */ + public Person getPersonLatest() throws MovieDbException { + URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.LATEST).buildUrl(); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, Person.class); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get latest person", url, ex); + } + } + } From 3078d12005e5bd40877416c2a97c2a6214d9221a Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 16 Feb 2015 18:19:08 +0000 Subject: [PATCH 007/100] Add Reviews --- .../omertron/themoviedbapi/TheMovieDbApi.java | 20 ++++++--- .../themoviedbapi/methods/TmdbMovies.java | 22 ---------- .../themoviedbapi/methods/TmdbReviews.java | 44 +++++++++++++++++++ 3 files changed, 59 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 491944c49..0b4cae287 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -1249,10 +1249,6 @@ public class TheMovieDbApi { return tmdbMovies.getSimilarMovies(movieId, language, page, appendToResponse); } - public TmdbResultsList getReviews(int movieId, String language, int page, String... appendToResponse) throws MovieDbException { - return tmdbMovies.getReviews(movieId, language, page, appendToResponse); - } - /** * Get the lists that the movie belongs to * @@ -1447,11 +1443,25 @@ public class TheMovieDbApi { return tmdbPeople.getPersonLatest(); } // - + // + /** + * + * @param movieId + * @param language + * @param page + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public TmdbResultsList getReviews(int movieId, String language, int page, String... appendToResponse) throws MovieDbException { + return tmdbReviews.getReviews(movieId, language, page, appendToResponse); + } // + // // + // // } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java index ee6e1d8f9..e0e73ca95 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java @@ -27,7 +27,6 @@ import com.omertron.themoviedbapi.model.MovieDb; import com.omertron.themoviedbapi.model.MovieList; import com.omertron.themoviedbapi.model.Person; import com.omertron.themoviedbapi.model.ReleaseInfo; -import com.omertron.themoviedbapi.model.Reviews; import com.omertron.themoviedbapi.model.StatusCode; import com.omertron.themoviedbapi.model.Translation; import com.omertron.themoviedbapi.model.Video; @@ -47,7 +46,6 @@ import com.omertron.themoviedbapi.wrapper.WrapperMovieCasts; import com.omertron.themoviedbapi.wrapper.WrapperMovieKeywords; import com.omertron.themoviedbapi.wrapper.WrapperMovieList; import com.omertron.themoviedbapi.wrapper.WrapperReleaseInfo; -import com.omertron.themoviedbapi.wrapper.WrapperReviews; import com.omertron.themoviedbapi.wrapper.WrapperTranslations; import com.omertron.themoviedbapi.wrapper.WrapperVideos; import java.io.IOException; @@ -368,26 +366,6 @@ public class TmdbMovies extends AbstractMethod { } } - public TmdbResultsList getReviews(int movieId, String language, int page, String... appendToResponse) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, movieId); - parameters.add(Param.LANGUAGE, language); - parameters.add(Param.PAGE, page); - parameters.add(Param.APPEND, appendToResponse); - - URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.REVIEWS).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperReviews wrapper = MAPPER.readValue(webpage, WrapperReviews.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getReviews()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get reviews", url, ex); - } - } - /** * Get the lists that the movie belongs to * diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbReviews.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbReviews.java index a6c3e16bd..be418d3d4 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbReviews.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbReviews.java @@ -19,7 +19,20 @@ */ package com.omertron.themoviedbapi.methods; +import com.omertron.themoviedbapi.MovieDbException; +import static com.omertron.themoviedbapi.methods.AbstractMethod.MAPPER; +import com.omertron.themoviedbapi.model.Reviews; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; +import com.omertron.themoviedbapi.tools.MethodBase; +import com.omertron.themoviedbapi.tools.MethodSub; +import com.omertron.themoviedbapi.tools.Param; +import com.omertron.themoviedbapi.tools.TmdbParameters; +import com.omertron.themoviedbapi.wrapper.WrapperReviews; +import java.io.IOException; +import java.net.URL; +import org.yamj.api.common.exception.ApiExceptionType; /** * Class to hold the Review Methods @@ -37,4 +50,35 @@ public class TmdbReviews extends AbstractMethod { public TmdbReviews(String apiKey, HttpTools httpTools) { super(apiKey, httpTools); } + + /** + * Get the full details of a review by ID. + * + * @param id + * @param language + * @param page + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public TmdbResultsList getReviews(int id, String language, int page, String... appendToResponse) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, id); + parameters.add(Param.LANGUAGE, language); + parameters.add(Param.PAGE, page); + parameters.add(Param.APPEND, appendToResponse); + + URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.REVIEWS).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + WrapperReviews wrapper = MAPPER.readValue(webpage, WrapperReviews.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getReviews()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get reviews", url, ex); + } + } + } From e5e7cd1ac3e9e47bc06b01a706fc33c3853bce9e Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 16 Feb 2015 18:25:52 +0000 Subject: [PATCH 008/100] Add Search --- .../omertron/themoviedbapi/TheMovieDbApi.java | 277 ++++++------------ .../themoviedbapi/methods/TmdbSearch.java | 199 +++++++++++++ 2 files changed, 283 insertions(+), 193 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 0b4cae287..bd5394316 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -72,26 +72,15 @@ 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 com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; import com.omertron.themoviedbapi.tools.MethodSub; -import com.omertron.themoviedbapi.tools.Param; -import com.omertron.themoviedbapi.tools.TmdbParameters; -import com.omertron.themoviedbapi.wrapper.WrapperCollection; -import com.omertron.themoviedbapi.wrapper.WrapperCompany; -import com.omertron.themoviedbapi.wrapper.WrapperKeywords; -import com.omertron.themoviedbapi.wrapper.WrapperMovie; -import com.omertron.themoviedbapi.wrapper.WrapperMovieList; -import com.omertron.themoviedbapi.wrapper.WrapperPerson; -import java.io.IOException; import java.net.URL; import java.util.List; import org.apache.commons.lang3.StringUtils; 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.SimpleHttpClientBuilder; /** @@ -279,188 +268,6 @@ public class TheMovieDbApi { return StringUtils.isNotBlank(year) && !"UNKNOWN".equals(year); } - /** - * 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 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) - * @return - * @throws MovieDbException - */ - public TmdbResultsList searchMovie(String movieName, int searchYear, String language, boolean includeAdult, int page) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.QUERY, movieName); - parameters.add(Param.YEAR, searchYear); - parameters.add(Param.LANGUAGE, language); - parameters.add(Param.ADULT, includeAdult); - parameters.add(Param.PAGE, page); - - URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.MOVIE).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperMovie wrapper = MAPPER.readValue(webpage, WrapperMovie.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getMovies()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - LOG.warn("Failed to find movie: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - - } - - /** - * Search for collections by name. - * - * @param query - * @param language - * @param page - * @return - * @throws MovieDbException - */ - public TmdbResultsList searchCollection(String query, String language, int page) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.QUERY, query); - parameters.add(Param.LANGUAGE, language); - parameters.add(Param.PAGE, page); - - URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.COLLECTION).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperCollection wrapper = MAPPER.readValue(webpage, WrapperCollection.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - LOG.warn("Failed to find collection: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * 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. - * - * @param personName - * @param includeAdult - * @param page - * @return - * @throws MovieDbException - */ - public TmdbResultsList searchPeople(String personName, boolean includeAdult, int page) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.QUERY, personName); - parameters.add(Param.ADULT, includeAdult); - parameters.add(Param.PAGE, page); - - URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.PERSON).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperPerson wrapper = MAPPER.readValue(webpage, WrapperPerson.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - LOG.warn("Failed to find person: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * Search for lists by name and description. - * - * @param query - * @param language - * @param page - * @return - * @throws MovieDbException - */ - public TmdbResultsList searchList(String query, String language, int page) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.QUERY, query); - parameters.add(Param.LANGUAGE, language); - parameters.add(Param.PAGE, page); - - URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.LIST).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperMovieList wrapper = MAPPER.readValue(webpage, WrapperMovieList.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getMovieList()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - LOG.warn("Failed to find list: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * 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. - * - * http://help.themoviedb.org/kb/api/search-companies - * - * @param companyName - * @param page - * @return - * @throws MovieDbException - */ - public TmdbResultsList searchCompanies(String companyName, int page) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.QUERY, companyName); - parameters.add(Param.PAGE, page); - - URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.COMPANY).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperCompany wrapper = MAPPER.readValue(webpage, WrapperCompany.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - LOG.warn("Failed to find company: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - - /** - * Search for keywords by name - * - * @param query - * @param page - * @return - * @throws MovieDbException - */ - public TmdbResultsList searchKeyword(String query, int page) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.QUERY, query); - parameters.add(Param.PAGE, page); - - URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.KEYWORD).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperKeywords wrapper = MAPPER.readValue(webpage, WrapperKeywords.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - LOG.warn("Failed to find keyword: {}", ex.getMessage(), ex); - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, webpage, url, ex); - } - } - // /** * Get the basic information for an account. You will need to have a valid session id. @@ -1460,6 +1267,90 @@ public class TheMovieDbApi { // // + /** + * 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 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) + * @return + * @throws MovieDbException + */ + public TmdbResultsList searchMovie(String movieName, int searchYear, String language, boolean includeAdult, int page) throws MovieDbException { + return tmdbSearch.searchMovie(movieName, searchYear, language, includeAdult, page); + } + + /** + * Search for collections by name. + * + * @param query + * @param language + * @param page + * @return + * @throws MovieDbException + */ + public TmdbResultsList searchCollection(String query, String language, int page) throws MovieDbException { + return tmdbSearch.searchCollection(query, language, page); + } + + /** + * 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. + * + * @param personName + * @param includeAdult + * @param page + * @return + * @throws MovieDbException + */ + public TmdbResultsList searchPeople(String personName, boolean includeAdult, int page) throws MovieDbException { + return tmdbSearch.searchPeople(personName, includeAdult, page); + } + + /** + * Search for lists by name and description. + * + * @param query + * @param language + * @param page + * @return + * @throws MovieDbException + */ + public TmdbResultsList searchList(String query, String language, int page) throws MovieDbException { + return tmdbSearch.searchList(query, language, page); + } + + /** + * 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. + * + * http://help.themoviedb.org/kb/api/search-companies + * + * @param companyName + * @param page + * @return + * @throws MovieDbException + */ + public TmdbResultsList searchCompanies(String companyName, int page) throws MovieDbException { + return tmdbSearch.searchCompanies(companyName, page); + } + + /** + * Search for keywords by name + * + * @param query + * @param page + * @return + * @throws MovieDbException + */ + public TmdbResultsList searchKeyword(String query, int page) throws MovieDbException { + return tmdbSearch.searchKeyword(query, page); + } // // diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java index 991063667..58e71d248 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java @@ -19,7 +19,29 @@ */ package com.omertron.themoviedbapi.methods; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.model.Collection; +import com.omertron.themoviedbapi.model.Company; +import com.omertron.themoviedbapi.model.Keyword; +import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.model.MovieList; +import com.omertron.themoviedbapi.model.Person; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; +import com.omertron.themoviedbapi.tools.MethodBase; +import com.omertron.themoviedbapi.tools.MethodSub; +import com.omertron.themoviedbapi.tools.Param; +import com.omertron.themoviedbapi.tools.TmdbParameters; +import com.omertron.themoviedbapi.wrapper.WrapperCollection; +import com.omertron.themoviedbapi.wrapper.WrapperCompany; +import com.omertron.themoviedbapi.wrapper.WrapperKeywords; +import com.omertron.themoviedbapi.wrapper.WrapperMovie; +import com.omertron.themoviedbapi.wrapper.WrapperMovieList; +import com.omertron.themoviedbapi.wrapper.WrapperPerson; +import java.io.IOException; +import java.net.URL; +import org.yamj.api.common.exception.ApiExceptionType; /** * Class to hold the Search Methods @@ -37,4 +59,181 @@ public class TmdbSearch extends AbstractMethod { public TmdbSearch(String apiKey, HttpTools httpTools) { super(apiKey, httpTools); } + + /** + * 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 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) + * @return + * @throws MovieDbException + */ + public TmdbResultsList searchMovie(String movieName, int searchYear, String language, boolean includeAdult, int page) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.QUERY, movieName); + parameters.add(Param.YEAR, searchYear); + parameters.add(Param.LANGUAGE, language); + parameters.add(Param.ADULT, includeAdult); + parameters.add(Param.PAGE, page); + + URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.MOVIE).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + WrapperMovie wrapper = MAPPER.readValue(webpage, WrapperMovie.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getMovies()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find movie", url, ex); + } + + } + + /** + * Search for collections by name. + * + * @param query + * @param language + * @param page + * @return + * @throws MovieDbException + */ + public TmdbResultsList searchCollection(String query, String language, int page) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.QUERY, query); + parameters.add(Param.LANGUAGE, language); + parameters.add(Param.PAGE, page); + + URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.COLLECTION).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + WrapperCollection wrapper = MAPPER.readValue(webpage, WrapperCollection.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find collection", url, ex); + } + } + + /** + * 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. + * + * @param personName + * @param includeAdult + * @param page + * @return + * @throws MovieDbException + */ + public TmdbResultsList searchPeople(String personName, boolean includeAdult, int page) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.QUERY, personName); + parameters.add(Param.ADULT, includeAdult); + parameters.add(Param.PAGE, page); + + URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.PERSON).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + WrapperPerson wrapper = MAPPER.readValue(webpage, WrapperPerson.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find person", url, ex); + } + } + + /** + * Search for lists by name and description. + * + * @param query + * @param language + * @param page + * @return + * @throws MovieDbException + */ + public TmdbResultsList searchList(String query, String language, int page) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.QUERY, query); + parameters.add(Param.LANGUAGE, language); + parameters.add(Param.PAGE, page); + + URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.LIST).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + WrapperMovieList wrapper = MAPPER.readValue(webpage, WrapperMovieList.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getMovieList()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find list", url, ex); + } + } + + /** + * 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. + * + * http://help.themoviedb.org/kb/api/search-companies + * + * @param companyName + * @param page + * @return + * @throws MovieDbException + */ + public TmdbResultsList searchCompanies(String companyName, int page) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.QUERY, companyName); + parameters.add(Param.PAGE, page); + + URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.COMPANY).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + WrapperCompany wrapper = MAPPER.readValue(webpage, WrapperCompany.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find company", url, ex); + } + } + + /** + * Search for keywords by name + * + * @param query + * @param page + * @return + * @throws MovieDbException + */ + public TmdbResultsList searchKeyword(String query, int page) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.QUERY, query); + parameters.add(Param.PAGE, page); + + URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.KEYWORD).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + WrapperKeywords wrapper = MAPPER.readValue(webpage, WrapperKeywords.class); + TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find keyword", url, ex); + } + } + } From debfb1209e9941ceccc50f6b1f5c76f390de5f52 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Tue, 17 Feb 2015 20:55:59 +0000 Subject: [PATCH 009/100] Replace CloseableHttpClient with HttpClient --- .../omertron/themoviedbapi/TheMovieDbApi.java | 4 +- .../themoviedbapi/tools/HttpTools.java | 6 +- .../omertron/themoviedbapi/TestAccounts.java | 70 +++++-------------- .../themoviedbapi/TheMovieDbApiTest.java | 62 +++------------- 4 files changed, 29 insertions(+), 113 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index bd5394316..ebe0b2dd6 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -78,7 +78,7 @@ import com.omertron.themoviedbapi.tools.MethodSub; import java.net.URL; import java.util.List; import org.apache.commons.lang3.StringUtils; -import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.client.HttpClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.yamj.api.common.http.SimpleHttpClientBuilder; @@ -137,7 +137,7 @@ public class TheMovieDbApi { * @param httpClient The httpClient to use for web requests. * @throws MovieDbException */ - public TheMovieDbApi(String apiKey, CloseableHttpClient httpClient) throws MovieDbException { + public TheMovieDbApi(String apiKey, HttpClient httpClient) throws MovieDbException { this.apiKey = apiKey; this.httpTools = new HttpTools(httpClient); initialise(apiKey, httpTools); diff --git a/src/main/java/com/omertron/themoviedbapi/tools/HttpTools.java b/src/main/java/com/omertron/themoviedbapi/tools/HttpTools.java index 99160d925..729227fac 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/HttpTools.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/HttpTools.java @@ -7,12 +7,12 @@ import java.net.URL; import java.nio.charset.Charset; import org.apache.http.HttpHeaders; import org.apache.http.HttpStatus; +import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.protocol.HTTP; import org.yamj.api.common.exception.ApiExceptionType; import org.yamj.api.common.http.DigestedResponse; @@ -25,11 +25,11 @@ import org.yamj.api.common.http.DigestedResponseReader; */ public class HttpTools { - private final CloseableHttpClient httpClient; + private final HttpClient httpClient; private static final Charset CHARSET = Charset.forName("UTF-8"); private static final String APPLICATION_JSON = "application/json"; - public HttpTools(CloseableHttpClient httpClient) { + public HttpTools(HttpClient httpClient) { this.httpClient = httpClient; } diff --git a/src/test/java/com/omertron/themoviedbapi/TestAccounts.java b/src/test/java/com/omertron/themoviedbapi/TestAccounts.java index ffdca8c55..547d1e5e0 100644 --- a/src/test/java/com/omertron/themoviedbapi/TestAccounts.java +++ b/src/test/java/com/omertron/themoviedbapi/TestAccounts.java @@ -19,39 +19,26 @@ */ package com.omertron.themoviedbapi; +import com.omertron.themoviedbapi.enumeration.MediaType; import com.omertron.themoviedbapi.model.Account; import com.omertron.themoviedbapi.model.MovieDb; import com.omertron.themoviedbapi.model.MovieDbList; import com.omertron.themoviedbapi.model.StatusCode; import com.omertron.themoviedbapi.model.TokenAuthorisation; import com.omertron.themoviedbapi.model.TokenSession; -import java.io.File; import java.util.List; -import java.util.Properties; import java.util.Random; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -public class TestAccounts { +public class TestAccounts extends AbstractTests { - private static final Logger LOG = LoggerFactory.getLogger(TestAccounts.class); - // API Key - private static final String PROP_FIlENAME = "testing.properties"; - private static String API_KEY; - private static String ACCOUNT_USERNAME; - private static String ACCOUNT_PASSWORD; private static TheMovieDbApi tmdb; private static TokenSession tokenSession = null; private static Account account = null; @@ -61,30 +48,11 @@ public class TestAccounts { @BeforeClass public static void setUpClass() throws MovieDbException { - TestLogger.Configure(); - - Properties props = new Properties(); - File f = new File(PROP_FIlENAME); - if (f.exists()) { - LOG.info("Loading properties from '{}'", PROP_FIlENAME); - TestLogger.loadProperties(props, f); - - API_KEY = props.getProperty("API_Key"); - ACCOUNT_USERNAME = props.getProperty("Username"); - ACCOUNT_PASSWORD = props.getProperty("Password"); - } else { - // Properties file is created in the main test class - fail("Failed to get key information from properties file '" + PROP_FIlENAME + "'"); - } - - tmdb = new TheMovieDbApi(API_KEY); - } - - @AfterClass - public static void tearDownClass() { + tmdb = new TheMovieDbApi(getApiKey()); } @Before + @Override public void setUp() throws MovieDbException { if (tokenSession == null) { testSessionCreation(); @@ -95,10 +63,6 @@ public class TestAccounts { } } - @After - public void tearDown() { - } - /** * Test and create a session token for the rest of the tests * @@ -115,7 +79,7 @@ public class TestAccounts { LOG.info("Token (auth): {}", token.toString()); // 2b; Get user permission - token = tmdb.getSessionTokenLogin(token, ACCOUNT_USERNAME, ACCOUNT_PASSWORD); + token = tmdb.getSessionTokenLogin(token, getUsername(), getPassword()); assertFalse("Token (login) is null", token == null); assertTrue("Token (login) is not valid", token.getSuccess()); LOG.info("Token (login): {}", token.toString()); @@ -140,7 +104,7 @@ public class TestAccounts { LOG.info("Account: {}", account); // Make sure properties are extracted correctly - assertEquals("Wrong username!", ACCOUNT_USERNAME, account.getUserName()); + assertEquals("Wrong username!", getUsername(), account.getUserName()); } @Test @@ -151,19 +115,19 @@ public class TestAccounts { } // make sure it's empty (because it's just a test account - Assert.assertTrue(tmdb.getWatchListMovie(tokenSession.getSessionId(), account.getId()).isEmpty()); + assertTrue(tmdb.getWatchListMovie(tokenSession.getSessionId(), account.getId()).isEmpty()); // add a movie - tmdb.addToWatchList(tokenSession.getSessionId(), account.getId(), 550); + tmdb.addToWatchList(tokenSession.getSessionId(), account.getId(), 550, MediaType.MOVIE); List watchList = tmdb.getWatchListMovie(tokenSession.getSessionId(), account.getId()); assertNotNull("Empty watch list returned", watchList); assertEquals("Watchlist wrong size", 1, watchList.size()); // clean up again - tmdb.removeFromWatchList(tokenSession.getSessionId(), account.getId(), 550); + tmdb.removeFromWatchList(tokenSession.getSessionId(), account.getId(), 550, MediaType.MOVIE); - Assert.assertTrue(tmdb.getWatchListMovie(tokenSession.getSessionId(), account.getId()).isEmpty()); + assertTrue(tmdb.getWatchListMovie(tokenSession.getSessionId(), account.getId()).isEmpty()); } @Test @@ -174,26 +138,25 @@ public class TestAccounts { } // make sure it's empty (because it's just a test account - Assert.assertTrue(tmdb.getFavoriteMovies(tokenSession.getSessionId(), account.getId()).isEmpty()); + assertTrue(tmdb.getFavoriteMovies(tokenSession.getSessionId(), account.getId()).isEmpty()); // add a movie - tmdb.changeFavoriteStatus(tokenSession.getSessionId(), account.getId(), 550, true); + tmdb.changeFavoriteStatus(tokenSession.getSessionId(), account.getId(), 550, MediaType.MOVIE, true); List watchList = tmdb.getFavoriteMovies(tokenSession.getSessionId(), account.getId()); assertNotNull("Empty watch list returned", watchList); assertEquals("Watchlist wrong size", 1, watchList.size()); // clean up again - tmdb.changeFavoriteStatus(tokenSession.getSessionId(), account.getId(), 550, false); + tmdb.changeFavoriteStatus(tokenSession.getSessionId(), account.getId(), 550, MediaType.MOVIE, false); - Assert.assertTrue(tmdb.getFavoriteMovies(tokenSession.getSessionId(), account.getId()).isEmpty()); + assertTrue(tmdb.getFavoriteMovies(tokenSession.getSessionId(), account.getId()).isEmpty()); } /** * Test of getSessionToken method, of class TheMovieDbApi. * - * TODO: Cannot be tested without a HTTP authorisation: - * http://help.themoviedb.org/kb/api/user-authentication + * TODO: Cannot be tested without a HTTP authorisation: http://help.themoviedb.org/kb/api/user-authentication * * @throws MovieDbException */ @@ -217,8 +180,7 @@ public class TestAccounts { /** * Test of postMovieRating method, of class TheMovieDbApi. * - * TODO: Cannot be tested without a HTTP authorisation: - * http://help.themoviedb.org/kb/api/user-authentication + * TODO: Cannot be tested without a HTTP authorisation: http://help.themoviedb.org/kb/api/user-authentication * * @throws MovieDbException */ diff --git a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java index 27832ef81..8f8369a9b 100644 --- a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java +++ b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java @@ -21,7 +21,6 @@ package com.omertron.themoviedbapi; import com.omertron.themoviedbapi.model.AlternativeTitle; import com.omertron.themoviedbapi.model.Artwork; -import com.omertron.themoviedbapi.model.ChangedItem; import com.omertron.themoviedbapi.model.ChangedMedia; import com.omertron.themoviedbapi.model.Collection; import com.omertron.themoviedbapi.model.CollectionInfo; @@ -44,37 +43,23 @@ import com.omertron.themoviedbapi.model.TokenSession; 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 java.io.File; -import java.util.List; -import java.util.Properties; import org.apache.commons.lang3.StringUtils; -import org.junit.After; -import org.junit.AfterClass; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Test cases for TheMovieDbApi API * * @author stuart.boston */ -public class TheMovieDbApiTest { +public class TheMovieDbApiTest extends AbstractTests{ - // Logger - private static final Logger LOG = LoggerFactory.getLogger(TheMovieDbApiTest.class); - // API Key - private static final String PROP_FIlENAME = "testing.properties"; - private static String API_KEY; private static TheMovieDbApi tmdb; // Test data private static final int ID_MOVIE_BLADE_RUNNER = 78; @@ -96,46 +81,15 @@ public class TheMovieDbApiTest { @BeforeClass public static void setUpClass() throws MovieDbException { - TestLogger.Configure(); - - Properties props = new Properties(); - File f = new File(PROP_FIlENAME); - if (f.exists()) { - LOG.info("Loading properties from '{}'", PROP_FIlENAME); - TestLogger.loadProperties(props, f); - - API_KEY = props.getProperty("API_Key"); - } else { - LOG.info("Property file '{}' not found, creating dummy file.", PROP_FIlENAME); - - props.setProperty("API_Key", "INSERT_YOUR_KEY_HERE"); - props.setProperty("Username", "INSERT_YOUR_USERNAME_HERE"); - props.setProperty("Password", "INSERT_YOUR_PASSWORD_HERE"); - - TestLogger.saveProperties(props, f, "Properties file for tests"); - fail("Failed to get key information from properties file '" + PROP_FIlENAME + "'"); - } - - tmdb = new TheMovieDbApi(API_KEY); - } - - @AfterClass - public static void tearDownClass() throws MovieDbException { - } - - @Before - public void setUp() { - } - - @After - public void tearDown() { + tmdb = new TheMovieDbApi(getApiKey()); } /** * Test of getConfiguration method, of class TheMovieDbApi. + * @throws com.omertron.themoviedbapi.MovieDbException */ @Test - public void testConfiguration() { + public void testConfiguration() throws MovieDbException { LOG.info("Test Configuration"); Configuration tmdbConfig = tmdb.getConfiguration(); @@ -599,7 +553,7 @@ public class TheMovieDbApiTest { // Get some popular movies TmdbResultsList movieList = tmdb.getPopularMovieList(LANGUAGE_DEFAULT, 0); for (MovieDb movie : movieList.getResults()) { - TmdbResultsMap> result = tmdb.getMovieChanges(movie.getId(), startDate, endDate); + TmdbResultsList result = tmdb.getMovieChanges(movie.getId(), startDate, endDate); LOG.info("{} has {} changes.", movie.getTitle(), result.getResults().size()); assertTrue("No changes found", result.getResults().size() > 0); break; @@ -750,7 +704,7 @@ public class TheMovieDbApiTest { int page = 0; String startDate = ""; String endDate = ""; - TmdbResultsList result = tmdb.getMovieChangesList(page, startDate, endDate); + TmdbResultsList result = tmdb.getMovieChangeList(page, startDate, endDate); assertFalse("No movie changes.", result.getResults().isEmpty()); } @@ -765,7 +719,7 @@ public class TheMovieDbApiTest { int page = 0; String startDate = ""; String endDate = ""; - tmdb.getPersonChangesList(page, startDate, endDate); + tmdb.getPersonChangeList(page, startDate, endDate); // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); } @@ -793,7 +747,7 @@ public class TheMovieDbApiTest { Discover discover = new Discover(); discover.year(2013).language(LANGUAGE_ENGLISH); - TmdbResultsList result = tmdb.getDiscover(discover); + TmdbResultsList result = tmdb.getDiscoverMovies(discover); assertFalse("No movies discovered", result.getResults().isEmpty()); } } From ba64e339b1c595579fdf8adcd5d4fa77781d6615 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Tue, 17 Feb 2015 21:03:57 +0000 Subject: [PATCH 010/100] Updated methods --- .../omertron/themoviedbapi/AbstractTests.java | 106 +++++ .../methods/TmdbAccountTest.java | 185 ++++++++ .../methods/TmdbAuthenticationTest.java | 99 +++++ .../methods/TmdbCertificationsTest.java | 79 ++++ .../methods/TmdbChangesTest.java | 86 ++++ .../methods/TmdbCollectionsTest.java | 81 ++++ .../methods/TmdbCompaniesTest.java | 98 ++++ .../methods/TmdbConfigurationTest.java | 105 +++++ .../methods/TmdbCreditsTest.java | 86 ++++ .../methods/TmdbDiscoverTest.java | 102 +++++ .../themoviedbapi/methods/TmdbFindTest.java | 97 ++++ .../themoviedbapi/methods/TmdbGenresTest.java | 97 ++++ .../themoviedbapi/methods/TmdbJobsTest.java | 82 ++++ .../methods/TmdbKeywordsTest.java | 99 +++++ .../themoviedbapi/methods/TmdbListsTest.java | 170 +++++++ .../themoviedbapi/methods/TmdbMoviesTest.java | 420 ++++++++++++++++++ .../methods/TmdbNetworksTest.java | 65 +++ .../themoviedbapi/methods/TmdbPeopleTest.java | 215 +++++++++ .../methods/TmdbReviewsTest.java | 85 ++++ .../themoviedbapi/methods/TmdbSearchTest.java | 168 +++++++ .../themoviedbapi/methods/TmdbTVTest.java | 225 ++++++++++ 21 files changed, 2750 insertions(+) create mode 100644 src/test/java/com/omertron/themoviedbapi/AbstractTests.java create mode 100644 src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java create mode 100644 src/test/java/com/omertron/themoviedbapi/methods/TmdbAuthenticationTest.java create mode 100644 src/test/java/com/omertron/themoviedbapi/methods/TmdbCertificationsTest.java create mode 100644 src/test/java/com/omertron/themoviedbapi/methods/TmdbChangesTest.java create mode 100644 src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java create mode 100644 src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java create mode 100644 src/test/java/com/omertron/themoviedbapi/methods/TmdbConfigurationTest.java create mode 100644 src/test/java/com/omertron/themoviedbapi/methods/TmdbCreditsTest.java create mode 100644 src/test/java/com/omertron/themoviedbapi/methods/TmdbDiscoverTest.java create mode 100644 src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java create mode 100644 src/test/java/com/omertron/themoviedbapi/methods/TmdbGenresTest.java create mode 100644 src/test/java/com/omertron/themoviedbapi/methods/TmdbJobsTest.java create mode 100644 src/test/java/com/omertron/themoviedbapi/methods/TmdbKeywordsTest.java create mode 100644 src/test/java/com/omertron/themoviedbapi/methods/TmdbListsTest.java create mode 100644 src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java create mode 100644 src/test/java/com/omertron/themoviedbapi/methods/TmdbNetworksTest.java create mode 100644 src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java create mode 100644 src/test/java/com/omertron/themoviedbapi/methods/TmdbReviewsTest.java create mode 100644 src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java create mode 100644 src/test/java/com/omertron/themoviedbapi/methods/TmdbTVTest.java diff --git a/src/test/java/com/omertron/themoviedbapi/AbstractTests.java b/src/test/java/com/omertron/themoviedbapi/AbstractTests.java new file mode 100644 index 000000000..0b19a628f --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/AbstractTests.java @@ -0,0 +1,106 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi; + +import com.omertron.themoviedbapi.tools.HttpTools; +import java.io.File; +import java.util.Properties; +import org.apache.http.impl.client.HttpClient; +import org.junit.After; +import org.junit.AfterClass; +import static org.junit.Assert.fail; +import org.junit.Before; +import org.junit.BeforeClass; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yamj.api.common.http.SimpleHttpClientBuilder; + +public class AbstractTests { + + protected static final Logger LOG = LoggerFactory.getLogger(AbstractTests.class); + private static final String PROP_FIlENAME = "testing.properties"; + private static final Properties props = new Properties(); + private static HttpClient httpClient; + private static HttpTools httpTools; + // Constants + protected static final String LANGUAGE_DEFAULT = ""; + protected static final String LANGUAGE_ENGLISH = "en"; + protected static final String LANGUAGE_RUSSIAN = "ru"; + + @BeforeClass + public static void setUpClass() throws MovieDbException { + TestLogger.Configure(); + httpClient = new SimpleHttpClientBuilder().build(); + httpTools = new HttpTools(httpClient); + + if (props.isEmpty()) { + File f = new File(PROP_FIlENAME); + if (f.exists()) { + LOG.info("Loading properties from '{}'", PROP_FIlENAME); + TestLogger.loadProperties(props, f); + } else { + LOG.info("Property file '{}' not found, creating dummy file.", PROP_FIlENAME); + + props.setProperty("API_Key", "INSERT_YOUR_KEY_HERE"); + props.setProperty("Username", "INSERT_YOUR_USERNAME_HERE"); + props.setProperty("Password", "INSERT_YOUR_PASSWORD_HERE"); + + TestLogger.saveProperties(props, f, "Properties file for tests"); + fail("Failed to get key information from properties file '" + PROP_FIlENAME + "'"); + } + } + } + + @AfterClass + public static void tearDownClass() throws MovieDbException { + } + + @Before + public void setUp() throws MovieDbException { + } + + @After + public void tearDown() throws MovieDbException { + } + + public static HttpClient getHttpClient() { + return httpClient; + } + + public static HttpTools getHttpTools() { + return httpTools; + } + + public static String getApiKey() { + return props.getProperty("API_Key"); + } + + public static String getUsername() { + return props.getProperty("Username"); + } + + public static String getPassword() { + return props.getProperty("Password"); + } + + public static String getProperty(String property) { + return props.getProperty(property); + } +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java new file mode 100644 index 000000000..f393e6f6a --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java @@ -0,0 +1,185 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.AbstractTests; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestLogger; +import com.omertron.themoviedbapi.model.Account; +import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.model.MovieDbList; +import com.omertron.themoviedbapi.model.StatusCode; +import java.util.List; +import org.junit.AfterClass; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +/** + * + * @author stuart.boston + */ +public class TmdbAccountTest extends AbstractTests { + + // API + private static TmdbAccount instance; + // Constants + private static final int ID_MOVIE_FIGHT_CLUB = 550; + + public TmdbAccountTest() { + } + + @BeforeClass + public static void setUpClass() throws MovieDbException { + TestLogger.Configure(); + instance = new TmdbAccount(getApiKey(), getHttpTools()); + } + + @AfterClass + public static void tearDownClass() { + } + + /** + * Test of getAccount method, of class TmdbAccount. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetAccount() throws MovieDbException { + LOG.info("getAccount"); + Account result = instance.getAccount(SESSION_ID_APITESTS); + assertEquals("Wrong account returned", ACCOUNT_ID_APITESTS, result.getId()); + } + + /** + * Test of getUserLists method, of class TmdbAccount. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetUserLists() throws MovieDbException { + LOG.info("getUserLists"); + List result = instance.getUserLists(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS); + assertNotNull("Null list returned", result); + } + + /** + * Test of getFavoriteMovies method, of class TmdbAccount. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetFavoriteMovies() throws MovieDbException { + LOG.info("getFavoriteMovies"); + + LOG.info("Check favorite list is empty"); + // make sure it's empty (because it's just a test account + List favList = instance.getFavoriteMovies(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS); + assertTrue("Favorite list was not empty!", favList.isEmpty()); + + LOG.info("Add movie to list"); + // add a movie + StatusCode status = instance.changeFavoriteStatus(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS, ID_MOVIE_FIGHT_CLUB, true); + LOG.info("Add Status: {}", status); + + LOG.info("Get favorite list"); + favList = instance.getFavoriteMovies(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS); + assertNotNull("Empty favorite list returned", favList); + assertFalse("Favorite list empty", favList.isEmpty()); + + // clean up again + LOG.info("Remove movie(s) from list"); + for (MovieDb movie : favList) { + LOG.info("Removing movie {}-'{}'", movie.getId(), movie.getTitle()); + status = instance.changeFavoriteStatus(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS, movie.getId(), false); + LOG.info("Remove status: {}", status); + } + assertTrue("Favorite list was not empty", instance.getFavoriteMovies(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS).isEmpty()); + } + + /** + * Test of changeFavoriteStatus method, of class TmdbAccount. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Ignore("Tested as part of getFavoriteMovies") + public void testChangeFavoriteStatus() throws MovieDbException { + } + + /** + * Test of getRatedMovies method, of class TmdbAccount. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetRatedMovies() throws MovieDbException { + LOG.info("getRatedMovies"); + List result = instance.getRatedMovies(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS); + assertFalse("No rated movies", result.isEmpty()); + } + + /** + * Test of getWatchList method, of class TmdbAccount. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetWatchList() throws MovieDbException { + LOG.info("getWatchList"); + + LOG.info("Check list is empty"); + // make sure it's empty (because it's just a test account + List watchList = instance.getWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS); + assertTrue("Watch list was not empty!", watchList.isEmpty()); + + LOG.info("Add movie to list"); + // add a movie + StatusCode status = instance.modifyWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS, ID_MOVIE_FIGHT_CLUB, true); + LOG.info("Add Status: {}", status); + + LOG.info("Get watch list"); + watchList = instance.getWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS); + assertNotNull("Empty watch list returned", watchList); + assertFalse("Watchlist list empty", watchList.isEmpty()); + + LOG.info("Removing movie(s) from list"); + // clean up again + for (MovieDb movie : watchList) { + LOG.info("Removing movie {}-'{}'", movie.getId(), movie.getTitle()); + status = instance.modifyWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS, movie.getId(), false); + LOG.info("Remove status: {}", status); + } + + assertTrue(instance.getWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS).isEmpty()); + } + + /** + * Test of modifyWatchList method, of class TmdbAccount. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Ignore("Tested as part of testGetWatchList") + public void testModifyWatchList() throws MovieDbException { + } +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAuthenticationTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAuthenticationTest.java new file mode 100644 index 000000000..69bf8e20c --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAuthenticationTest.java @@ -0,0 +1,99 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.AbstractTests; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestLogger; +import com.omertron.themoviedbapi.model.TokenAuthorisation; +import com.omertron.themoviedbapi.model.TokenSession; +import org.junit.AfterClass; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +/** + * + * @author stuart.boston + */ +public class TmdbAuthenticationTest extends AbstractTests{ + + // API + private static TmdbAuthentication instance; + + public TmdbAuthenticationTest() { + } + + @BeforeClass + public static void setUpClass() throws MovieDbException { + TestLogger.Configure(); + instance = new TmdbAuthentication(getApiKey(),getHttpTools()); + } + + @AfterClass + public static void tearDownClass() { + } + + /** + * Test of getAuthorisationToken method, of class TmdbAuthentication. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetAuthorisationToken() throws MovieDbException { + LOG.info("getAuthorisationToken"); + TokenAuthorisation token = instance.getAuthorisationToken(); + assertFalse("Token is null", token == null); + assertTrue("Token is not valid", token.getSuccess()); + } + + /** + * Test of getSessionToken method, of class TmdbAuthentication. + * + * TODO: Cannot be tested without a HTTP authorisation:
+ * http://help.themoviedb.org/kb/api/user-authentication + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Ignore("Session needs to be authorised") + public void testGetSessionToken() throws MovieDbException { + LOG.info("getSessionToken"); + TokenAuthorisation token = instance.getAuthorisationToken(); + // Need to authorise the token here. + TokenSession result = instance.getSessionToken(token); + assertFalse("Session token is null", result == null); + assertTrue("Session token is not valid", result.getSuccess()); + } + + /** + * Test of getGuestSessionToken method, of class TmdbAuthentication. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetGuestSessionToken() throws MovieDbException { + LOG.info("getGuestSessionToken"); + TokenSession result = instance.getGuestSessionToken(); + assertTrue("Failed to get guest session", result.getSuccess()); + } + +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCertificationsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCertificationsTest.java new file mode 100644 index 000000000..20bbf8625 --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCertificationsTest.java @@ -0,0 +1,79 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.AbstractTests; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestLogger; +import com.omertron.themoviedbapi.model.Certification; +import com.omertron.themoviedbapi.results.TmdbResultsMap; +import java.util.List; +import org.junit.AfterClass; +import static org.junit.Assert.assertFalse; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * + * @author stuart.boston + * @author Luca Tagliani + */ +public class TmdbCertificationsTest extends AbstractTests { + + // API + private static TmdbCertifications instance; + + public TmdbCertificationsTest() { + } + + @BeforeClass + public static void setUpClass() throws MovieDbException { + TestLogger.Configure(); + instance = new TmdbCertifications(getApiKey(), getHttpTools()); + } + + @AfterClass + public static void tearDownClass() { + } + + /** + * Test of getMoviesCertification method, of class TmdbCertifications. + * + * @throws MovieDbException + */ + @Test + public void testGetMovieCertifications() throws MovieDbException { + LOG.info("getMovieCertifications"); + TmdbResultsMap> result = instance.getMoviesCertification(); + assertFalse("No movie certifications.", result.getResults().isEmpty()); + } + + /** + * Test of getTvCertification method, of class TmdbCertifications. + * + * @throws MovieDbException + */ + @Test + public void testGetTvCertifications() throws MovieDbException { + LOG.info("getTvCertifications"); + TmdbResultsMap> result = instance.getTvCertification(); + assertFalse("No tv certifications.", result.getResults().isEmpty()); + } +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbChangesTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbChangesTest.java new file mode 100644 index 000000000..fd84ba761 --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbChangesTest.java @@ -0,0 +1,86 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.AbstractTests; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestLogger; +import com.omertron.themoviedbapi.model.ChangedMovie; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import org.junit.AfterClass; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +/** + * + * @author stuart.boston + */ +public class TmdbChangesTest extends AbstractTests { + + // API + private static TmdbChanges instance; + + public TmdbChangesTest() { + } + + @BeforeClass + public static void setUpClass() throws MovieDbException { + TestLogger.Configure(); + instance = new TmdbChanges(getApiKey(), getHttpTools()); + } + + @AfterClass + public static void tearDownClass() { + } + + /** + * Test of getMovieChangesList method, of class TmdbChanges. + * + * @throws MovieDbException + */ + @Test + public void testGetMovieChangesList() throws MovieDbException { + LOG.info("getMovieChangesList"); + int page = 0; + String startDate = ""; + String endDate = ""; + TmdbResultsList result = instance.getMovieChangesList(page, startDate, endDate); + assertFalse("No movie changes.", result.getResults().isEmpty()); + } + + /** + * Test of getPersonMovieOldChangesList method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Ignore("Not ready yet") + public void testGetPersonChangesList() throws MovieDbException { + LOG.info("getPersonChangesList"); + int page = 0; + String startDate = ""; + String endDate = ""; + instance.getPersonChangesList(page, startDate, endDate); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java new file mode 100644 index 000000000..50649b3ea --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java @@ -0,0 +1,81 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.AbstractTests; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestLogger; +import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model.CollectionInfo; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import org.junit.AfterClass; +import static org.junit.Assert.assertFalse; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * + * @author stuart.boston + */ +public class TmdbCollectionsTest extends AbstractTests { + + // API + private static TmdbCollections instance; + private static final int ID_COLLECTION_STAR_WARS = 10; + + public TmdbCollectionsTest() { + } + + @BeforeClass + public static void setUpClass() throws MovieDbException { + TestLogger.Configure(); + instance = new TmdbCollections(getApiKey(), getHttpTools()); + } + + @AfterClass + public static void tearDownClass() { + } + + /** + * Test of getCollectionInfo method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetCollectionInfo() throws MovieDbException { + LOG.info("getCollectionInfo"); + String language = ""; + CollectionInfo result = instance.getCollectionInfo(ID_COLLECTION_STAR_WARS, language); + assertFalse("No collection information", result.getParts().isEmpty()); + } + + /** + * Test of getCollectionImages method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetCollectionImages() throws MovieDbException { + LOG.info("getCollectionImages"); + TmdbResultsList result = instance.getCollectionImages(ID_COLLECTION_STAR_WARS, LANGUAGE_DEFAULT); + assertFalse("No artwork found", result.getResults().isEmpty()); + } + +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java new file mode 100644 index 000000000..50344ba87 --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java @@ -0,0 +1,98 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.AbstractTests; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestLogger; +import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey(); +import static com.omertron.themoviedbapi.TheMovieDbApiTest.LANGUAGE_DEFAULT; +import com.omertron.themoviedbapi.model.Company; +import com.omertron.themoviedbapi.model.movie.MovieDb; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import org.junit.After; +import org.junit.AfterClass; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yamj.api.common.http.DefaultPoolingHttpClient; + +/** + * + * @author stuart.boston + */ +public class TmdbCompaniesTest extends AbstractTests{ + + // Logger + private static final Logger LOG = LoggerFactory.getLogger(TmdbCompaniesTest.class); + // API + private static TmdbCompanies instance; + private static final int ID_COMPANY = 2; + + public TmdbCompaniesTest() { + } + + @BeforeClass + public static void setUpClass() throws MovieDbException { + TestLogger.Configure(); + instance = new TmdbCompanies(getApiKey(),getHttpTools()); + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getCompanyInfo method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetCompanyInfo() throws MovieDbException { + LOG.info("getCompanyInfo"); + Company company = instance.getCompanyInfo(ID_COMPANY); + assertTrue("No company information found", company.getCompanyId() > 0); + assertNotNull("No parent company found", company.getParentCompany()); + } + + /** + * Test of getCompanyMovies method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetCompanyMovies() throws MovieDbException { + LOG.info("getCompanyMovies"); + TmdbResultsList result = instance.getCompanyMovies(ID_COMPANY, LANGUAGE_DEFAULT, 0); + assertTrue("No company movies found", !result.getResults().isEmpty()); + } +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbConfigurationTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbConfigurationTest.java new file mode 100644 index 000000000..73b80c431 --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbConfigurationTest.java @@ -0,0 +1,105 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.AbstractTests; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestLogger; +import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey(); +import com.omertron.themoviedbapi.model.Configuration; +import com.omertron.themoviedbapi.model.type.ArtworkType; +import org.apache.commons.lang3.StringUtils; +import org.junit.After; +import org.junit.AfterClass; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yamj.api.common.http.DefaultPoolingHttpClient; + +/** + * + * @author stuart.boston + */ +public class TmdbConfigurationTest extends AbstractTests { + + // Logger + private static final Logger LOG = LoggerFactory.getLogger(TmdbConfigurationTest.class); + + // API + private static TmdbConfiguration instance; + + public TmdbConfigurationTest() { + } + + @BeforeClass + public static void setUpClass() { + TestLogger.Configure(); + instance = new TmdbConfiguration(getApiKey(),getHttpTools()); + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getConfig method, of class TmdbConfiguration. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetConfig() throws MovieDbException { + LOG.info("getConfig"); + Configuration result = instance.getConfig(); + LOG.info(result.toString()); + assertFalse("No backdrop sizes", result.getBackdropSizes().isEmpty()); + assertFalse("No logo sizes", result.getLogoSizes().isEmpty()); + assertFalse("No poster sizes", result.getPosterSizes().isEmpty()); + assertFalse("No profile sizes", result.getProfileSizes().isEmpty()); + assertTrue("No base url", StringUtils.isNotBlank(result.getBaseUrl())); + assertTrue("No secure base url", StringUtils.isNotBlank(result.getSecureBaseUrl())); + } + + /** + * Test of createImageUrl method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testCreateImageUrl() throws MovieDbException { + LOG.info("createImageUrl"); + Configuration config = instance.getConfig(); + + String result = config.createImageUrl("http://mediaplayersite.com/image.jpg", ArtworkType.POSTER, "original").toString(); + assertTrue("Error compiling image URL", !result.isEmpty()); + } + +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCreditsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCreditsTest.java new file mode 100644 index 000000000..e2186a91c --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCreditsTest.java @@ -0,0 +1,86 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.AbstractTests; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestLogger; +import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey(); +import com.omertron.themoviedbapi.model.person.PersonCredits; +import org.junit.After; +import org.junit.AfterClass; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yamj.api.common.http.DefaultPoolingHttpClient; + +/** + * + * @author stuart.boston + */ +public class TmdbCreditsTest extends AbstractTests{ + + // Logger + private static final Logger LOG = LoggerFactory.getLogger(TmdbCreditsTest.class); + // API + private static TmdbCredits instance; + + public TmdbCreditsTest() { + } + + @BeforeClass + public static void setUpClass() throws MovieDbException { + TestLogger.Configure(); + instance = new TmdbCredits(getApiKey(),getHttpTools()); + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getCreditInfo method, of class TmdbCredits. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetCreditInfo() throws MovieDbException { + LOG.info("getCreditInfo"); + String creditId = "525346f619c29579400d4145"; + String language = ""; + PersonCredits result = instance.getCreditInfo(creditId, language); + assertEquals("Wrong name", "Sean Bean", result.getPerson().getName()); + assertEquals("Wrong job", "Actor", result.getJob()); + assertFalse("No seasons", result.getMedia().getSeasons().isEmpty()); + } + +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbDiscoverTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbDiscoverTest.java new file mode 100644 index 000000000..ee2e55e17 --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbDiscoverTest.java @@ -0,0 +1,102 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.AbstractTests; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestLogger; +import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey(); +import static com.omertron.themoviedbapi.TheMovieDbApiTest.LANGUAGE_ENGLISH; +import com.omertron.themoviedbapi.model.discover.Discover; +import com.omertron.themoviedbapi.model.movie.MovieDb; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import org.junit.After; +import org.junit.AfterClass; +import static org.junit.Assert.assertFalse; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yamj.api.common.http.DefaultPoolingHttpClient; + +/** + * + * @author stuart.boston + */ +public class TmdbDiscoverTest extends AbstractTests { + + // Logger + private static final Logger LOG = LoggerFactory.getLogger(TmdbDiscoverTest.class); + // API + private static TmdbDiscover instance; + + public TmdbDiscoverTest() { + } + + @BeforeClass + public static void setUpClass() throws MovieDbException { + TestLogger.Configure(); + instance = new TmdbDiscover(getApiKey(),getHttpTools()); + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getDiscoverMovie method, of class TmdbDiscover. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetDiscoverMovie() throws MovieDbException { + LOG.info("getDiscoverMovie"); + Discover discover = new Discover(); + discover.year(2013).language(LANGUAGE_ENGLISH); + + TmdbResultsList result = instance.getDiscoverMovie(discover); + assertFalse("No movies discovered", result.getResults().isEmpty()); + } + + /** + * Test of getDiscoverTv method, of class TmdbDiscover. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetDiscoverTv() throws MovieDbException { + LOG.info("getDiscoverTv"); + Discover discover = new Discover(); + discover.year(2013).language(LANGUAGE_ENGLISH); + + TmdbResultsList result = instance.getDiscoverMovie(discover); + assertFalse("No TV shows discovered", result.getResults().isEmpty()); + } + +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java new file mode 100644 index 000000000..048d03dbe --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java @@ -0,0 +1,97 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.AbstractTests; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestLogger; +import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey(); +import com.omertron.themoviedbapi.model.FindResults; +import org.junit.After; +import org.junit.AfterClass; +import static org.junit.Assert.assertFalse; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yamj.api.common.http.DefaultPoolingHttpClient; + +/** + * + * @author stuart.boston + * @author Luca Tagliani + */ +public class TmdbFindTest extends AbstractTests { + + // Logger + private static final Logger LOG = LoggerFactory.getLogger(TmdbFindTest.class); + // API + private static TmdbFind instance; + + public TmdbFindTest() { + } + + @BeforeClass + public static void setUpClass() throws MovieDbException { + TestLogger.Configure(); + instance = new TmdbFind(getApiKey(),getHttpTools()); + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getMovieChangesList method, of class TmdbFindTest. + * + * @throws MovieDbException + */ + @Test + public void testFindMoviesImdbID() throws MovieDbException { + LOG.info("findMoviesImdbID"); + FindResults result = instance.find("tt0196229", TmdbFind.ExternalSource.imdb_id, "it"); + assertFalse("No movie for id.", result.getMovieResults().isEmpty()); + } + + @Test + public void testFindTvSeriesImdbID() throws MovieDbException { + LOG.info("findTvSeriesImdbID"); + FindResults result = instance.find("tt1219024", TmdbFind.ExternalSource.imdb_id, "it"); + assertFalse("No tv for id.", result.getTvResults().isEmpty()); + } + + @Test + public void testFindPersonImdbID() throws MovieDbException { + LOG.info("findPersonImdbID"); + FindResults result = instance.find("nm0001774", TmdbFind.ExternalSource.imdb_id, "it"); + assertFalse("No person for id.", result.getPersonResults().isEmpty()); + } + + +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbGenresTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbGenresTest.java new file mode 100644 index 000000000..74cbcc547 --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbGenresTest.java @@ -0,0 +1,97 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.AbstractTests; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestLogger; +import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey(); +import static com.omertron.themoviedbapi.TheMovieDbApiTest.LANGUAGE_DEFAULT; +import com.omertron.themoviedbapi.model.Genre; +import com.omertron.themoviedbapi.model.movie.MovieDb; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import org.junit.After; +import org.junit.AfterClass; +import static org.junit.Assert.assertTrue; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yamj.api.common.http.DefaultPoolingHttpClient; + +/** + * + * @author stuart.boston + */ +public class TmdbGenresTest extends AbstractTests { + + // Logger + private static final Logger LOG = LoggerFactory.getLogger(TmdbGenresTest.class); + // API + private static TmdbGenres instance; + private static final int ID_GENRE_ACTION = 28; + + public TmdbGenresTest() { + } + + @BeforeClass + public static void setUpClass() throws MovieDbException { + TestLogger.Configure(); + instance = new TmdbGenres(getApiKey(),getHttpTools()); + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getGenreList method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetGenreList() throws MovieDbException { + LOG.info("getGenreList"); + TmdbResultsList result = instance.getGenreList(LANGUAGE_DEFAULT); + assertTrue("No genres found", !result.getResults().isEmpty()); + } + + /** + * Test of getGenreMovies method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetGenreMovies() throws MovieDbException { + LOG.info("getGenreMovies"); + TmdbResultsList result = instance.getGenreMovies(ID_GENRE_ACTION, LANGUAGE_DEFAULT, 0, Boolean.TRUE); + assertTrue("No genre movies found", !result.getResults().isEmpty()); + } + +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbJobsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbJobsTest.java new file mode 100644 index 000000000..7d23343ef --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbJobsTest.java @@ -0,0 +1,82 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.AbstractTests; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestLogger; +import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey(); +import com.omertron.themoviedbapi.model.JobDepartment; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import org.junit.After; +import org.junit.AfterClass; +import static org.junit.Assert.assertFalse; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yamj.api.common.http.DefaultPoolingHttpClient; + +/** + * + * @author stuart.boston + */ +public class TmdbJobsTest extends AbstractTests { + + // Logger + private static final Logger LOG = LoggerFactory.getLogger(TmdbGenresTest.class); + // API + private static TmdbJobs tmdb; + + public TmdbJobsTest() { + } + + @BeforeClass + public static void setUpClass() throws MovieDbException { + TestLogger.Configure(); + tmdb = new TmdbJobs(getApiKey(),getHttpTools()); + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getJobs method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetJobs() throws MovieDbException { + LOG.info("getJobs"); + TmdbResultsList result = tmdb.getJobs(); + assertFalse("No jobs found", result.getResults().isEmpty()); + } + +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbKeywordsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbKeywordsTest.java new file mode 100644 index 000000000..3e758109c --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbKeywordsTest.java @@ -0,0 +1,99 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.AbstractTests; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestLogger; +import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey(); +import static com.omertron.themoviedbapi.TheMovieDbApiTest.LANGUAGE_DEFAULT; +import com.omertron.themoviedbapi.model.Keyword; +import com.omertron.themoviedbapi.model.movie.MovieDbBasic; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import org.junit.After; +import org.junit.AfterClass; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yamj.api.common.http.DefaultPoolingHttpClient; + +/** + * + * @author stuart.boston + */ +public class TmdbKeywordsTest extends AbstractTests{ + + // Logger + private static final Logger LOG = LoggerFactory.getLogger(TmdbGenresTest.class); + // API + private static TmdbKeywords tmdb; + private static final String ID_KEYWORD = "1721"; + + public TmdbKeywordsTest() { + } + + @BeforeClass + public static void setUpClass() throws MovieDbException { + TestLogger.Configure(); + tmdb = new TmdbKeywords(getApiKey(),getHttpTools()); + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getKeyword method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetKeyword() throws MovieDbException { + LOG.info("getKeyword"); + Keyword result = tmdb.getKeyword(ID_KEYWORD); + assertEquals("fight", result.getName()); + } + + /** + * Test of getMovieDbBasics method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetKeywordMovies() throws MovieDbException { + LOG.info("getKeywordMovies"); + int page = 0; + TmdbResultsList result = tmdb.getKeywordMovies(ID_KEYWORD, LANGUAGE_DEFAULT, page); + assertFalse("No keyword movies found", result.getResults().isEmpty()); + } + +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbListsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbListsTest.java new file mode 100644 index 000000000..a31c28b49 --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbListsTest.java @@ -0,0 +1,170 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.AbstractTests; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestLogger; +import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey(); +import static com.omertron.themoviedbapi.TheMovieDbApiTest.SESSION_ID_APITESTS; +import com.omertron.themoviedbapi.model.StatusCode; +import com.omertron.themoviedbapi.model.StatusCodeList; +import com.omertron.themoviedbapi.model.movie.MovieDbList; +import org.junit.After; +import org.junit.AfterClass; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runners.MethodSorters; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yamj.api.common.http.DefaultPoolingHttpClient; + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class TmdbListsTest extends AbstractTests{ + + // Logger + private static final Logger LOG = LoggerFactory.getLogger(TmdbGenresTest.class); + // API + private static TmdbLists instance; + + public TmdbListsTest() { + } + + @BeforeClass + public static void setUpClass() throws MovieDbException { + TestLogger.Configure(); + instance = new TmdbLists(getApiKey(),getHttpTools()); + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of createList method, of class TmdbList. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Ignore("Not working") + public void test1CreateList() throws MovieDbException { + LOG.info("createList"); + String name = "My Totally Awesome List"; + String description = "This list was created to share all of the totally awesome movies I've seen."; + StatusCodeList result = instance.createList(SESSION_ID_APITESTS, name, description); + LOG.info(result.toString()); + // TODO review the generated test code and remove the default call to fail. +// fail("The test case is a prototype."); + } + + /** + * Test of getList method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void test2GetList() throws MovieDbException { + LOG.info("getList"); + String listId = "509ec17b19c2950a0600050d"; + MovieDbList result = instance.getList(listId); + assertFalse("List not found", result.getItems().isEmpty()); + } + + /** + * Test of addMovieToList method, of class TmdbList. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Ignore("Not working") + public void test3AddMovieToList() throws MovieDbException { + LOG.info("addMovieToList"); + String listId = ""; + Integer movieId = null; + StatusCode expResult = null; + StatusCode result = instance.addMovieToList(SESSION_ID_APITESTS, listId, movieId); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of isMovieOnList method, of class TmdbList. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Ignore("Not working") + public void test4IsMovieOnList() throws MovieDbException { + LOG.info("isMovieOnList"); + String listId = ""; + Integer movieId = null; + boolean expResult = false; + boolean result = instance.isMovieOnList(listId, movieId); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of removeMovieFromList method, of class TmdbList. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Ignore("Not working") + public void test5RemoveMovieFromList() throws MovieDbException { + LOG.info("removeMovieFromList"); + String listId = ""; + Integer movieId = null; + StatusCode expResult = null; + StatusCode result = instance.removeMovieFromList(SESSION_ID_APITESTS, listId, movieId); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of deleteMovieList method, of class TmdbList. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Ignore("Not working") + public void test6DeleteMovieList() throws MovieDbException { + LOG.info("deleteMovieList"); + String listId = ""; + StatusCode expResult = null; + StatusCode result = instance.deleteMovieList(SESSION_ID_APITESTS, listId); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java new file mode 100644 index 000000000..c6add35c5 --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java @@ -0,0 +1,420 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.AbstractTests; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestLogger; +import static com.omertron.themoviedbapi.TheMovieDbApiTest.ACCOUNT_ID_APITESTS; +import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey(); +import static com.omertron.themoviedbapi.TheMovieDbApiTest.LANGUAGE_DEFAULT; +import static com.omertron.themoviedbapi.TheMovieDbApiTest.LANGUAGE_ENGLISH; +import static com.omertron.themoviedbapi.TheMovieDbApiTest.SESSION_ID_APITESTS; +import com.omertron.themoviedbapi.model.AlternativeTitle; +import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model.ChangedItem; +import com.omertron.themoviedbapi.model.Keyword; +import com.omertron.themoviedbapi.model.ReleaseInfo; +import com.omertron.themoviedbapi.model.Review; +import com.omertron.themoviedbapi.model.Trailer; +import com.omertron.themoviedbapi.model.Translation; +import com.omertron.themoviedbapi.model.movie.MovieDb; +import com.omertron.themoviedbapi.model.movie.MovieList; +import com.omertron.themoviedbapi.model.movie.MovieState; +import com.omertron.themoviedbapi.model.person.PersonMovieOld; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import com.omertron.themoviedbapi.results.TmdbResultsMap; +import java.util.List; +import java.util.Random; +import org.junit.AfterClass; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +/** + * + * @author stuart.boston + */ +public class TmdbMoviesTest extends AbstractTests{ + + // API + private static TmdbMovies instance; + private static final int ID_MOVIE_BLADE_RUNNER = 78; + private static final int ID_MOVIE_THE_AVENGERS = 24428; + + public TmdbMoviesTest() { + } + + @BeforeClass + public static void setUpClass() throws MovieDbException { + TestLogger.Configure(); + instance = new TmdbMovies(getApiKey(),getHttpTools()); + } + + @AfterClass + public static void tearDownClass() { + } + + /** + * Test of getMovieInfo method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetMovieInfo() throws MovieDbException { + LOG.info("getMovieInfo"); + MovieDb result = instance.getMovieInfo(ID_MOVIE_BLADE_RUNNER, LANGUAGE_ENGLISH, "alternative_titles,casts,images,keywords,releases,trailers,translations,similar_movies,reviews,lists"); + assertEquals("Incorrect movie information", "Blade Runner", result.getOriginalTitle()); + } + + /** + * Test of getMovieInfoImdb method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetMovieInfoImdb() throws MovieDbException { + LOG.info("getMovieInfoImdb"); + MovieDb result = instance.getMovieInfoImdb("tt0076759", "en-US"); + assertTrue("Error getting the movie from IMDB ID", result.getId() == 11); + } + + /** + * Test of getMovieAlternativeTitles method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetMovieAlternativeTitles() throws MovieDbException { + LOG.info("getMovieAlternativeTitles"); + String country = ""; + TmdbResultsList result = instance.getMovieAlternativeTitles(ID_MOVIE_BLADE_RUNNER, country, "casts,images,keywords,releases,trailers,translations,similar_movies,reviews,lists"); + assertTrue("No alternative titles found", result.getResults().size() > 0); + + country = "US"; + result = instance.getMovieAlternativeTitles(ID_MOVIE_BLADE_RUNNER, country); + assertTrue("No alternative titles found", result.getResults().size() > 0); + + } + + /** + * Test of getMovieCredits method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetMovieCasts() throws MovieDbException { + LOG.info("getMovieCasts"); + TmdbResultsList people = instance.getMovieCredits(ID_MOVIE_BLADE_RUNNER, "alternative_titles,casts,images,keywords,releases,trailers,translations,similar_movies,reviews,lists"); + assertTrue("No cast information", people.getResults().size() > 0); + + String name1 = "Harrison Ford"; + String name2 = "Charles Knode"; + boolean foundName1 = Boolean.FALSE; + boolean foundName2 = Boolean.FALSE; + + for (PersonMovieOld person : people.getResults()) { + if (!foundName1 && person.getName().equalsIgnoreCase(name1)) { + foundName1 = Boolean.TRUE; + } + + if (!foundName2 && person.getName().equalsIgnoreCase(name2)) { + foundName2 = Boolean.TRUE; + } + } + assertTrue("Couldn't find " + name1, foundName1); + assertTrue("Couldn't find " + name2, foundName2); + } + + /** + * Test of getMovieImages method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetMovieImages() throws MovieDbException { + LOG.info("getMovieImages"); + String language = ""; + TmdbResultsList result = instance.getMovieImages(ID_MOVIE_BLADE_RUNNER, language); + assertFalse("No artwork found", result.getResults().isEmpty()); + } + + /** + * Test of getMovieKeywords method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetMovieKeywords() throws MovieDbException { + LOG.info("getMovieKeywords"); + TmdbResultsList result = instance.getMovieKeywords(ID_MOVIE_BLADE_RUNNER); + assertFalse("No keywords found", result.getResults().isEmpty()); + } + + /** + * Test of getMovieReleaseInfo method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetMovieReleaseInfo() throws MovieDbException { + LOG.info("getMovieReleaseInfo"); + TmdbResultsList result = instance.getMovieReleaseInfo(ID_MOVIE_BLADE_RUNNER, ""); + assertFalse("Release information missing", result.getResults().isEmpty()); + } + + /** + * Test of getMovieTrailers method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetMovieTrailers() throws MovieDbException { + LOG.info("getMovieTrailers"); + TmdbResultsList result = instance.getMovieTrailers(ID_MOVIE_BLADE_RUNNER, ""); + assertFalse("Movie trailers missing", result.getResults().isEmpty()); + } + + /** + * Test of getMovieTranslations method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetMovieTranslations() throws MovieDbException { + LOG.info("getMovieTranslations"); + TmdbResultsList result = instance.getMovieTranslations(ID_MOVIE_BLADE_RUNNER); + assertFalse("No translations found", result.getResults().isEmpty()); + } + + /** + * Test of getSimilarMovies method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetSimilarMovies() throws MovieDbException { + LOG.info("getSimilarMovies"); + TmdbResultsList result = instance.getSimilarMovies(ID_MOVIE_BLADE_RUNNER, LANGUAGE_DEFAULT, 0); + assertTrue("No similar movies found", !result.getResults().isEmpty()); + } + + /** + * Test of getReview method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetReviews() throws MovieDbException { + LOG.info("getReviews"); + int page = 0; + TmdbResultsList result = instance.getReviews(ID_MOVIE_THE_AVENGERS, LANGUAGE_DEFAULT, page); + assertFalse("No reviews found", result.getResults().isEmpty()); + } + + /** + * Test of getMovieLists method, of class TmdbMovie. + * + * @throws MovieDbException + */ + @Test + public void testGetMovieLists() throws MovieDbException { + LOG.info("getMovieLists"); + TmdbResultsList result = instance.getMovieLists(ID_MOVIE_BLADE_RUNNER, LANGUAGE_ENGLISH, 0); + assertNotNull("No results found", result); + assertTrue("No results found", result.getResults().size() > 0); + } + + /** + * Test of getMovieChanges method,of class TheMovieDbApi + * + * @throws MovieDbException + */ + @Ignore("Do not test this until it is fixed") + public void testGetMovieChanges() throws MovieDbException { + LOG.info("getMovieChanges"); + + String startDate = ""; + String endDate = null; + + // Get some popular movies + TmdbResultsList movieList = instance.getPopularMovieList(LANGUAGE_DEFAULT, 0); + for (MovieDb movie : movieList.getResults()) { + TmdbResultsMap> result = instance.getMovieChanges(movie.getId(), startDate, endDate); + LOG.info("{} has {} changes.", movie.getTitle(), result.getResults().size()); + assertTrue("No changes found", result.getResults().size() > 0); + break; + } + } + + /** + * Test of getLatestMovie method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetLatestMovie() throws MovieDbException { + LOG.info("getLatestMovie"); + MovieDb result = instance.getLatestMovie(); + assertTrue("No latest movie found", result != null); + assertTrue("No latest movie found", result.getId() > 0); + } + + /** + * Test of getUpcoming method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetUpcoming() throws MovieDbException { + LOG.info("getUpcoming"); + TmdbResultsList result = instance.getUpcoming(LANGUAGE_DEFAULT, 0); + assertTrue("No upcoming movies found", !result.getResults().isEmpty()); + } + + /** + * Test of getNowPlayingMovies method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetNowPlayingMovies() throws MovieDbException { + LOG.info("getNowPlayingMovies"); + TmdbResultsList result = instance.getNowPlayingMovies(LANGUAGE_DEFAULT, 0); + assertTrue("No now playing movies found", !result.getResults().isEmpty()); + } + + /** + * Test of getPopularMovieList method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetPopularMovieList() throws MovieDbException { + LOG.info("getPopularMovieList"); + TmdbResultsList result = instance.getPopularMovieList(LANGUAGE_DEFAULT, 0); + assertTrue("No popular movies found", !result.getResults().isEmpty()); + } + + /** + * Test of getTopRatedMovies method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetTopRatedMovies() throws MovieDbException { + LOG.info("getTopRatedMovies"); + TmdbResultsList result = instance.getTopRatedMovies(LANGUAGE_DEFAULT, 0); + assertTrue("No top rated movies found", !result.getResults().isEmpty()); + } + + /** + * Test of postMovieRating method, of class TheMovieDbApi. + * + * TODO: Cannot be tested without a HTTP authorisation: http://help.themoviedb.org/kb/api/user-authentication /** + * + * @throws MovieDbException + */ + @Test + public void testMovieRating() throws MovieDbException { + LOG.info("postMovieRating"); + Integer movieID = 68724; + Integer rating = new Random().nextInt(10) + 1; + + boolean wasPosted = instance.postMovieRating(SESSION_ID_APITESTS, movieID, rating); + assertTrue("Failed to post rating", wasPosted); + + try { + // Make sure that we pause long enough for the record to by updated + Thread.sleep(5000); + } catch (InterruptedException ex) { + // Ignore the exception and move on + } + + // get all rated movies + TmdbAccount account = new TmdbAccount(getApiKey(),getHttpTools()); + List ratedMovies = account.getRatedMovies(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS); + assertTrue(ratedMovies.size() > 0); + + // make sure that we find the movie and it is rated correctly + boolean foundMovie = false; + for (MovieDb movie : ratedMovies) { + if (movie.getId() == movieID) { + assertEquals("Incorrect rating", movie.getUserRating(), (float) rating, 0); + foundMovie = true; + break; + } + } + assertTrue("Movie not found!", foundMovie); + } + + /** + * Test of getMovieCredits method, of class TmdbMovies. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetMovieCredits() throws MovieDbException { + LOG.info("getMovieCredits"); + TmdbResultsList result = instance.getMovieCredits(ID_MOVIE_BLADE_RUNNER, ""); + assertFalse("No credits returned", result.getResults().isEmpty()); + } + + /** + * Test of getMovieStatus method, of class TmdbMovies. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetMovieStatus() throws MovieDbException { + LOG.info("getMovieStatus"); + // This movie should be rated + MovieState result = instance.getMovieStatus(SESSION_ID_APITESTS, ID_MOVIE_BLADE_RUNNER); + assertNotNull("No state returned", result); + assertFalse("Movie is favourited", result.isFavorite()); + assertFalse("Movie is not rated", result.getRating() < 0); + assertFalse("Movie is watch listed", result.isWatchlist()); + + // This movie should not be rated + result = instance.getMovieStatus(SESSION_ID_APITESTS, ID_MOVIE_THE_AVENGERS); + assertNotNull("No state returned", result); + assertFalse("Movie is favourited", result.isFavorite()); + assertFalse("Movie is rated", result.getRating() > -1); + assertFalse("Movie is watch listed", result.isWatchlist()); + } + + /** + * Test of postMovieRating method, of class TmdbMovies. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testPostMovieRating() throws MovieDbException { + LOG.info("postMovieRating"); + Integer rating = 10; + boolean result = instance.postMovieRating(SESSION_ID_APITESTS, ID_MOVIE_BLADE_RUNNER, rating); + assertEquals("Failed to set rating", true, result); + } + +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbNetworksTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbNetworksTest.java new file mode 100644 index 000000000..54b9c51d0 --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbNetworksTest.java @@ -0,0 +1,65 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.AbstractTests; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestLogger; +import com.omertron.themoviedbapi.model.tv.Network; +import org.junit.AfterClass; +import static org.junit.Assert.assertEquals; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * + * @author stuart.boston + */ +public class TmdbNetworksTest extends AbstractTests { + + // API + private static TmdbNetworks instance; + + public TmdbNetworksTest() { + } + + @BeforeClass + public static void setUpClass() throws MovieDbException { + TestLogger.Configure(); + instance = new TmdbNetworks(getApiKey(), getHttpTools()); + } + + @AfterClass + public static void tearDownClass() { + } + + /** + * Test of getNetworkInfo method, of class TmdbNetworks. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetNetworkInfo() throws MovieDbException { + LOG.info("getNetworkInfo"); + Network result = instance.getNetworkInfo(1); + assertEquals("Wrong network returned", "Fuji Television", result.getName()); + } + +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java new file mode 100644 index 000000000..29320677e --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java @@ -0,0 +1,215 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.AbstractTests; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestLogger; +import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey(); +import static com.omertron.themoviedbapi.TheMovieDbApiTest.LANGUAGE_DEFAULT; +import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model.person.NewCast; +import com.omertron.themoviedbapi.model.person.NewPersonCredits; +import com.omertron.themoviedbapi.model.person.Person; +import com.omertron.themoviedbapi.model.person.PersonBasic; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import org.apache.commons.lang3.StringUtils; +import org.junit.After; +import org.junit.AfterClass; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yamj.api.common.http.DefaultPoolingHttpClient; + +/** + * + * @author stuart.boston + */ +public class TmdbPeopleTest extends AbstractTests{ + + // Logger + private static final Logger LOG = LoggerFactory.getLogger(TmdbGenresTest.class); + // API + private static TmdbPeople instance; + private static final int ID_BRUCE_WILLIS = 62; + private static final int ID_SEAN_BEAN = 48; + private static final int ID_DICK_WOLF = 117443; + + public TmdbPeopleTest() { + } + + @BeforeClass + public static void setUpClass() throws MovieDbException { + TestLogger.Configure(); + instance = new TmdbPeople(getApiKey(),getHttpTools()); + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getPersonMovieOldInfo method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ +// @Test + public void testGetPersonInfo() throws MovieDbException { + LOG.info("getPersonInfo"); + Person result = instance.getPersonInfo(ID_BRUCE_WILLIS); + assertTrue("Wrong actor returned", result.getId() == ID_BRUCE_WILLIS); + assertTrue("Missing bio", StringUtils.isNotBlank(result.getBiography())); + assertTrue("Missing birthday", StringUtils.isNotBlank(result.getBirthday())); + assertTrue("Missing homepage", StringUtils.isNotBlank(result.getHomepage())); + assertTrue("Missing IMDB", StringUtils.isNotBlank(result.getImdbId())); + assertTrue("Missing name", StringUtils.isNotBlank(result.getName())); + assertTrue("Missing birth place", StringUtils.isNotBlank(result.getBirthplace())); + assertTrue("Missing artwork", StringUtils.isNotBlank(result.getProfilePath())); + assertTrue("Missing bio", result.getPopularity() > 0F); + } + + /** + * Test of getPersonMovieOldImages method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ +// @Test + public void testGetPersonImages() throws MovieDbException { + LOG.info("getPersonImages"); + + TmdbResultsList result = instance.getPersonImages(ID_BRUCE_WILLIS); + assertTrue("No cast information", result.getResults().size() > 0); + for (Artwork artwork : result.getResults()) { + assertTrue("Artwork is blank", StringUtils.isNotBlank(artwork.getFilePath())); + } + + } + + /** + * Test of getPersonChanges method, of class TmdbPeople. + * + * @throws MovieDbException + */ + @Ignore("Not ready yet") + public void testGetPersonChanges() throws MovieDbException { + LOG.info("getPersonChanges"); + String startDate = ""; + String endDate = ""; + instance.getPersonChanges(ID_BRUCE_WILLIS, startDate, endDate); + } + + /** + * Test of getPersonPopular method, of class TmdbPeople. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ +// @Test + public void testGetPersonPopular() throws MovieDbException { + LOG.info("getPersonPopular"); + int page = 0; + TmdbResultsList result = instance.getPersonPopular(page); + assertFalse("No popular people", result.getResults().isEmpty()); + for (PersonBasic person : result.getResults()) { + assertTrue("Missing name", StringUtils.isNotBlank(person.getName())); + } + } + + /** + * Test of getPersonLatest method, of class TmdbPeople. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ +// @Test + public void testGetPersonLatest() throws MovieDbException { + LOG.info("getPersonLatest"); + + Person result = instance.getPersonLatest(); + + assertNotNull("No results found", result); + assertTrue("No results found", StringUtils.isNotBlank(result.getName())); + } + + /** + * Test of getPersonMovieOldCredits method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testGetPersonMovieCredits() throws MovieDbException { + LOG.info("getPersonMovieCredits"); + + NewPersonCredits result = instance.getPersonMovieCredits(ID_BRUCE_WILLIS, LANGUAGE_DEFAULT); + assertEquals("Invalid ID", ID_BRUCE_WILLIS, result.getId()); + assertFalse("No cast information returned", result.getCast().isEmpty()); + for(NewCast person:result.getCast()) { + LOG.info(person.toString()); + } + + assertFalse("No crew information returned", result.getCrew().isEmpty()); + } + + /** + * Test of getPersonTvCredits method, of class TmdbPeople. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ +// @Test + public void testGetPersonTvCredits() throws MovieDbException { + LOG.info("getPersonTvCredits"); + + NewPersonCredits result = instance.getPersonTvCredits(ID_DICK_WOLF, LANGUAGE_DEFAULT); + assertEquals("Invalid ID", ID_DICK_WOLF, result.getId()); + assertFalse("No cast information returned", result.getCast().isEmpty()); + assertFalse("No crew information returned", result.getCrew().isEmpty()); + } + + /** + * Test of getPersonCombinedCredits method, of class TmdbPeople. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ +// @Test + public void testGetPersonCombinedCredits() throws MovieDbException { + LOG.info("getPersonCombinedCredits"); + + NewPersonCredits result = instance.getPersonCombinedCredits(ID_SEAN_BEAN, LANGUAGE_DEFAULT); + assertEquals("Invalid ID", ID_SEAN_BEAN, result.getId()); + assertFalse("No cast information returned", result.getCast().isEmpty()); + assertFalse("No crew information returned", result.getCrew().isEmpty()); + + LOG.info("{}", result.toString()); + } + +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbReviewsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbReviewsTest.java new file mode 100644 index 000000000..91fddb8db --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbReviewsTest.java @@ -0,0 +1,85 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.AbstractTests; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestLogger; +import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey(); +import com.omertron.themoviedbapi.model.Review; +import org.apache.commons.lang3.StringUtils; +import org.junit.After; +import org.junit.AfterClass; +import static org.junit.Assert.assertTrue; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yamj.api.common.http.DefaultPoolingHttpClient; + +/** + * + * @author stuart.boston + */ +public class TmdbReviewsTest extends AbstractTests{ + + // Logger + private static final Logger LOG = LoggerFactory.getLogger(TmdbAuthenticationTest.class); + // API + private static TmdbReviews instance; + + public TmdbReviewsTest() { + } + + @BeforeClass + public static void setUpClass() throws MovieDbException { + TestLogger.Configure(); + instance = new TmdbReviews(getApiKey(),getHttpTools()); + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of getReview method, of class TmdbReviews. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetReview() throws MovieDbException { + LOG.info("getReview"); + String reviewId = "5013bc76760ee372cb00253e"; + Review result = instance.getReview(reviewId); + LOG.info(result.toString()); + assertTrue("No Author", StringUtils.isNotBlank(result.getAuthor())); + assertTrue("No Content", StringUtils.isNotBlank(result.getContent())); + } + +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java new file mode 100644 index 000000000..c18b2d454 --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java @@ -0,0 +1,168 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.AbstractTests; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestLogger; +import com.omertron.themoviedbapi.model.Collection; +import com.omertron.themoviedbapi.model.Company; +import com.omertron.themoviedbapi.model.Keyword; +import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.model.MovieList; +import com.omertron.themoviedbapi.model.person.PersonMovieOld; +import com.omertron.themoviedbapi.model.tv.TVSeriesBasic; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import org.junit.AfterClass; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * + * @author stuart.boston + */ +public class TmdbSearchTest extends AbstractTests { + + // API + private static TmdbSearch instance; + private static final String COMPANY_NAME = "Marvel Studios"; + + public TmdbSearchTest() { + } + + @BeforeClass + public static void setUpClass() throws MovieDbException { + TestLogger.Configure(); + instance = new TmdbSearch(getApiKey(), getHttpTools()); + } + + @AfterClass + public static void tearDownClass() { + } + + /** + * Test of searchMovie method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testSearchMovie() throws MovieDbException { + LOG.info("searchMovie"); + + // Try a movie with less than 1 page of results + TmdbResultsList movieList = instance.searchMovie("Blade Runner", 0, "", true, 0); +// List movieList = tmdb.searchMovie("Blade Runner", "", true); + assertTrue("No movies found, should be at least 1", movieList.getResults().size() > 0); + + // Try a russian langugage movie + movieList = instance.searchMovie("О чём говорят мужчины", 0, LANGUAGE_RUSSIAN, true, 0); + assertTrue("No 'RU' movies found, should be at least 1", movieList.getResults().size() > 0); + + // Try a movie with more than 20 results + movieList = instance.searchMovie("Star Wars", 0, LANGUAGE_ENGLISH, false, 0); + assertTrue("Not enough movies found, should be over 15, found " + movieList.getResults().size(), movieList.getResults().size() >= 15); + } + + /** + * Test of searchTv method, of class TmdbSearch. + * + * @throws MovieDbException + */ + @Test + public void testSearchTv() throws MovieDbException { + LOG.info("searchTv"); + TmdbResultsList results = instance.searchTv("Big Bang Theory", 0, LANGUAGE_DEFAULT, null, 0); + assertFalse("No shows found, should be at least 1", results.getResults().isEmpty()); + } + + /** + * Test of searchCollection method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testSearchCollection() throws MovieDbException { + LOG.info("searchCollection"); + String query = "batman"; + int page = 0; + TmdbResultsList result = instance.searchCollection(query, LANGUAGE_DEFAULT, page); + assertFalse("No collections found", result == null); + assertTrue("No collections found", result.getResults().size() > 0); + } + + /** + * Test of searchPeople method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testSearchPeople() throws MovieDbException { + LOG.info("searchPeople"); + String personName = "Bruce Willis"; + boolean includeAdult = false; + TmdbResultsList result = instance.searchPeople(personName, includeAdult, 0); + assertTrue("Couldn't find the person", result.getResults().size() > 0); + } + + /** + * Test of searchList method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testSearchList() throws MovieDbException { + LOG.info("searchList"); + String query = "watch"; + int page = 0; + TmdbResultsList result = instance.searchList(query, LANGUAGE_DEFAULT, page); + assertFalse("No lists found", result.getResults() == null); + assertTrue("No lists found", result.getResults().size() > 0); + } + + /** + * Test of searchCompanies method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testSearchCompanies() throws MovieDbException { + LOG.info("searchCompanies"); + TmdbResultsList result = instance.searchCompanies(COMPANY_NAME, 0); + assertTrue("No company information found", !result.getResults().isEmpty()); + } + + /** + * Test of searchKeyword method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testSearchKeyword() throws MovieDbException { + LOG.info("searchKeyword"); + String query = "action"; + int page = 0; + TmdbResultsList result = instance.searchKeyword(query, page); + assertFalse("No keywords found", result.getResults() == null); + assertTrue("No keywords found", result.getResults().size() > 0); + } + +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbTVTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbTVTest.java new file mode 100644 index 000000000..4e5ced56f --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbTVTest.java @@ -0,0 +1,225 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.methods; + +import com.omertron.themoviedbapi.AbstractTests; +import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestLogger; +import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model.ExternalIds; +import com.omertron.themoviedbapi.model.tv.TVCredits; +import com.omertron.themoviedbapi.model.tv.TVEpisode; +import com.omertron.themoviedbapi.model.tv.TVSeason; +import com.omertron.themoviedbapi.model.tv.TVSeries; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import org.apache.commons.lang3.StringUtils; +import org.junit.AfterClass; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +/** + * Test for the TV Method + * + * @author stuart.boston + */ +public class TmdbTVTest extends AbstractTests { + + // API + private static TmdbTV instance; + // IDs + private static final int ID_BIG_BANG_THEORY = 1418; + + public TmdbTVTest() { + } + + @BeforeClass + public static void setUpClass() throws MovieDbException { + TestLogger.Configure(); + instance = new TmdbTV(getApiKey(),getHttpTools()); + } + + @AfterClass + public static void tearDownClass() { + } + + /** + * Test of getTv method, of class TV. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + //@Test + public void testGetTv() throws MovieDbException { + LOG.info("getTv"); + TVSeries result = instance.getTv(ID_BIG_BANG_THEORY, LANGUAGE_DEFAULT, null); + assertEquals("Wrong title returned", "The Big Bang Theory", result.getName()); + assertTrue("No seasons returned", result.getNumberSeasons() >= 5); + assertTrue("No episodes returned", result.getNumberEpisodes() > 100); + assertFalse("No genres returned", result.getGenres().isEmpty()); + assertFalse("No created by", result.getCreatedBy().isEmpty()); + } + + /** + * Test of getTvCredits method, of class TV. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetTvCredits() throws MovieDbException { + LOG.info("getTvCredits"); + + TVCredits result = instance.getTvCredits(ID_BIG_BANG_THEORY, LANGUAGE_DEFAULT, null); + assertFalse("No cast", result.getCast().isEmpty()); + assertFalse("No crew", result.getCrew().isEmpty()); + assertTrue("Guest stars returned", result.getGuestStar().isEmpty()); + } + + /** + * Test of getTvExternalIds method, of class TV. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + //@Test + public void testGetTvExternalIds() throws MovieDbException { + LOG.info("getTvExternalIds"); + ExternalIds result = instance.getTvExternalIds(ID_BIG_BANG_THEORY, LANGUAGE_DEFAULT); + assertFalse("No ids found", result.getIds().isEmpty()); + assertTrue("TMDB Id not found", result.hasId("id")); + assertEquals("Wrong id returned", Integer.toString(ID_BIG_BANG_THEORY), result.getId("id")); + assertEquals("Wrong TVDB Id returned", "80379", result.getId("tvdb_id")); + } + + /** + * Test of getTvImages method, of class TV. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + //@Test + public void testGetTvImages() throws MovieDbException { + LOG.info("getTvImages"); + TmdbResultsList result = instance.getTvImages(ID_BIG_BANG_THEORY, LANGUAGE_DEFAULT); + assertFalse("No results found", result.getResults().isEmpty()); + } + + /** + * Test of getTvSeason method, of class TV. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + //@Test + public void testGetTvSeason() throws MovieDbException { + LOG.info("getTvSeason"); + + TVSeason result = instance.getTvSeason(ID_BIG_BANG_THEORY, 1, LANGUAGE_DEFAULT, null); + assertFalse("No episodes found for season", result.getEpisodes().isEmpty()); + assertEquals("Wrong air date", "2007-09-24", result.getAirDate()); + assertEquals("Wrong season name", "Season 1", result.getName()); + } + + /** + * Test of getTvSeasonExternalIds method, of class TV. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + //@Test + public void testGetTvSeasonExternalIds() throws MovieDbException { + LOG.info("getTvSeasonExternalIds"); + + ExternalIds result = instance.getTvSeasonExternalIds(ID_BIG_BANG_THEORY, 1, LANGUAGE_DEFAULT); + assertFalse("No ids found", result.getIds().isEmpty()); + assertTrue("TMDB Id not found", result.hasId("id")); + assertEquals("Wrong season id returned", "3738", result.getId("id")); + assertEquals("Wrong TVDB Id returned", "28047", result.getId("tvdb_id")); + } + + /** + * Test of getTvSeasonImages method, of class TV. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + //@Test + public void testGetTvSeasonImages() throws MovieDbException { + LOG.info("getTvSeasonImages"); + TmdbResultsList result = instance.getTvSeasonImages(ID_BIG_BANG_THEORY, 1, LANGUAGE_DEFAULT); + assertFalse("No results found", result.getResults().isEmpty()); + } + + /** + * Test of getTvEpisode method, of class TV. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + //@Test + public void testGetTvEpisode() throws MovieDbException { + LOG.info("getTvEpisode"); + TVEpisode result = instance.getTvEpisode(ID_BIG_BANG_THEORY, 1, 1, LANGUAGE_DEFAULT, null); + assertEquals("Wrong ID", 64766, result.getId()); + assertEquals("Wrong date", "2007-09-24", result.getAirDate()); + assertTrue("No overview", StringUtils.isNotBlank(result.getOverview())); + } + + /** + * Test of getTvEpisodeCredits method, of class TV. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetTvEpisodeCredits() throws MovieDbException { + LOG.info("getTvEpisodeCredits"); + TVCredits result = instance.getTvEpisodeCredits(ID_BIG_BANG_THEORY, 1, 1, LANGUAGE_DEFAULT); + assertFalse("No cast", result.getCast().isEmpty()); + assertFalse("No crew", result.getCrew().isEmpty()); + assertFalse("No Guest stars returned", result.getGuestStar().isEmpty()); + } + + /** + * Test of getTvEpisodeExternalIds method, of class TV. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Ignore("Find an episode with ids to test this on") + public void testGetTvEpisodeExternalIds() throws MovieDbException { + LOG.info("getTvEpisodeExternalIds"); + ExternalIds result = instance.getTvEpisodeExternalIds(ID_BIG_BANG_THEORY, 1, 1, LANGUAGE_DEFAULT); + LOG.info("{}", result); + assertFalse("No ids found", result.getIds().isEmpty()); + assertTrue("TMDB Id not found", result.hasId("id")); + assertEquals("Wrong season id returned", "3738", result.getId("id")); + assertEquals("Wrong TVDB Id returned", "28047", result.getId("tvdb_id")); + } + + /** + * Test of getTvEpisodeImages method, of class TV. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + //@Test + public void testGetTvEpisodeImages() throws MovieDbException { + LOG.info("getTvEpisodeImages"); + String result = instance.getTvEpisodeImages(ID_BIG_BANG_THEORY, 1, 1, LANGUAGE_DEFAULT); + LOG.info("{}", result); + fail("Unfinished"); + } + +} From af2d8400fcbb2c283e1cd6a556c0150a459dee16 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Wed, 18 Feb 2015 10:19:26 +0000 Subject: [PATCH 011/100] Tidy up of test cases --- .../omertron/themoviedbapi/TheMovieDbApi.java | 10 +- .../methods/TmdbConfiguration.java | 24 --- .../themoviedbapi/model/Configuration.java | 29 +++ .../results/TmdbResultsList.java | 4 + .../omertron/themoviedbapi/AbstractTests.java | 48 +++-- .../omertron/themoviedbapi/TestAccounts.java | 2 +- .../methods/TmdbAccountTest.java | 37 ++-- .../methods/TmdbAuthenticationTest.java | 4 +- .../methods/TmdbCertificationsTest.java | 5 +- .../methods/TmdbChangesTest.java | 31 +++- .../methods/TmdbCollectionsTest.java | 4 +- .../methods/TmdbCompaniesTest.java | 19 +- .../methods/TmdbConfigurationTest.java | 18 +- .../methods/TmdbCreditsTest.java | 24 +-- .../methods/TmdbDiscoverTest.java | 19 +- .../themoviedbapi/methods/TmdbFindTest.java | 33 ++-- .../themoviedbapi/methods/TmdbGenresTest.java | 17 +- .../themoviedbapi/methods/TmdbJobsTest.java | 82 --------- .../methods/TmdbKeywordsTest.java | 17 +- .../themoviedbapi/methods/TmdbListsTest.java | 31 ++-- .../themoviedbapi/methods/TmdbMoviesTest.java | 137 ++++---------- .../methods/TmdbNetworksTest.java | 9 +- .../themoviedbapi/methods/TmdbPeopleTest.java | 98 +--------- .../methods/TmdbReviewsTest.java | 23 +-- .../themoviedbapi/methods/TmdbSearchTest.java | 20 +- .../themoviedbapi/methods/TmdbTVTest.java | 173 +----------------- 26 files changed, 231 insertions(+), 687 deletions(-) delete mode 100644 src/test/java/com/omertron/themoviedbapi/methods/TmdbJobsTest.java diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index ebe0b2dd6..939b50702 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -19,7 +19,6 @@ */ package com.omertron.themoviedbapi; -import com.fasterxml.jackson.databind.ObjectMapper; import com.omertron.themoviedbapi.enumeration.MediaType; import com.omertron.themoviedbapi.methods.TmdbAccount; import com.omertron.themoviedbapi.methods.TmdbAuthentication; @@ -79,8 +78,6 @@ import java.net.URL; import java.util.List; import org.apache.commons.lang3.StringUtils; import org.apache.http.client.HttpClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.yamj.api.common.http.SimpleHttpClientBuilder; /** @@ -92,11 +89,7 @@ import org.yamj.api.common.http.SimpleHttpClientBuilder; */ public class TheMovieDbApi { - private static final Logger LOG = LoggerFactory.getLogger(TheMovieDbApi.class); - private String apiKey; private HttpTools httpTools; - // Jackson JSON configuration - private static final ObjectMapper MAPPER = new ObjectMapper(); // Constants private static final int YEAR_LENGTH = 4; // Sub-methods @@ -138,7 +131,6 @@ public class TheMovieDbApi { * @throws MovieDbException */ public TheMovieDbApi(String apiKey, HttpClient httpClient) throws MovieDbException { - this.apiKey = apiKey; this.httpTools = new HttpTools(httpClient); initialise(apiKey, httpTools); } @@ -687,7 +679,7 @@ public class TheMovieDbApi { * @throws MovieDbException */ public URL createImageUrl(String imagePath, String requiredSize) throws MovieDbException { - return tmdbConfiguration.createImageUrl(imagePath, requiredSize); + return tmdbConfiguration.getConfig().createImageUrl(imagePath, requiredSize); } /** diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java index 81b7f5ce5..a36f85983 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java @@ -31,7 +31,6 @@ import com.omertron.themoviedbapi.tools.MethodSub; import com.omertron.themoviedbapi.wrapper.WrapperConfig; import com.omertron.themoviedbapi.wrapper.WrapperJobList; import java.io.IOException; -import java.net.MalformedURLException; import java.net.URL; import org.yamj.api.common.exception.ApiExceptionType; @@ -80,29 +79,6 @@ public class TmdbConfiguration extends AbstractMethod { return config; } - /** - * Generate the full image URL from the size and image path - * - * @param imagePath - * @param requiredSize - * @return - * @throws MovieDbException - */ - public URL createImageUrl(String imagePath, String requiredSize) throws MovieDbException { - if (!config.isValidSize(requiredSize)) { - throw new MovieDbException(ApiExceptionType.INVALID_IMAGE, "Required size '" + requiredSize + "' is not valid"); - } - - StringBuilder sb = new StringBuilder(config.getBaseUrl()); - sb.append(requiredSize); - sb.append(imagePath); - try { - return new URL(sb.toString()); - } catch (MalformedURLException ex) { - throw new MovieDbException(ApiExceptionType.INVALID_URL, "Failed to create image URL", sb.toString(), ex); - } - } - /** * Get a list of valid jobs * diff --git a/src/main/java/com/omertron/themoviedbapi/model/Configuration.java b/src/main/java/com/omertron/themoviedbapi/model/Configuration.java index 9e21dfe31..a8338cc13 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/Configuration.java +++ b/src/main/java/com/omertron/themoviedbapi/model/Configuration.java @@ -20,8 +20,12 @@ package com.omertron.themoviedbapi.model; import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.MovieDbException; +import java.net.MalformedURLException; +import java.net.URL; import java.util.List; import org.apache.commons.lang3.StringUtils; +import org.yamj.api.common.exception.ApiExceptionType; /** * @author stuart.boston @@ -180,4 +184,29 @@ public class Configuration extends AbstractJsonMapping { || isValidProfileSize(sizeToCheck) || isValidLogoSize(sizeToCheck); } + + /** + * Generate the full image URL from the size and image path + * + * @param imagePath + * @param requiredSize + * @return + * @throws MovieDbException + */ + public URL createImageUrl(String imagePath, String requiredSize) throws MovieDbException { + if (!isValidSize(requiredSize)) { + throw new MovieDbException(ApiExceptionType.INVALID_IMAGE, "Required size '" + requiredSize + "' is not valid"); + } + + StringBuilder sb = new StringBuilder(getBaseUrl()); + sb.append(requiredSize); + sb.append(imagePath); + + try { + return new URL(sb.toString()); + } catch (MalformedURLException ex) { + throw new MovieDbException(ApiExceptionType.INVALID_URL, "Failed to create image URL", sb.toString(), ex); + } + } + } diff --git a/src/main/java/com/omertron/themoviedbapi/results/TmdbResultsList.java b/src/main/java/com/omertron/themoviedbapi/results/TmdbResultsList.java index f9b29e5f6..d6d7c422f 100644 --- a/src/main/java/com/omertron/themoviedbapi/results/TmdbResultsList.java +++ b/src/main/java/com/omertron/themoviedbapi/results/TmdbResultsList.java @@ -48,6 +48,10 @@ public final class TmdbResultsList extends AbstractResults { this.results = results; } + public boolean isEmpty() { + return results.isEmpty(); + } + @Override public int getTotalResults() { if (super.getTotalResults() == 0) { diff --git a/src/test/java/com/omertron/themoviedbapi/AbstractTests.java b/src/test/java/com/omertron/themoviedbapi/AbstractTests.java index 0b19a628f..a7cb01b55 100644 --- a/src/test/java/com/omertron/themoviedbapi/AbstractTests.java +++ b/src/test/java/com/omertron/themoviedbapi/AbstractTests.java @@ -19,15 +19,17 @@ */ package com.omertron.themoviedbapi; +import com.omertron.themoviedbapi.methods.TmdbAccount; +import com.omertron.themoviedbapi.methods.TmdbAuthentication; +import com.omertron.themoviedbapi.model.Account; +import com.omertron.themoviedbapi.model.TokenAuthorisation; +import com.omertron.themoviedbapi.model.TokenSession; import com.omertron.themoviedbapi.tools.HttpTools; import java.io.File; import java.util.Properties; -import org.apache.http.impl.client.HttpClient; -import org.junit.After; -import org.junit.AfterClass; +import org.apache.http.client.HttpClient; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import org.junit.Before; -import org.junit.BeforeClass; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.yamj.api.common.http.SimpleHttpClientBuilder; @@ -39,13 +41,15 @@ public class AbstractTests { private static final Properties props = new Properties(); private static HttpClient httpClient; private static HttpTools httpTools; + // Session informaion + private static TokenSession tokenSession = null; + private static Account account = null; // Constants protected static final String LANGUAGE_DEFAULT = ""; protected static final String LANGUAGE_ENGLISH = "en"; protected static final String LANGUAGE_RUSSIAN = "ru"; - @BeforeClass - public static void setUpClass() throws MovieDbException { + public static final void doConfiguration() throws MovieDbException { TestLogger.Configure(); httpClient = new SimpleHttpClientBuilder().build(); httpTools = new HttpTools(httpClient); @@ -68,16 +72,30 @@ public class AbstractTests { } } - @AfterClass - public static void tearDownClass() throws MovieDbException { + public static final String getSessionId() throws MovieDbException { + if (tokenSession == null) { + TmdbAuthentication auth = new TmdbAuthentication(getApiKey(), getHttpTools()); + LOG.info("Test and create a session token for the rest of the tests"); + // 1: Create a request token + TokenAuthorisation token = auth.getAuthorisationToken(); + assertTrue("Token (auth) is not valid", token.getSuccess()); + token = auth.getSessionTokenLogin(token, getUsername(), getPassword()); + assertTrue("Token (login) is not valid", token.getSuccess()); + // 3: Create the sessions ID + tokenSession = auth.getSessionToken(token); + assertTrue("Session token is not valid", tokenSession.getSuccess()); + + } + return tokenSession.getSessionId(); } - @Before - public void setUp() throws MovieDbException { - } - - @After - public void tearDown() throws MovieDbException { + public static final int getAccountId() throws MovieDbException { + if (account == null) { + TmdbAccount instance = new TmdbAccount(getApiKey(), getHttpTools()); + // Get the account for later tests + account = instance.getAccount(tokenSession.getSessionId()); + } + return account.getId(); } public static HttpClient getHttpClient() { diff --git a/src/test/java/com/omertron/themoviedbapi/TestAccounts.java b/src/test/java/com/omertron/themoviedbapi/TestAccounts.java index 547d1e5e0..13699beae 100644 --- a/src/test/java/com/omertron/themoviedbapi/TestAccounts.java +++ b/src/test/java/com/omertron/themoviedbapi/TestAccounts.java @@ -48,11 +48,11 @@ public class TestAccounts extends AbstractTests { @BeforeClass public static void setUpClass() throws MovieDbException { + doConfiguration(); tmdb = new TheMovieDbApi(getApiKey()); } @Before - @Override public void setUp() throws MovieDbException { if (tokenSession == null) { testSessionCreation(); diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java index f393e6f6a..a7cd50f13 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java @@ -21,7 +21,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.TestLogger; +import com.omertron.themoviedbapi.enumeration.MediaType; import com.omertron.themoviedbapi.model.Account; import com.omertron.themoviedbapi.model.MovieDb; import com.omertron.themoviedbapi.model.MovieDbList; @@ -42,7 +42,6 @@ import org.junit.Test; */ public class TmdbAccountTest extends AbstractTests { - // API private static TmdbAccount instance; // Constants private static final int ID_MOVIE_FIGHT_CLUB = 550; @@ -52,7 +51,7 @@ public class TmdbAccountTest extends AbstractTests { @BeforeClass public static void setUpClass() throws MovieDbException { - TestLogger.Configure(); + doConfiguration(); instance = new TmdbAccount(getApiKey(), getHttpTools()); } @@ -61,15 +60,17 @@ public class TmdbAccountTest extends AbstractTests { } /** - * Test of getAccount method, of class TmdbAccount. + * Test of getAccountId method, of class TmdbAccount. * * @throws com.omertron.themoviedbapi.MovieDbException */ @Test public void testGetAccount() throws MovieDbException { LOG.info("getAccount"); - Account result = instance.getAccount(SESSION_ID_APITESTS); - assertEquals("Wrong account returned", ACCOUNT_ID_APITESTS, result.getId()); + Account result = instance.getAccount(getSessionId()); + assertNotNull("No account returned", result); + // Make sure properties are extracted correctly + assertEquals("Wrong username!", getUsername(), result.getUserName()); } /** @@ -80,7 +81,7 @@ public class TmdbAccountTest extends AbstractTests { @Test public void testGetUserLists() throws MovieDbException { LOG.info("getUserLists"); - List result = instance.getUserLists(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS); + List result = instance.getUserLists(getSessionId(), getAccountId()); assertNotNull("Null list returned", result); } @@ -95,16 +96,16 @@ public class TmdbAccountTest extends AbstractTests { LOG.info("Check favorite list is empty"); // make sure it's empty (because it's just a test account - List favList = instance.getFavoriteMovies(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS); + List favList = instance.getFavoriteMovies(getSessionId(), getAccountId()); assertTrue("Favorite list was not empty!", favList.isEmpty()); LOG.info("Add movie to list"); // add a movie - StatusCode status = instance.changeFavoriteStatus(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS, ID_MOVIE_FIGHT_CLUB, true); + StatusCode status = instance.changeFavoriteStatus(getSessionId(), getAccountId(), ID_MOVIE_FIGHT_CLUB, MediaType.MOVIE, true); LOG.info("Add Status: {}", status); LOG.info("Get favorite list"); - favList = instance.getFavoriteMovies(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS); + favList = instance.getFavoriteMovies(getSessionId(), getAccountId()); assertNotNull("Empty favorite list returned", favList); assertFalse("Favorite list empty", favList.isEmpty()); @@ -112,10 +113,10 @@ public class TmdbAccountTest extends AbstractTests { LOG.info("Remove movie(s) from list"); for (MovieDb movie : favList) { LOG.info("Removing movie {}-'{}'", movie.getId(), movie.getTitle()); - status = instance.changeFavoriteStatus(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS, movie.getId(), false); + status = instance.changeFavoriteStatus(getSessionId(), getAccountId(), movie.getId(), MediaType.MOVIE, false); LOG.info("Remove status: {}", status); } - assertTrue("Favorite list was not empty", instance.getFavoriteMovies(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS).isEmpty()); + assertTrue("Favorite list was not empty", instance.getFavoriteMovies(getSessionId(), getAccountId()).isEmpty()); } /** @@ -135,7 +136,7 @@ public class TmdbAccountTest extends AbstractTests { @Test public void testGetRatedMovies() throws MovieDbException { LOG.info("getRatedMovies"); - List result = instance.getRatedMovies(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS); + List result = instance.getRatedMovies(getSessionId(), getAccountId()); assertFalse("No rated movies", result.isEmpty()); } @@ -150,16 +151,16 @@ public class TmdbAccountTest extends AbstractTests { LOG.info("Check list is empty"); // make sure it's empty (because it's just a test account - List watchList = instance.getWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS); + List watchList = instance.getWatchListMovie(getSessionId(), getAccountId()); assertTrue("Watch list was not empty!", watchList.isEmpty()); LOG.info("Add movie to list"); // add a movie - StatusCode status = instance.modifyWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS, ID_MOVIE_FIGHT_CLUB, true); + StatusCode status = instance.modifyWatchList(getSessionId(), getAccountId(), ID_MOVIE_FIGHT_CLUB, MediaType.MOVIE, true); LOG.info("Add Status: {}", status); LOG.info("Get watch list"); - watchList = instance.getWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS); + watchList = instance.getWatchListMovie(getSessionId(), getAccountId()); assertNotNull("Empty watch list returned", watchList); assertFalse("Watchlist list empty", watchList.isEmpty()); @@ -167,11 +168,11 @@ public class TmdbAccountTest extends AbstractTests { // clean up again for (MovieDb movie : watchList) { LOG.info("Removing movie {}-'{}'", movie.getId(), movie.getTitle()); - status = instance.modifyWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS, movie.getId(), false); + status = instance.modifyWatchList(getSessionId(), getAccountId(), movie.getId(), MediaType.MOVIE, false); LOG.info("Remove status: {}", status); } - assertTrue(instance.getWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS).isEmpty()); + assertTrue(instance.getWatchListMovie(getSessionId(), getAccountId()).isEmpty()); } /** diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAuthenticationTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAuthenticationTest.java index 69bf8e20c..9a73574a6 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAuthenticationTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAuthenticationTest.java @@ -21,7 +21,6 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.TestLogger; import com.omertron.themoviedbapi.model.TokenAuthorisation; import com.omertron.themoviedbapi.model.TokenSession; import org.junit.AfterClass; @@ -37,7 +36,6 @@ import org.junit.Test; */ public class TmdbAuthenticationTest extends AbstractTests{ - // API private static TmdbAuthentication instance; public TmdbAuthenticationTest() { @@ -45,7 +43,7 @@ public class TmdbAuthenticationTest extends AbstractTests{ @BeforeClass public static void setUpClass() throws MovieDbException { - TestLogger.Configure(); + doConfiguration(); instance = new TmdbAuthentication(getApiKey(),getHttpTools()); } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCertificationsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCertificationsTest.java index 20bbf8625..bf8debd19 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCertificationsTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCertificationsTest.java @@ -20,8 +20,8 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; +import static com.omertron.themoviedbapi.AbstractTests.doConfiguration; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.TestLogger; import com.omertron.themoviedbapi.model.Certification; import com.omertron.themoviedbapi.results.TmdbResultsMap; import java.util.List; @@ -37,7 +37,6 @@ import org.junit.Test; */ public class TmdbCertificationsTest extends AbstractTests { - // API private static TmdbCertifications instance; public TmdbCertificationsTest() { @@ -45,7 +44,7 @@ public class TmdbCertificationsTest extends AbstractTests { @BeforeClass public static void setUpClass() throws MovieDbException { - TestLogger.Configure(); + doConfiguration(); instance = new TmdbCertifications(getApiKey(), getHttpTools()); } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbChangesTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbChangesTest.java index fd84ba761..4923c503d 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbChangesTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbChangesTest.java @@ -21,9 +21,9 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.TestLogger; -import com.omertron.themoviedbapi.model.ChangedMovie; +import com.omertron.themoviedbapi.model.ChangedMedia; import com.omertron.themoviedbapi.results.TmdbResultsList; +import com.omertron.themoviedbapi.tools.MethodBase; import org.junit.AfterClass; import static org.junit.Assert.assertFalse; import static org.junit.Assert.fail; @@ -45,7 +45,7 @@ public class TmdbChangesTest extends AbstractTests { @BeforeClass public static void setUpClass() throws MovieDbException { - TestLogger.Configure(); + doConfiguration(); instance = new TmdbChanges(getApiKey(), getHttpTools()); } @@ -54,7 +54,7 @@ public class TmdbChangesTest extends AbstractTests { } /** - * Test of getMovieChangesList method, of class TmdbChanges. + * Test of getChangeList(MOVIE) method, of class TmdbChanges. * * @throws MovieDbException */ @@ -64,12 +64,13 @@ public class TmdbChangesTest extends AbstractTests { int page = 0; String startDate = ""; String endDate = ""; - TmdbResultsList result = instance.getMovieChangesList(page, startDate, endDate); + + TmdbResultsList result = instance.getChangeList(MethodBase.MOVIE, page, startDate, endDate); assertFalse("No movie changes.", result.getResults().isEmpty()); } /** - * Test of getPersonMovieOldChangesList method, of class TheMovieDbApi. + * Test of getChangeList(PERSON) method, of class TheMovieDbApi. * * @throws MovieDbException */ @@ -79,7 +80,23 @@ public class TmdbChangesTest extends AbstractTests { int page = 0; String startDate = ""; String endDate = ""; - instance.getPersonChangesList(page, startDate, endDate); + TmdbResultsList result = instance.getChangeList(MethodBase.PERSON, page, startDate, endDate); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of getChangeList(TV) method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Ignore("Not ready yet") + public void testGetTVChangesList() throws MovieDbException { + LOG.info("getPersonChangesList"); + int page = 0; + String startDate = ""; + String endDate = ""; + TmdbResultsList result = instance.getChangeList(MethodBase.PERSON, page, startDate, endDate); // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java index 50649b3ea..4c9414e9f 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java @@ -21,7 +21,6 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.TestLogger; import com.omertron.themoviedbapi.model.Artwork; import com.omertron.themoviedbapi.model.CollectionInfo; import com.omertron.themoviedbapi.results.TmdbResultsList; @@ -36,7 +35,6 @@ import org.junit.Test; */ public class TmdbCollectionsTest extends AbstractTests { - // API private static TmdbCollections instance; private static final int ID_COLLECTION_STAR_WARS = 10; @@ -45,7 +43,7 @@ public class TmdbCollectionsTest extends AbstractTests { @BeforeClass public static void setUpClass() throws MovieDbException { - TestLogger.Configure(); + doConfiguration(); instance = new TmdbCollections(getApiKey(), getHttpTools()); } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java index 50344ba87..a3898d00f 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java @@ -21,11 +21,8 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.TestLogger; -import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey(); -import static com.omertron.themoviedbapi.TheMovieDbApiTest.LANGUAGE_DEFAULT; import com.omertron.themoviedbapi.model.Company; -import com.omertron.themoviedbapi.model.movie.MovieDb; +import com.omertron.themoviedbapi.model.MovieDb; import com.omertron.themoviedbapi.results.TmdbResultsList; import org.junit.After; import org.junit.AfterClass; @@ -34,19 +31,13 @@ import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.yamj.api.common.http.DefaultPoolingHttpClient; /** * * @author stuart.boston */ -public class TmdbCompaniesTest extends AbstractTests{ +public class TmdbCompaniesTest extends AbstractTests { - // Logger - private static final Logger LOG = LoggerFactory.getLogger(TmdbCompaniesTest.class); - // API private static TmdbCompanies instance; private static final int ID_COMPANY = 2; @@ -55,8 +46,8 @@ public class TmdbCompaniesTest extends AbstractTests{ @BeforeClass public static void setUpClass() throws MovieDbException { - TestLogger.Configure(); - instance = new TmdbCompanies(getApiKey(),getHttpTools()); + doConfiguration(); + instance = new TmdbCompanies(getApiKey(), getHttpTools()); } @AfterClass @@ -93,6 +84,6 @@ public class TmdbCompaniesTest extends AbstractTests{ public void testGetCompanyMovies() throws MovieDbException { LOG.info("getCompanyMovies"); TmdbResultsList result = instance.getCompanyMovies(ID_COMPANY, LANGUAGE_DEFAULT, 0); - assertTrue("No company movies found", !result.getResults().isEmpty()); + assertTrue("No company movies found", !result.isEmpty()); } } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbConfigurationTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbConfigurationTest.java index 73b80c431..f59f8acfe 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbConfigurationTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbConfigurationTest.java @@ -21,10 +21,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.TestLogger; -import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey(); import com.omertron.themoviedbapi.model.Configuration; -import com.omertron.themoviedbapi.model.type.ArtworkType; import org.apache.commons.lang3.StringUtils; import org.junit.After; import org.junit.AfterClass; @@ -33,9 +30,6 @@ import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.yamj.api.common.http.DefaultPoolingHttpClient; /** * @@ -43,19 +37,15 @@ import org.yamj.api.common.http.DefaultPoolingHttpClient; */ public class TmdbConfigurationTest extends AbstractTests { - // Logger - private static final Logger LOG = LoggerFactory.getLogger(TmdbConfigurationTest.class); - - // API private static TmdbConfiguration instance; public TmdbConfigurationTest() { } @BeforeClass - public static void setUpClass() { - TestLogger.Configure(); - instance = new TmdbConfiguration(getApiKey(),getHttpTools()); + public static void setUpClass() throws MovieDbException { + doConfiguration(); + instance = new TmdbConfiguration(getApiKey(), getHttpTools()); } @AfterClass @@ -98,7 +88,7 @@ public class TmdbConfigurationTest extends AbstractTests { LOG.info("createImageUrl"); Configuration config = instance.getConfig(); - String result = config.createImageUrl("http://mediaplayersite.com/image.jpg", ArtworkType.POSTER, "original").toString(); + String result = config.createImageUrl("http://mediaplayersite.com/image.jpg", "original").toString(); assertTrue("Error compiling image URL", !result.isEmpty()); } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCreditsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCreditsTest.java index e2186a91c..2fe107517 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCreditsTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCreditsTest.java @@ -21,19 +21,13 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.TestLogger; -import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey(); -import com.omertron.themoviedbapi.model.person.PersonCredits; +import com.omertron.themoviedbapi.model.TBD_PersonCredits; import org.junit.After; import org.junit.AfterClass; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.yamj.api.common.http.DefaultPoolingHttpClient; /** * @@ -41,9 +35,6 @@ import org.yamj.api.common.http.DefaultPoolingHttpClient; */ public class TmdbCreditsTest extends AbstractTests{ - // Logger - private static final Logger LOG = LoggerFactory.getLogger(TmdbCreditsTest.class); - // API private static TmdbCredits instance; public TmdbCreditsTest() { @@ -51,7 +42,7 @@ public class TmdbCreditsTest extends AbstractTests{ @BeforeClass public static void setUpClass() throws MovieDbException { - TestLogger.Configure(); + doConfiguration(); instance = new TmdbCredits(getApiKey(),getHttpTools()); } @@ -77,10 +68,11 @@ public class TmdbCreditsTest extends AbstractTests{ LOG.info("getCreditInfo"); String creditId = "525346f619c29579400d4145"; String language = ""; - PersonCredits result = instance.getCreditInfo(creditId, language); - assertEquals("Wrong name", "Sean Bean", result.getPerson().getName()); - assertEquals("Wrong job", "Actor", result.getJob()); - assertFalse("No seasons", result.getMedia().getSeasons().isEmpty()); + TBD_PersonCredits result = instance.getCreditInfo(creditId, language); +// assertEquals("Wrong name", "Sean Bean", result.getPerson().getName()); +// assertEquals("Wrong job", "Actor", result.getJob()); +// assertFalse("No seasons", result.getMedia().getSeasons().isEmpty()); + fail("The test case is a prototype."); } } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbDiscoverTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbDiscoverTest.java index ee2e55e17..773f26d70 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbDiscoverTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbDiscoverTest.java @@ -21,11 +21,8 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.TestLogger; -import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey(); -import static com.omertron.themoviedbapi.TheMovieDbApiTest.LANGUAGE_ENGLISH; -import com.omertron.themoviedbapi.model.discover.Discover; -import com.omertron.themoviedbapi.model.movie.MovieDb; +import com.omertron.themoviedbapi.model.Discover; +import com.omertron.themoviedbapi.model.MovieDb; import com.omertron.themoviedbapi.results.TmdbResultsList; import org.junit.After; import org.junit.AfterClass; @@ -33,9 +30,6 @@ import static org.junit.Assert.assertFalse; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.yamj.api.common.http.DefaultPoolingHttpClient; /** * @@ -43,9 +37,6 @@ import org.yamj.api.common.http.DefaultPoolingHttpClient; */ public class TmdbDiscoverTest extends AbstractTests { - // Logger - private static final Logger LOG = LoggerFactory.getLogger(TmdbDiscoverTest.class); - // API private static TmdbDiscover instance; public TmdbDiscoverTest() { @@ -53,7 +44,7 @@ public class TmdbDiscoverTest extends AbstractTests { @BeforeClass public static void setUpClass() throws MovieDbException { - TestLogger.Configure(); + doConfiguration(); instance = new TmdbDiscover(getApiKey(),getHttpTools()); } @@ -80,7 +71,7 @@ public class TmdbDiscoverTest extends AbstractTests { Discover discover = new Discover(); discover.year(2013).language(LANGUAGE_ENGLISH); - TmdbResultsList result = instance.getDiscoverMovie(discover); + TmdbResultsList result = instance.getDiscoverMovies(discover); assertFalse("No movies discovered", result.getResults().isEmpty()); } @@ -95,7 +86,7 @@ public class TmdbDiscoverTest extends AbstractTests { Discover discover = new Discover(); discover.year(2013).language(LANGUAGE_ENGLISH); - TmdbResultsList result = instance.getDiscoverMovie(discover); + TmdbResultsList result = instance.getDiscoverMovies(discover); assertFalse("No TV shows discovered", result.getResults().isEmpty()); } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java index 048d03dbe..f4215fde0 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java @@ -21,29 +21,20 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.TestLogger; -import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey(); -import com.omertron.themoviedbapi.model.FindResults; import org.junit.After; import org.junit.AfterClass; -import static org.junit.Assert.assertFalse; +import static org.junit.Assert.fail; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.yamj.api.common.http.DefaultPoolingHttpClient; /** * * @author stuart.boston * @author Luca Tagliani - */ + */ public class TmdbFindTest extends AbstractTests { - // Logger - private static final Logger LOG = LoggerFactory.getLogger(TmdbFindTest.class); - // API private static TmdbFind instance; public TmdbFindTest() { @@ -51,8 +42,8 @@ public class TmdbFindTest extends AbstractTests { @BeforeClass public static void setUpClass() throws MovieDbException { - TestLogger.Configure(); - instance = new TmdbFind(getApiKey(),getHttpTools()); + doConfiguration(); + instance = new TmdbFind(getApiKey(), getHttpTools()); } @AfterClass @@ -75,23 +66,25 @@ public class TmdbFindTest extends AbstractTests { @Test public void testFindMoviesImdbID() throws MovieDbException { LOG.info("findMoviesImdbID"); - FindResults result = instance.find("tt0196229", TmdbFind.ExternalSource.imdb_id, "it"); - assertFalse("No movie for id.", result.getMovieResults().isEmpty()); +// TBD_FindResults result = instance.find("tt0196229", TBD_ExternalSource.imdb_id, "it"); +// assertFalse("No movie for id.", result.getMovieResults().isEmpty()); + fail("The test case is a prototype."); } @Test public void testFindTvSeriesImdbID() throws MovieDbException { LOG.info("findTvSeriesImdbID"); - FindResults result = instance.find("tt1219024", TmdbFind.ExternalSource.imdb_id, "it"); - assertFalse("No tv for id.", result.getTvResults().isEmpty()); +// TBD_FindResults result = instance.find("tt1219024", TBD_ExternalSource.imdb_id, "it"); +// assertFalse("No tv for id.", result.getTvResults().isEmpty()); + fail("The test case is a prototype."); } @Test public void testFindPersonImdbID() throws MovieDbException { LOG.info("findPersonImdbID"); - FindResults result = instance.find("nm0001774", TmdbFind.ExternalSource.imdb_id, "it"); - assertFalse("No person for id.", result.getPersonResults().isEmpty()); +// TBD_FindResults result = instance.find("nm0001774", TBD_ExternalSource.imdb_id, "it"); +// assertFalse("No person for id.", result.getPersonResults().isEmpty()); + fail("The test case is a prototype."); } - } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbGenresTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbGenresTest.java index 74cbcc547..0300efce9 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbGenresTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbGenresTest.java @@ -21,11 +21,8 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.TestLogger; -import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey(); -import static com.omertron.themoviedbapi.TheMovieDbApiTest.LANGUAGE_DEFAULT; import com.omertron.themoviedbapi.model.Genre; -import com.omertron.themoviedbapi.model.movie.MovieDb; +import com.omertron.themoviedbapi.model.MovieDb; import com.omertron.themoviedbapi.results.TmdbResultsList; import org.junit.After; import org.junit.AfterClass; @@ -33,9 +30,6 @@ import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.yamj.api.common.http.DefaultPoolingHttpClient; /** * @@ -43,9 +37,6 @@ import org.yamj.api.common.http.DefaultPoolingHttpClient; */ public class TmdbGenresTest extends AbstractTests { - // Logger - private static final Logger LOG = LoggerFactory.getLogger(TmdbGenresTest.class); - // API private static TmdbGenres instance; private static final int ID_GENRE_ACTION = 28; @@ -54,8 +45,8 @@ public class TmdbGenresTest extends AbstractTests { @BeforeClass public static void setUpClass() throws MovieDbException { - TestLogger.Configure(); - instance = new TmdbGenres(getApiKey(),getHttpTools()); + doConfiguration(); + instance = new TmdbGenres(getApiKey(), getHttpTools()); } @AfterClass @@ -91,7 +82,7 @@ public class TmdbGenresTest extends AbstractTests { public void testGetGenreMovies() throws MovieDbException { LOG.info("getGenreMovies"); TmdbResultsList result = instance.getGenreMovies(ID_GENRE_ACTION, LANGUAGE_DEFAULT, 0, Boolean.TRUE); - assertTrue("No genre movies found", !result.getResults().isEmpty()); + assertTrue("No genre movies found", !result.isEmpty()); } } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbJobsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbJobsTest.java deleted file mode 100644 index 7d23343ef..000000000 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbJobsTest.java +++ /dev/null @@ -1,82 +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 . - * - */ -package com.omertron.themoviedbapi.methods; - -import com.omertron.themoviedbapi.AbstractTests; -import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.TestLogger; -import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey(); -import com.omertron.themoviedbapi.model.JobDepartment; -import com.omertron.themoviedbapi.results.TmdbResultsList; -import org.junit.After; -import org.junit.AfterClass; -import static org.junit.Assert.assertFalse; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.yamj.api.common.http.DefaultPoolingHttpClient; - -/** - * - * @author stuart.boston - */ -public class TmdbJobsTest extends AbstractTests { - - // Logger - private static final Logger LOG = LoggerFactory.getLogger(TmdbGenresTest.class); - // API - private static TmdbJobs tmdb; - - public TmdbJobsTest() { - } - - @BeforeClass - public static void setUpClass() throws MovieDbException { - TestLogger.Configure(); - tmdb = new TmdbJobs(getApiKey(),getHttpTools()); - } - - @AfterClass - public static void tearDownClass() { - } - - @Before - public void setUp() { - } - - @After - public void tearDown() { - } - - /** - * Test of getJobs method, of class TheMovieDbApi. - * - * @throws MovieDbException - */ - @Test - public void testGetJobs() throws MovieDbException { - LOG.info("getJobs"); - TmdbResultsList result = tmdb.getJobs(); - assertFalse("No jobs found", result.getResults().isEmpty()); - } - -} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbKeywordsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbKeywordsTest.java index 3e758109c..bfbb2ed45 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbKeywordsTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbKeywordsTest.java @@ -21,11 +21,8 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.TestLogger; -import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey(); -import static com.omertron.themoviedbapi.TheMovieDbApiTest.LANGUAGE_DEFAULT; import com.omertron.themoviedbapi.model.Keyword; -import com.omertron.themoviedbapi.model.movie.MovieDbBasic; +import com.omertron.themoviedbapi.model.KeywordMovie; import com.omertron.themoviedbapi.results.TmdbResultsList; import org.junit.After; import org.junit.AfterClass; @@ -34,9 +31,6 @@ import static org.junit.Assert.assertFalse; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.yamj.api.common.http.DefaultPoolingHttpClient; /** * @@ -44,9 +38,6 @@ import org.yamj.api.common.http.DefaultPoolingHttpClient; */ public class TmdbKeywordsTest extends AbstractTests{ - // Logger - private static final Logger LOG = LoggerFactory.getLogger(TmdbGenresTest.class); - // API private static TmdbKeywords tmdb; private static final String ID_KEYWORD = "1721"; @@ -55,7 +46,7 @@ public class TmdbKeywordsTest extends AbstractTests{ @BeforeClass public static void setUpClass() throws MovieDbException { - TestLogger.Configure(); + doConfiguration(); tmdb = new TmdbKeywords(getApiKey(),getHttpTools()); } @@ -92,8 +83,8 @@ public class TmdbKeywordsTest extends AbstractTests{ public void testGetKeywordMovies() throws MovieDbException { LOG.info("getKeywordMovies"); int page = 0; - TmdbResultsList result = tmdb.getKeywordMovies(ID_KEYWORD, LANGUAGE_DEFAULT, page); - assertFalse("No keyword movies found", result.getResults().isEmpty()); + TmdbResultsList result = tmdb.getKeywordMovies(ID_KEYWORD, LANGUAGE_DEFAULT, page); + assertFalse("No keyword movies found", result.isEmpty()); } } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbListsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbListsTest.java index a31c28b49..640072366 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbListsTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbListsTest.java @@ -21,12 +21,9 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.TestLogger; -import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey(); -import static com.omertron.themoviedbapi.TheMovieDbApiTest.SESSION_ID_APITESTS; +import com.omertron.themoviedbapi.model.MovieDbList; import com.omertron.themoviedbapi.model.StatusCode; -import com.omertron.themoviedbapi.model.StatusCodeList; -import com.omertron.themoviedbapi.model.movie.MovieDbList; +import com.omertron.themoviedbapi.tools.MethodSub; import org.junit.After; import org.junit.AfterClass; import static org.junit.Assert.assertEquals; @@ -38,16 +35,10 @@ import org.junit.FixMethodOrder; import org.junit.Ignore; import org.junit.Test; import org.junit.runners.MethodSorters; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.yamj.api.common.http.DefaultPoolingHttpClient; @FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TmdbListsTest extends AbstractTests{ +public class TmdbListsTest extends AbstractTests { - // Logger - private static final Logger LOG = LoggerFactory.getLogger(TmdbGenresTest.class); - // API private static TmdbLists instance; public TmdbListsTest() { @@ -55,8 +46,8 @@ public class TmdbListsTest extends AbstractTests{ @BeforeClass public static void setUpClass() throws MovieDbException { - TestLogger.Configure(); - instance = new TmdbLists(getApiKey(),getHttpTools()); + doConfiguration(); + instance = new TmdbLists(getApiKey(), getHttpTools()); } @AfterClass @@ -81,10 +72,10 @@ public class TmdbListsTest extends AbstractTests{ LOG.info("createList"); String name = "My Totally Awesome List"; String description = "This list was created to share all of the totally awesome movies I've seen."; - StatusCodeList result = instance.createList(SESSION_ID_APITESTS, name, description); - LOG.info(result.toString()); + String result = instance.createList(getSessionId(), name, description); + LOG.info(result); // TODO review the generated test code and remove the default call to fail. -// fail("The test case is a prototype."); + fail("The test case is a prototype."); } /** @@ -111,7 +102,7 @@ public class TmdbListsTest extends AbstractTests{ String listId = ""; Integer movieId = null; StatusCode expResult = null; - StatusCode result = instance.addMovieToList(SESSION_ID_APITESTS, listId, movieId); + StatusCode result = instance.modifyMovieList(getSessionId(), listId, movieId, MethodSub.MOVIE); assertEquals(expResult, result); // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); @@ -145,7 +136,7 @@ public class TmdbListsTest extends AbstractTests{ String listId = ""; Integer movieId = null; StatusCode expResult = null; - StatusCode result = instance.removeMovieFromList(SESSION_ID_APITESTS, listId, movieId); + StatusCode result = instance.modifyMovieList(getSessionId(), listId, movieId, MethodSub.MOVIE); assertEquals(expResult, result); // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); @@ -161,7 +152,7 @@ public class TmdbListsTest extends AbstractTests{ LOG.info("deleteMovieList"); String listId = ""; StatusCode expResult = null; - StatusCode result = instance.deleteMovieList(SESSION_ID_APITESTS, listId); + StatusCode result = instance.deleteMovieList(getSessionId(), listId); assertEquals(expResult, result); // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java index c6add35c5..051bac584 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java @@ -21,26 +21,15 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.TestLogger; -import static com.omertron.themoviedbapi.TheMovieDbApiTest.ACCOUNT_ID_APITESTS; -import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey(); -import static com.omertron.themoviedbapi.TheMovieDbApiTest.LANGUAGE_DEFAULT; -import static com.omertron.themoviedbapi.TheMovieDbApiTest.LANGUAGE_ENGLISH; -import static com.omertron.themoviedbapi.TheMovieDbApiTest.SESSION_ID_APITESTS; import com.omertron.themoviedbapi.model.AlternativeTitle; import com.omertron.themoviedbapi.model.Artwork; -import com.omertron.themoviedbapi.model.ChangedItem; import com.omertron.themoviedbapi.model.Keyword; +import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.model.MovieList; import com.omertron.themoviedbapi.model.ReleaseInfo; -import com.omertron.themoviedbapi.model.Review; -import com.omertron.themoviedbapi.model.Trailer; import com.omertron.themoviedbapi.model.Translation; -import com.omertron.themoviedbapi.model.movie.MovieDb; -import com.omertron.themoviedbapi.model.movie.MovieList; -import com.omertron.themoviedbapi.model.movie.MovieState; -import com.omertron.themoviedbapi.model.person.PersonMovieOld; +import com.omertron.themoviedbapi.model.Video; import com.omertron.themoviedbapi.results.TmdbResultsList; -import com.omertron.themoviedbapi.results.TmdbResultsMap; import java.util.List; import java.util.Random; import org.junit.AfterClass; @@ -48,17 +37,16 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; /** * * @author stuart.boston */ -public class TmdbMoviesTest extends AbstractTests{ +public class TmdbMoviesTest extends AbstractTests { - // API private static TmdbMovies instance; private static final int ID_MOVIE_BLADE_RUNNER = 78; private static final int ID_MOVIE_THE_AVENGERS = 24428; @@ -68,8 +56,9 @@ public class TmdbMoviesTest extends AbstractTests{ @BeforeClass public static void setUpClass() throws MovieDbException { - TestLogger.Configure(); - instance = new TmdbMovies(getApiKey(),getHttpTools()); + doConfiguration(); + instance = new TmdbMovies(getApiKey(), getHttpTools()); + } @AfterClass @@ -126,25 +115,29 @@ public class TmdbMoviesTest extends AbstractTests{ @Test public void testGetMovieCasts() throws MovieDbException { LOG.info("getMovieCasts"); - TmdbResultsList people = instance.getMovieCredits(ID_MOVIE_BLADE_RUNNER, "alternative_titles,casts,images,keywords,releases,trailers,translations,similar_movies,reviews,lists"); - assertTrue("No cast information", people.getResults().size() > 0); + /* + TmdbResultsList people = instance.getMovieCredits(ID_MOVIE_BLADE_RUNNER, "alternative_titles,casts,images,keywords,releases,trailers,translations,similar_movies,reviews,lists"); + assertTrue("No cast information", people.getResults().size() > 0); - String name1 = "Harrison Ford"; - String name2 = "Charles Knode"; - boolean foundName1 = Boolean.FALSE; - boolean foundName2 = Boolean.FALSE; + String name1 = "Harrison Ford"; + String name2 = "Charles Knode"; + boolean foundName1 = Boolean.FALSE; + boolean foundName2 = Boolean.FALSE; - for (PersonMovieOld person : people.getResults()) { - if (!foundName1 && person.getName().equalsIgnoreCase(name1)) { - foundName1 = Boolean.TRUE; - } + for (PersonMovieOld person : people.getResults()) { + if (!foundName1 && person.getName().equalsIgnoreCase(name1)) { + foundName1 = Boolean.TRUE; + } + + if (!foundName2 && person.getName().equalsIgnoreCase(name2)) { + foundName2 = Boolean.TRUE; + } + } + assertTrue("Couldn't find " + name1, foundName1); + assertTrue("Couldn't find " + name2, foundName2); + */ + fail("The test case is a prototype."); - if (!foundName2 && person.getName().equalsIgnoreCase(name2)) { - foundName2 = Boolean.TRUE; - } - } - assertTrue("Couldn't find " + name1, foundName1); - assertTrue("Couldn't find " + name2, foundName2); } /** @@ -192,7 +185,7 @@ public class TmdbMoviesTest extends AbstractTests{ @Test public void testGetMovieTrailers() throws MovieDbException { LOG.info("getMovieTrailers"); - TmdbResultsList result = instance.getMovieTrailers(ID_MOVIE_BLADE_RUNNER, ""); + TmdbResultsList
// - /** - * Get the changes for a specific movie id. - * - * Changes are grouped by key, and ordered by date in descending order. - * - * 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 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 - * - * @param id - * @param startDate the start date of the changes, optional - * @param endDate the end date of the changes, optional - * @return - * @throws MovieDbException - */ - public TmdbResultsList getMovieChanges(int id, String startDate, String endDate) throws MovieDbException { - return tmdbChanges.getMovieChanges(id, startDate, endDate); - } - - /** - * Get the changes for a specific TV id. - * - * Changes are grouped by key, and ordered by date in descending order. - * - * 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 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 - * - * @param id - * @param startDate the start date of the changes, optional - * @param endDate the end date of the changes, optional - * @return - * @throws MovieDbException - */ - public TmdbResultsList getTVChanges(int id, String startDate, String endDate) throws MovieDbException { - return tmdbChanges.getMovieChanges(id, startDate, endDate); - } - - /** - * Get the changes for a specific person id. - * - * Changes are grouped by key, and ordered by date in descending order. - * - * 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 language is present on fields that are translatable. - * - * @param id - * @param startDate - * @param endDate - * @return - * @throws MovieDbException - */ - public TmdbResultsList getPersonChanges(int id, String startDate, String endDate) throws MovieDbException { - return tmdbChanges.getPersonChanges(id, startDate, endDate); - } - /** * Get a list of Movie IDs that have been edited. * diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbChanges.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbChanges.java index b4de487be..66067077a 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbChanges.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbChanges.java @@ -53,8 +53,7 @@ public class TmdbChanges extends AbstractMethod { /** * Get a list of Media IDs that have been edited. * - * You can then use the movie/TV/person changes API to get the actual data - * that has been changed. + * You can then use the movie/TV/person changes API to get the actual data that has been changed. * * @param method The method base to get * @param page @@ -63,7 +62,7 @@ public class TmdbChanges extends AbstractMethod { * @return List of changed movie * @throws MovieDbException */ - public TmdbResultsList getChangeList(MethodBase method, int page, String startDate, String endDate) throws MovieDbException { + public TmdbResultsList getChangeList(MethodBase method, Integer page, String startDate, String endDate) throws MovieDbException { TmdbParameters params = new TmdbParameters(); params.add(Param.PAGE, page); params.add(Param.START_DATE, startDate); @@ -83,45 +82,4 @@ public class TmdbChanges extends AbstractMethod { } } - /** - * Get the changes for a specific movie id. - * - * @param id - * @param startDate the start date of the changes, optional - * @param endDate the end date of the changes, optional - * @return - * @throws MovieDbException - */ - public TmdbResultsList getMovieChanges(int id, String startDate, String endDate) throws MovieDbException { - LOG.trace("Movie Changes: id: {}, start: {}, end: {}", id, startDate, endDate); - throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not implemented yet"); - } - - /** - * Get the changes for a specific TV Show - * - * @param id - * @param startDate - * @param endDate - * @return - * @throws MovieDbException - */ - public TmdbResultsList getTvChanges(int id, String startDate, String endDate) throws MovieDbException { - LOG.trace("TV Changes: id: {}, start: {}, end: {}", id, startDate, endDate); - throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not implemented yet"); - } - - /** - * Get the changes for a specific person id. - * - * @param id - * @param startDate - * @param endDate - * @return - * @throws MovieDbException - */ - public TmdbResultsList getPersonChanges(int id, String startDate, String endDate) throws MovieDbException { - LOG.trace("Person Changes: id: {}, start: {}, end: {}", id, startDate, endDate); - throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not implemented yet", ""); - } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt index d7f323cf1..f49d1b0e4 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt +++ b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt @@ -1,4 +1,4 @@ -Account (done) +Account (Done) /account Get the basic information for an account. You will need to have a valid session id. /account/{id}/lists Get the lists that you have created and marked as a favorite. /account/{id}/favorite/movies Get the list of favorite movies for an account. @@ -10,17 +10,17 @@ Account (done) /account/{id}/watchlist/tv Get the list of TV series on an accounts watchlist /account/{id}/watchlist Add or remove a movie to an accounts watch list -Authentication (done) +Authentication (Done) /authentication/token/new This method is used to generate a valid request token for user based authentication /authentication/token/validate_with_login Once you have a valid request token you can use this method to authenticate a user with a TMDb username and password. /authentication/session/new 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. /authentication/guest_session/new 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. -Certifications +Certifications (Done) /certification/movie/list Get the list of supported certifications for movies. /certification/tv/list Get the list of supported certifications for tv shows -Changes +Changes (Done) /movie/changes Get a list of movie ids that have been edited. /person/changes Get a list of people ids that have been edited. /tv/changes Get a list of TV show ids that have been edited diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCertificationsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCertificationsTest.java index bf8debd19..fe7f220ea 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCertificationsTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCertificationsTest.java @@ -25,6 +25,7 @@ import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model.Certification; import com.omertron.themoviedbapi.results.TmdbResultsMap; import java.util.List; +import java.util.Map; import org.junit.AfterClass; import static org.junit.Assert.assertFalse; import org.junit.BeforeClass; @@ -62,6 +63,10 @@ public class TmdbCertificationsTest extends AbstractTests { LOG.info("getMovieCertifications"); TmdbResultsMap> result = instance.getMoviesCertification(); assertFalse("No movie certifications.", result.getResults().isEmpty()); + for (Map.Entry> entry : result.getResults().entrySet()) { + LOG.info("{} = {} entries", entry.getKey(), entry.getValue().size()); + assertFalse("No entries for " + entry.getKey(), entry.getValue().isEmpty()); + } } /** @@ -74,5 +79,9 @@ public class TmdbCertificationsTest extends AbstractTests { LOG.info("getTvCertifications"); TmdbResultsMap> result = instance.getTvCertification(); assertFalse("No tv certifications.", result.getResults().isEmpty()); + for (Map.Entry> entry : result.getResults().entrySet()) { + LOG.info("{} = {} entries", entry.getKey(), entry.getValue().size()); + assertFalse("No entries for " + entry.getKey(), entry.getValue().isEmpty()); + } } } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbChangesTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbChangesTest.java index 81f0745b6..ca539e21e 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbChangesTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbChangesTest.java @@ -26,7 +26,6 @@ import com.omertron.themoviedbapi.results.TmdbResultsList; import com.omertron.themoviedbapi.tools.MethodBase; import org.junit.AfterClass; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; @@ -61,11 +60,7 @@ public class TmdbChangesTest extends AbstractTests { @Test public void testGetMovieChangesList() throws MovieDbException { LOG.info("getMovieChangesList"); - int page = 0; - String startDate = ""; - String endDate = ""; - - TmdbResultsList result = instance.getChangeList(MethodBase.MOVIE, page, startDate, endDate); + TmdbResultsList result = instance.getChangeList(MethodBase.MOVIE, null, null, null); assertFalse("No movie changes.", result.getResults().isEmpty()); } @@ -77,12 +72,8 @@ public class TmdbChangesTest extends AbstractTests { @Ignore("Not ready yet") public void testGetPersonChangesList() throws MovieDbException { LOG.info("getPersonChangesList"); - int page = 0; - String startDate = ""; - String endDate = ""; - TmdbResultsList result = instance.getChangeList(MethodBase.PERSON, page, startDate, endDate); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); + TmdbResultsList result = instance.getChangeList(MethodBase.PERSON, null, null, null); + assertFalse("No Person changes.", result.getResults().isEmpty()); } /** @@ -93,11 +84,7 @@ public class TmdbChangesTest extends AbstractTests { @Ignore("Not ready yet") public void testGetTVChangesList() throws MovieDbException { LOG.info("getPersonChangesList"); - int page = 0; - String startDate = ""; - String endDate = ""; - TmdbResultsList result = instance.getChangeList(MethodBase.PERSON, page, startDate, endDate); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); + TmdbResultsList result = instance.getChangeList(MethodBase.PERSON, null, null, null); + assertFalse("No TV changes.", result.getResults().isEmpty()); } } From 69d2eba4db803cf57e51d3f35848f4c9750c2c48 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 23 Feb 2015 17:24:29 +0000 Subject: [PATCH 024/100] Collections --- .../omertron/themoviedbapi/TheMovieDbApi.java | 4 +- .../methods/TmdbCollections.java | 2 +- .../themoviedbapi/methods/TmdbSearch.java | 2 +- .../themoviedbapi/methods/_Method_List.txt | 2 +- .../omertron/themoviedbapi/model/MovieDb.java | 1 + .../themoviedbapi/model2/StatusCode.java | 1 - .../collection}/Collection.java | 4 +- .../collection}/CollectionInfo.java | 4 +- .../wrapper/WrapperCollection.java | 2 +- .../themoviedbapi/TheMovieDbApiTest.java | 52 ++----------------- .../methods/TmdbCollectionsTest.java | 2 +- .../themoviedbapi/methods/TmdbSearchTest.java | 2 +- 12 files changed, 18 insertions(+), 60 deletions(-) rename src/main/java/com/omertron/themoviedbapi/{model => model2/collection}/Collection.java (98%) rename src/main/java/com/omertron/themoviedbapi/{model => model2/collection}/CollectionInfo.java (97%) diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 51e033a18..94011e8d5 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -44,8 +44,8 @@ import com.omertron.themoviedbapi.model.AlternativeTitle; import com.omertron.themoviedbapi.model.Artwork; import com.omertron.themoviedbapi.model.Certification; import com.omertron.themoviedbapi.model.change.ChangedMedia; -import com.omertron.themoviedbapi.model.Collection; -import com.omertron.themoviedbapi.model.CollectionInfo; +import com.omertron.themoviedbapi.model2.collection.Collection; +import com.omertron.themoviedbapi.model2.collection.CollectionInfo; import com.omertron.themoviedbapi.model.Company; import com.omertron.themoviedbapi.model2.Configuration; import com.omertron.themoviedbapi.model.discover.Discover; diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCollections.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCollections.java index fb935096b..49c1cafaf 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCollections.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCollections.java @@ -22,7 +22,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model.Artwork; import com.omertron.themoviedbapi.enumeration.ArtworkType; -import com.omertron.themoviedbapi.model.CollectionInfo; +import com.omertron.themoviedbapi.model2.collection.CollectionInfo; import com.omertron.themoviedbapi.results.TmdbResultsList; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java index 4823f02b1..41256eeb0 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java @@ -20,7 +20,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.Collection; +import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model.Company; import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.MovieDb; diff --git a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt index f49d1b0e4..bf5cb3acb 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt +++ b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt @@ -25,7 +25,7 @@ Changes (Done) /person/changes Get a list of people ids that have been edited. /tv/changes Get a list of TV show ids that have been edited -Collections +Collections (Done) /collection/{id} Get the basic collection information for a specific collection id. /collection/{id}/images Get all of the images for a particular collection by collection id. diff --git a/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java b/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java index f42f2060d..518cd93ab 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java +++ b/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java @@ -20,6 +20,7 @@ package com.omertron.themoviedbapi.model; import com.omertron.themoviedbapi.model2.AbstractJsonMapping; +import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.person.PersonCast; import com.omertron.themoviedbapi.model.person.PersonCrew; diff --git a/src/main/java/com/omertron/themoviedbapi/model2/StatusCode.java b/src/main/java/com/omertron/themoviedbapi/model2/StatusCode.java index 6a8dafae1..1a9d28830 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/StatusCode.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/StatusCode.java @@ -19,7 +19,6 @@ */ package com.omertron.themoviedbapi.model2; -import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.fasterxml.jackson.annotation.JsonProperty; /** diff --git a/src/main/java/com/omertron/themoviedbapi/model/Collection.java b/src/main/java/com/omertron/themoviedbapi/model2/collection/Collection.java similarity index 98% rename from src/main/java/com/omertron/themoviedbapi/model/Collection.java rename to src/main/java/com/omertron/themoviedbapi/model2/collection/Collection.java index df63d7a21..125c31ada 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/Collection.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/collection/Collection.java @@ -17,11 +17,11 @@ * along with TheMovieDB API. If not, see . * */ -package com.omertron.themoviedbapi.model; +package com.omertron.themoviedbapi.model2.collection; -import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonRootName; +import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; diff --git a/src/main/java/com/omertron/themoviedbapi/model/CollectionInfo.java b/src/main/java/com/omertron/themoviedbapi/model2/collection/CollectionInfo.java similarity index 97% rename from src/main/java/com/omertron/themoviedbapi/model/CollectionInfo.java rename to src/main/java/com/omertron/themoviedbapi/model2/collection/CollectionInfo.java index f4ae0af18..89ceca031 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/CollectionInfo.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/collection/CollectionInfo.java @@ -17,10 +17,10 @@ * along with TheMovieDB API. If not, see . * */ -package com.omertron.themoviedbapi.model; +package com.omertron.themoviedbapi.model2.collection; -import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCollection.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCollection.java index cccf68a51..e6c6c74cb 100644 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCollection.java +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCollection.java @@ -20,7 +20,7 @@ package com.omertron.themoviedbapi.wrapper; import com.fasterxml.jackson.annotation.JsonProperty; -import com.omertron.themoviedbapi.model.Collection; +import com.omertron.themoviedbapi.model2.collection.Collection; import java.util.List; /** diff --git a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java index d48758b10..4d0c587d1 100644 --- a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java +++ b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java @@ -22,8 +22,8 @@ package com.omertron.themoviedbapi; import com.omertron.themoviedbapi.model.AlternativeTitle; import com.omertron.themoviedbapi.model.Artwork; import com.omertron.themoviedbapi.model.change.ChangedMedia; -import com.omertron.themoviedbapi.model.Collection; -import com.omertron.themoviedbapi.model.CollectionInfo; +import com.omertron.themoviedbapi.model2.collection.Collection; +import com.omertron.themoviedbapi.model2.collection.CollectionInfo; import com.omertron.themoviedbapi.model.Company; import com.omertron.themoviedbapi.model.discover.Discover; import com.omertron.themoviedbapi.model.Genre; @@ -58,7 +58,7 @@ import org.junit.Test; * * @author stuart.boston */ -public class TheMovieDbApiTest extends AbstractTests{ +public class TheMovieDbApiTest extends AbstractTests { private static TheMovieDbApi tmdb; // Test data @@ -70,11 +70,6 @@ public class TheMovieDbApiTest extends AbstractTests{ private static final String COMPANY_NAME = "Marvel Studios"; private static final int ID_GENRE_ACTION = 28; private static final String ID_KEYWORD = "1721"; - // Languages - private static final String LANGUAGE_DEFAULT = ""; - private static final String LANGUAGE_ENGLISH = "en"; - private static final String LANGUAGE_RUSSIAN = "ru"; - // session and account id of test users named 'apitests' public TheMovieDbApiTest() throws MovieDbException { } @@ -86,6 +81,7 @@ public class TheMovieDbApiTest extends AbstractTests{ /** * Test of getConfiguration method, of class TheMovieDbApi. + * * @throws com.omertron.themoviedbapi.MovieDbException */ @Test @@ -497,8 +493,7 @@ public class TheMovieDbApiTest extends AbstractTests{ /** * Test of getSessionToken method, of class TheMovieDbApi. * - * TODO: Cannot be tested without a HTTP authorisation: - * http://help.themoviedb.org/kb/api/user-authentication + * TODO: Cannot be tested without a HTTP authorisation: http://help.themoviedb.org/kb/api/user-authentication * * @throws MovieDbException */ @@ -536,30 +531,6 @@ public class TheMovieDbApiTest extends AbstractTests{ assertTrue("No results found", result.getResults().size() > 0); } - /** - * Test of getMovieChanges method,of class TheMovieDbApi - * - * TODO: Do not test this until it is fixed - * - * @throws MovieDbException - */ - @Ignore("Do not test this until it is fixed") - public void testGetMovieChanges() throws MovieDbException { - LOG.info("getMovieChanges"); - - String startDate = ""; - String endDate = null; - - // Get some popular movies - TmdbResultsList movieList = tmdb.getPopularMovieList(LANGUAGE_DEFAULT, 0); - for (MovieDb movie : movieList.getResults()) { - TmdbResultsList result = tmdb.getMovieChanges(movie.getId(), startDate, endDate); - LOG.info("{} has {} changes.", movie.getTitle(), result.getResults().size()); - assertTrue("No changes found", result.getResults().size() > 0); - break; - } - } - @Test public void testGetPersonLatest() throws MovieDbException { LOG.info("getPersonLatest"); @@ -615,19 +586,6 @@ public class TheMovieDbApiTest extends AbstractTests{ assertTrue("No keywords found", result.getResults().size() > 0); } - /** - * Test of getPersonChanges method, of class TheMovieDbApi. - * - * @throws MovieDbException - */ - @Ignore("Not ready yet") - public void testGetPersonChanges() throws MovieDbException { - LOG.info("getPersonChanges"); - String startDate = ""; - String endDate = ""; - tmdb.getPersonChanges(ID_PERSON_BRUCE_WILLIS, startDate, endDate); - } - /** * Test of getList method, of class TheMovieDbApi. * diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java index 4c9414e9f..a50a3e4ff 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java @@ -22,7 +22,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model.Artwork; -import com.omertron.themoviedbapi.model.CollectionInfo; +import com.omertron.themoviedbapi.model2.collection.CollectionInfo; import com.omertron.themoviedbapi.results.TmdbResultsList; import org.junit.AfterClass; import static org.junit.Assert.assertFalse; diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java index e3686c69b..5ce63d84e 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java @@ -21,7 +21,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.Collection; +import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model.Company; import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.MovieDb; From 410df1f056a7fb72220f70ad4b94ad67b23113cd Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 23 Feb 2015 19:50:03 +0000 Subject: [PATCH 025/100] Company --- .../omertron/themoviedbapi/TheMovieDbApi.java | 4 +-- .../themoviedbapi/methods/TmdbCompanies.java | 25 ++++++------------- .../themoviedbapi/methods/TmdbSearch.java | 2 +- .../{model => model2/company}/Company.java | 3 ++- .../themoviedbapi/wrapper/WrapperCompany.java | 2 +- .../wrapper/WrapperCompanyMovies.java | 8 +++--- .../themoviedbapi/TheMovieDbApiTest.java | 2 +- .../methods/TmdbCompaniesTest.java | 11 ++++---- .../themoviedbapi/methods/TmdbSearchTest.java | 2 +- 9 files changed, 25 insertions(+), 34 deletions(-) rename src/main/java/com/omertron/themoviedbapi/{model => model2/company}/Company.java (96%) diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 94011e8d5..ff76fc166 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -46,7 +46,7 @@ import com.omertron.themoviedbapi.model.Certification; import com.omertron.themoviedbapi.model.change.ChangedMedia; import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.collection.CollectionInfo; -import com.omertron.themoviedbapi.model.Company; +import com.omertron.themoviedbapi.model2.company.Company; import com.omertron.themoviedbapi.model2.Configuration; import com.omertron.themoviedbapi.model.discover.Discover; import com.omertron.themoviedbapi.model.Genre; @@ -602,7 +602,7 @@ public class TheMovieDbApi { * @return * @throws MovieDbException */ - public TmdbResultsList getCompanyMovies(int companyId, String language, int page) throws MovieDbException { + public List getCompanyMovies(int companyId, String language, int page) throws MovieDbException { return tmdbCompany.getCompanyMovies(companyId, language, page); } // diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java index 64eb74dea..a92e2bb14 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java @@ -20,18 +20,17 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.Company; -import com.omertron.themoviedbapi.model.MovieDb; -import com.omertron.themoviedbapi.results.TmdbResultsList; +import com.omertron.themoviedbapi.model2.company.Company; +import com.omertron.themoviedbapi.model2.movie.MovieFavorite; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; import com.omertron.themoviedbapi.tools.MethodSub; import com.omertron.themoviedbapi.tools.Param; import com.omertron.themoviedbapi.tools.TmdbParameters; -import com.omertron.themoviedbapi.wrapper.WrapperCompanyMovies; import java.io.IOException; import java.net.URL; +import java.util.List; import org.yamj.api.common.exception.ApiExceptionType; /** @@ -52,8 +51,7 @@ public class TmdbCompanies extends AbstractMethod { } /** - * 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 @@ -76,8 +74,7 @@ public class TmdbCompanies extends AbstractMethod { /** * 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 * @@ -87,7 +84,7 @@ public class TmdbCompanies extends AbstractMethod { * @return * @throws MovieDbException */ - public TmdbResultsList getCompanyMovies(int companyId, String language, int page) throws MovieDbException { + public List getCompanyMovies(int companyId, String language, Integer page) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.ID, companyId); parameters.add(Param.LANGUAGE, language); @@ -95,15 +92,7 @@ public class TmdbCompanies extends AbstractMethod { URL url = new ApiUrl(apiKey, MethodBase.COMPANY).setSubMethod(MethodSub.MOVIES).buildUrl(parameters); String webpage = httpTools.getRequest(url); - - try { - WrapperCompanyMovies wrapper = MAPPER.readValue(webpage, WrapperCompanyMovies.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get company movies", url, ex); - } + return processWrapperList(TR_MOVIE_FAV, url, webpage); } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java index 41256eeb0..7d68eef35 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java @@ -21,7 +21,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model2.collection.Collection; -import com.omertron.themoviedbapi.model.Company; +import com.omertron.themoviedbapi.model2.company.Company; import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.MovieDb; import com.omertron.themoviedbapi.model.MovieList; diff --git a/src/main/java/com/omertron/themoviedbapi/model/Company.java b/src/main/java/com/omertron/themoviedbapi/model2/company/Company.java similarity index 96% rename from src/main/java/com/omertron/themoviedbapi/model/Company.java rename to src/main/java/com/omertron/themoviedbapi/model2/company/Company.java index c7093334a..eb614662e 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/Company.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/company/Company.java @@ -17,10 +17,11 @@ * along with TheMovieDB API. If not, see . * */ -package com.omertron.themoviedbapi.model; +package com.omertron.themoviedbapi.model2.company; import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model2.AbstractJsonMapping; /** * Company information diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompany.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompany.java index dd4c1430f..cf8f1897f 100644 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompany.java +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompany.java @@ -20,7 +20,7 @@ package com.omertron.themoviedbapi.wrapper; import com.fasterxml.jackson.annotation.JsonProperty; -import com.omertron.themoviedbapi.model.Company; +import com.omertron.themoviedbapi.model2.company.Company; import java.util.List; /** diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompanyMovies.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompanyMovies.java index 2ff464822..5f636882b 100644 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompanyMovies.java +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompanyMovies.java @@ -20,7 +20,7 @@ package com.omertron.themoviedbapi.wrapper; import com.fasterxml.jackson.annotation.JsonProperty; -import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.model2.movie.MovieFavorite; import java.util.List; /** @@ -30,13 +30,13 @@ import java.util.List; public class WrapperCompanyMovies extends AbstractWrapperAll { @JsonProperty("results") - private List results; + private List results; - public List getResults() { + public List getResults() { return results; } - public void setResults(List results) { + public void setResults(List results) { this.results = results; } } diff --git a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java index 4d0c587d1..e05a5c4f6 100644 --- a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java +++ b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java @@ -24,7 +24,7 @@ import com.omertron.themoviedbapi.model.Artwork; import com.omertron.themoviedbapi.model.change.ChangedMedia; import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.collection.CollectionInfo; -import com.omertron.themoviedbapi.model.Company; +import com.omertron.themoviedbapi.model2.company.Company; import com.omertron.themoviedbapi.model.discover.Discover; import com.omertron.themoviedbapi.model.Genre; import com.omertron.themoviedbapi.model2.JobDepartment; diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java index a3898d00f..0ac9a4246 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java @@ -21,11 +21,12 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.Company; -import com.omertron.themoviedbapi.model.MovieDb; -import com.omertron.themoviedbapi.results.TmdbResultsList; +import com.omertron.themoviedbapi.model2.company.Company; +import com.omertron.themoviedbapi.model2.movie.MovieFavorite; +import java.util.List; import org.junit.After; import org.junit.AfterClass; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import org.junit.Before; @@ -83,7 +84,7 @@ public class TmdbCompaniesTest extends AbstractTests { @Test public void testGetCompanyMovies() throws MovieDbException { LOG.info("getCompanyMovies"); - TmdbResultsList result = instance.getCompanyMovies(ID_COMPANY, LANGUAGE_DEFAULT, 0); - assertTrue("No company movies found", !result.isEmpty()); + List result = instance.getCompanyMovies(ID_COMPANY, LANGUAGE_DEFAULT, 0); + assertFalse("No company movies found", result.isEmpty()); } } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java index 5ce63d84e..30a46b995 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java @@ -22,7 +22,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model2.collection.Collection; -import com.omertron.themoviedbapi.model.Company; +import com.omertron.themoviedbapi.model2.company.Company; import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.MovieDb; import com.omertron.themoviedbapi.model.MovieList; From 5642d7c99ed2343aa648df119dfd5db39cebd0da Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 23 Feb 2015 19:52:20 +0000 Subject: [PATCH 026/100] rename movie and tv fav classes --- .../omertron/themoviedbapi/TheMovieDbApi.java | 16 +++++------ .../themoviedbapi/methods/AbstractMethod.java | 8 +++--- .../themoviedbapi/methods/TmdbAccount.java | 28 +++++++++---------- .../themoviedbapi/methods/TmdbCompanies.java | 6 ++-- .../{MovieFavorite.java => MovieBasic.java} | 2 +- .../tv/{TVFavorite.java => TVBasic.java} | 2 +- .../wrapper/WrapperCompanyMovies.java | 8 +++--- .../themoviedbapi/TheMovieDbApiTest.java | 6 ++-- .../methods/TmdbAccountTest.java | 26 ++++++++--------- .../methods/TmdbCompaniesTest.java | 4 +-- .../themoviedbapi/methods/TmdbMoviesTest.java | 6 ++-- 11 files changed, 57 insertions(+), 55 deletions(-) rename src/main/java/com/omertron/themoviedbapi/model2/movie/{MovieFavorite.java => MovieBasic.java} (98%) rename src/main/java/com/omertron/themoviedbapi/model2/tv/{TVFavorite.java => TVBasic.java} (98%) diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index ff76fc166..cbb0753b6 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -69,8 +69,8 @@ import com.omertron.themoviedbapi.model2.authentication.TokenAuthorisation; import com.omertron.themoviedbapi.model2.authentication.TokenSession; import com.omertron.themoviedbapi.model.Translation; import com.omertron.themoviedbapi.model.Video; -import com.omertron.themoviedbapi.model2.movie.MovieFavorite; -import com.omertron.themoviedbapi.model2.tv.TVFavorite; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; +import com.omertron.themoviedbapi.model2.tv.TVBasic; import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.results.TmdbResultsList; import com.omertron.themoviedbapi.results.TmdbResultsMap; @@ -295,7 +295,7 @@ public class TheMovieDbApi { * @return * @throws MovieDbException */ - public List getFavoriteMovies(String sessionId, int accountId) throws MovieDbException { + public List getFavoriteMovies(String sessionId, int accountId) throws MovieDbException { return tmdbAccount.getFavoriteMovies(sessionId, accountId); } @@ -325,7 +325,7 @@ public class TheMovieDbApi { * @return * @throws MovieDbException */ - public List getRatedMovies(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { + public List getRatedMovies(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { return tmdbAccount.getRatedMovies(sessionId, accountId, page, sortBy, language); } @@ -340,7 +340,7 @@ public class TheMovieDbApi { * @return * @throws MovieDbException */ - public List getRatedTV(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { + public List getRatedTV(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { return tmdbAccount.getRatedTV(sessionId, accountId, page, sortBy, language); } @@ -355,7 +355,7 @@ public class TheMovieDbApi { * @return The watchlist of the user * @throws MovieDbException */ - public List getWatchListMovie(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { + public List getWatchListMovie(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { return tmdbAccount.getWatchListMovie(sessionId, accountId, page, sortBy, language); } @@ -370,7 +370,7 @@ public class TheMovieDbApi { * @return The watchlist of the user * @throws MovieDbException */ - public List getWatchListTV(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { + public List getWatchListTV(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { return tmdbAccount.getWatchListTV(sessionId, accountId, page, sortBy, language); } @@ -602,7 +602,7 @@ public class TheMovieDbApi { * @return * @throws MovieDbException */ - public List getCompanyMovies(int companyId, String language, int page) throws MovieDbException { + public List getCompanyMovies(int companyId, String language, int page) throws MovieDbException { return tmdbCompany.getCompanyMovies(companyId, language, page); } // diff --git a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java index ca4feb1f5..11dc8fd5d 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java @@ -22,8 +22,8 @@ package com.omertron.themoviedbapi.methods; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model2.movie.MovieFavorite; -import com.omertron.themoviedbapi.model2.tv.TVFavorite; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; +import com.omertron.themoviedbapi.model2.tv.TVBasic; import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.wrapper.WrapperGenericList; @@ -49,9 +49,9 @@ public class AbstractMethod { protected static final ObjectMapper MAPPER = new ObjectMapper(); // Logger protected static final Logger LOG = LoggerFactory.getLogger(TmdbAccount.class); - protected static final TypeReference> TR_MOVIE_FAV = new TypeReference>() { + protected static final TypeReference> TR_MOVIE_BASIC = new TypeReference>() { }; - protected static final TypeReference> TR_TV_FAV = new TypeReference>() { + protected static final TypeReference> TR_TV_BASIC = new TypeReference>() { }; protected static final TypeReference> TR_USER_LIST = new TypeReference>() { }; diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java index 1e5513bcc..22574f209 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java @@ -23,8 +23,8 @@ import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.MediaType; import com.omertron.themoviedbapi.model2.account.Account; import com.omertron.themoviedbapi.model2.StatusCode; -import com.omertron.themoviedbapi.model2.movie.MovieFavorite; -import com.omertron.themoviedbapi.model2.tv.TVFavorite; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; +import com.omertron.themoviedbapi.model2.tv.TVBasic; import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; @@ -102,13 +102,13 @@ public class TmdbAccount extends AbstractMethod { * @return * @throws MovieDbException */ - public List getFavoriteMovies(String sessionId, int accountId) throws MovieDbException { + public List getFavoriteMovies(String sessionId, int accountId) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.SESSION, sessionId); parameters.add(Param.ID, accountId); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.FAVORITE_MOVIES).buildUrl(parameters); - return processWrapperList(TR_MOVIE_FAV, url, "favorite movies"); + return processWrapperList(TR_MOVIE_BASIC, url, "favorite movies"); } /** @@ -119,13 +119,13 @@ public class TmdbAccount extends AbstractMethod { * @return * @throws MovieDbException */ - public List getFavoriteTv(String sessionId, int accountId) throws MovieDbException { + public List getFavoriteTv(String sessionId, int accountId) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.SESSION, sessionId); parameters.add(Param.ID, accountId); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.FAVORITE_TV).buildUrl(parameters); - return processWrapperList(TR_TV_FAV, url, "favorite TV shows"); + return processWrapperList(TR_TV_BASIC, url, "favorite TV shows"); } /** @@ -171,7 +171,7 @@ public class TmdbAccount extends AbstractMethod { * @return * @throws MovieDbException */ - public List getRatedMovies(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { + public List getRatedMovies(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.SESSION, sessionId); parameters.add(Param.ID, accountId); @@ -180,7 +180,7 @@ public class TmdbAccount extends AbstractMethod { parameters.add(Param.LANGUAGE, language); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.RATED_MOVIES).buildUrl(parameters); - return processWrapperList(TR_MOVIE_FAV, url, "rated movies"); + return processWrapperList(TR_MOVIE_BASIC, url, "rated movies"); } /** @@ -194,7 +194,7 @@ public class TmdbAccount extends AbstractMethod { * @return * @throws MovieDbException */ - public List getRatedTV(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { + public List getRatedTV(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.SESSION, sessionId); parameters.add(Param.ID, accountId); @@ -203,7 +203,7 @@ public class TmdbAccount extends AbstractMethod { parameters.add(Param.LANGUAGE, language); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.RATED_TV).buildUrl(parameters); - return processWrapperList(TR_TV_FAV, url, "rated TV shows"); + return processWrapperList(TR_TV_BASIC, url, "rated TV shows"); } /** @@ -217,7 +217,7 @@ public class TmdbAccount extends AbstractMethod { * @return The watch list of the user * @throws MovieDbException */ - public List getWatchListMovie(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { + public List getWatchListMovie(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.SESSION, sessionId); parameters.add(Param.ID, accountId); @@ -226,7 +226,7 @@ public class TmdbAccount extends AbstractMethod { parameters.add(Param.LANGUAGE, language); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.WATCHLIST_MOVIES).buildUrl(parameters); - return processWrapperList(TR_MOVIE_FAV, url, "movie watch list"); + return processWrapperList(TR_MOVIE_BASIC, url, "movie watch list"); } /** @@ -240,7 +240,7 @@ public class TmdbAccount extends AbstractMethod { * @return The watch list of the user * @throws MovieDbException */ - public List getWatchListTV(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { + public List getWatchListTV(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.SESSION, sessionId); parameters.add(Param.ID, accountId); @@ -249,7 +249,7 @@ public class TmdbAccount extends AbstractMethod { parameters.add(Param.LANGUAGE, language); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.WATCHLIST_TV).buildUrl(parameters); - return processWrapperList(TR_TV_FAV, url, "TV watch list"); + return processWrapperList(TR_TV_BASIC, url, "TV watch list"); } /** diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java index a92e2bb14..d03571ccd 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java @@ -21,7 +21,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model2.company.Company; -import com.omertron.themoviedbapi.model2.movie.MovieFavorite; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; @@ -84,7 +84,7 @@ public class TmdbCompanies extends AbstractMethod { * @return * @throws MovieDbException */ - public List getCompanyMovies(int companyId, String language, Integer page) throws MovieDbException { + public List getCompanyMovies(int companyId, String language, Integer page) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.ID, companyId); parameters.add(Param.LANGUAGE, language); @@ -92,7 +92,7 @@ public class TmdbCompanies extends AbstractMethod { URL url = new ApiUrl(apiKey, MethodBase.COMPANY).setSubMethod(MethodSub.MOVIES).buildUrl(parameters); String webpage = httpTools.getRequest(url); - return processWrapperList(TR_MOVIE_FAV, url, webpage); + return processWrapperList(TR_MOVIE_BASIC, url, webpage); } } diff --git a/src/main/java/com/omertron/themoviedbapi/model2/movie/MovieFavorite.java b/src/main/java/com/omertron/themoviedbapi/model2/movie/MovieBasic.java similarity index 98% rename from src/main/java/com/omertron/themoviedbapi/model2/movie/MovieFavorite.java rename to src/main/java/com/omertron/themoviedbapi/model2/movie/MovieBasic.java index eac5c7c05..55357bdba 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/movie/MovieFavorite.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/movie/MovieBasic.java @@ -28,7 +28,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; * * @author stuart.boston */ -public class MovieFavorite extends AbstractJsonMapping { +public class MovieBasic extends AbstractJsonMapping { @JsonProperty("id") private int id; diff --git a/src/main/java/com/omertron/themoviedbapi/model2/tv/TVFavorite.java b/src/main/java/com/omertron/themoviedbapi/model2/tv/TVBasic.java similarity index 98% rename from src/main/java/com/omertron/themoviedbapi/model2/tv/TVFavorite.java rename to src/main/java/com/omertron/themoviedbapi/model2/tv/TVBasic.java index 8e70360d2..85399f3a5 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/tv/TVFavorite.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/tv/TVBasic.java @@ -29,7 +29,7 @@ import java.util.List; * * @author stuart.boston */ -public class TVFavorite extends AbstractJsonMapping { +public class TVBasic extends AbstractJsonMapping { @JsonProperty("id") private int id; diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompanyMovies.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompanyMovies.java index 5f636882b..2715332fe 100644 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompanyMovies.java +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCompanyMovies.java @@ -20,7 +20,7 @@ package com.omertron.themoviedbapi.wrapper; import com.fasterxml.jackson.annotation.JsonProperty; -import com.omertron.themoviedbapi.model2.movie.MovieFavorite; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; import java.util.List; /** @@ -30,13 +30,13 @@ import java.util.List; public class WrapperCompanyMovies extends AbstractWrapperAll { @JsonProperty("results") - private List results; + private List results; - public List getResults() { + public List getResults() { return results; } - public void setResults(List results) { + public void setResults(List results) { this.results = results; } } diff --git a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java index e05a5c4f6..de575d792 100644 --- a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java +++ b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java @@ -42,7 +42,9 @@ import com.omertron.themoviedbapi.model2.authentication.TokenAuthorisation; import com.omertron.themoviedbapi.model2.authentication.TokenSession; import com.omertron.themoviedbapi.model.Translation; import com.omertron.themoviedbapi.model.Video; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; import com.omertron.themoviedbapi.results.TmdbResultsList; +import java.util.List; import org.apache.commons.lang3.StringUtils; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -400,8 +402,8 @@ public class TheMovieDbApiTest extends AbstractTests { @Test public void testGetCompanyMovies() throws MovieDbException { LOG.info("getCompanyMovies"); - TmdbResultsList result = tmdb.getCompanyMovies(ID_COMPANY, LANGUAGE_DEFAULT, 0); - assertTrue("No company movies found", !result.getResults().isEmpty()); + List result = tmdb.getCompanyMovies(ID_COMPANY, LANGUAGE_DEFAULT, 0); + assertFalse("No company movies found", result.isEmpty()); } /** diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java index 5ed8712e5..229807fa3 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java @@ -24,8 +24,8 @@ import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.MediaType; import com.omertron.themoviedbapi.model2.account.Account; import com.omertron.themoviedbapi.model2.StatusCode; -import com.omertron.themoviedbapi.model2.movie.MovieFavorite; -import com.omertron.themoviedbapi.model2.tv.TVFavorite; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; +import com.omertron.themoviedbapi.model2.tv.TVBasic; import com.omertron.themoviedbapi.model2.list.UserList; import java.util.List; import org.junit.After; @@ -108,10 +108,10 @@ public class TmdbAccountTest extends AbstractTests { @Test public void testGetFavoriteMovies() throws MovieDbException { LOG.info("getFavoriteMovies"); - List results = instance.getFavoriteMovies(getSessionId(), getAccountId()); + List results = instance.getFavoriteMovies(getSessionId(), getAccountId()); assertNotNull("No list found", results); assertFalse("No entries found", results.isEmpty()); - for (MovieFavorite r : results) { + for (MovieBasic r : results) { LOG.info(" {}", r.toString()); } } @@ -124,10 +124,10 @@ public class TmdbAccountTest extends AbstractTests { @Test public void testGetFavoriteTv() throws MovieDbException { LOG.info("getFavoriteTv"); - List results = instance.getFavoriteTv(getSessionId(), getAccountId()); + List results = instance.getFavoriteTv(getSessionId(), getAccountId()); assertNotNull("No list found", results); assertFalse("No entries found", results.isEmpty()); - for (TVFavorite r : results) { + for (TVBasic r : results) { LOG.info(" {}", r.toString()); } } @@ -170,7 +170,7 @@ public class TmdbAccountTest extends AbstractTests { @Test public void testGetRatedMovies() throws MovieDbException { LOG.info("getRatedMovies"); - List results = instance.getRatedMovies(getSessionId(), getAccountId(), null, null, null); + List results = instance.getRatedMovies(getSessionId(), getAccountId(), null, null, null); assertNotNull("No rated list found", results); assertFalse("No entries found", results.isEmpty()); } @@ -183,10 +183,10 @@ public class TmdbAccountTest extends AbstractTests { @Test public void testGetRatedTV() throws MovieDbException { LOG.info("getRatedTV"); - List results = instance.getRatedTV(getSessionId(), getAccountId(), null, null, null); + List results = instance.getRatedTV(getSessionId(), getAccountId(), null, null, null); assertNotNull("No rated list found", results); assertFalse("No entries found", results.isEmpty()); - for (TVFavorite r : results) { + for (TVBasic r : results) { LOG.info(" {}", r.toString()); } } @@ -199,10 +199,10 @@ public class TmdbAccountTest extends AbstractTests { @Test public void testGetWatchListMovie() throws MovieDbException { LOG.info("getWatchListMovie"); - List results = instance.getWatchListMovie(getSessionId(), getAccountId(), null, null, null); + List results = instance.getWatchListMovie(getSessionId(), getAccountId(), null, null, null); assertNotNull("No rated list found", results); assertFalse("No entries found", results.isEmpty()); - for (MovieFavorite r : results) { + for (MovieBasic r : results) { LOG.info(" {}", r.toString()); } } @@ -215,10 +215,10 @@ public class TmdbAccountTest extends AbstractTests { @Test public void testGetWatchListTV() throws MovieDbException { LOG.info("getWatchListTV"); - List results = instance.getWatchListTV(getSessionId(), getAccountId(), null, null, null); + List results = instance.getWatchListTV(getSessionId(), getAccountId(), null, null, null); assertNotNull("No rated list found", results); assertFalse("No entries found", results.isEmpty()); - for (TVFavorite r : results) { + for (TVBasic r : results) { LOG.info(" {}", r.toString()); } } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java index 0ac9a4246..eef25701d 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java @@ -22,7 +22,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model2.company.Company; -import com.omertron.themoviedbapi.model2.movie.MovieFavorite; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; import java.util.List; import org.junit.After; import org.junit.AfterClass; @@ -84,7 +84,7 @@ public class TmdbCompaniesTest extends AbstractTests { @Test public void testGetCompanyMovies() throws MovieDbException { LOG.info("getCompanyMovies"); - List result = instance.getCompanyMovies(ID_COMPANY, LANGUAGE_DEFAULT, 0); + List result = instance.getCompanyMovies(ID_COMPANY, LANGUAGE_DEFAULT, 0); assertFalse("No company movies found", result.isEmpty()); } } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java index f57e707d1..828efd858 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java @@ -29,7 +29,7 @@ import com.omertron.themoviedbapi.model.MovieList; import com.omertron.themoviedbapi.model.ReleaseInfo; import com.omertron.themoviedbapi.model.Translation; import com.omertron.themoviedbapi.model.Video; -import com.omertron.themoviedbapi.model2.movie.MovieFavorite; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; import com.omertron.themoviedbapi.results.TmdbResultsList; import java.util.List; import java.util.Random; @@ -313,12 +313,12 @@ public class TmdbMoviesTest extends AbstractTests { // get all rated movies TmdbAccount account = new TmdbAccount(getApiKey(), getHttpTools()); - List ratedMovies = account.getRatedMovies(getSessionId(), getAccountId(), null, null, null); + List ratedMovies = account.getRatedMovies(getSessionId(), getAccountId(), null, null, null); assertTrue(ratedMovies.size() > 0); // make sure that we find the movie and it is rated correctly boolean foundMovie = false; - for (MovieFavorite movie : ratedMovies) { + for (MovieBasic movie : ratedMovies) { if (movie.getId() == movieID) { assertEquals("Incorrect rating", movie.getRating(), (float) rating, 0); foundMovie = true; From 3e1b0f268bc07f82a21dc0878e8d671330f91e39 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 23 Feb 2015 21:19:38 +0000 Subject: [PATCH 027/100] Credits --- .../omertron/themoviedbapi/TheMovieDbApi.java | 4 +- .../themoviedbapi/methods/TmdbCredits.java | 6 +- .../themoviedbapi/methods/_Method_List.txt | 2 +- .../model2/person/CreditInfo.java | 104 ++++++++++++++++++ .../person/PersonBasic.java} | 20 +--- .../themoviedbapi/model2/tv/TVCredit.java | 74 +++++++++++++ .../model2/tv/TVEpisodeBasic.java | 93 ++++++++++++++++ .../model2/tv/TVSeasonBasic.java | 62 +++++++++++ .../methods/TmdbCreditsTest.java | 22 ++-- 9 files changed, 353 insertions(+), 34 deletions(-) create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/person/CreditInfo.java rename src/main/java/com/omertron/themoviedbapi/{model/TBD_PersonCredits.java => model2/person/PersonBasic.java} (65%) create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/tv/TVCredit.java create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/tv/TVEpisodeBasic.java create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/tv/TVSeasonBasic.java diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index cbb0753b6..33b4ce09e 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -64,7 +64,7 @@ import com.omertron.themoviedbapi.model2.StatusCode; import com.omertron.themoviedbapi.model.TBD_ExternalSource; import com.omertron.themoviedbapi.model.TBD_FindResults; import com.omertron.themoviedbapi.model.TBD_Network; -import com.omertron.themoviedbapi.model.TBD_PersonCredits; +import com.omertron.themoviedbapi.model2.person.CreditInfo; import com.omertron.themoviedbapi.model2.authentication.TokenAuthorisation; import com.omertron.themoviedbapi.model2.authentication.TokenSession; import com.omertron.themoviedbapi.model.Translation; @@ -658,7 +658,7 @@ public class TheMovieDbApi { * @return * @throws MovieDbException */ - public TBD_PersonCredits getCreditInfo(String creditId, String language) throws MovieDbException { + public CreditInfo getCreditInfo(String creditId, String language) throws MovieDbException { return tmdbCredits.getCreditInfo(creditId, language); } // diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCredits.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCredits.java index 2873f028d..f37ea21ae 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCredits.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCredits.java @@ -20,7 +20,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.TBD_PersonCredits; +import com.omertron.themoviedbapi.model2.person.CreditInfo; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; @@ -66,7 +66,7 @@ public class TmdbCredits extends AbstractMethod { * @return * @throws MovieDbException */ - public TBD_PersonCredits getCreditInfo(String creditId, String language) throws MovieDbException { + public CreditInfo getCreditInfo(String creditId, String language) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.ID, creditId); parameters.add(Param.LANGUAGE, language); @@ -75,7 +75,7 @@ public class TmdbCredits extends AbstractMethod { String webpage = httpTools.getRequest(url); try { - return MAPPER.readValue(webpage, TBD_PersonCredits.class); + return MAPPER.readValue(webpage, CreditInfo.class); } catch (IOException ex) { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get credit info", url, ex); } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt index bf5cb3acb..b2ff5a730 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt +++ b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt @@ -29,7 +29,7 @@ Collections (Done) /collection/{id} Get the basic collection information for a specific collection id. /collection/{id}/images Get all of the images for a particular collection by collection id. -Companies +Companies (Done) /company/{id} This method is used to retrieve all of the basic information about a company /company/{id}/movies Get the list of movies associated with a particular company. diff --git a/src/main/java/com/omertron/themoviedbapi/model2/person/CreditInfo.java b/src/main/java/com/omertron/themoviedbapi/model2/person/CreditInfo.java new file mode 100644 index 000000000..94b0a13b8 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/person/CreditInfo.java @@ -0,0 +1,104 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model2.person; + +import com.omertron.themoviedbapi.model2.AbstractJsonMapping; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model2.tv.TVCredit; + +/** + * @author stuart.boston + */ +public class CreditInfo extends AbstractJsonMapping { + + private static final long serialVersionUID = 1L; + + @JsonProperty("id") + private String id; + @JsonProperty("credit_type") + private String creditType; + @JsonProperty("department") + private String department; + @JsonProperty("job") + private String job; + @JsonProperty("media_type") + private String mediaType; + @JsonProperty("person") + private PersonBasic person; + @JsonProperty("media") + private TVCredit media; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getCreditType() { + return creditType; + } + + public void setCreditType(String creditType) { + this.creditType = creditType; + } + + public String getDepartment() { + return department; + } + + public void setDepartment(String department) { + this.department = department; + } + + public String getJob() { + return job; + } + + public void setJob(String job) { + this.job = job; + } + + public String getMediaType() { + return mediaType; + } + + public void setMediaType(String mediaType) { + this.mediaType = mediaType; + } + + public PersonBasic getPerson() { + return person; + } + + public void setPerson(PersonBasic person) { + this.person = person; + } + + public TVCredit getMedia() { + return media; + } + + public void setMedia(TVCredit media) { + this.media = media; + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/TBD_PersonCredits.java b/src/main/java/com/omertron/themoviedbapi/model2/person/PersonBasic.java similarity index 65% rename from src/main/java/com/omertron/themoviedbapi/model/TBD_PersonCredits.java rename to src/main/java/com/omertron/themoviedbapi/model2/person/PersonBasic.java index 92801a275..8accb1b18 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/TBD_PersonCredits.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/person/PersonBasic.java @@ -17,29 +17,15 @@ * along with TheMovieDB API. If not, see . * */ -package com.omertron.themoviedbapi.model; +package com.omertron.themoviedbapi.model2.person; -import com.omertron.themoviedbapi.model2.AbstractJsonMapping; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonRootName; +import com.omertron.themoviedbapi.model.AbstractIdName; /** * @author stuart.boston */ -@JsonRootName("???") -public class TBD_PersonCredits extends AbstractJsonMapping { +public class PersonBasic extends AbstractIdName { private static final long serialVersionUID = 1L; - // Properties - @JsonProperty("id") - private int id; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } } diff --git a/src/main/java/com/omertron/themoviedbapi/model2/tv/TVCredit.java b/src/main/java/com/omertron/themoviedbapi/model2/tv/TVCredit.java new file mode 100644 index 000000000..ce8ceae39 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/tv/TVCredit.java @@ -0,0 +1,74 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model2.tv; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.AbstractIdName; +import java.util.List; + +/** + * TV Favorite information + * + * @author stuart.boston + */ +public class TVCredit extends AbstractIdName { + + @JsonProperty("original_name") + private String originalName; + @JsonProperty("character") + private String character; + @JsonProperty("seasons") + private List seasons; + @JsonProperty("episodes") + private List episodes; + + public String getOriginalName() { + return originalName; + } + + public void setOriginalName(String originalName) { + this.originalName = originalName; + } + + public String getCharacter() { + return character; + } + + public void setCharacter(String character) { + this.character = character; + } + + public List getSeasons() { + return seasons; + } + + public void setSeasons(List seasons) { + this.seasons = seasons; + } + + public List getEpisodes() { + return episodes; + } + + public void setEpisodes(List episodes) { + this.episodes = episodes; + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/tv/TVEpisodeBasic.java b/src/main/java/com/omertron/themoviedbapi/model2/tv/TVEpisodeBasic.java new file mode 100644 index 000000000..7af9f79ec --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/tv/TVEpisodeBasic.java @@ -0,0 +1,93 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model2.tv; + +import com.omertron.themoviedbapi.model2.AbstractJsonMapping; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * TV Favorite information + * + * @author stuart.boston + */ +public class TVEpisodeBasic extends AbstractJsonMapping { + + @JsonProperty("air_date") + private String airDate; + @JsonProperty("season_number") + private int seasonNumber; + @JsonProperty("episode_number") + private int episodeNumber; + @JsonProperty("name") + private String name; + @JsonProperty("overview") + private String overview; + @JsonProperty("still_path") + private String stillPath; + + public String getAirDate() { + return airDate; + } + + public void setAirDate(String airDate) { + this.airDate = airDate; + } + + public int getSeasonNumber() { + return seasonNumber; + } + + public void setSeasonNumber(int seasonNumber) { + this.seasonNumber = seasonNumber; + } + + public int getEpisodeNumber() { + return episodeNumber; + } + + public void setEpisodeNumber(int episodeNumber) { + this.episodeNumber = episodeNumber; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getOverview() { + return overview; + } + + public void setOverview(String overview) { + this.overview = overview; + } + + public String getStillPath() { + return stillPath; + } + + public void setStillPath(String stillPath) { + this.stillPath = stillPath; + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/tv/TVSeasonBasic.java b/src/main/java/com/omertron/themoviedbapi/model2/tv/TVSeasonBasic.java new file mode 100644 index 000000000..52b2c7716 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/tv/TVSeasonBasic.java @@ -0,0 +1,62 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model2.tv; + +import com.omertron.themoviedbapi.model2.AbstractJsonMapping; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * TV Favorite information + * + * @author stuart.boston + */ +public class TVSeasonBasic extends AbstractJsonMapping { + + @JsonProperty("air_date") + private String airDate; + @JsonProperty("poster_path") + private String posterPath; + @JsonProperty("season_number") + private int seasonNumber; + + public String getAirDate() { + return airDate; + } + + public void setAirDate(String airDate) { + this.airDate = airDate; + } + + public String getPosterPath() { + return posterPath; + } + + public void setPosterPath(String posterPath) { + this.posterPath = posterPath; + } + + public int getSeasonNumber() { + return seasonNumber; + } + + public void setSeasonNumber(int seasonNumber) { + this.seasonNumber = seasonNumber; + } +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCreditsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCreditsTest.java index 2fe107517..8508edf93 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCreditsTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCreditsTest.java @@ -21,10 +21,11 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.TBD_PersonCredits; +import com.omertron.themoviedbapi.model2.person.CreditInfo; import org.junit.After; import org.junit.AfterClass; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -33,7 +34,7 @@ import org.junit.Test; * * @author stuart.boston */ -public class TmdbCreditsTest extends AbstractTests{ +public class TmdbCreditsTest extends AbstractTests { private static TmdbCredits instance; @@ -43,7 +44,7 @@ public class TmdbCreditsTest extends AbstractTests{ @BeforeClass public static void setUpClass() throws MovieDbException { doConfiguration(); - instance = new TmdbCredits(getApiKey(),getHttpTools()); + instance = new TmdbCredits(getApiKey(), getHttpTools()); } @AfterClass @@ -66,13 +67,12 @@ public class TmdbCreditsTest extends AbstractTests{ @Test public void testGetCreditInfo() throws MovieDbException { LOG.info("getCreditInfo"); - String creditId = "525346f619c29579400d4145"; - String language = ""; - TBD_PersonCredits result = instance.getCreditInfo(creditId, language); -// assertEquals("Wrong name", "Sean Bean", result.getPerson().getName()); -// assertEquals("Wrong job", "Actor", result.getJob()); -// assertFalse("No seasons", result.getMedia().getSeasons().isEmpty()); - fail("The test case is a prototype."); + String creditId = "53392a9c9251417da10041c8"; + CreditInfo result = instance.getCreditInfo(creditId, LANGUAGE_DEFAULT); + assertEquals("Wrong name", "Josh McDermitt", result.getPerson().getName()); + assertEquals("Wrong job", "Actor", result.getJob()); + assertFalse("No seasons", result.getMedia().getSeasons().isEmpty()); + assertFalse("No episodes", result.getMedia().getEpisodes().isEmpty()); } } From e4dc8e9465f93a57a84e56b84630c54082d9dcbb Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 23 Feb 2015 21:34:13 +0000 Subject: [PATCH 028/100] Remove unused variable --- .../themoviedbapi/wrapper/WrapperGenericList.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperGenericList.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperGenericList.java index 5c9c0cb2e..be3aec7bb 100644 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperGenericList.java +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperGenericList.java @@ -20,9 +20,7 @@ package com.omertron.themoviedbapi.wrapper; import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.core.type.TypeReference; import java.io.Serializable; import java.util.List; @@ -34,9 +32,6 @@ import java.util.List; */ public class WrapperGenericList extends AbstractWrapperAll implements Serializable { - @JsonIgnore - private final TypeReference typeRef = new TypeReference>() { - }; @JsonProperty("results") private List results; @@ -48,8 +43,4 @@ public class WrapperGenericList extends AbstractWrapperAll implements Seriali public void setResults(List results) { this.results = results; } - - public TypeReference getTypeRef() { - return typeRef; - } } From 45caa4d14d043747e446a871231333c6e0cd89fe Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Tue, 24 Feb 2015 13:15:44 +0000 Subject: [PATCH 029/100] Discover --- .../omertron/themoviedbapi/TheMovieDbApi.java | 6 +- .../themoviedbapi/enumeration/SortBy.java | 23 + .../themoviedbapi/methods/TmdbDiscover.java | 33 +- .../themoviedbapi/methods/_Method_List.txt | 2 +- .../model/discover/Discover.java | 248 --------- .../themoviedbapi/model2/company/Company.java | 1 - .../model2/discover/Discover.java | 506 ++++++++++++++++++ .../model2/discover/WithBuilder.java | 112 ++++ .../omertron/themoviedbapi/tools/Param.java | 14 +- .../themoviedbapi/TheMovieDbApiTest.java | 2 +- .../methods/TmdbDiscoverTest.java | 19 +- 11 files changed, 680 insertions(+), 286 deletions(-) create mode 100644 src/main/java/com/omertron/themoviedbapi/enumeration/SortBy.java delete mode 100644 src/main/java/com/omertron/themoviedbapi/model/discover/Discover.java create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/discover/Discover.java create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/discover/WithBuilder.java diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 33b4ce09e..8257c73f3 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -48,7 +48,7 @@ import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.collection.CollectionInfo; import com.omertron.themoviedbapi.model2.company.Company; import com.omertron.themoviedbapi.model2.Configuration; -import com.omertron.themoviedbapi.model.discover.Discover; +import com.omertron.themoviedbapi.model2.discover.Discover; import com.omertron.themoviedbapi.model.Genre; import com.omertron.themoviedbapi.model2.JobDepartment; import com.omertron.themoviedbapi.model.keyword.Keyword; @@ -671,7 +671,7 @@ public class TheMovieDbApi { * @return * @throws MovieDbException */ - public TmdbResultsList getDiscoverMovies(Discover discover) throws MovieDbException { + public List getDiscoverMovies(Discover discover) throws MovieDbException { return tmdbDiscover.getDiscoverMovies(discover); } @@ -682,7 +682,7 @@ public class TheMovieDbApi { * @return * @throws MovieDbException */ - public TmdbResultsList getDiscoverTV(Discover discover) throws MovieDbException { + public List getDiscoverTV(Discover discover) throws MovieDbException { return tmdbDiscover.getDiscoverTV(discover); } // diff --git a/src/main/java/com/omertron/themoviedbapi/enumeration/SortBy.java b/src/main/java/com/omertron/themoviedbapi/enumeration/SortBy.java new file mode 100644 index 000000000..b023362e1 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/enumeration/SortBy.java @@ -0,0 +1,23 @@ +package com.omertron.themoviedbapi.enumeration; + +public enum SortBy { + + POPULARITY_ASC, + POPULARITY_DESC, + RELEASE_DATE_ASC, + RELEASE_DATE_DESC, + REVENUE_ASC, + REVENUE_DESC, + PRIMARY_RELEASE_DATE_ASC, + PRIMARY_RELEASE_DATE_DESC, + ORIGINAL_TITLE_ASC, + ORIGINAL_TITLE_DESC, + VOTE_AVERAGE_ASC, + VOTE_AVERAGE_DESC, + VOTE_COUNT_ASC, + VOTE_COUNT_DESC; + + public String getPropertyString() { + return this.name().toLowerCase().replace("_asc", ".asc").replaceAll("_desc", ".desc"); + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbDiscover.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbDiscover.java index 130118be5..44313a679 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbDiscover.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbDiscover.java @@ -20,17 +20,15 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.discover.Discover; -import com.omertron.themoviedbapi.model.MovieDb; -import com.omertron.themoviedbapi.results.TmdbResultsList; +import com.omertron.themoviedbapi.model2.discover.Discover; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; +import com.omertron.themoviedbapi.model2.tv.TVBasic; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; import com.omertron.themoviedbapi.tools.MethodSub; -import com.omertron.themoviedbapi.wrapper.WrapperMovie; -import java.io.IOException; import java.net.URL; -import org.yamj.api.common.exception.ApiExceptionType; +import java.util.List; /** * Class to hold the Discover Methods @@ -50,37 +48,28 @@ public class TmdbDiscover extends AbstractMethod { } /** - * 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 * @throws MovieDbException */ - public TmdbResultsList getDiscoverMovies(Discover discover) throws MovieDbException { + public List getDiscoverMovies(Discover discover) throws MovieDbException { URL url = new ApiUrl(apiKey, MethodBase.DISCOVER).setSubMethod(MethodSub.MOVIE).buildUrl(discover.getParams()); String webpage = httpTools.getRequest(url); - - try { - WrapperMovie wrapper = MAPPER.readValue(webpage, WrapperMovie.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getMovies()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get movie discover list", url, ex); - } + return processWrapperList(TR_MOVIE_BASIC, url, webpage); } /** - * 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 * @throws MovieDbException */ - public TmdbResultsList getDiscoverTV(Discover discover) throws MovieDbException { + public List getDiscoverTV(Discover discover) throws MovieDbException { URL url = new ApiUrl(apiKey, MethodBase.DISCOVER).setSubMethod(MethodSub.TV).buildUrl(discover.getParams()); - throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not implemented yet"); + String webpage = httpTools.getRequest(url); + return processWrapperList(TR_TV_BASIC, url, webpage); } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt index b2ff5a730..0b905491a 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt +++ b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt @@ -33,7 +33,7 @@ Companies (Done) /company/{id} This method is used to retrieve all of the basic information about a company /company/{id}/movies Get the list of movies associated with a particular company. -Credits +Credits (Done) /credit/{credit_id} Get the detailed information about a particular credit record. Discover diff --git a/src/main/java/com/omertron/themoviedbapi/model/discover/Discover.java b/src/main/java/com/omertron/themoviedbapi/model/discover/Discover.java deleted file mode 100644 index a5010aa09..000000000 --- a/src/main/java/com/omertron/themoviedbapi/model/discover/Discover.java +++ /dev/null @@ -1,248 +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;private either version 3 of the License;private or - * any later version. - * - * TheMovieDB API is distributed in the hope that it will be useful;private - * 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;private see . - * - */ -package com.omertron.themoviedbapi.model.discover; - -import com.omertron.themoviedbapi.tools.Param; -import com.omertron.themoviedbapi.tools.TmdbParameters; - -/** - * Generate a discover object for use in the MovieDbApi - *

- * This allows you to just add the search components you are concerned with - * - * @author stuart.boston - */ -public class Discover { - - private final TmdbParameters params = new TmdbParameters(); - - private static final int YEAR_MIN = 1900; - private static final int YEAR_MAX = 2100; - - /** - * Get the parameters - *

- * This will be used to construct the URL in the API - * - * @return - */ - public TmdbParameters getParams() { - return params; - } - - /** - * Minimum value is 1 if included. - * - * @param page - * @return - */ - public Discover page(int page) { - params.add(Param.PAGE, page); - return this; - } - - /** - * ISO 639-1 code - * - * @param language - * @return - */ - public Discover language(String language) { - params.add(Param.LANGUAGE, language); - return this; - } - - /** - * Available options are
- * vote_average.desc
- * vote_average.asc
- * release_date.desc
- * release_date.asc
- * popularity.desc
- * popularity.asc - * - * @param sortBy - * @return - */ - public Discover sortBy(String sortBy) { - params.add(Param.SORT_BY, sortBy); - return this; - } - - /** - * Toggle the inclusion of adult titles - * - * @param includeAdult - * @return - */ - public Discover includeAdult(boolean includeAdult) { - params.add(Param.ADULT, includeAdult); - return this; - } - - /** - * Filter the results release dates to matches that include this value. - * - * @param year - * @return - */ - public Discover year(int year) { - if (checkYear(year)) { - params.add(Param.YEAR, year); - } - return this; - } - - /** - * Filter the results so that only the primary release date year has this - * value - * - * @param primaryReleaseYear - * @return - */ - public Discover primaryReleaseYear(int primaryReleaseYear) { - if (checkYear(primaryReleaseYear)) { - params.add(Param.PRIMARY_RELEASE_YEAR, primaryReleaseYear); - } - return this; - } - - /** - * Only include movies that are equal to, or have a vote count higher than - * this value - * - * @param voteCountGte - * @return - */ - public Discover voteCountGte(int voteCountGte) { - params.add(Param.VOTE_COUNT_GTE, voteCountGte); - return this; - } - - /** - * Only include movies that are equal to, or have a higher average rating - * than this value - * - * @param voteAverageGte - * @return - */ - public Discover voteAverageGte(float voteAverageGte) { - params.add(Param.VOTE_AVERAGE_GTE, voteAverageGte); - return this; - } - - /** - * 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 withGenres - * @return - */ - public Discover withGenres(String withGenres) { - params.add(Param.WITH_GENRES, withGenres); - return this; - } - - /** - * The minimum release to include. - *

- * Expected format is YYYY-MM-DD. - * - * @param releaseDateGte - * @return - */ - public Discover releaseDateGte(String releaseDateGte) { - params.add(Param.RELEASE_DATE_GTE, releaseDateGte); - return this; - } - - /** - * The maximum release to include. - *

- * Expected format is YYYY-MM-DD. - * - * @param releaseDateLte - * @return - */ - public Discover releaseDateLte(String releaseDateLte) { - params.add(Param.RELEASE_DATE_LTE, releaseDateLte); - return this; - } - - /** - * Only include movies with certifications for a specific country. - *

- * When this value is specified, 'certificationLte' is required. - *

- * A ISO 3166-1 is expected - * - * @param certificationCountry - * @return - */ - public Discover certificationCountry(String certificationCountry) { - params.add(Param.CERTIFICATION_COUNTRY, certificationCountry); - return this; - } - - /** - * Only include movies with this certification and lower. - *

- * Expected value is a valid certification for the specified - * 'certificationCountry'. - * - * @param certificationLte - * @return - */ - public Discover certificationLte(String certificationLte) { - params.add(Param.CERTIFICATION_LTE, certificationLte); - return this; - } - - /** - * 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 withCompanies - * @return - */ - public Discover withCompanies(String withCompanies) { - params.add(Param.WITH_COMPANIES, withCompanies); - return this; - } - - /** - * check the year is between the min and max - * - * @param year - * @return - */ - private boolean checkYear(int year) { - return year >= YEAR_MIN && year <= YEAR_MAX; - } -} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/company/Company.java b/src/main/java/com/omertron/themoviedbapi/model2/company/Company.java index eb614662e..eb5da77bb 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/company/Company.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/company/Company.java @@ -19,7 +19,6 @@ */ package com.omertron.themoviedbapi.model2.company; -import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.fasterxml.jackson.annotation.JsonProperty; import com.omertron.themoviedbapi.model2.AbstractJsonMapping; diff --git a/src/main/java/com/omertron/themoviedbapi/model2/discover/Discover.java b/src/main/java/com/omertron/themoviedbapi/model2/discover/Discover.java new file mode 100644 index 000000000..d2f975048 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/discover/Discover.java @@ -0,0 +1,506 @@ +/* + * 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;private either version 3 of the License;private or + * any later version. + * + * TheMovieDB API is distributed in the hope that it will be useful;private + * 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;private see . + * + */ +package com.omertron.themoviedbapi.model2.discover; + +import com.omertron.themoviedbapi.enumeration.SortBy; +import com.omertron.themoviedbapi.tools.Param; +import com.omertron.themoviedbapi.tools.TmdbParameters; + +/** + * Generate a discover object for use in the MovieDbApi + *

+ * This allows you to just add the search components you are concerned with + * + * @author stuart.boston + */ +public class Discover { + + private final TmdbParameters params = new TmdbParameters(); + + private static final int YEAR_MIN = 1900; + private static final int YEAR_MAX = 2100; + + /** + * Get the parameters + *

+ * This will be used to construct the URL in the API + * + * @return + */ + public TmdbParameters getParams() { + return params; + } + + /** + * Minimum value is 1 if included. + * + * @param page + * @return + */ + public Discover page(int page) { + params.add(Param.PAGE, page); + return this; + } + + /** + * ISO 639-1 code + * + * @param language + * @return + */ + public Discover language(String language) { + params.add(Param.LANGUAGE, language); + return this; + } + + /** + * Available options are
+ * vote_average.desc
+ * vote_average.asc
+ * release_date.desc
+ * release_date.asc
+ * popularity.desc
+ * popularity.asc + * + * @param sortBy + * @return + */ + public Discover sortBy(SortBy sortBy) { + params.add(Param.SORT_BY, sortBy.getPropertyString()); + return this; + } + + /** + * Toggle the inclusion of adult titles + * + * @param includeAdult + * @return + */ + public Discover includeAdult(boolean includeAdult) { + params.add(Param.ADULT, includeAdult); + return this; + } + + /** + * Toggle the inclusion of items marked as a video. + * + * Expected value is a boolean, true or false. Default is true. + * + * @param includeVideo + * @return + */ + public Discover includeVideo(boolean includeVideo) { + params.add(Param.INCLUDE_VIDEO, includeVideo); + return this; + } + + /** + * Filter the results release dates to matches that include this value. + * + * @param year + * @return + */ + public Discover year(int year) { + if (checkYear(year)) { + params.add(Param.YEAR, year); + } + return this; + } + + /** + * Filter the results so that only the primary release date year has this value + * + * @param primaryReleaseYear + * @return + */ + public Discover primaryReleaseYear(int primaryReleaseYear) { + if (checkYear(primaryReleaseYear)) { + params.add(Param.PRIMARY_RELEASE_YEAR, primaryReleaseYear); + } + return this; + } + + /** + * Only include movies that are equal to, or have a vote count higher than this value + * + * @param voteCountGte + * @return + */ + public Discover voteCountGte(int voteCountGte) { + params.add(Param.VOTE_COUNT_GTE, voteCountGte); + return this; + } + + /** + * Only include movies that are equal to, or have a vote count higher than this value + * + * @param voteCountLte + * @return + */ + public Discover voteCountLte(int voteCountLte) { + params.add(Param.VOTE_COUNT_LTE, voteCountLte); + return this; + } + + /** + * Only include movies that are equal to, or have a higher average rating than this value + * + * @param voteAverageGte + * @return + */ + public Discover voteAverageGte(float voteAverageGte) { + params.add(Param.VOTE_AVERAGE_GTE, voteAverageGte); + return this; + } + + /** + * Only include movies that are less than or equal to this value + * + * @param voteAverageLte + * @return + */ + public Discover voteAverageLte(float voteAverageLte) { + params.add(Param.VOTE_AVERAGE_LTE, voteAverageLte); + return this; + } + + /** + * The minimum release to include. + *

+ * Expected format is YYYY-MM-DD. + * + * @param releaseDateGte + * @return + */ + public Discover releaseDateGte(String releaseDateGte) { + params.add(Param.RELEASE_DATE_GTE, releaseDateGte); + return this; + } + + /** + * The maximum release to include. + *

+ * Expected format is YYYY-MM-DD. + * + * @param releaseDateLte + * @return + */ + public Discover releaseDateLte(String releaseDateLte) { + params.add(Param.RELEASE_DATE_LTE, releaseDateLte); + return this; + } + + /** + * Only include movies with certifications for a specific country. + *

+ * When this value is specified, 'certificationLte' is required. + *

+ * A ISO 3166-1 is expected + * + * @param certificationCountry + * @return + */ + public Discover certificationCountry(String certificationCountry) { + params.add(Param.CERTIFICATION_COUNTRY, certificationCountry); + return this; + } + + /** + * Only include movies with this certification and lower. + *

+ * Expected value is a valid certification for the specified 'certificationCountry'. + * + * @param certificationLte + * @return + */ + public Discover certificationLte(String certificationLte) { + params.add(Param.CERTIFICATION_LTE, certificationLte); + return this; + } + + /** + * Only include movies with this certification. + * + * Expected value is a valid certification for the specified 'certificationCountry'. + * + * @param certification + * @return + */ + public Discover certification(String certification) { + params.add(Param.CERTIFICATION, certification); + return this; + } + + /** + * Only include movies that have this person id added as a cast member. + * + * Expected value is an integer (the id of a person). + * + * Comma separated indicates an 'AND' query, while a pipe (|) separated value indicates an 'OR' + * + * @param withCast + * @return + */ + public Discover withCast(String withCast) { + params.add(Param.WITH_CAST, withCast); + return this; + } + + /** + * Only include media that have these person IDs added as cast members. + * + * Use the WithBuilder to generate the list,e.g. + * + * new WithBuilder(1).and(2).and(3) + * + * @param withCast + * @return + */ + public Discover withCast(WithBuilder withCast) { + return withCast(withCast.build()); + } + + /** + * Only include movies that have this person id added as a crew member. + * + * Expected value is an integer (the id of a person). + * + * Comma separated indicates an 'AND' query, while a pipe (|) separated value indicates an 'OR'. + * + * @param withCrew + * @return + */ + public Discover withCrew(String withCrew) { + params.add(Param.WITH_CREW, withCrew); + return this; + } + + /** + * Only include media that have these person IDs added as crew members. + * + * Use the WithBuilder to generate the list,e.g. + * + * new WithBuilder(1).and(2).and(3) + * + * @param withCrew + * @return + */ + public Discover withCrew(WithBuilder withCrew) { + return withCrew(withCrew.build()); + } + + /** + * Filter movies to include a specific company. + * + * Expected value is an integer (the id of a company). + * + * Comma separated indicates an 'AND' query, while a pipe (|) separated value indicates an 'OR' + * + * @param withCompanies + * @return + */ + public Discover withCompanies(String withCompanies) { + params.add(Param.WITH_COMPANIES, withCompanies); + return this; + } + + /** + * Filter movies to include a specific company. + * + * Use the WithBuilder to generate the list,e.g. + * + * new WithBuilder(1).and(2).and(3) + * + * @param withCompanies + * @return + */ + public Discover withCompanies(WithBuilder withCompanies) { + return withCompanies(withCompanies.build()); + } + + /** + * 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 withGenres + * @return + */ + public Discover withGenres(String withGenres) { + params.add(Param.WITH_GENRES, withGenres); + return this; + } + + /** + * Only include movies with the specified genres. + * + * Use the WithBuilder to generate the list,e.g. + * + * new WithBuilder(1).and(2).and(3) + * + * @param withGenres + * @return + */ + public Discover withGenres(WithBuilder withGenres) { + return withGenres(withGenres.build()); + } + + /** + * Only include movies with the specified genres. + * + * Expected value is an integer (the id of a genre). + * + * Comma separated indicates an 'AND' query, while a pipe (|) separated value indicates an 'OR'. + * + * @param withKeywords + * @return + */ + public Discover withKeywords(String withKeywords) { + params.add(Param.WITH_KEYWORDS, withKeywords); + return this; + } + + /** + * Only include movies with the specified genres. + * + * Use the WithBuilder to generate the list,e.g. + * + * new WithBuilder(1).and(2).and(3) + * + * @param withKeywords + * @return + */ + public Discover withKeywords(WithBuilder withKeywords) { + return withKeywords(withKeywords.build()); + } + + /** + * Only include movies that have these person id's added as a cast or crew member. + * + * Expected value is an integer (the id or ids of a person). + * + * Comma separated indicates an 'AND' query, while a pipe (|) separated value indicates an 'OR'. + * + * @param withPeople + * @return + */ + public Discover withPeople(String withPeople) { + params.add(Param.WITH_PEOPLE, withPeople); + return this; + } + + /** + * Only include movies that have these person id's added as a cast or crew member. + * + * Use the WithBuilder to generate the list,e.g. + * + * new WithBuilder(1).and(2).and(3) + * + * @param withPeople + * @return + */ + public Discover withPeople(WithBuilder withPeople) { + return withPeople(withPeople.build()); + } + + /** + * Filter the air dates that match this year + * + * Expected value is a year. + * + * @param year + * @return + */ + public Discover firstAirDateYear(int year) { + if (checkYear(year)) { + params.add(Param.FIRST_AIR_DATE_YEAR, year); + } + return this; + } + + /** + * Filter the air dates to years that are greater than or equal to this year + * + * @param year + * @return + */ + public Discover firstAirDateYearGte(int year) { + if (checkYear(year)) { + params.add(Param.FIRST_AIR_DATE_GTE, year); + } + return this; + } + + /** + * Filter the air dates to years that are less than or equal to this year + * + * @param year + * @return + */ + public Discover firstAirDateYearLte(int year) { + if (checkYear(year)) { + params.add(Param.FIRST_AIR_DATE_LTE, year); + } + return this; + } + + /** + * Filter TV shows to include a specific network. + * + * Expected value is an integer (the id of a network). + * + * They can be comma separated to indicate an 'AND' query. + * + * @param withNetworks + * @return + */ + public Discover withNetworks(String withNetworks) { + params.add(Param.WITH_NETWORKS, withNetworks); + return this; + } + + /** + * Filter TV shows to include a specific network. + * + * Use the WithBuilder to generate the list,e.g. + * + * new WithBuilder(1).and(2).and(3) + * + * @param withNetworks + * @return + */ + public Discover withNetworks(WithBuilder withNetworks) { + return withNetworks(withNetworks.build()); + } + + /** + * check the year is between the min and max + * + * @param year + * @return + */ + private boolean checkYear(int year) { + return year >= YEAR_MIN && year <= YEAR_MAX; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/discover/WithBuilder.java b/src/main/java/com/omertron/themoviedbapi/model2/discover/WithBuilder.java new file mode 100644 index 000000000..71d685364 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/discover/WithBuilder.java @@ -0,0 +1,112 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model2.discover; + +/** + * Class to create a String for the "with???" parameters of the Discover method + * + * @author Stuart + */ +public class WithBuilder { + + StringBuilder value = new StringBuilder(); + + /** + * Create the first ID in the string + * + * @param id + */ + public WithBuilder(int id) { + value.append(id); + } + + /** + * Create the first ID in the string + * + * @param id + */ + public WithBuilder(String id) { + value.append(id); + } + + /** + * Generate the string to pass to the method + * + * @return + */ + public String build() { + return value.toString(); + } + + /** + * Generate the string to pass to the method + * + * @return + */ + @Override + public String toString() { + return build(); + } + + /** + * Add an "AND ID" + * + * @param id + * @return + */ + public WithBuilder and(int id) { + value.append(",").append(id); + return this; + } + + /** + * Add an "AND ID" + * + * @param id + * @return + */ + public WithBuilder and(String id) { + value.append(",").append(id); + return this; + } + + /** + * Add an "OR ID" + * + * @param id + * @return + */ + public WithBuilder or(int id) { + value.append("|").append(id); + return this; + } + + /** + * Add an "OR ID" + * + * @param id + * @return + */ + public WithBuilder or(String id) { + value.append("|").append(id); + return this; + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/tools/Param.java b/src/main/java/com/omertron/themoviedbapi/tools/Param.java index 137fdedfe..6c6b7b729 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/Param.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/Param.java @@ -50,16 +50,28 @@ public enum Param { VALUE("value="), YEAR("year="), // Discover parameters + CERTIFICATION("certification="), CERTIFICATION_COUNTRY("certification_country="), CERTIFICATION_LTE("certification.lte="), + FIRST_AIR_DATE_GTE("first_air_date.gte"), + FIRST_AIR_DATE_LTE("first_air_date.lte"), + FIRST_AIR_DATE_YEAR("first_air_date_year="), + INCLUDE_VIDEO("include_video="), PRIMARY_RELEASE_YEAR("primary_release_year="), RELEASE_DATE_GTE("release_date.gte="), RELEASE_DATE_LTE("release_date.lte="), SORT_BY("sort_by="), VOTE_AVERAGE_GTE("vote_average.gte="), + VOTE_AVERAGE_LTE("vote_average.lte="), VOTE_COUNT_GTE("vote_count.gte="), + VOTE_COUNT_LTE("vote_count.lte="), + WITH_CAST("with_cast="), WITH_COMPANIES("with_companies="), - WITH_GENRES("with_genres="); + WITH_CREW("with_crew="), + WITH_GENRES("with_genres="), + WITH_KEYWORDS("with_keywords="), + WITH_NETWORKS("with_networks="), + WITH_PEOPLE("with_people="); private final String value; diff --git a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java index de575d792..445e4e8ea 100644 --- a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java +++ b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java @@ -25,7 +25,7 @@ import com.omertron.themoviedbapi.model.change.ChangedMedia; import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.collection.CollectionInfo; import com.omertron.themoviedbapi.model2.company.Company; -import com.omertron.themoviedbapi.model.discover.Discover; +import com.omertron.themoviedbapi.model2.discover.Discover; import com.omertron.themoviedbapi.model.Genre; import com.omertron.themoviedbapi.model2.JobDepartment; import com.omertron.themoviedbapi.model.keyword.Keyword; diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbDiscoverTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbDiscoverTest.java index 63a393d95..e99443916 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbDiscoverTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbDiscoverTest.java @@ -21,9 +21,10 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.discover.Discover; -import com.omertron.themoviedbapi.model.MovieDb; -import com.omertron.themoviedbapi.results.TmdbResultsList; +import com.omertron.themoviedbapi.model2.discover.Discover; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; +import com.omertron.themoviedbapi.model2.tv.TVBasic; +import java.util.List; import org.junit.After; import org.junit.AfterClass; import static org.junit.Assert.assertFalse; @@ -45,7 +46,7 @@ public class TmdbDiscoverTest extends AbstractTests { @BeforeClass public static void setUpClass() throws MovieDbException { doConfiguration(); - instance = new TmdbDiscover(getApiKey(),getHttpTools()); + instance = new TmdbDiscover(getApiKey(), getHttpTools()); } @AfterClass @@ -65,14 +66,14 @@ public class TmdbDiscoverTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test +// @Test public void testGetDiscoverMovie() throws MovieDbException { LOG.info("getDiscoverMovie"); Discover discover = new Discover(); discover.year(2013).language(LANGUAGE_ENGLISH); - TmdbResultsList result = instance.getDiscoverMovies(discover); - assertFalse("No movies discovered", result.getResults().isEmpty()); + List result = instance.getDiscoverMovies(discover); + assertFalse("No movies discovered", result.isEmpty()); } /** @@ -86,8 +87,8 @@ public class TmdbDiscoverTest extends AbstractTests { Discover discover = new Discover(); discover.year(2013).language(LANGUAGE_ENGLISH); - TmdbResultsList result = instance.getDiscoverMovies(discover); - assertFalse("No TV shows discovered", result.getResults().isEmpty()); + List result = instance.getDiscoverTV(discover); + assertFalse("No TV shows discovered", result.isEmpty()); } } From 5b4acf1f8c11360d79ad8ac75c423f05a23579e3 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Tue, 24 Feb 2015 13:33:10 +0000 Subject: [PATCH 030/100] Remove unused tests --- .../themoviedbapi/methods/_Method_List.txt | 2 +- .../themoviedbapi/TheMovieDbApiTest.java | 713 ------------------ 2 files changed, 1 insertion(+), 714 deletions(-) delete mode 100644 src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java diff --git a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt index 0b905491a..ee326d7ad 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt +++ b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt @@ -36,7 +36,7 @@ Companies (Done) Credits (Done) /credit/{credit_id} Get the detailed information about a particular credit record. -Discover +Discover (Done) /discover/movie Discover movies by different types of data like average rating, number of votes, genres and certifications. /discover/tv Discover TV shows by different types of data like average rating, number of votes, genres, the network they aired on and air dates. diff --git a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java deleted file mode 100644 index 445e4e8ea..000000000 --- a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java +++ /dev/null @@ -1,713 +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 . - * - */ -package com.omertron.themoviedbapi; - -import com.omertron.themoviedbapi.model.AlternativeTitle; -import com.omertron.themoviedbapi.model.Artwork; -import com.omertron.themoviedbapi.model.change.ChangedMedia; -import com.omertron.themoviedbapi.model2.collection.Collection; -import com.omertron.themoviedbapi.model2.collection.CollectionInfo; -import com.omertron.themoviedbapi.model2.company.Company; -import com.omertron.themoviedbapi.model2.discover.Discover; -import com.omertron.themoviedbapi.model.Genre; -import com.omertron.themoviedbapi.model2.JobDepartment; -import com.omertron.themoviedbapi.model.keyword.Keyword; -import com.omertron.themoviedbapi.model.keyword.KeywordMovie; -import com.omertron.themoviedbapi.model.MovieDb; -import com.omertron.themoviedbapi.model.MovieDbList; -import com.omertron.themoviedbapi.model.MovieList; -import com.omertron.themoviedbapi.model.person.Person; -import com.omertron.themoviedbapi.model.person.PersonCredit; -import com.omertron.themoviedbapi.model.ReleaseInfo; -import com.omertron.themoviedbapi.model.Reviews; -import com.omertron.themoviedbapi.model2.Configuration; -import com.omertron.themoviedbapi.model2.authentication.TokenAuthorisation; -import com.omertron.themoviedbapi.model2.authentication.TokenSession; -import com.omertron.themoviedbapi.model.Translation; -import com.omertron.themoviedbapi.model.Video; -import com.omertron.themoviedbapi.model2.movie.MovieBasic; -import com.omertron.themoviedbapi.results.TmdbResultsList; -import java.util.List; -import org.apache.commons.lang3.StringUtils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -/** - * Test cases for TheMovieDbApi API - * - * @author stuart.boston - */ -public class TheMovieDbApiTest extends AbstractTests { - - private static TheMovieDbApi tmdb; - // Test data - private static final int ID_MOVIE_BLADE_RUNNER = 78; - private static final int ID_MOVIE_THE_AVENGERS = 24428; - private static final int ID_COLLECTION_STAR_WARS = 10; - private static final int ID_PERSON_BRUCE_WILLIS = 62; - private static final int ID_COMPANY = 2; - private static final String COMPANY_NAME = "Marvel Studios"; - private static final int ID_GENRE_ACTION = 28; - private static final String ID_KEYWORD = "1721"; - - public TheMovieDbApiTest() throws MovieDbException { - } - - @BeforeClass - public static void setUpClass() throws MovieDbException { - tmdb = new TheMovieDbApi(getApiKey()); - } - - /** - * Test of getConfiguration method, of class TheMovieDbApi. - * - * @throws com.omertron.themoviedbapi.MovieDbException - */ - @Test - public void testConfiguration() throws MovieDbException { - LOG.info("Test Configuration"); - - Configuration tmdbConfig = tmdb.getConfiguration(); - assertNotNull("Configuration failed", tmdbConfig); - assertTrue("No base URL", StringUtils.isNotBlank(tmdbConfig.getBaseUrl())); - assertTrue("No backdrop sizes", tmdbConfig.getBackdropSizes().size() > 0); - assertTrue("No poster sizes", tmdbConfig.getPosterSizes().size() > 0); - assertTrue("No profile sizes", tmdbConfig.getProfileSizes().size() > 0); - LOG.info(tmdbConfig.toString()); - } - - /** - * Test of searchMovie method, of class TheMovieDbApi. - * - * @throws MovieDbException - */ - @Test - public void testSearchMovie() throws MovieDbException { - LOG.info("searchMovie"); - - // Try a movie with less than 1 page of results - TmdbResultsList movieList = tmdb.searchMovie("Blade Runner", 0, "", true, 0); -// List movieList = tmdb.searchMovie("Blade Runner", "", true); - assertTrue("No movies found, should be at least 1", movieList.getResults().size() > 0); - - // Try a russian langugage movie - movieList = tmdb.searchMovie("О чём говорят мужчины", 0, LANGUAGE_RUSSIAN, true, 0); - assertTrue("No 'RU' movies found, should be at least 1", movieList.getResults().size() > 0); - - // Try a movie with more than 20 results - movieList = tmdb.searchMovie("Star Wars", 0, LANGUAGE_ENGLISH, false, 0); - assertTrue("Not enough movies found, should be over 15, found " + movieList.getResults().size(), movieList.getResults().size() >= 15); - } - - /** - * Test of getMovieInfo method, of class TheMovieDbApi. - * - * @throws MovieDbException - */ - @Test - public void testGetMovieInfo() throws MovieDbException { - LOG.info("getMovieInfo"); - MovieDb result = tmdb.getMovieInfo(ID_MOVIE_BLADE_RUNNER, LANGUAGE_ENGLISH, "alternative_titles,casts,images,keywords,releases,trailers,translations,similar_movies,reviews,lists"); - assertEquals("Incorrect movie information", "Blade Runner", result.getOriginalTitle()); - } - - /** - * Test of getMovieAlternativeTitles method, of class TheMovieDbApi. - * - * @throws MovieDbException - */ - @Test - public void testGetMovieAlternativeTitles() throws MovieDbException { - LOG.info("getMovieAlternativeTitles"); - String country = ""; - TmdbResultsList result = tmdb.getMovieAlternativeTitles(ID_MOVIE_BLADE_RUNNER, country, "casts,images,keywords,releases,trailers,translations,similar_movies,reviews,lists"); - assertTrue("No alternative titles found", result.getResults().size() > 0); - - country = "US"; - result = tmdb.getMovieAlternativeTitles(ID_MOVIE_BLADE_RUNNER, country); - assertTrue("No alternative titles found", result.getResults().size() > 0); - - } - - /** - * Test of getMovieCasts method, of class TheMovieDbApi. - * - * @throws MovieDbException - */ - @Test - public void testGetMovieCasts() throws MovieDbException { - LOG.info("getMovieCasts"); - TmdbResultsList people = tmdb.getMovieCasts(ID_MOVIE_BLADE_RUNNER, "alternative_titles,casts,images,keywords,releases,trailers,translations,similar_movies,reviews,lists"); - assertTrue("No cast information", people.getResults().size() > 0); - - String name1 = "Harrison Ford"; - String name2 = "Charles Knode"; - boolean foundName1 = Boolean.FALSE; - boolean foundName2 = Boolean.FALSE; - - for (Person person : people.getResults()) { - if (!foundName1 && person.getName().equalsIgnoreCase(name1)) { - foundName1 = Boolean.TRUE; - } - - if (!foundName2 && person.getName().equalsIgnoreCase(name2)) { - foundName2 = Boolean.TRUE; - } - } - assertTrue("Couldn't find " + name1, foundName1); - assertTrue("Couldn't find " + name2, foundName2); - } - - /** - * Test of getMovieImages method, of class TheMovieDbApi. - * - * @throws MovieDbException - */ - @Test - public void testGetMovieImages() throws MovieDbException { - LOG.info("getMovieImages"); - String language = ""; - TmdbResultsList result = tmdb.getMovieImages(ID_MOVIE_BLADE_RUNNER, language); - assertFalse("No artwork found", result.getResults().isEmpty()); - } - - /** - * Test of getMovieKeywords method, of class TheMovieDbApi. - * - * @throws MovieDbException - */ - @Test - public void testGetMovieKeywords() throws MovieDbException { - LOG.info("getMovieKeywords"); - TmdbResultsList result = tmdb.getMovieKeywords(ID_MOVIE_BLADE_RUNNER); - assertFalse("No keywords found", result.getResults().isEmpty()); - } - - /** - * Test of getMovieReleaseInfo method, of class TheMovieDbApi. - * - * @throws MovieDbException - */ - @Test - public void testGetMovieReleaseInfo() throws MovieDbException { - LOG.info("getMovieReleaseInfo"); - TmdbResultsList result = tmdb.getMovieReleaseInfo(ID_MOVIE_BLADE_RUNNER, ""); - assertFalse("Release information missing", result.getResults().isEmpty()); - } - - /** - * Test of getMovieTrailers method, of class TheMovieDbApi. - * - * @throws MovieDbException - */ - @Test - public void testGetMovieTrailers() throws MovieDbException { - LOG.info("getMovieTrailers"); - TmdbResultsList

    *
  • Movies: imdb_id
  • *
  • People: imdb_id, freebase_mid, freebase_id, tvrage_id
  • - *
  • TV Series: imdb_id, freebase_mid, freebase_id, tvdb_id, - * tvrage_id
  • + *
  • TV Series: imdb_id, freebase_mid, freebase_id, tvdb_id, tvrage_id
  • *
  • TV Seasons: freebase_mid, freebase_id, tvdb_id, tvrage_id
  • - *
  • TV Episodes: imdb_id, freebase_mid, freebase_id, tvdb_id, - * tvrage_idimdb_id, freebase_mid, freebase_id, tvrage_id, tvdb_id. + *
  • TV Episodes: imdb_id, freebase_mid, freebase_id, tvdb_id, tvrage_idimdb_id, freebase_mid, freebase_id, tvrage_id, + * tvdb_id. *
* * For details see http://docs.themoviedb.apiary.io/#find @@ -65,7 +69,20 @@ public class TmdbFind extends AbstractMethod { * @return * @throws MovieDbException */ - public TBD_FindResults find(String id, TBD_ExternalSource externalSource, String language) throws MovieDbException { - throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "not implemented yet"); + public FindResults find(String id, ExternalSource externalSource, String language) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, id); + parameters.add(Param.LANGUAGE, language); + parameters.add(Param.EXTERNAL_SOURCE, externalSource.getPropertyString()); + + URL url = new ApiUrl(apiKey, MethodBase.FIND).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, FindResults.class); + } catch (IOException ex) { + LOG.info("{}",ex.getMessage(),ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get find results", url, ex); + } } } diff --git a/src/main/java/com/omertron/themoviedbapi/model/TBD_ExternalSource.java b/src/main/java/com/omertron/themoviedbapi/model/TBD_ExternalSource.java deleted file mode 100644 index fb52a06e2..000000000 --- a/src/main/java/com/omertron/themoviedbapi/model/TBD_ExternalSource.java +++ /dev/null @@ -1,45 +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 . - * - */ -package com.omertron.themoviedbapi.model; - -import com.omertron.themoviedbapi.model2.AbstractJsonMapping; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonRootName; - -/** - * @author stuart.boston - */ -@JsonRootName("???") -public class TBD_ExternalSource extends AbstractJsonMapping { - - private static final long serialVersionUID = 1L; - - // Properties - @JsonProperty("id") - private int id; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } -} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/FindResults.java b/src/main/java/com/omertron/themoviedbapi/model2/FindResults.java new file mode 100644 index 000000000..88c1b3027 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/FindResults.java @@ -0,0 +1,88 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model2; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; +import com.omertron.themoviedbapi.model2.person.PersonFind; +import com.omertron.themoviedbapi.model2.tv.TVBasic; +import com.omertron.themoviedbapi.model2.tv.TVEpisodeBasic; +import com.omertron.themoviedbapi.model2.tv.TVSeasonBasic; +import java.util.List; + +/** + * @author stuart.boston + */ +public class FindResults extends AbstractJsonMapping { + + private static final long serialVersionUID = 1L; + + @JsonProperty("movie_results") + private List movieResults; + @JsonProperty("person_results") + private List personResults; + @JsonProperty("tv_results") + private List tvResults; + @JsonProperty("tv_season_results") + private List tvSeasonResults; + @JsonProperty("tv_episode_results") + private List tvEpisodeResults; + + public List getMovieResults() { + return movieResults; + } + + public void setMovieResults(List movieResults) { + this.movieResults = movieResults; + } + + public List getPersonResults() { + return personResults; + } + + public void setPersonResults(List personResults) { + this.personResults = personResults; + } + + public List getTvResults() { + return tvResults; + } + + public void setTvResults(List tvResults) { + this.tvResults = tvResults; + } + + public List getTvSeasonResults() { + return tvSeasonResults; + } + + public void setTvSeasonResults(List tvSeasonResults) { + this.tvSeasonResults = tvSeasonResults; + } + + public List getTvEpisodeResults() { + return tvEpisodeResults; + } + + public void setTvEpisodeResults(List tvEpisodeResults) { + this.tvEpisodeResults = tvEpisodeResults; + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/MediaBasic.java b/src/main/java/com/omertron/themoviedbapi/model2/MediaBasic.java new file mode 100644 index 000000000..cbf8c2f4d --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/MediaBasic.java @@ -0,0 +1,117 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model2; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonSubTypes.Type; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; +import com.omertron.themoviedbapi.model2.tv.TVBasic; + +/** + * Basic media information + * + * @author stuart.boston + */ +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.EXTERNAL_PROPERTY, + property = "media_type", + defaultImpl = MovieBasic.class +) +@JsonSubTypes({ + @Type(value = MovieBasic.class, name = "movie"), + @Type(value = TVBasic.class, name = "tv") +}) +public class MediaBasic extends AbstractJsonMapping { + + @JsonProperty("id") + private int id; + @JsonProperty("media_type") + private String mediaType; + @JsonProperty("backdrop_path") + private String backdropPath; + @JsonProperty("poster_path") + private String posterPath; + @JsonProperty("popularity") + private float popularity; + @JsonProperty("vote_average") + private float voteAverage; + @JsonProperty("vote_count") + private int voteCount; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getMediaType() { + return mediaType; + } + + public void setMediaType(String mediaType) { + this.mediaType = mediaType; + } + + public String getBackdropPath() { + return backdropPath; + } + + public void setBackdropPath(String backdropPath) { + this.backdropPath = backdropPath; + } + + public String getPosterPath() { + return posterPath; + } + + public void setPosterPath(String posterPath) { + this.posterPath = posterPath; + } + + public float getPopularity() { + return popularity; + } + + public void setPopularity(float popularity) { + this.popularity = popularity; + } + + public float getVoteAverage() { + return voteAverage; + } + + public void setVoteAverage(float voteAverage) { + this.voteAverage = voteAverage; + } + + public int getVoteCount() { + return voteCount; + } + + public void setVoteCount(int voteCount) { + this.voteCount = voteCount; + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/MediaTypeMixIn.java b/src/main/java/com/omertron/themoviedbapi/model2/MediaTypeMixIn.java new file mode 100644 index 000000000..62c5b5c00 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/MediaTypeMixIn.java @@ -0,0 +1,5 @@ +package com.omertron.themoviedbapi.model2; + +public class MediaTypeMixIn { + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/movie/MovieBasic.java b/src/main/java/com/omertron/themoviedbapi/model2/movie/MovieBasic.java index 55357bdba..b6a7456a3 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/movie/MovieBasic.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/movie/MovieBasic.java @@ -19,50 +19,29 @@ */ package com.omertron.themoviedbapi.model2.movie; -import com.omertron.themoviedbapi.model2.AbstractJsonMapping; -import com.omertron.themoviedbapi.model.*; import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model2.MediaBasic; /** - * Movie Favorite information + * Basic Movie information * * @author stuart.boston */ -public class MovieBasic extends AbstractJsonMapping { +public class MovieBasic extends MediaBasic { - @JsonProperty("id") - private int id; @JsonProperty("adult") private boolean adult; - @JsonProperty("backdrop_path") - private String backdropPath; @JsonProperty("original_title") private String originalTitle; @JsonProperty("release_date") private String releaseDate; - @JsonProperty("poster_path") - private String posterPath; - @JsonProperty("popularity") - private float popularity; @JsonProperty("title") private String title; @JsonProperty("video") private boolean video; - @JsonProperty("vote_average") - private float voteAverage; - @JsonProperty("vote_count") - private int voteCount; @JsonProperty("rating") private float rating = -1f; - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - public boolean isAdult() { return adult; } @@ -71,14 +50,6 @@ public class MovieBasic extends AbstractJsonMapping { this.adult = adult; } - public String getBackdropPath() { - return backdropPath; - } - - public void setBackdropPath(String backdropPath) { - this.backdropPath = backdropPath; - } - public String getOriginalTitle() { return originalTitle; } @@ -95,22 +66,6 @@ public class MovieBasic extends AbstractJsonMapping { this.releaseDate = releaseDate; } - public String getPosterPath() { - return posterPath; - } - - public void setPosterPath(String posterPath) { - this.posterPath = posterPath; - } - - public float getPopularity() { - return popularity; - } - - public void setPopularity(float popularity) { - this.popularity = popularity; - } - public String getTitle() { return title; } @@ -127,22 +82,6 @@ public class MovieBasic extends AbstractJsonMapping { this.video = video; } - public float getVoteAverage() { - return voteAverage; - } - - public void setVoteAverage(float voteAverage) { - this.voteAverage = voteAverage; - } - - public int getVoteCount() { - return voteCount; - } - - public void setVoteCount(int voteCount) { - this.voteCount = voteCount; - } - public float getRating() { return rating; } diff --git a/src/main/java/com/omertron/themoviedbapi/model2/person/PersonBasic.java b/src/main/java/com/omertron/themoviedbapi/model2/person/PersonBasic.java index 8accb1b18..3de122563 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/person/PersonBasic.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/person/PersonBasic.java @@ -27,5 +27,4 @@ import com.omertron.themoviedbapi.model.AbstractIdName; public class PersonBasic extends AbstractIdName { private static final long serialVersionUID = 1L; - } diff --git a/src/main/java/com/omertron/themoviedbapi/model2/person/PersonFind.java b/src/main/java/com/omertron/themoviedbapi/model2/person/PersonFind.java new file mode 100644 index 000000000..506a972c0 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/person/PersonFind.java @@ -0,0 +1,73 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model2.person; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model2.MediaBasic; +import java.util.List; + +/** + * @author stuart.boston + */ +public class PersonFind extends PersonBasic { + + private static final long serialVersionUID = 1L; + @JsonProperty("adult") + private Boolean adult; + @JsonProperty("popularity") + private Float popularity; + @JsonProperty("profile_path") + private String profilePath; + @JsonProperty("known_for") + private List knownFor; + + public Boolean getAdult() { + return adult; + } + + public void setAdult(Boolean adult) { + this.adult = adult; + } + + public Float getPopularity() { + return popularity; + } + + public void setPopularity(Float popularity) { + this.popularity = popularity; + } + + public String getProfilePath() { + return profilePath; + } + + public void setProfilePath(String profilePath) { + this.profilePath = profilePath; + } + + public List getKnownFor() { + return knownFor; + } + + public void setKnownFor(List knownFor) { + this.knownFor = knownFor; + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/tv/TVBasic.java b/src/main/java/com/omertron/themoviedbapi/model2/tv/TVBasic.java index 85399f3a5..3df890205 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/tv/TVBasic.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/tv/TVBasic.java @@ -19,49 +19,28 @@ */ package com.omertron.themoviedbapi.model2.tv; -import com.omertron.themoviedbapi.model2.AbstractJsonMapping; -import com.omertron.themoviedbapi.model.*; import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model2.MediaBasic; import java.util.List; /** - * TV Favorite information + * Basic TV information * * @author stuart.boston */ -public class TVBasic extends AbstractJsonMapping { +public class TVBasic extends MediaBasic { - @JsonProperty("id") - private int id; @JsonProperty("name") private String name; @JsonProperty("original_name") private String originalName; - @JsonProperty("backdrop_path") - private String backdropPath; - @JsonProperty("poster_path") - private String posterPath; - @JsonProperty("vote_average") - private float voteAverage; - @JsonProperty("vote_count") - private int voteCount; @JsonProperty("first_air_date") private String firstAirDate; - @JsonProperty("popularity") - private float popularity; @JsonProperty("origin_country") private List originCountry; @JsonProperty("rating") private float rating = -1f; - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - public String getName() { return name; } @@ -78,38 +57,6 @@ public class TVBasic extends AbstractJsonMapping { this.originalName = originalName; } - public String getBackdropPath() { - return backdropPath; - } - - public void setBackdropPath(String backdropPath) { - this.backdropPath = backdropPath; - } - - public String getPosterPath() { - return posterPath; - } - - public void setPosterPath(String posterPath) { - this.posterPath = posterPath; - } - - public float getVoteAverage() { - return voteAverage; - } - - public void setVoteAverage(float voteAverage) { - this.voteAverage = voteAverage; - } - - public int getVoteCount() { - return voteCount; - } - - public void setVoteCount(int voteCount) { - this.voteCount = voteCount; - } - public String getFirstAirDate() { return firstAirDate; } @@ -118,14 +65,6 @@ public class TVBasic extends AbstractJsonMapping { this.firstAirDate = firstAirDate; } - public float getPopularity() { - return popularity; - } - - public void setPopularity(float popularity) { - this.popularity = popularity; - } - public List getOriginCountry() { return originCountry; } diff --git a/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java b/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java index a1f7a27a3..c3894b7c2 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java @@ -32,6 +32,7 @@ public enum MethodBase { CONFIGURATION("configuration"), CREDIT("credit"), DISCOVER("discover"), + FIND("find"), GENRE("genre"), JOB("job"), KEYWORD("keyword"), diff --git a/src/main/java/com/omertron/themoviedbapi/tools/Param.java b/src/main/java/com/omertron/themoviedbapi/tools/Param.java index 6c6b7b729..b84683035 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/Param.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/Param.java @@ -34,6 +34,7 @@ public enum Param { APPEND("append_to_response="), COUNTRY("country="), END_DATE("end_date="), + EXTERNAL_SOURCE("external_source="), FAVORITE("favorite="), ID("id="), INCLUDE_ALL_MOVIES("include_all_movies="), diff --git a/src/test/java/com/omertron/themoviedbapi/TestID.java b/src/test/java/com/omertron/themoviedbapi/TestID.java new file mode 100644 index 000000000..1c30381a0 --- /dev/null +++ b/src/test/java/com/omertron/themoviedbapi/TestID.java @@ -0,0 +1,70 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi; + +public class TestID { + + private String name; + private String imdb; + private int tmdb; + private String other = null; + + public TestID() { + } + + public TestID(String name, String imdb, int tmdb) { + this.name = name; + this.imdb = imdb; + this.tmdb = tmdb; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getImdb() { + return imdb; + } + + public void setImdb(String imdb) { + this.imdb = imdb; + } + + public int getTmdb() { + return tmdb; + } + + public void setTmdb(int tmdb) { + this.tmdb = tmdb; + } + + public String getOther() { + return other; + } + + public void setOther(String other) { + this.other = other; + } + +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java index f4215fde0..ccb4f8e20 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java @@ -21,9 +21,18 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.TestID; +import com.omertron.themoviedbapi.enumeration.ExternalSource; +import com.omertron.themoviedbapi.model2.FindResults; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; +import com.omertron.themoviedbapi.model2.person.PersonFind; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; import org.junit.After; import org.junit.AfterClass; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -36,6 +45,9 @@ import org.junit.Test; public class TmdbFindTest extends AbstractTests { private static TmdbFind instance; + private static final List PERSON_IDS = new ArrayList(); + private static final List FILM_IDS = new ArrayList(); + private static final List TV_IDS = new ArrayList(); public TmdbFindTest() { } @@ -44,6 +56,15 @@ public class TmdbFindTest extends AbstractTests { public static void setUpClass() throws MovieDbException { doConfiguration(); instance = new TmdbFind(getApiKey(), getHttpTools()); + + PERSON_IDS.add(new TestID("Mila Kunis", "nm0005109", 18973)); + PERSON_IDS.add(new TestID("Andrew Lincoln", "nm0511088", 7062)); + + FILM_IDS.add(new TestID("Jupiter Ascending", "tt1617661", 76757)); + FILM_IDS.add(new TestID("Lucy", "tt2872732", 240832)); + + TV_IDS.add(new TestID("The Walking Dead", "tt1520211", 1402)); + TV_IDS.add(new TestID("Supernatural", "tt0460681", 1622)); } @AfterClass @@ -59,32 +80,76 @@ public class TmdbFindTest extends AbstractTests { } /** - * Test of getMovieChangesList method, of class TmdbFindTest. + * Test of Find Movie + * + * @throws MovieDbException + */ +// @Test + public void testFindMoviesImdbID() throws MovieDbException { + LOG.info("findMoviesImdbID"); + FindResults result; + + for (TestID test : FILM_IDS) { + result = instance.find(test.getImdb(), ExternalSource.IMDB_ID, LANGUAGE_DEFAULT); + assertFalse("No movie for ID " + test.getName(), result.getMovieResults().isEmpty()); + boolean found = false; + for (MovieBasic m : result.getMovieResults()) { + if (m.getId() == test.getTmdb()) { + found = true; + break; + } + } + assertTrue("No movie found: " + test.getName(), found); + } + } + + /** + * Test of Find Person + * + * @throws MovieDbException + * @throws IOException + */ +// @Test + public void testFindPersonImdbID() throws MovieDbException, IOException { + LOG.info("findPersonImdbID"); + FindResults result; + + for (TestID test : PERSON_IDS) { + result = instance.find(test.getImdb(), ExternalSource.IMDB_ID, LANGUAGE_DEFAULT); + assertFalse("No person for ID: " + test.getName(), result.getPersonResults().isEmpty()); + boolean found = false; + for (PersonFind p : result.getPersonResults()) { + if (p.getId() == test.getTmdb()) { + found = true; + break; + } + } + assertTrue("No person found for ID: " + test.getName(), found); + } + } + + /** + * Test of Find TV * * @throws MovieDbException */ - @Test - public void testFindMoviesImdbID() throws MovieDbException { - LOG.info("findMoviesImdbID"); -// TBD_FindResults result = instance.find("tt0196229", TBD_ExternalSource.imdb_id, "it"); -// assertFalse("No movie for id.", result.getMovieResults().isEmpty()); - fail("The test case is a prototype."); - } - @Test public void testFindTvSeriesImdbID() throws MovieDbException { LOG.info("findTvSeriesImdbID"); -// TBD_FindResults result = instance.find("tt1219024", TBD_ExternalSource.imdb_id, "it"); -// assertFalse("No tv for id.", result.getTvResults().isEmpty()); - fail("The test case is a prototype."); - } + FindResults result; - @Test - public void testFindPersonImdbID() throws MovieDbException { - LOG.info("findPersonImdbID"); -// TBD_FindResults result = instance.find("nm0001774", TBD_ExternalSource.imdb_id, "it"); -// assertFalse("No person for id.", result.getPersonResults().isEmpty()); - fail("The test case is a prototype."); + for (TestID test : TV_IDS) { + result = instance.find(test.getImdb(), ExternalSource.IMDB_ID, LANGUAGE_DEFAULT); + assertFalse("No TV Show for ID: " + test.getName(), result.getPersonResults().isEmpty()); + boolean found = false; + for (PersonFind p : result.getPersonResults()) { + if (p.getId() == test.getTmdb()) { + found = true; + break; + } + } + assertTrue("No TV Show found for ID: " + test.getName(), found); + } } } From 57673d3f11930cf900513ebe48e7f1909cd11097 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Wed, 25 Feb 2015 20:57:35 +0000 Subject: [PATCH 032/100] Partial Find (not working) --- .../omertron/themoviedbapi/methods/TmdbFind.java | 5 ++++- .../omertron/themoviedbapi/model2/MediaBasic.java | 15 --------------- .../themoviedbapi/model2/MediaTypeMixIn.java | 15 +++++++++++++++ .../themoviedbapi/methods/TmdbFindTest.java | 3 +++ 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java index 2bd8b936c..d96b96288 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java @@ -22,6 +22,8 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.ExternalSource; import com.omertron.themoviedbapi.model2.FindResults; +import com.omertron.themoviedbapi.model2.MediaBasic; +import com.omertron.themoviedbapi.model2.MediaTypeMixIn; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; @@ -46,6 +48,8 @@ public class TmdbFind extends AbstractMethod { */ public TmdbFind(String apiKey, HttpTools httpTools) { super(apiKey, httpTools); + + MAPPER.addMixIn(MediaBasic.class, MediaTypeMixIn.class); } /** @@ -81,7 +85,6 @@ public class TmdbFind extends AbstractMethod { try { return MAPPER.readValue(webpage, FindResults.class); } catch (IOException ex) { - LOG.info("{}",ex.getMessage(),ex); throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get find results", url, ex); } } diff --git a/src/main/java/com/omertron/themoviedbapi/model2/MediaBasic.java b/src/main/java/com/omertron/themoviedbapi/model2/MediaBasic.java index cbf8c2f4d..d430c3f2a 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/MediaBasic.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/MediaBasic.java @@ -20,27 +20,12 @@ package com.omertron.themoviedbapi.model2; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonSubTypes; -import com.fasterxml.jackson.annotation.JsonSubTypes.Type; -import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.omertron.themoviedbapi.model2.movie.MovieBasic; -import com.omertron.themoviedbapi.model2.tv.TVBasic; /** * Basic media information * * @author stuart.boston */ -@JsonTypeInfo( - use = JsonTypeInfo.Id.NAME, - include = JsonTypeInfo.As.EXTERNAL_PROPERTY, - property = "media_type", - defaultImpl = MovieBasic.class -) -@JsonSubTypes({ - @Type(value = MovieBasic.class, name = "movie"), - @Type(value = TVBasic.class, name = "tv") -}) public class MediaBasic extends AbstractJsonMapping { @JsonProperty("id") diff --git a/src/main/java/com/omertron/themoviedbapi/model2/MediaTypeMixIn.java b/src/main/java/com/omertron/themoviedbapi/model2/MediaTypeMixIn.java index 62c5b5c00..f74bd886d 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/MediaTypeMixIn.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/MediaTypeMixIn.java @@ -1,5 +1,20 @@ package com.omertron.themoviedbapi.model2; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; +import com.omertron.themoviedbapi.model2.tv.TVBasic; + +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.EXTERNAL_PROPERTY, + property = "media_type", + defaultImpl = MovieBasic.class +) +@JsonSubTypes({ + @JsonSubTypes.Type(value = MovieBasic.class, name = "movie"), + @JsonSubTypes.Type(value = TVBasic.class, name = "tv") +}) public class MediaTypeMixIn { } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java index ccb4f8e20..cf7b3faa3 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java @@ -119,6 +119,9 @@ public class TmdbFindTest extends AbstractTests { assertFalse("No person for ID: " + test.getName(), result.getPersonResults().isEmpty()); boolean found = false; for (PersonFind p : result.getPersonResults()) { + for (Object x : p.getKnownFor()) { + LOG.info(" {}", x.toString()); + } if (p.getId() == test.getTmdb()) { found = true; break; From a129692ae34ceb1b01b2142a747664f927979c5b Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Wed, 25 Feb 2015 20:58:00 +0000 Subject: [PATCH 033/100] Partial Find (not working) --- src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java index d96b96288..6fc6c702c 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java @@ -48,7 +48,6 @@ public class TmdbFind extends AbstractMethod { */ public TmdbFind(String apiKey, HttpTools httpTools) { super(apiKey, httpTools); - MAPPER.addMixIn(MediaBasic.class, MediaTypeMixIn.class); } From 6231130d462980401a8e636c9b07cfc813a54f60 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Wed, 25 Feb 2015 21:35:02 +0000 Subject: [PATCH 034/100] Genres --- .../themoviedbapi/methods/TmdbGenres.java | 57 +++++++++++-------- .../omertron/themoviedbapi/tools/Param.java | 1 + .../themoviedbapi/methods/TmdbGenresTest.java | 44 ++++++++++---- 3 files changed, 67 insertions(+), 35 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbGenres.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbGenres.java index d714ef499..3937ec2cf 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbGenres.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbGenres.java @@ -21,7 +21,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model.Genre; -import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; import com.omertron.themoviedbapi.results.TmdbResultsList; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; @@ -30,9 +30,9 @@ import com.omertron.themoviedbapi.tools.MethodSub; import com.omertron.themoviedbapi.tools.Param; import com.omertron.themoviedbapi.tools.TmdbParameters; import com.omertron.themoviedbapi.wrapper.WrapperGenres; -import com.omertron.themoviedbapi.wrapper.WrapperMovie; import java.io.IOException; import java.net.URL; +import java.util.List; import org.yamj.api.common.exception.ApiExceptionType; /** @@ -53,19 +53,39 @@ public class TmdbGenres extends AbstractMethod { } /** - * You can use this method to retrieve the list of genres used on TMDb. - * - * These IDs will correspond to those found in movie calls. + * Get the list of movie genres. * * @param language * @return * @throws MovieDbException */ - public TmdbResultsList getGenreList(String language) throws MovieDbException { + public TmdbResultsList getGenreMovieList(String language) throws MovieDbException { + return getGenreList(language, MethodSub.MOVIE_LIST); + } + + /** + * Get the list of TV genres. + * + * @param language + * @return + * @throws MovieDbException + */ + public TmdbResultsList getGenreTVList(String language) throws MovieDbException { + return getGenreList(language, MethodSub.TV_LIST); + } + + /** + * Get the list of genres for movies or TV + * @param language + * @param sub + * @return + * @throws MovieDbException + */ + private TmdbResultsList getGenreList(String language, MethodSub sub) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.LANGUAGE, language); - URL url = new ApiUrl(apiKey, MethodBase.GENRE).setSubMethod(MethodSub.LIST).buildUrl(parameters); + URL url = new ApiUrl(apiKey, MethodBase.GENRE).setSubMethod(sub).buildUrl(parameters); String webpage = httpTools.getRequest(url); try { @@ -74,43 +94,34 @@ public class TmdbGenres extends AbstractMethod { results.copyWrapper(wrapper); return results; } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get genre list", url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get genre " + sub.toString(), url, ex); } } /** - * Get a list of movies per genre. + * Get the list of movies for a particular genre by id. * - * 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. + * By default, only movies with 10 or more votes are included. * * @param genreId * @param language * @param page * @param includeAllMovies + * @param includeAdult * @return * @throws MovieDbException */ - public TmdbResultsList getGenreMovies(int genreId, String language, int page, boolean includeAllMovies) throws MovieDbException { + public List getGenreMovies(int genreId, String language, Integer page, Boolean includeAllMovies, Boolean includeAdult) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.ID, genreId); parameters.add(Param.LANGUAGE, language); parameters.add(Param.PAGE, page); parameters.add(Param.INCLUDE_ALL_MOVIES, includeAllMovies); + parameters.add(Param.INCLUDE_ADULT, includeAdult); URL url = new ApiUrl(apiKey, MethodBase.GENRE).setSubMethod(MethodSub.MOVIES).buildUrl(parameters); String webpage = httpTools.getRequest(url); - try { - WrapperMovie wrapper = MAPPER.readValue(webpage, WrapperMovie.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getMovies()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get genre movie list", url, ex); - } + return processWrapperList(TR_MOVIE_BASIC, url, webpage); } } diff --git a/src/main/java/com/omertron/themoviedbapi/tools/Param.java b/src/main/java/com/omertron/themoviedbapi/tools/Param.java index b84683035..4ee819bfc 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/Param.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/Param.java @@ -38,6 +38,7 @@ public enum Param { FAVORITE("favorite="), ID("id="), INCLUDE_ALL_MOVIES("include_all_movies="), + INCLUDE_ADULT("include_adult="), LANGUAGE("language="), MOVIE_ID("movie_id="), MOVIE_WATCHLIST("movie_watchlist="), diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbGenresTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbGenresTest.java index 0300efce9..1e3c25634 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbGenresTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbGenresTest.java @@ -22,11 +22,13 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model.Genre; -import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; import com.omertron.themoviedbapi.results.TmdbResultsList; +import java.util.List; import org.junit.After; import org.junit.AfterClass; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -62,27 +64,45 @@ public class TmdbGenresTest extends AbstractTests { } /** - * Test of getGenreList method, of class TheMovieDbApi. + * Test of getGenreMovieList method, of class TmdbGenres. * - * @throws MovieDbException + * @throws com.omertron.themoviedbapi.MovieDbException */ @Test - public void testGetGenreList() throws MovieDbException { - LOG.info("getGenreList"); - TmdbResultsList result = instance.getGenreList(LANGUAGE_DEFAULT); - assertTrue("No genres found", !result.getResults().isEmpty()); + public void testGetGenreMovieList() throws MovieDbException { + LOG.info("getGenreMovieList"); + TmdbResultsList result = instance.getGenreMovieList(LANGUAGE_DEFAULT); + assertNotNull("List is null", result.getResults()); + assertFalse("List is empty", result.getResults().isEmpty()); } /** - * Test of getGenreMovies method, of class TheMovieDbApi. + * Test of getGenreTVList method, of class TmdbGenres. * - * @throws MovieDbException + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetGenreTVList() throws MovieDbException { + LOG.info("getGenreTVList"); + TmdbResultsList result = instance.getGenreTVList(LANGUAGE_DEFAULT); + assertNotNull("List is null", result.getResults()); + assertFalse("List is empty", result.getResults().isEmpty()); + } + + /** + * Test of getGenreMovies method, of class TmdbGenres. + * + * @throws com.omertron.themoviedbapi.MovieDbException */ @Test public void testGetGenreMovies() throws MovieDbException { LOG.info("getGenreMovies"); - TmdbResultsList result = instance.getGenreMovies(ID_GENRE_ACTION, LANGUAGE_DEFAULT, 0, Boolean.TRUE); - assertTrue("No genre movies found", !result.isEmpty()); + Integer page = null; + Boolean includeAllMovies = null; + Boolean includeAdult = null; + List result = instance.getGenreMovies(ID_GENRE_ACTION, LANGUAGE_DEFAULT, page, includeAllMovies, includeAdult); + assertNotNull("List is null", result); + assertFalse("List is empty", result.isEmpty()); } } From 50820a437f7ec0738e10a4632c99a99889b1809c Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Thu, 26 Feb 2015 08:52:50 +0000 Subject: [PATCH 035/100] Guest session (partial) --- .../omertron/themoviedbapi/TheMovieDbApi.java | 39 +++++++++++++++---- .../themoviedbapi/enumeration/SortBy.java | 2 + .../themoviedbapi/methods/TmdbAccount.java | 25 ++++++++++++ .../themoviedbapi/methods/_Method_List.txt | 2 +- .../themoviedbapi/tools/MethodBase.java | 1 + .../themoviedbapi/tools/MethodSub.java | 1 + .../methods/TmdbAccountTest.java | 25 ++++++++++++ .../methods/TmdbAuthenticationTest.java | 30 +++++++++++++- 8 files changed, 115 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index e5c14be42..b2e9f9317 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -62,6 +62,7 @@ import com.omertron.themoviedbapi.model.ReleaseInfo; import com.omertron.themoviedbapi.model.Reviews; import com.omertron.themoviedbapi.model2.StatusCode; import com.omertron.themoviedbapi.enumeration.ExternalSource; +import com.omertron.themoviedbapi.enumeration.SortBy; import com.omertron.themoviedbapi.model2.FindResults; import com.omertron.themoviedbapi.model.TBD_Network; import com.omertron.themoviedbapi.model2.person.CreditInfo; @@ -413,6 +414,20 @@ public class TheMovieDbApi { public List getFavoriteTv(String sessionId, int accountId) throws MovieDbException { return tmdbAccount.getFavoriteTv(sessionId, accountId); } + + /** + * Get a list of rated movies for a specific guest session id. + * + * @param guestSessionId + * @param language + * @param page + * @param sortBy only CREATED_AT_ASC or CREATED_AT_DESC is supported + * @return + * @throws MovieDbException + */ + public List getGuestRatedMovies(String guestSessionId, String language, Integer page, SortBy sortBy) throws MovieDbException { + return tmdbAccount.getGuestRatedMovies(guestSessionId, language, page, sortBy); + } // // @@ -716,16 +731,25 @@ public class TheMovieDbApi { // /** - * You can use this method to retrieve the list of genres used on TMDb. - * - * These IDs will correspond to those found in movie calls. + * Get the list of Movie genres. * * @param language * @return * @throws MovieDbException */ - public TmdbResultsList getGenreList(String language) throws MovieDbException { - return tmdbGenre.getGenreList(language); + public TmdbResultsList getGenreMovieList(String language) throws MovieDbException { + return tmdbGenre.getGenreMovieList(language); + } + + /** + * Get the list of TV genres.. + * + * @param language + * @return + * @throws MovieDbException + */ + public TmdbResultsList getGenreTVList(String language) throws MovieDbException { + return tmdbGenre.getGenreTVList(language); } /** @@ -739,11 +763,12 @@ public class TheMovieDbApi { * @param language * @param page * @param includeAllMovies + * @param includeAdult * @return * @throws MovieDbException */ - public TmdbResultsList getGenreMovies(int genreId, String language, int page, boolean includeAllMovies) throws MovieDbException { - return tmdbGenre.getGenreMovies(genreId, language, page, includeAllMovies); + public List getGenreMovies(int genreId, String language, Integer page, Boolean includeAllMovies, Boolean includeAdult) throws MovieDbException { + return tmdbGenre.getGenreMovies(genreId, language, page, includeAllMovies, includeAdult); } // diff --git a/src/main/java/com/omertron/themoviedbapi/enumeration/SortBy.java b/src/main/java/com/omertron/themoviedbapi/enumeration/SortBy.java index b023362e1..78e62a63d 100644 --- a/src/main/java/com/omertron/themoviedbapi/enumeration/SortBy.java +++ b/src/main/java/com/omertron/themoviedbapi/enumeration/SortBy.java @@ -2,6 +2,8 @@ package com.omertron.themoviedbapi.enumeration; public enum SortBy { + CREATED_AT_ASC, + CREATED_AT_DESC, POPULARITY_ASC, POPULARITY_DESC, RELEASE_DATE_ASC, diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java index 22574f209..1f6188dd6 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java @@ -21,6 +21,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.MediaType; +import com.omertron.themoviedbapi.enumeration.SortBy; import com.omertron.themoviedbapi.model2.account.Account; import com.omertron.themoviedbapi.model2.StatusCode; import com.omertron.themoviedbapi.model2.movie.MovieBasic; @@ -283,4 +284,28 @@ public class TmdbAccount extends AbstractMethod { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to modify watch list", url, ex); } } + + /** + * Get a list of rated movies for a specific guest session id. + * + * @param guestSessionId + * @param language + * @param page + * @param sortBy only CREATED_AT_ASC or CREATED_AT_DESC is supported + * @return + * @throws MovieDbException + */ + public List getGuestRatedMovies(String guestSessionId, String language, Integer page, SortBy sortBy) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, guestSessionId); + parameters.add(Param.LANGUAGE, language); + parameters.add(Param.PAGE, page); + //TODO: Test this works + if (sortBy != null) { + parameters.add(Param.SORT_BY, sortBy.getPropertyString()); + } + + URL url = new ApiUrl(apiKey, MethodBase.GUEST_SESSION).setSubMethod(MethodSub.RATED_MOVIES_GUEST).buildUrl(parameters); + return processWrapperList(TR_MOVIE_BASIC, url, "Guest Session Movies"); + } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt index ee326d7ad..86852bedb 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt +++ b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt @@ -43,7 +43,7 @@ Discover (Done) Find /find/{id} The find method makes it easy to search for objects in our database by an external id. -Genres +Genres (Done) /genre/movie/list Get the list of movie genres. /genre/tv/list Get the list of TV genres. /genre/{id}/movies Get the list of movies for a particular genre by id. diff --git a/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java b/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java index c3894b7c2..3c2a38a7d 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java @@ -34,6 +34,7 @@ public enum MethodBase { DISCOVER("discover"), FIND("find"), GENRE("genre"), + GUEST_SESSION("guest_session"), JOB("job"), KEYWORD("keyword"), LIST("list"), diff --git a/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java b/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java index f8bbda057..767adce11 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java @@ -49,6 +49,7 @@ public enum MethodSub { PERSON("person"), POPULAR("popular"), RATED_MOVIES("rated/movies"), + RATED_MOVIES_GUEST("rated_movies"), RATED_TV("rated/tv"), RATING("rating"), RELEASES("releases"), diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java index 229807fa3..1da8fadc3 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java @@ -22,8 +22,10 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.MediaType; +import com.omertron.themoviedbapi.enumeration.SortBy; import com.omertron.themoviedbapi.model2.account.Account; import com.omertron.themoviedbapi.model2.StatusCode; +import com.omertron.themoviedbapi.model2.authentication.TokenSession; import com.omertron.themoviedbapi.model2.movie.MovieBasic; import com.omertron.themoviedbapi.model2.tv.TVBasic; import com.omertron.themoviedbapi.model2.list.UserList; @@ -34,6 +36,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -252,4 +255,26 @@ public class TmdbAccountTest extends AbstractTests { LOG.info("Result: {}", result); assertTrue("Incorrect status code", result.getStatusCode() == 13); } + + /** + * Test of getGuestRatedMovies method, of class TmdbAccount. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetGuestRatedMovies() throws MovieDbException { + LOG.info("getGuestRatedMovies"); + + //TODO: Need to use rated movies with the guest session to add some movies to get + TmdbAuthentication auth = new TmdbAuthentication(getApiKey(), getHttpTools()); + TokenSession guestToken = auth.getGuestSessionToken(); + TmdbMovies tmdbM = new TmdbMovies(getApiKey(), getHttpTools()); + + String language = LANGUAGE_DEFAULT; + Integer page = null; + SortBy sortBy = null; + List result = instance.getGuestRatedMovies(guestToken.getGuestSessionId(), language, page, sortBy); + LOG.info("{}", result); + fail("Need rated movies"); + } } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAuthenticationTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAuthenticationTest.java index c8e74f4b0..68bfa7ff3 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAuthenticationTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAuthenticationTest.java @@ -23,9 +23,13 @@ import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model2.authentication.TokenAuthorisation; import com.omertron.themoviedbapi.model2.authentication.TokenSession; +import org.apache.commons.lang3.StringUtils; +import org.junit.After; import org.junit.AfterClass; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; @@ -34,7 +38,7 @@ import org.junit.Test; * * @author stuart.boston */ -public class TmdbAuthenticationTest extends AbstractTests{ +public class TmdbAuthenticationTest extends AbstractTests { private static TmdbAuthentication instance; @@ -44,13 +48,21 @@ public class TmdbAuthenticationTest extends AbstractTests{ @BeforeClass public static void setUpClass() throws MovieDbException { doConfiguration(); - instance = new TmdbAuthentication(getApiKey(),getHttpTools()); + instance = new TmdbAuthentication(getApiKey(), getHttpTools()); } @AfterClass public static void tearDownClass() { } + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + /** * Test of getAuthorisationToken method, of class TmdbAuthentication. * @@ -94,4 +106,18 @@ public class TmdbAuthenticationTest extends AbstractTests{ assertTrue("Failed to get guest session", result.getSuccess()); } + /** + * Test of getSessionTokenLogin method, of class TmdbAuthentication. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetSessionTokenLogin() throws MovieDbException { + System.out.println("getSessionTokenLogin"); + TokenAuthorisation token = instance.getAuthorisationToken(); + TokenAuthorisation result = instance.getSessionTokenLogin(token, getUsername(), getPassword()); + assertNotNull("Null token returned", result); + assertTrue("Empty token", StringUtils.isNotBlank(result.getRequestToken())); + } + } From 8522ac41715065268f53b43293452571dfb692b4 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Fri, 27 Feb 2015 20:40:11 +0000 Subject: [PATCH 036/100] Lists --- .../omertron/themoviedbapi/TheMovieDbApi.java | 90 ++++----- .../themoviedbapi/methods/TmdbLists.java | 110 ++++++++--- .../themoviedbapi/methods/_Method_List.txt | 8 +- .../list/ListItem.java} | 15 +- .../omertron/themoviedbapi/tools/ApiUrl.java | 1 + .../themoviedbapi/tools/MethodSub.java | 1 + .../omertron/themoviedbapi/tools/Param.java | 1 + .../wrapper/WrapperMovieDbList.java | 8 +- .../themoviedbapi/methods/TmdbListsTest.java | 178 ++++++++++-------- 9 files changed, 256 insertions(+), 156 deletions(-) rename src/main/java/com/omertron/themoviedbapi/{model/MovieDbList.java => model2/list/ListItem.java} (91%) diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index b2e9f9317..c6ca4948b 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -54,7 +54,7 @@ import com.omertron.themoviedbapi.model2.JobDepartment; import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.keyword.KeywordMovie; import com.omertron.themoviedbapi.model.MovieDb; -import com.omertron.themoviedbapi.model.MovieDbList; +import com.omertron.themoviedbapi.model2.list.ListItem; import com.omertron.themoviedbapi.model.MovieList; import com.omertron.themoviedbapi.model.person.Person; import com.omertron.themoviedbapi.model.person.PersonCredit; @@ -77,7 +77,6 @@ import com.omertron.themoviedbapi.results.TmdbResultsList; import com.omertron.themoviedbapi.results.TmdbResultsMap; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; -import com.omertron.themoviedbapi.tools.MethodSub; import java.net.URL; import java.util.List; import org.apache.commons.lang3.StringUtils; @@ -806,7 +805,7 @@ public class TheMovieDbApi { * @return The list and its items * @throws MovieDbException */ - public MovieDbList getList(String listId) throws MovieDbException { + public ListItem getList(String listId) throws MovieDbException { return tmdbList.getList(listId); } @@ -823,44 +822,6 @@ public class TheMovieDbApi { return tmdbList.createList(sessionId, name, description); } - /** - * Check to see if a movie ID is already added to a list. - * - * @param listId - * @param movieId - * @return true if the movie is on the list - * @throws MovieDbException - */ - public boolean isMovieOnList(String listId, Integer movieId) throws MovieDbException { - return tmdbList.isMovieOnList(listId, movieId); - } - - /** - * This method lets users add new movies to a list that they created. A valid session id is required. - * - * @param sessionId - * @param listId - * @param movieId - * @return true if the movie is on the list - * @throws MovieDbException - */ - public StatusCode addMovieToList(String sessionId, String listId, Integer movieId) throws MovieDbException { - return tmdbList.modifyMovieList(sessionId, listId, movieId, MethodSub.ADD_ITEM); - } - - /** - * This method lets users remove movies from a list that they created. A valid session id is required. - * - * @param sessionId - * @param listId - * @param movieId - * @return true if the movie is on the list - * @throws MovieDbException - */ - public StatusCode removeMovieFromList(String sessionId, String listId, Integer movieId) throws MovieDbException { - return tmdbList.modifyMovieList(sessionId, listId, movieId, MethodSub.REMOVE_ITEM); - } - /** * This method lets users delete a list that they created. A valid session id is required. * @@ -869,9 +830,52 @@ public class TheMovieDbApi { * @return * @throws MovieDbException */ - public StatusCode deleteMovieList(String sessionId, String listId) throws MovieDbException { - return tmdbList.deleteMovieList(sessionId, listId); + public StatusCode deleteList(String sessionId, String listId) throws MovieDbException { + return tmdbList.deleteList(sessionId, listId); } + + /** + * Check to see if an item is already on a list. + * + * @param listId + * @param mediaId + * @return true if the item is on the list + * @throws MovieDbException + */ + public boolean checkItemStatus(String listId, Integer mediaId) throws MovieDbException { + return tmdbList.checkItemStatus(listId, mediaId); + } + + /** + * This method lets users add new items to a list that they created. + * + * A valid session id is required. + * + * @param sessionId + * @param listId + * @param mediaId + * @return true if the movie is on the list + * @throws MovieDbException + */ + public StatusCode addItemToList(String sessionId, String listId, Integer mediaId) throws MovieDbException { + return tmdbList.addItem(sessionId, listId, mediaId); + } + + /** + * This method lets users remove items from a list that they created. + * + * A valid session id is required. + * + * @param sessionId + * @param listId + * @param mediaId + * @return true if the movie is on the list + * @throws MovieDbException + */ + public StatusCode removeItemFromList(String sessionId, String listId, Integer mediaId) throws MovieDbException { + return tmdbList.removeItem(sessionId, listId, mediaId); + } + // // diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbLists.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbLists.java index a6fa981cd..4113c547c 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbLists.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbLists.java @@ -19,9 +19,11 @@ */ package com.omertron.themoviedbapi.methods; +import com.fasterxml.jackson.core.type.TypeReference; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model.ListItemStatus; -import com.omertron.themoviedbapi.model.MovieDbList; +import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.model2.list.ListItem; import com.omertron.themoviedbapi.model.MovieDbListStatus; import com.omertron.themoviedbapi.model2.StatusCode; import com.omertron.themoviedbapi.tools.ApiUrl; @@ -61,7 +63,7 @@ public class TmdbLists extends AbstractMethod { * @return The list and its items * @throws MovieDbException */ - public MovieDbList getList(String listId) throws MovieDbException { + public ListItem getList(String listId) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.ID, listId); @@ -69,12 +71,35 @@ public class TmdbLists extends AbstractMethod { String webpage = httpTools.getRequest(url); try { - return MAPPER.readValue(webpage, MovieDbList.class); + return MAPPER.readValue(webpage, new TypeReference>(){}); } catch (IOException ex) { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get list", url, ex); } } + /** + * Check to see if an ID is already on a list. + * + * @param listId + * @param mediaId + * @return true if the movie is on the list + * @throws MovieDbException + */ + public boolean checkItemStatus(String listId, int mediaId) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, listId); + parameters.add(Param.MOVIE_ID, mediaId); + + URL url = new ApiUrl(apiKey, MethodBase.LIST).setSubMethod(MethodSub.ITEM_STATUS).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, ListItemStatus.class).isItemPresent(); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get item status", url, ex); + } + } + /** * This method lets users create a new list. A valid session id is required. * @@ -104,31 +129,33 @@ public class TmdbLists extends AbstractMethod { } /** - * Check to see if a movie ID is already added to a list. + * This method lets users delete a list that they created. A valid session id is required. * + * @param sessionId * @param listId - * @param movieId - * @return true if the movie is on the list + * @return * @throws MovieDbException */ - public boolean isMovieOnList(String listId, Integer movieId) throws MovieDbException { + public StatusCode deleteList(String sessionId, String listId) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.ID, listId); - parameters.add(Param.MOVIE_ID, movieId); + parameters.add(Param.SESSION, sessionId); - URL url = new ApiUrl(apiKey, MethodBase.LIST).setSubMethod(MethodSub.ITEM_STATUS).buildUrl(parameters); - String webpage = httpTools.getRequest(url); + URL url = new ApiUrl(apiKey, MethodBase.LIST).buildUrl(parameters); + String webpage = httpTools.deleteRequest(url); try { - return MAPPER.readValue(webpage, ListItemStatus.class).isItemPresent(); + return MAPPER.readValue(webpage, StatusCode.class); } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get media status", url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to delete list", url, ex); } } /** * Modify a list * + * This can be used to add or remove an item from the list + * * @param sessionId * @param listId * @param movieId @@ -136,7 +163,7 @@ public class TmdbLists extends AbstractMethod { * @return * @throws MovieDbException */ - public StatusCode modifyMovieList(String sessionId, String listId, Integer movieId, MethodSub operation) throws MovieDbException { + private StatusCode modifyMovieList(String sessionId, String listId, int movieId, MethodSub operation) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.SESSION, sessionId); parameters.add(Param.ID, listId); @@ -151,31 +178,68 @@ public class TmdbLists extends AbstractMethod { try { return MAPPER.readValue(webpage, StatusCode.class); } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to remove movie from list", url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to remove item from list", url, ex); } } /** - * This method lets users delete a list that they created. A valid session - * id is required. + * This method lets users add new items to a list that they created. + * + * A valid session id is required. * * @param sessionId * @param listId + * @param mediaId * @return * @throws MovieDbException */ - public StatusCode deleteMovieList(String sessionId, String listId) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, listId); - parameters.add(Param.SESSION, sessionId); + public StatusCode addItem(String sessionId, String listId, int mediaId) throws MovieDbException { + return modifyMovieList(sessionId, listId, mediaId, MethodSub.ADD_ITEM); + } - URL url = new ApiUrl(apiKey, MethodBase.LIST).buildUrl(parameters); - String webpage = httpTools.deleteRequest(url); + /** + * This method lets users delete items from a list that they created. + * + * A valid session id is required. + * + * @param sessionId + * @param listId + * @param mediaId + * @return + * @throws MovieDbException + */ + public StatusCode removeItem(String sessionId, String listId, int mediaId) throws MovieDbException { + return modifyMovieList(sessionId, listId, mediaId, MethodSub.REMOVE_ITEM); + } + + /** + * Clear all of the items within a list. + * + * This is a irreversible action and should be treated with caution. + * + * A valid session id is required. A call without confirm=true will return status code 29. + * + * @param sessionId + * @param listId + * @param confirm + * @return + * @throws MovieDbException + */ + public StatusCode clear(String sessionId, String listId, boolean confirm) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.SESSION, sessionId); + parameters.add(Param.ID, listId); + parameters.add(Param.CONFIRM, confirm); + + URL url = new ApiUrl(apiKey, MethodBase.LIST).setSubMethod(MethodSub.CLEAR).buildUrl(parameters); + String webpage = httpTools.postRequest(url, ""); try { return MAPPER.readValue(webpage, StatusCode.class); } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to delete movie list", url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to clear list", url, ex); } + } + } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt index 86852bedb..e79b09932 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt +++ b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt @@ -41,24 +41,24 @@ Discover (Done) /discover/tv Discover TV shows by different types of data like average rating, number of votes, genres, the network they aired on and air dates. Find -/find/{id} The find method makes it easy to search for objects in our database by an external id. +*** /find/{id} The find method makes it easy to search for objects in our database by an external id. Genres (Done) /genre/movie/list Get the list of movie genres. /genre/tv/list Get the list of TV genres. /genre/{id}/movies Get the list of movies for a particular genre by id. -Guest Sessions +Guest Sessions (Partial - in Account) /guest_session/{guest_session_id}/rated_movies Get a list of rated movies for a specific guest session id. Jobs (Done) /job/list Get a list of valid jobs. -Keyword +Keyword (Done) /keyword/{id} Get the basic information for a specific keyword id /keyword/{id}/movies Get the list of movies for a particular keyword by id -Lists +Lists (Done) /list/{id} Get a list by id. /list/{id}/item_status Check to see if a movie ID is already added to a list. /list This method lets users create a new list. A valid session id is required. diff --git a/src/main/java/com/omertron/themoviedbapi/model/MovieDbList.java b/src/main/java/com/omertron/themoviedbapi/model2/list/ListItem.java similarity index 91% rename from src/main/java/com/omertron/themoviedbapi/model/MovieDbList.java rename to src/main/java/com/omertron/themoviedbapi/model2/list/ListItem.java index 6c3e6f31f..16b0ae6cf 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/MovieDbList.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/list/ListItem.java @@ -17,19 +17,20 @@ * along with TheMovieDB API. If not, see . * */ -package com.omertron.themoviedbapi.model; +package com.omertron.themoviedbapi.model2.list; -import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import java.util.Collections; import java.util.List; /** - * Wrapper for the MovieDbList function + * Wrapper for the ListItem function * * @author stuart.boston + * @param Type of list */ -public class MovieDbList extends AbstractJsonMapping { +public class ListItem extends AbstractJsonMapping { @JsonProperty("id") private String id; @@ -40,7 +41,7 @@ public class MovieDbList extends AbstractJsonMapping { @JsonProperty("favorite_count") private int favoriteCount; @JsonProperty("items") - private List items = Collections.emptyList(); + private List items = Collections.emptyList(); @JsonProperty("item_count") private int itemCount; @JsonProperty("iso_639_1") @@ -70,7 +71,7 @@ public class MovieDbList extends AbstractJsonMapping { return favoriteCount; } - public List getItems() { + public List getItems() { return items; } @@ -114,7 +115,7 @@ public class MovieDbList extends AbstractJsonMapping { this.favoriteCount = favoriteCount; } - public void setItems(List items) { + public void setItems(List items) { this.items = items; } diff --git a/src/main/java/com/omertron/themoviedbapi/tools/ApiUrl.java b/src/main/java/com/omertron/themoviedbapi/tools/ApiUrl.java index d9d11da9a..6f483b7ac 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/ApiUrl.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/ApiUrl.java @@ -40,6 +40,7 @@ public class ApiUrl { private static final Logger LOG = LoggerFactory.getLogger(ApiUrl.class); // TheMovieDbApi API Base URL private static final String TMDB_API_BASE = "http://api.themoviedb.org/3/"; +// private static final String TMDB_API_BASE = "http://private-639f-themoviedb.apiary-proxy.com/3/"; // Parameter configuration private static final String DELIMITER_FIRST = "?"; private static final String DELIMITER_SUBSEQUENT = "&"; diff --git a/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java b/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java index 767adce11..b911025e9 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java @@ -28,6 +28,7 @@ public enum MethodSub { ALT_TITLES("alternative_titles"), CASTS("casts"), CHANGES("changes"), + CLEAR("clear"), COLLECTION("collection"), COMPANY("company"), CREDITS("credits"), diff --git a/src/main/java/com/omertron/themoviedbapi/tools/Param.java b/src/main/java/com/omertron/themoviedbapi/tools/Param.java index 4ee819bfc..a1b1e08be 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/Param.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/Param.java @@ -32,6 +32,7 @@ public enum Param { ADULT("include_adult="), API_KEY("api_key="), APPEND("append_to_response="), + CONFIRM("confirm="), COUNTRY("country="), END_DATE("end_date="), EXTERNAL_SOURCE("external_source="), diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovieDbList.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovieDbList.java index 37cdf8945..b17a4777e 100644 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovieDbList.java +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovieDbList.java @@ -20,20 +20,20 @@ package com.omertron.themoviedbapi.wrapper; import com.fasterxml.jackson.annotation.JsonProperty; -import com.omertron.themoviedbapi.model.MovieDbList; +import com.omertron.themoviedbapi.model2.list.ListItem; import java.util.List; public class WrapperMovieDbList extends AbstractWrapperAll { @JsonProperty("results") - private List lists; + private List lists; - public List getLists() { + public List getLists() { return lists; } - public void setLists(List lists) { + public void setLists(List lists) { this.lists = lists; } } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbListsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbListsTest.java index c119391b3..578e0341c 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbListsTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbListsTest.java @@ -21,25 +21,33 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.MovieDbList; import com.omertron.themoviedbapi.model2.StatusCode; -import com.omertron.themoviedbapi.tools.MethodSub; +import com.omertron.themoviedbapi.model2.list.ListItem; +import java.util.Random; +import org.apache.commons.lang3.StringUtils; import org.junit.After; import org.junit.AfterClass; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Ignore; +import org.junit.Rule; import org.junit.Test; -import org.junit.runners.MethodSorters; +import org.junit.rules.ExpectedException; -@FixMethodOrder(MethodSorters.NAME_ASCENDING) +//@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class TmdbListsTest extends AbstractTests { private static TmdbLists instance; + private static final int ID_JUPITER_ASCENDING = 76757; + private static final int ID_BIG_HERO_6 = 177572; + // Status codes + private static final int SC_SUCCESS_UPD = 12; + private static final int SC_SUCCESS_DEL = 13; + // Expected exception + @Rule + public ExpectedException exception = ExpectedException.none(); public TmdbListsTest() { } @@ -62,100 +70,120 @@ public class TmdbListsTest extends AbstractTests { public void tearDown() { } - /** - * Test of createList method, of class TmdbList. - * - * @throws com.omertron.themoviedbapi.MovieDbException - */ - @Ignore("Not working") - public void test1CreateList() throws MovieDbException { - LOG.info("createList"); - String name = "My Totally Awesome List"; - String description = "This list was created to share all of the totally awesome movies I've seen."; - String result = instance.createList(getSessionId(), name, description); - LOG.info(result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); - } - - /** - * Test of getList method, of class TheMovieDbApi. - * - * @throws MovieDbException - */ @Test - public void test2GetList() throws MovieDbException { + public void testSuite() throws MovieDbException { + // Test the list creation + String listId = testCreateList(); + + // Add two items to the list + testAddItem(listId, ID_JUPITER_ASCENDING); + testAddItem(listId, ID_BIG_HERO_6); + + // Get information on the list + testGetList(listId); + + // Check item status on the list + testCheckItemStatus(listId, ID_JUPITER_ASCENDING); + + // Delete an item from the list + testRemoveItem(listId, ID_BIG_HERO_6); + + // Clear the list + testClear(listId); + + // Delete the list + testDeleteList(listId); + + } + + /** + * Test of getList method, of class TmdbLists. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + private void testGetList(String listId) throws MovieDbException { LOG.info("getList"); - String listId = "509ec17b19c2950a0600050d"; - MovieDbList result = instance.getList(listId); - assertFalse("List not found", result.getItems().isEmpty()); + + ListItem result = instance.getList(listId); + LOG.info("Found {} movies on list", result.getItems().size()); + assertFalse("No movies in list", result.getItems().isEmpty()); } /** - * Test of addMovieToList method, of class TmdbList. + * Test of createList method, of class TmdbLists. * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Ignore("Not working") - public void test3AddMovieToList() throws MovieDbException { - LOG.info("addMovieToList"); - String listId = ""; - Integer movieId = null; - StatusCode expResult = null; - StatusCode result = instance.modifyMovieList(getSessionId(), listId, movieId, MethodSub.MOVIE); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); + private String testCreateList() throws MovieDbException { + LOG.info("createList"); + int r = new Random().nextInt(); + + String name = "Random list name #" + r; + String description = "This is random list number " + r + " used for testing purposes"; + String result = instance.createList(getSessionId(), name, description); + assertTrue("No list ID returned", StringUtils.isNotBlank(result)); + return result; } /** - * Test of isMovieOnList method, of class TmdbList. + * Test of checkItemStatus method, of class TmdbLists. * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Ignore("Not working") - public void test4IsMovieOnList() throws MovieDbException { - LOG.info("isMovieOnList"); - String listId = ""; - Integer movieId = null; - boolean expResult = false; - boolean result = instance.isMovieOnList(listId, movieId); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); + private void testCheckItemStatus(String listId, int mediaId) throws MovieDbException { + LOG.info("checkItemStatus"); + boolean expResult = true; + boolean result = instance.checkItemStatus(listId, mediaId); + assertEquals("Item is not on list!", expResult, result); } /** - * Test of removeMovieFromList method, of class TmdbList. + * Test of deleteList method, of class TmdbLists. * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Ignore("Not working") - public void test5RemoveMovieFromList() throws MovieDbException { - LOG.info("removeMovieFromList"); - String listId = ""; - Integer movieId = null; - StatusCode expResult = null; - StatusCode result = instance.modifyMovieList(getSessionId(), listId, movieId, MethodSub.MOVIE); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); + private void testDeleteList(String listId) throws MovieDbException { + LOG.info("deleteList"); + StatusCode result = instance.deleteList(getSessionId(), listId); + LOG.info("Result: {}", result); + + // We expect there to be an exception thrown here + exception.expect(MovieDbException.class); + ListItem result2 = instance.getList(listId); + LOG.info("Result: {}", result2); } /** - * Test of deleteMovieList method, of class TmdbList. + * Test of addItem method, of class TmdbLists. * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Ignore("Not working") - public void test6DeleteMovieList() throws MovieDbException { - LOG.info("deleteMovieList"); - String listId = ""; - StatusCode expResult = null; - StatusCode result = instance.deleteMovieList(getSessionId(), listId); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); + private void testAddItem(String listId, int mediaId) throws MovieDbException { + LOG.info("addItem"); + StatusCode result = instance.addItem(getSessionId(), listId, mediaId); + assertEquals("Invalid response: " + result.toString(), SC_SUCCESS_UPD, result.getStatusCode()); + } + + /** + * Test of removeItem method, of class TmdbLists. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + private void testRemoveItem(String listId, int mediaId) throws MovieDbException { + LOG.info("removeItem"); + StatusCode result = instance.removeItem(getSessionId(), listId, mediaId); + assertEquals("Invalid response: " + result.toString(), SC_SUCCESS_DEL, result.getStatusCode()); + } + + /** + * Test of clear method, of class TmdbLists. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + private void testClear(String listId) throws MovieDbException { + LOG.info("clear"); + StatusCode result = instance.clear(getSessionId(), listId, true); + assertEquals("Invalid response: " + result.toString(), SC_SUCCESS_UPD, result.getStatusCode()); } } From 2c71a1485c430ca43c9d3778099b2c318eae36bd Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Fri, 27 Feb 2015 20:57:54 +0000 Subject: [PATCH 037/100] Networks --- .../omertron/themoviedbapi/TheMovieDbApi.java | 4 ++-- .../themoviedbapi/methods/TmdbNetworks.java | 6 ++--- .../network/Network.java} | 18 +++++++++++---- .../methods/TmdbNetworksTest.java | 23 ++++++++++++------- 4 files changed, 33 insertions(+), 18 deletions(-) rename src/main/java/com/omertron/themoviedbapi/{model/TBD_Network.java => model2/network/Network.java} (80%) diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index c6ca4948b..f821b6bb1 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -64,7 +64,7 @@ import com.omertron.themoviedbapi.model2.StatusCode; import com.omertron.themoviedbapi.enumeration.ExternalSource; import com.omertron.themoviedbapi.enumeration.SortBy; import com.omertron.themoviedbapi.model2.FindResults; -import com.omertron.themoviedbapi.model.TBD_Network; +import com.omertron.themoviedbapi.model2.network.Network; import com.omertron.themoviedbapi.model2.person.CreditInfo; import com.omertron.themoviedbapi.model2.authentication.TokenAuthorisation; import com.omertron.themoviedbapi.model2.authentication.TokenSession; @@ -1139,7 +1139,7 @@ public class TheMovieDbApi { * @return * @throws MovieDbException */ - public TBD_Network getNetworkInfo(int networkId) throws MovieDbException { + public Network getNetworkInfo(int networkId) throws MovieDbException { return tmdbNetworks.getNetworkInfo(networkId); } // diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbNetworks.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbNetworks.java index 9fc093071..5d9be6e78 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbNetworks.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbNetworks.java @@ -20,7 +20,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.TBD_Network; +import com.omertron.themoviedbapi.model2.network.Network; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; @@ -56,7 +56,7 @@ public class TmdbNetworks extends AbstractMethod { * @return * @throws MovieDbException */ - public TBD_Network getNetworkInfo(int networkId) throws MovieDbException { + public Network getNetworkInfo(int networkId) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.ID, networkId); @@ -64,7 +64,7 @@ public class TmdbNetworks extends AbstractMethod { String webpage = httpTools.getRequest(url); try { - return MAPPER.readValue(webpage, TBD_Network.class); + return MAPPER.readValue(webpage, Network.class); } catch (IOException ex) { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get network information", url, ex); } diff --git a/src/main/java/com/omertron/themoviedbapi/model/TBD_Network.java b/src/main/java/com/omertron/themoviedbapi/model2/network/Network.java similarity index 80% rename from src/main/java/com/omertron/themoviedbapi/model/TBD_Network.java rename to src/main/java/com/omertron/themoviedbapi/model2/network/Network.java index e0db300ce..3227135f7 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/TBD_Network.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/network/Network.java @@ -17,23 +17,22 @@ * along with TheMovieDB API. If not, see . * */ -package com.omertron.themoviedbapi.model; +package com.omertron.themoviedbapi.model2.network; import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonRootName; /** * @author stuart.boston */ -@JsonRootName("???") -public class TBD_Network extends AbstractJsonMapping { +public class Network extends AbstractJsonMapping { private static final long serialVersionUID = 1L; - // Properties @JsonProperty("id") private int id; + @JsonProperty("name") + private String name; public int getId() { return id; @@ -42,4 +41,13 @@ public class TBD_Network extends AbstractJsonMapping { public void setId(int id) { this.id = id; } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbNetworksTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbNetworksTest.java index d3da682a6..c9c3dc7d6 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbNetworksTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbNetworksTest.java @@ -21,10 +21,12 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.TestLogger; -import com.omertron.themoviedbapi.model.TBD_Network; +import com.omertron.themoviedbapi.TestID; +import com.omertron.themoviedbapi.model2.network.Network; +import java.util.ArrayList; +import java.util.List; import org.junit.AfterClass; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertEquals; import org.junit.BeforeClass; import org.junit.Test; @@ -34,16 +36,18 @@ import org.junit.Test; */ public class TmdbNetworksTest extends AbstractTests { - // API private static TmdbNetworks instance; + private static final List testIDs = new ArrayList(); public TmdbNetworksTest() { } @BeforeClass public static void setUpClass() throws MovieDbException { - TestLogger.Configure(); + doConfiguration(); instance = new TmdbNetworks(getApiKey(), getHttpTools()); + testIDs.add(new TestID("Fuji Television", "", 1)); + testIDs.add(new TestID("Sonshine Media Network International", "", 200)); } @AfterClass @@ -58,9 +62,12 @@ public class TmdbNetworksTest extends AbstractTests { @Test public void testGetNetworkInfo() throws MovieDbException { LOG.info("getNetworkInfo"); - TBD_Network result = instance.getNetworkInfo(1); -// assertEquals("Wrong network returned", "Fuji Television", result.getName()); - fail("The test case is a prototype."); + + Network result; + for (TestID t : testIDs) { + result = instance.getNetworkInfo(t.getTmdb()); + assertEquals("Wrong network returned", t.getName(), result.getName()); + } } } From bc333a4cb6523ad06af6bc4a903240ca3de8b66a Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Fri, 27 Feb 2015 21:38:36 +0000 Subject: [PATCH 038/100] Reviews --- .../omertron/themoviedbapi/TheMovieDbApi.java | 6 +- .../themoviedbapi/methods/TmdbReviews.java | 26 ++----- .../themoviedbapi/methods/_Method_List.txt | 4 +- .../omertron/themoviedbapi/model/MovieDb.java | 3 +- .../review/Review.java} | 72 ++++++++++++++----- .../themoviedbapi/tools/MethodBase.java | 1 + .../themoviedbapi/wrapper/WrapperReviews.java | 8 +-- .../methods/TmdbReviewsTest.java | 12 +++- 8 files changed, 84 insertions(+), 48 deletions(-) rename src/main/java/com/omertron/themoviedbapi/{model/Reviews.java => model2/review/Review.java} (63%) diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index f821b6bb1..34f1a204b 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -59,7 +59,7 @@ import com.omertron.themoviedbapi.model.MovieList; import com.omertron.themoviedbapi.model.person.Person; import com.omertron.themoviedbapi.model.person.PersonCredit; import com.omertron.themoviedbapi.model.ReleaseInfo; -import com.omertron.themoviedbapi.model.Reviews; +import com.omertron.themoviedbapi.model2.review.Review; import com.omertron.themoviedbapi.model2.StatusCode; import com.omertron.themoviedbapi.enumeration.ExternalSource; import com.omertron.themoviedbapi.enumeration.SortBy; @@ -1220,7 +1220,7 @@ public class TheMovieDbApi { } // - // + // /** * * @param movieId @@ -1230,7 +1230,7 @@ public class TheMovieDbApi { * @return * @throws MovieDbException */ - public TmdbResultsList getReviews(int movieId, String language, int page, String... appendToResponse) throws MovieDbException { + public TmdbResultsList getReviews(int movieId, String language, int page, String... appendToResponse) throws MovieDbException { return tmdbReviews.getReviews(movieId, language, page, appendToResponse); } // diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbReviews.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbReviews.java index be418d3d4..d47bcaab9 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbReviews.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbReviews.java @@ -21,15 +21,12 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; import static com.omertron.themoviedbapi.methods.AbstractMethod.MAPPER; -import com.omertron.themoviedbapi.model.Reviews; -import com.omertron.themoviedbapi.results.TmdbResultsList; +import com.omertron.themoviedbapi.model2.review.Review; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; -import com.omertron.themoviedbapi.tools.MethodSub; import com.omertron.themoviedbapi.tools.Param; import com.omertron.themoviedbapi.tools.TmdbParameters; -import com.omertron.themoviedbapi.wrapper.WrapperReviews; import java.io.IOException; import java.net.URL; import org.yamj.api.common.exception.ApiExceptionType; @@ -54,30 +51,21 @@ public class TmdbReviews extends AbstractMethod { /** * Get the full details of a review by ID. * - * @param id - * @param language - * @param page - * @param appendToResponse + * @param reviewId * @return * @throws MovieDbException */ - public TmdbResultsList getReviews(int id, String language, int page, String... appendToResponse) throws MovieDbException { + public Review getReview(String reviewId) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, id); - parameters.add(Param.LANGUAGE, language); - parameters.add(Param.PAGE, page); - parameters.add(Param.APPEND, appendToResponse); + parameters.add(Param.ID, reviewId); - URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.REVIEWS).buildUrl(parameters); + URL url = new ApiUrl(apiKey, MethodBase.REVIEW).buildUrl(parameters); String webpage = httpTools.getRequest(url); try { - WrapperReviews wrapper = MAPPER.readValue(webpage, WrapperReviews.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getReviews()); - results.copyWrapper(wrapper); - return results; + return MAPPER.readValue(webpage, Review.class); } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get reviews", url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get review", url, ex); } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt index e79b09932..2b0e38894 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt +++ b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt @@ -87,7 +87,7 @@ Movies /movie/popular Get the list of popular movies on The Movie Database. This list refreshes every day. /movie/top_rated Get the list of top rated movies. By default, this list will only include movies that have 10 or more votes. This list refreshes every day. -Networks +Networks (Done) /network/{id} This method is used to retrieve the basic information about a TV network. People @@ -102,7 +102,7 @@ People /person/popular Get the list of popular people on The Movie Database. This list refreshes every day. /person/latest Get the latest person id. -Reviews +Reviews (Done) /review/{id} Get the full details of a review by ID. Search diff --git a/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java b/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java index 518cd93ab..fa9b9cbed 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java +++ b/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java @@ -19,6 +19,7 @@ */ package com.omertron.themoviedbapi.model; +import com.omertron.themoviedbapi.model2.review.Review; import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model.keyword.Keyword; @@ -374,7 +375,7 @@ public class MovieDb extends AbstractJsonMapping { return lists.getMovieList(); } - public List getReviews() { + public List getReviews() { return reviews.getReviews(); } // diff --git a/src/main/java/com/omertron/themoviedbapi/model/Reviews.java b/src/main/java/com/omertron/themoviedbapi/model2/review/Review.java similarity index 63% rename from src/main/java/com/omertron/themoviedbapi/model/Reviews.java rename to src/main/java/com/omertron/themoviedbapi/model2/review/Review.java index 34f75a288..b73b3028d 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/Reviews.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/review/Review.java @@ -17,7 +17,7 @@ * along with TheMovieDB API. If not, see . * */ -package com.omertron.themoviedbapi.model; +package com.omertron.themoviedbapi.model2.review; import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.fasterxml.jackson.annotation.JsonProperty; @@ -25,19 +25,24 @@ import com.fasterxml.jackson.annotation.JsonProperty; /** * @author Stuart */ -public class Reviews extends AbstractJsonMapping { +public class Review extends AbstractJsonMapping { private static final long serialVersionUID = 1L; - /* - * Properties - */ @JsonProperty("id") private String id; @JsonProperty("author") private String author; @JsonProperty("content") private String content; + @JsonProperty("iso_639_1") + private String langauage; + @JsonProperty("media_id") + private String mediaId; + @JsonProperty("media_title") + private String mediaTitle; + @JsonProperty("media_type") + private String mediaType; @JsonProperty("url") private String url; @@ -45,31 +50,64 @@ public class Reviews extends AbstractJsonMapping { return id; } - public String getAuthor() { - return author; - } - - public String getContent() { - return content; - } - - public String getUrl() { - return url; - } - public void setId(String id) { this.id = id; } + public String getAuthor() { + return author; + } + public void setAuthor(String author) { this.author = author; } + public String getContent() { + return content; + } + public void setContent(String content) { this.content = content; } + public String getLangauage() { + return langauage; + } + + public void setLangauage(String langauage) { + this.langauage = langauage; + } + + public String getMediaId() { + return mediaId; + } + + public void setMediaId(String mediaId) { + this.mediaId = mediaId; + } + + public String getMediaTitle() { + return mediaTitle; + } + + public void setMediaTitle(String mediaTitle) { + this.mediaTitle = mediaTitle; + } + + public String getMediaType() { + return mediaType; + } + + public void setMediaType(String mediaType) { + this.mediaType = mediaType; + } + + public String getUrl() { + return url; + } + public void setUrl(String url) { this.url = url; } + } diff --git a/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java b/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java index 3c2a38a7d..59a3f039a 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java @@ -41,6 +41,7 @@ public enum MethodBase { MOVIE("movie"), NETWORK("network"), PERSON("person"), + REVIEW("review"), SEARCH("search"), TV("tv"); diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperReviews.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperReviews.java index 0ffa79ee6..9441ab615 100644 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperReviews.java +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperReviews.java @@ -20,7 +20,7 @@ package com.omertron.themoviedbapi.wrapper; import com.fasterxml.jackson.annotation.JsonProperty; -import com.omertron.themoviedbapi.model.Reviews; +import com.omertron.themoviedbapi.model2.review.Review; import java.io.Serializable; import java.util.List; @@ -32,13 +32,13 @@ public class WrapperReviews extends AbstractWrapperAll implements Serializable { private static final long serialVersionUID = 1L; @JsonProperty("results") - private List reviews; + private List reviews; - public List getReviews() { + public List getReviews() { return reviews; } - public void setReviews(List reviews) { + public void setReviews(List reviews) { this.reviews = reviews; } } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbReviewsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbReviewsTest.java index f47810e76..c2017a98d 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbReviewsTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbReviewsTest.java @@ -21,9 +21,13 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.model2.review.Review; +import org.apache.commons.lang3.StringUtils; import org.junit.After; import org.junit.AfterClass; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -66,7 +70,11 @@ public class TmdbReviewsTest extends AbstractTests { @Test public void testGetReview() throws MovieDbException { LOG.info("getReview"); - fail("The test case is a prototype."); + String reviewId = "53fc2f600e0a267a7b009aba"; + Review result = instance.getReview(reviewId); + assertNotNull("No review", result); + assertTrue("No content", StringUtils.isNotBlank(result.getContent())); + assertEquals("Wrong media ID", "70160", result.getMediaId()); } } From bbc85c09c4790cb703bbf65bbf9cf7b2be0803fa Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Sat, 28 Feb 2015 11:49:13 +0000 Subject: [PATCH 039/100] Timezones --- .../omertron/themoviedbapi/TheMovieDbApi.java | 29 ++++++++------ .../methods/TmdbConfiguration.java | 31 +++++++++++++- .../themoviedbapi/methods/_Method_List.txt | 4 +- .../model2/{ => config}/Configuration.java | 3 +- .../model2/{ => config}/JobDepartment.java | 3 +- .../themoviedbapi/tools/MethodBase.java | 1 + .../themoviedbapi/wrapper/WrapperConfig.java | 2 +- .../themoviedbapi/wrapper/WrapperJobList.java | 2 +- .../methods/TmdbConfigurationTest.java | 40 +++++++++++++++++-- 9 files changed, 92 insertions(+), 23 deletions(-) rename src/main/java/com/omertron/themoviedbapi/model2/{ => config}/Configuration.java (98%) rename src/main/java/com/omertron/themoviedbapi/model2/{ => config}/JobDepartment.java (93%) diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 34f1a204b..8a4529caa 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -47,10 +47,10 @@ import com.omertron.themoviedbapi.model.change.ChangedMedia; import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.collection.CollectionInfo; import com.omertron.themoviedbapi.model2.company.Company; -import com.omertron.themoviedbapi.model2.Configuration; +import com.omertron.themoviedbapi.model2.config.Configuration; import com.omertron.themoviedbapi.model2.discover.Discover; import com.omertron.themoviedbapi.model.Genre; -import com.omertron.themoviedbapi.model2.JobDepartment; +import com.omertron.themoviedbapi.model2.config.JobDepartment; import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.keyword.KeywordMovie; import com.omertron.themoviedbapi.model.MovieDb; @@ -79,6 +79,7 @@ import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; import java.net.URL; import java.util.List; +import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.apache.http.client.HttpClient; import org.yamj.api.common.http.SimpleHttpClientBuilder; @@ -653,8 +654,17 @@ public class TheMovieDbApi { public TmdbResultsList getJobs() throws MovieDbException { return tmdbConfiguration.getJobs(); } - // + /** + * Get the list of supported timezones for the API methods that support them. + * + * @return @throws MovieDbException + */ + public Map> getTimezones() throws MovieDbException { + return tmdbConfiguration.getTimezones(); + } + // + // /** * Get the detailed information about a particular credit record. @@ -875,7 +885,6 @@ public class TheMovieDbApi { public StatusCode removeItemFromList(String sessionId, String listId, Integer mediaId) throws MovieDbException { return tmdbList.removeItem(sessionId, listId, mediaId); } - // // @@ -1223,15 +1232,11 @@ public class TheMovieDbApi { // /** * - * @param movieId - * @param language - * @param page - * @param appendToResponse - * @return - * @throws MovieDbException + * @param reviewId + * @return @throws MovieDbException */ - public TmdbResultsList getReviews(int movieId, String language, int page, String... appendToResponse) throws MovieDbException { - return tmdbReviews.getReviews(movieId, language, page, appendToResponse); + public Review getReviews(String reviewId) throws MovieDbException { + return tmdbReviews.getReview(reviewId); } // diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java index 7cd8d57bc..469af49bd 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbConfiguration.java @@ -19,10 +19,11 @@ */ package com.omertron.themoviedbapi.methods; +import com.fasterxml.jackson.core.type.TypeReference; import com.omertron.themoviedbapi.MovieDbException; import static com.omertron.themoviedbapi.methods.AbstractMethod.MAPPER; -import com.omertron.themoviedbapi.model2.Configuration; -import com.omertron.themoviedbapi.model2.JobDepartment; +import com.omertron.themoviedbapi.model2.config.Configuration; +import com.omertron.themoviedbapi.model2.config.JobDepartment; import com.omertron.themoviedbapi.results.TmdbResultsList; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; @@ -32,6 +33,9 @@ import com.omertron.themoviedbapi.wrapper.WrapperConfig; import com.omertron.themoviedbapi.wrapper.WrapperJobList; import java.io.IOException; import java.net.URL; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.yamj.api.common.exception.ApiExceptionType; /** @@ -99,4 +103,27 @@ public class TmdbConfiguration extends AbstractMethod { } } + public Map> getTimezones() throws MovieDbException { + URL url = new ApiUrl(apiKey, MethodBase.TIMEZONES).setSubMethod(MethodSub.LIST).buildUrl(); + String webpage = httpTools.getRequest(url); + + List>> tzList; + try { + tzList = MAPPER.readValue(webpage, new TypeReference>>>() { + }); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get timezone list", url, ex); + } + + Map> timezones = new HashMap>(); + + for (Map> tzMap : tzList) { + for (Map.Entry> x : tzMap.entrySet()) { + timezones.put(x.getKey(), x.getValue()); + } + } + + return timezones; + } + } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt index 2b0e38894..35502c4e1 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt +++ b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt @@ -51,7 +51,7 @@ Genres (Done) Guest Sessions (Partial - in Account) /guest_session/{guest_session_id}/rated_movies Get a list of rated movies for a specific guest session id. -Jobs (Done) +Jobs (Done - part of configuration) /job/list Get a list of valid jobs. Keyword (Done) @@ -115,7 +115,7 @@ Search /search/person Search for people by name. /search/tv Search for TV shows by title. -Timezones +Timezones (Done - part of configuration) /timezones/list Get the list of supported timezones for the API methods that support them. TV diff --git a/src/main/java/com/omertron/themoviedbapi/model2/Configuration.java b/src/main/java/com/omertron/themoviedbapi/model2/config/Configuration.java similarity index 98% rename from src/main/java/com/omertron/themoviedbapi/model2/Configuration.java rename to src/main/java/com/omertron/themoviedbapi/model2/config/Configuration.java index 069f8a9ef..501e04450 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/Configuration.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/config/Configuration.java @@ -17,11 +17,12 @@ * along with TheMovieDB API. If not, see . * */ -package com.omertron.themoviedbapi.model2; +package com.omertron.themoviedbapi.model2.config; import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.fasterxml.jackson.annotation.JsonProperty; import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import java.net.MalformedURLException; import java.net.URL; import java.util.List; diff --git a/src/main/java/com/omertron/themoviedbapi/model2/JobDepartment.java b/src/main/java/com/omertron/themoviedbapi/model2/config/JobDepartment.java similarity index 93% rename from src/main/java/com/omertron/themoviedbapi/model2/JobDepartment.java rename to src/main/java/com/omertron/themoviedbapi/model2/config/JobDepartment.java index e50763d9b..403d48584 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/JobDepartment.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/config/JobDepartment.java @@ -17,10 +17,11 @@ * along with TheMovieDB API. If not, see . * */ -package com.omertron.themoviedbapi.model2; +package com.omertron.themoviedbapi.model2.config; import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import java.util.List; diff --git a/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java b/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java index 59a3f039a..249a63e03 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java @@ -43,6 +43,7 @@ public enum MethodBase { PERSON("person"), REVIEW("review"), SEARCH("search"), + TIMEZONES("timezones"), TV("tv"); private final String value; diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperConfig.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperConfig.java index fd535cbee..b06c26a1b 100644 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperConfig.java +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperConfig.java @@ -20,7 +20,7 @@ package com.omertron.themoviedbapi.wrapper; import com.fasterxml.jackson.annotation.JsonProperty; -import com.omertron.themoviedbapi.model2.Configuration; +import com.omertron.themoviedbapi.model2.config.Configuration; import java.util.Collections; import java.util.List; diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperJobList.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperJobList.java index e21e509e3..76734f607 100644 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperJobList.java +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperJobList.java @@ -20,7 +20,7 @@ package com.omertron.themoviedbapi.wrapper; import com.fasterxml.jackson.annotation.JsonProperty; -import com.omertron.themoviedbapi.model2.JobDepartment; +import com.omertron.themoviedbapi.model2.config.JobDepartment; import java.util.List; /** diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbConfigurationTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbConfigurationTest.java index 65f661a18..324e34800 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbConfigurationTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbConfigurationTest.java @@ -21,11 +21,16 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model2.Configuration; +import com.omertron.themoviedbapi.model2.config.Configuration; +import com.omertron.themoviedbapi.model2.config.JobDepartment; +import com.omertron.themoviedbapi.results.TmdbResultsList; +import java.util.List; +import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.junit.After; import org.junit.AfterClass; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.BeforeClass; @@ -65,7 +70,7 @@ public class TmdbConfigurationTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test +// @Test public void testGetConfig() throws MovieDbException { LOG.info("getConfig"); Configuration result = instance.getConfig(); @@ -83,7 +88,7 @@ public class TmdbConfigurationTest extends AbstractTests { * * @throws MovieDbException */ - @Test +// @Test public void testCreateImageUrl() throws MovieDbException { LOG.info("createImageUrl"); Configuration config = instance.getConfig(); @@ -92,4 +97,33 @@ public class TmdbConfigurationTest extends AbstractTests { assertTrue("Error compiling image URL", !result.isEmpty()); } + /** + * Test of getJobs method, of class TmdbConfiguration. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ +// @Test + public void testGetJobs() throws MovieDbException { + LOG.info("getJobs"); + TmdbResultsList result = instance.getJobs(); + assertNotNull("Null results", result); + assertFalse("Empty results", result.getResults().isEmpty()); + assertTrue("No results", result.getResults().size() > 0); + } + + /** + * Test of getTimezones method, of class TmdbConfiguration. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetTimezones() throws MovieDbException { + LOG.info("getTimezones"); + Map> result = instance.getTimezones(); + assertNotNull("Null results", result); + assertFalse("Empty results", result.isEmpty()); + assertTrue("No US TZ",result.containsKey("US")); + assertTrue("No GB TZ",result.containsKey("GB")); + } + } From c22ac9333e472f882255f10125372c71f3db9d82 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Sat, 28 Feb 2015 14:43:31 +0000 Subject: [PATCH 040/100] Search (Partial - missing multi) --- .../themoviedbapi/enumeration/SearchType.java | 35 ++ .../themoviedbapi/enumeration/SortBy.java | 19 ++ .../themoviedbapi/methods/AbstractMethod.java | 34 +- .../themoviedbapi/methods/TmdbSearch.java | 311 ++++++++++-------- .../themoviedbapi/methods/_Method_List.txt | 4 +- .../themoviedbapi/tools/MethodSub.java | 1 + .../omertron/themoviedbapi/tools/Param.java | 1 + .../themoviedbapi/methods/TmdbSearchTest.java | 184 +++++++---- 8 files changed, 373 insertions(+), 216 deletions(-) create mode 100644 src/main/java/com/omertron/themoviedbapi/enumeration/SearchType.java diff --git a/src/main/java/com/omertron/themoviedbapi/enumeration/SearchType.java b/src/main/java/com/omertron/themoviedbapi/enumeration/SearchType.java new file mode 100644 index 000000000..c367bed08 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/enumeration/SearchType.java @@ -0,0 +1,35 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.enumeration; + +/** + * + * @author Stuart + */ +public enum SearchType { + + PHRASE, + NGRAM; + + public String getPropertyString() { + return this.name().toLowerCase(); + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/enumeration/SortBy.java b/src/main/java/com/omertron/themoviedbapi/enumeration/SortBy.java index 78e62a63d..b80de72d9 100644 --- a/src/main/java/com/omertron/themoviedbapi/enumeration/SortBy.java +++ b/src/main/java/com/omertron/themoviedbapi/enumeration/SortBy.java @@ -1,3 +1,22 @@ +/* + * 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 . + * + */ package com.omertron.themoviedbapi.enumeration; public enum SortBy { diff --git a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java index 11dc8fd5d..f94fe5c83 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java @@ -49,12 +49,14 @@ public class AbstractMethod { protected static final ObjectMapper MAPPER = new ObjectMapper(); // Logger protected static final Logger LOG = LoggerFactory.getLogger(TmdbAccount.class); - protected static final TypeReference> TR_MOVIE_BASIC = new TypeReference>() { - }; - protected static final TypeReference> TR_TV_BASIC = new TypeReference>() { - }; - protected static final TypeReference> TR_USER_LIST = new TypeReference>() { - }; + protected static final TypeReference> TR_MOVIE_BASIC = getTypeReference(MovieBasic.class); + protected static final TypeReference> TR_TV_BASIC = getTypeReference(TVBasic.class); + protected static final TypeReference> TR_USER_LIST = getTypeReference(UserList.class); + + protected static TypeReference getTypeReference(T Class) { + return new TypeReference>() { + }; + } /** * Default constructor for the methods @@ -78,16 +80,28 @@ public class AbstractMethod { * @throws MovieDbException */ public List processWrapperList(TypeReference typeRef, URL url, String errorMessageSuffix) throws MovieDbException { + WrapperGenericList val = processWrapper(typeRef, url, errorMessageSuffix); + return val.getResults(); + } + + /** + * Process the wrapper list and return the whole wrapper + * + * @param Type of list to process + * @param typeRef + * @param url URL of the page (Error output only) + * @param errorMessageSuffix Error message to output (Error output only) + * @return + * @throws MovieDbException + */ + public WrapperGenericList processWrapper(TypeReference typeRef, URL url, String errorMessageSuffix) throws MovieDbException { String webpage = httpTools.getRequest(url); try { // Due to type erasure, this doesn't work // TypeReference> typeRef = new TypeReference>() {}; - WrapperGenericList results = MAPPER.readValue(webpage, typeRef); - return results.getResults(); + return MAPPER.readValue(webpage, typeRef); } catch (IOException ex) { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get " + errorMessageSuffix, url, ex); } - } - } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java index 7d68eef35..169744e80 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java @@ -20,12 +20,14 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.enumeration.SearchType; import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.company.Company; import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.MovieDb; -import com.omertron.themoviedbapi.model.MovieList; import com.omertron.themoviedbapi.model.person.Person; +import com.omertron.themoviedbapi.model2.list.UserList; +import com.omertron.themoviedbapi.model2.tv.TVBasic; import com.omertron.themoviedbapi.results.TmdbResultsList; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; @@ -33,13 +35,7 @@ import com.omertron.themoviedbapi.tools.MethodBase; import com.omertron.themoviedbapi.tools.MethodSub; import com.omertron.themoviedbapi.tools.Param; import com.omertron.themoviedbapi.tools.TmdbParameters; -import com.omertron.themoviedbapi.wrapper.WrapperCollection; -import com.omertron.themoviedbapi.wrapper.WrapperCompany; -import com.omertron.themoviedbapi.wrapper.WrapperKeywords; -import com.omertron.themoviedbapi.wrapper.WrapperMovie; -import com.omertron.themoviedbapi.wrapper.WrapperMovieList; -import com.omertron.themoviedbapi.wrapper.WrapperPerson; -import java.io.IOException; +import com.omertron.themoviedbapi.wrapper.WrapperGenericList; import java.net.URL; import org.yamj.api.common.exception.ApiExceptionType; @@ -61,36 +57,28 @@ public class TmdbSearch extends AbstractMethod { } /** - * Search Movies This is a good starting point to start finding movies on TMDb. + * Search Companies. * - * @param movieName - * @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) + * 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 + * + * @param query + * @param page * @return * @throws MovieDbException */ - public TmdbResultsList searchMovie(String movieName, int searchYear, String language, boolean includeAdult, int page) throws MovieDbException { + public TmdbResultsList searchCompanies(String query, Integer page) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.QUERY, movieName); - parameters.add(Param.YEAR, searchYear); - parameters.add(Param.LANGUAGE, language); - parameters.add(Param.ADULT, includeAdult); + parameters.add(Param.QUERY, query); parameters.add(Param.PAGE, page); - URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.MOVIE).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperMovie wrapper = MAPPER.readValue(webpage, WrapperMovie.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getMovies()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find movie", url, ex); - } - + URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.COMPANY).buildUrl(parameters); + WrapperGenericList wrapper = processWrapper(getTypeReference(Company.class), url, "company"); + TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); + results.copyWrapper(wrapper); + return results; } /** @@ -102,112 +90,17 @@ public class TmdbSearch extends AbstractMethod { * @return * @throws MovieDbException */ - public TmdbResultsList searchCollection(String query, String language, int page) throws MovieDbException { + public TmdbResultsList searchCollection(String query, Integer page, String language) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.QUERY, query); - parameters.add(Param.LANGUAGE, language); parameters.add(Param.PAGE, page); + parameters.add(Param.LANGUAGE, language); URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.COLLECTION).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperCollection wrapper = MAPPER.readValue(webpage, WrapperCollection.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find collection", url, ex); - } - } - - /** - * 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. - * - * @param personName - * @param includeAdult - * @param page - * @return - * @throws MovieDbException - */ - public TmdbResultsList searchPeople(String personName, boolean includeAdult, int page) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.QUERY, personName); - parameters.add(Param.ADULT, includeAdult); - parameters.add(Param.PAGE, page); - - URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.PERSON).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperPerson wrapper = MAPPER.readValue(webpage, WrapperPerson.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find person", url, ex); - } - } - - /** - * Search for lists by name and description. - * - * @param query - * @param language - * @param page - * @return - * @throws MovieDbException - */ - public TmdbResultsList searchList(String query, String language, int page) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.QUERY, query); - parameters.add(Param.LANGUAGE, language); - parameters.add(Param.PAGE, page); - - URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.LIST).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperMovieList wrapper = MAPPER.readValue(webpage, WrapperMovieList.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getMovieList()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find list", url, ex); - } - } - - /** - * 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. - * - * http://help.themoviedb.org/kb/api/search-companies - * - * @param companyName - * @param page - * @return - * @throws MovieDbException - */ - public TmdbResultsList searchCompanies(String companyName, int page) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.QUERY, companyName); - parameters.add(Param.PAGE, page); - - URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.COMPANY).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperCompany wrapper = MAPPER.readValue(webpage, WrapperCompany.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find company", url, ex); - } + WrapperGenericList wrapper = processWrapper(getTypeReference(Collection.class), url, "collection"); + TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); + results.copyWrapper(wrapper); + return results; } /** @@ -218,22 +111,158 @@ public class TmdbSearch extends AbstractMethod { * @return * @throws MovieDbException */ - public TmdbResultsList searchKeyword(String query, int page) throws MovieDbException { + public TmdbResultsList searchKeyword(String query, Integer page) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.QUERY, query); parameters.add(Param.PAGE, page); URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.KEYWORD).buildUrl(parameters); - String webpage = httpTools.getRequest(url); + WrapperGenericList wrapper = processWrapper(getTypeReference(Keyword.class), url, "keyword"); + TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); + results.copyWrapper(wrapper); + return results; + } - try { - WrapperKeywords wrapper = MAPPER.readValue(webpage, WrapperKeywords.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find keyword", url, ex); + /** + * Search for lists by name and description. + * + * @param query + * @param language + * @param includeAdult + * @param page + * @return + * @throws MovieDbException + */ + public TmdbResultsList searchList(String query, Integer page, Boolean includeAdult) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.QUERY, query); + parameters.add(Param.PAGE, page); + parameters.add(Param.INCLUDE_ADULT, includeAdult); + + URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.LIST).buildUrl(parameters); + WrapperGenericList wrapper = processWrapper(getTypeReference(UserList.class), url, "list"); + TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); + results.copyWrapper(wrapper); + return results; + } + + /** + * Search Movies This is a good starting point to start finding movies on TMDb. + * + * @param query + * @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 primaryReleaseYear + * @param searchType + * @return + * @throws MovieDbException + */ + public TmdbResultsList searchMovie(String query, + Integer page, + String language, + Boolean includeAdult, + Integer searchYear, + Integer primaryReleaseYear, + SearchType searchType) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.QUERY, query); + parameters.add(Param.PAGE, page); + parameters.add(Param.LANGUAGE, language); + parameters.add(Param.ADULT, includeAdult); + parameters.add(Param.YEAR, searchYear); + parameters.add(Param.PRIMARY_RELEASE_YEAR, primaryReleaseYear); + if (searchType != null) { + parameters.add(Param.SEARCH_TYPE, searchType.getPropertyString()); } + URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.MOVIE).buildUrl(parameters); + + WrapperGenericList wrapper = processWrapper(getTypeReference(MovieDb.class), url, "movie"); + TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); + results.copyWrapper(wrapper); + return results; + } + + /** + * Search the movie, tv show and person collections with a single query. + * + * Each item returned in the result array has a media_type field that maps to either movie, tv or person. + * + * Each mapped result is the same response you would get from each independent search + * + * @param query + * @param page + * @param language + * @param includeAdult + * @return + * @throws MovieDbException + */ + public String searchMulti(String query, Integer page, String language, Boolean includeAdult) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.QUERY, query); + parameters.add(Param.PAGE, page); + parameters.add(Param.LANGUAGE, language); + parameters.add(Param.ADULT, includeAdult); + + URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.MULTI).buildUrl(parameters); + throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not implemented yet"); + } + + /** + * 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. + * + * @param query + * @param includeAdult + * @param page + * @param searchType + * @return + * @throws MovieDbException + */ + public TmdbResultsList searchPeople(String query, Integer page, Boolean includeAdult, SearchType searchType) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.QUERY, query); + parameters.add(Param.ADULT, includeAdult); + parameters.add(Param.PAGE, page); + if (searchType != null) { + parameters.add(Param.SEARCH_TYPE, searchType.getPropertyString()); + } + URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.PERSON).buildUrl(parameters); + + WrapperGenericList wrapper = processWrapper(getTypeReference(Person.class), url, "person"); + TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); + results.copyWrapper(wrapper); + return results; + } + + /** + * Search for TV shows by title. + * + * @param query + * @param page + * @param language + * @param firstAirDateYear + * @param searchType + * @return + * @throws com.omertron.themoviedbapi.MovieDbException + */ + public TmdbResultsList searchTV(String query, Integer page, String language, Integer firstAirDateYear, SearchType searchType) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.QUERY, query); + parameters.add(Param.PAGE, page); + parameters.add(Param.LANGUAGE, language); + parameters.add(Param.FIRST_AIR_DATE_YEAR, firstAirDateYear); + if (searchType != null) { + parameters.add(Param.SEARCH_TYPE, searchType.getPropertyString()); + } + URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.MOVIE).buildUrl(parameters); + + WrapperGenericList wrapper = processWrapper(getTypeReference(TVBasic.class), url, "TV Show"); + TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); + results.copyWrapper(wrapper); + return results; } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt index 35502c4e1..0e2023986 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt +++ b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt @@ -105,13 +105,13 @@ People Reviews (Done) /review/{id} Get the full details of a review by ID. -Search +Search (Partial - multi search to do) /search/company Search for companies by name. /search/collection Search for collections by name. /search/keyword Search for keywords by name. /search/list Search for lists by name and description. /search/movie Search for movies by title. -/search/multi Search the movie, tv show and person collections with a single query. +*** /search/multi Search the movie, tv show and person collections with a single query. /search/person Search for people by name. /search/tv Search for TV shows by title. diff --git a/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java b/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java index b911025e9..d8b73dfda 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java @@ -46,6 +46,7 @@ public enum MethodSub { MOVIE("movie"), MOVIES("movies"), MOVIE_LIST("movie/list"), + MULTI("multi"), NOW_PLAYING("now-playing"), PERSON("person"), POPULAR("popular"), diff --git a/src/main/java/com/omertron/themoviedbapi/tools/Param.java b/src/main/java/com/omertron/themoviedbapi/tools/Param.java index a1b1e08be..b52efc98c 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/Param.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/Param.java @@ -46,6 +46,7 @@ public enum Param { PAGE("page="), PASSWORD("password="), QUERY("query="), + SEARCH_TYPE("search_type="), SESSION("session_id="), START_DATE("start_date="), TOKEN("request_token="), diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java index 30a46b995..193513409 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java @@ -21,16 +21,23 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.enumeration.SearchType; import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.company.Company; import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.MovieDb; -import com.omertron.themoviedbapi.model.MovieList; import com.omertron.themoviedbapi.model.person.Person; +import com.omertron.themoviedbapi.model2.list.UserList; +import com.omertron.themoviedbapi.model2.tv.TVBasic; import com.omertron.themoviedbapi.results.TmdbResultsList; +import org.junit.After; import org.junit.AfterClass; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -57,27 +64,26 @@ public class TmdbSearchTest extends AbstractTests { public static void tearDownClass() { } + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + /** - * Test of searchMovie method, of class TheMovieDbApi. + * Test of searchCompanies method, of class TheMovieDbApi. * * @throws MovieDbException */ @Test - public void testSearchMovie() throws MovieDbException { - LOG.info("searchMovie"); - - // Try a movie with less than 1 page of results - TmdbResultsList movieList = instance.searchMovie("Blade Runner", 0, "", true, 0); -// List movieList = tmdb.searchMovie("Blade Runner", "", true); - assertTrue("No movies found, should be at least 1", movieList.getResults().size() > 0); - - // Try a russian langugage movie - movieList = instance.searchMovie("О чём говорят мужчины", 0, LANGUAGE_RUSSIAN, true, 0); - assertTrue("No 'RU' movies found, should be at least 1", movieList.getResults().size() > 0); - - // Try a movie with more than 20 results - movieList = instance.searchMovie("Star Wars", 0, LANGUAGE_ENGLISH, false, 0); - assertTrue("Not enough movies found, should be over 15, found " + movieList.getResults().size(), movieList.getResults().size() >= 15); + public void testSearchCompanies() throws MovieDbException { + LOG.info("searchCompanies"); + TmdbResultsList result = instance.searchCompanies(COMPANY_NAME, 0); + assertNotNull("Null results", result); + assertNotNull("Null company", result.getResults()); + assertFalse("Empty company", result.isEmpty()); } /** @@ -90,50 +96,10 @@ public class TmdbSearchTest extends AbstractTests { LOG.info("searchCollection"); String query = "batman"; int page = 0; - TmdbResultsList result = instance.searchCollection(query, LANGUAGE_DEFAULT, page); - assertFalse("No collections found", result == null); - assertTrue("No collections found", result.getResults().size() > 0); - } - - /** - * Test of searchPeople method, of class TheMovieDbApi. - * - * @throws MovieDbException - */ - @Test - public void testSearchPeople() throws MovieDbException { - LOG.info("searchPeople"); - String personName = "Bruce Willis"; - boolean includeAdult = false; - TmdbResultsList result = instance.searchPeople(personName, includeAdult, 0); - assertTrue("Couldn't find the person", result.getResults().size() > 0); - } - - /** - * Test of searchList method, of class TheMovieDbApi. - * - * @throws MovieDbException - */ - @Test - public void testSearchList() throws MovieDbException { - LOG.info("searchList"); - String query = "watch"; - int page = 0; - TmdbResultsList result = instance.searchList(query, LANGUAGE_DEFAULT, page); - assertFalse("No lists found", result.getResults() == null); - assertTrue("No lists found", result.getResults().size() > 0); - } - - /** - * Test of searchCompanies method, of class TheMovieDbApi. - * - * @throws MovieDbException - */ - @Test - public void testSearchCompanies() throws MovieDbException { - LOG.info("searchCompanies"); - TmdbResultsList result = instance.searchCompanies(COMPANY_NAME, 0); - assertTrue("No company information found", !result.getResults().isEmpty()); + TmdbResultsList result = instance.searchCollection(query, page, LANGUAGE_DEFAULT); + assertNotNull("Null results", result); + assertNotNull("Null collection", result.getResults()); + assertFalse("Empty collection", result.isEmpty()); } /** @@ -147,8 +113,100 @@ public class TmdbSearchTest extends AbstractTests { String query = "action"; int page = 0; TmdbResultsList result = instance.searchKeyword(query, page); - assertFalse("No keywords found", result.getResults() == null); - assertTrue("No keywords found", result.getResults().size() > 0); + assertNotNull("Null results", result); + assertNotNull("Null keyword", result.getResults()); + assertFalse("Empty keyword", result.isEmpty()); + } + + /** + * Test of searchList method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testSearchList() throws MovieDbException { + LOG.info("searchList"); + String query = "watch"; + int page = 0; + TmdbResultsList result = instance.searchList(query, page, null); + assertNotNull("Null results", result); + assertNotNull("Null list", result.getResults()); + assertFalse("Empty list", result.isEmpty()); + } + + /** + * Test of searchMovie method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testSearchMovie() throws MovieDbException { + LOG.info("searchMovie"); + + // Try a movie with less than 1 page of results + TmdbResultsList movieList = instance.searchMovie("Blade Runner", 0, "", null, 0, 0, SearchType.PHRASE); + assertTrue("No movies found, should be at least 1", movieList.getResults().size() > 0); + + // Try a russian langugage movie + movieList = instance.searchMovie("О чём говорят мужчины", 0, LANGUAGE_RUSSIAN, null, 0, 0, SearchType.PHRASE); + assertTrue("No 'RU' movies found, should be at least 1", movieList.getResults().size() > 0); + + // Try a movie with more than 20 results + movieList = instance.searchMovie("Star Wars", 0, LANGUAGE_ENGLISH, null, 0, 0, SearchType.PHRASE); + assertTrue("Not enough movies found, should be over 15, found " + movieList.getResults().size(), movieList.getResults().size() >= 15); + } + + /** + * Test of searchMulti method, of class TmdbSearch. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testSearchMulti() throws MovieDbException { + System.out.println("searchMulti"); + String query = "j"; + Integer page = null; + String language = ""; + Boolean includeAdult = null; + String expResult = ""; + String result = instance.searchMulti(query, page, language, includeAdult); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of searchPeople method, of class TheMovieDbApi. + * + * @throws MovieDbException + */ + @Test + public void testSearchPeople() throws MovieDbException { + LOG.info("searchPeople"); + String personName = "Bruce Willis"; + TmdbResultsList result = instance.searchPeople(personName, null, null, SearchType.PHRASE); + assertNotNull("Null results", result); + assertNotNull("Null people", result.getResults()); + assertFalse("Empty people", result.isEmpty()); + } + + /** + * Test of searchTV method, of class TmdbSearch. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testSearchTV() throws MovieDbException { + System.out.println("searchTV"); + String query = "The Walking Dead"; + Integer page = null; + String language = LANGUAGE_ENGLISH; + Integer firstAirDateYear = null; + SearchType searchType = SearchType.PHRASE; + TmdbResultsList result = instance.searchTV(query, page, language, firstAirDateYear, searchType); + assertNotNull("Null results", result); + assertNotNull("Null TV", result.getResults()); + assertFalse("Empty TV", result.isEmpty()); } } From d97e39c77eaee25a3162bea761833e044046071b Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Sat, 28 Feb 2015 14:47:55 +0000 Subject: [PATCH 041/100] Search (Partial - missing multi) --- .../omertron/themoviedbapi/TheMovieDbApi.java | 157 +++++++++++------- .../themoviedbapi/methods/TmdbSearch.java | 1 - 2 files changed, 100 insertions(+), 58 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 8a4529caa..666148b9f 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -62,6 +62,7 @@ import com.omertron.themoviedbapi.model.ReleaseInfo; import com.omertron.themoviedbapi.model2.review.Review; import com.omertron.themoviedbapi.model2.StatusCode; import com.omertron.themoviedbapi.enumeration.ExternalSource; +import com.omertron.themoviedbapi.enumeration.SearchType; import com.omertron.themoviedbapi.enumeration.SortBy; import com.omertron.themoviedbapi.model2.FindResults; import com.omertron.themoviedbapi.model2.network.Network; @@ -664,7 +665,7 @@ public class TheMovieDbApi { return tmdbConfiguration.getTimezones(); } // - + // /** * Get the detailed information about a particular credit record. @@ -1242,18 +1243,20 @@ public class TheMovieDbApi { // /** - * Search Movies This is a good starting point to start finding movies on TMDb. + * Search Companies. * - * @param movieName - * @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) + * 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 + * + * @param query + * @param page * @return * @throws MovieDbException */ - public TmdbResultsList searchMovie(String movieName, int searchYear, String language, boolean includeAdult, int page) throws MovieDbException { - return tmdbSearch.searchMovie(movieName, searchYear, language, includeAdult, page); + public TmdbResultsList searchCompanies(String query, Integer page) throws MovieDbException { + return tmdbSearch.searchCompanies(query, page); } /** @@ -1265,53 +1268,8 @@ public class TheMovieDbApi { * @return * @throws MovieDbException */ - public TmdbResultsList searchCollection(String query, String language, int page) throws MovieDbException { - return tmdbSearch.searchCollection(query, language, page); - } - - /** - * 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. - * - * @param personName - * @param includeAdult - * @param page - * @return - * @throws MovieDbException - */ - public TmdbResultsList searchPeople(String personName, boolean includeAdult, int page) throws MovieDbException { - return tmdbSearch.searchPeople(personName, includeAdult, page); - } - - /** - * Search for lists by name and description. - * - * @param query - * @param language - * @param page - * @return - * @throws MovieDbException - */ - public TmdbResultsList searchList(String query, String language, int page) throws MovieDbException { - return tmdbSearch.searchList(query, language, page); - } - - /** - * 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. - * - * http://help.themoviedb.org/kb/api/search-companies - * - * @param companyName - * @param page - * @return - * @throws MovieDbException - */ - public TmdbResultsList searchCompanies(String companyName, int page) throws MovieDbException { - return tmdbSearch.searchCompanies(companyName, page); + public TmdbResultsList searchCollection(String query, Integer page, String language) throws MovieDbException { + return tmdbSearch.searchCollection(query, page, language); } /** @@ -1322,9 +1280,94 @@ public class TheMovieDbApi { * @return * @throws MovieDbException */ - public TmdbResultsList searchKeyword(String query, int page) throws MovieDbException { + public TmdbResultsList searchKeyword(String query, Integer page) throws MovieDbException { return tmdbSearch.searchKeyword(query, page); } + + /** + * Search for lists by name and description. + * + * @param query + * @param includeAdult + * @param page + * @return + * @throws MovieDbException + */ + public TmdbResultsList searchList(String query, Integer page, Boolean includeAdult) throws MovieDbException { + return tmdbSearch.searchList(query, page, includeAdult); + } + + /** + * Search Movies This is a good starting point to start finding movies on TMDb. + * + * @param query + * @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 primaryReleaseYear + * @param searchType + * @return + * @throws MovieDbException + */ + public TmdbResultsList searchMovie(String query, + Integer page, + String language, + Boolean includeAdult, + Integer searchYear, + Integer primaryReleaseYear, + SearchType searchType) throws MovieDbException { + return tmdbSearch.searchMovie(query, page, language, includeAdult, searchYear, primaryReleaseYear, SearchType.PHRASE); + } + + /** + * Search the movie, tv show and person collections with a single query. + * + * Each item returned in the result array has a media_type field that maps to either movie, tv or person. + * + * Each mapped result is the same response you would get from each independent search + * + * @param query + * @param page + * @param language + * @param includeAdult + * @return + * @throws MovieDbException + */ + public String searchMulti(String query, Integer page, String language, Boolean includeAdult) throws MovieDbException { + return tmdbSearch.searchMulti(query, page, language, includeAdult); + } + + /** + * 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. + * + * @param query + * @param includeAdult + * @param page + * @param searchType + * @return + * @throws MovieDbException + */ + public TmdbResultsList searchPeople(String query, Integer page, Boolean includeAdult, SearchType searchType) throws MovieDbException { + return tmdbSearch.searchPeople(query, page, includeAdult, searchType); + } + + /** + * Search for TV shows by title. + * + * @param query + * @param page + * @param language + * @param firstAirDateYear + * @param searchType + * @return + * @throws com.omertron.themoviedbapi.MovieDbException + */ + public TmdbResultsList searchTV(String query, Integer page, String language, Integer firstAirDateYear, SearchType searchType) throws MovieDbException { + return tmdbSearch.searchTV(query, page, language, firstAirDateYear, searchType); + } // // diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java index 169744e80..bde166555 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java @@ -127,7 +127,6 @@ public class TmdbSearch extends AbstractMethod { * Search for lists by name and description. * * @param query - * @param language * @param includeAdult * @param page * @return From 45b66ef0b1e2c2c84a64ec9f01773d9d071321b9 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Sat, 28 Feb 2015 15:54:52 +0000 Subject: [PATCH 042/100] Stub methods --- .../themoviedbapi/methods/TmdbPeople.java | 118 ++++++++++++++---- .../themoviedbapi/tools/MethodSub.java | 3 + 2 files changed, 96 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java index 2b968aa24..b0ca3158a 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java @@ -22,6 +22,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model.Artwork; import com.omertron.themoviedbapi.enumeration.ArtworkType; +import static com.omertron.themoviedbapi.methods.AbstractMethod.getTypeReference; import com.omertron.themoviedbapi.model.person.Person; import com.omertron.themoviedbapi.model.person.PersonCredit; import com.omertron.themoviedbapi.results.TmdbResultsList; @@ -31,8 +32,8 @@ import com.omertron.themoviedbapi.tools.MethodBase; import com.omertron.themoviedbapi.tools.MethodSub; import com.omertron.themoviedbapi.tools.Param; import com.omertron.themoviedbapi.tools.TmdbParameters; +import com.omertron.themoviedbapi.wrapper.WrapperGenericList; import com.omertron.themoviedbapi.wrapper.WrapperImages; -import com.omertron.themoviedbapi.wrapper.WrapperPersonCredits; import com.omertron.themoviedbapi.wrapper.WrapperPersonList; import java.io.IOException; import java.net.URL; @@ -56,9 +57,7 @@ public class TmdbPeople extends AbstractMethod { } /** - * This method is used to retrieve all of the basic person information. - * - * It will return the single highest rated profile image. + * Get the general person information for a specific id. * * @param personId * @param appendToResponse @@ -81,35 +80,74 @@ public class TmdbPeople extends AbstractMethod { } /** - * 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. + * Get the movie credits for a specific person id. * * @param personId + * @param language * @param appendToResponse * @return * @throws MovieDbException */ - public TmdbResultsList getPersonCredits(int personId, String... appendToResponse) throws MovieDbException { + public TmdbResultsList getPersonMovieCredits(int personId, String language, String... appendToResponse) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.ID, personId); + parameters.add(Param.LANGUAGE, language); parameters.add(Param.APPEND, appendToResponse); + URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.MOVIE_CREDITS).buildUrl(parameters); - URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.CREDITS).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperPersonCredits wrapper = MAPPER.readValue(webpage, WrapperPersonCredits.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getAll()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person credits", url, ex); - } + WrapperGenericList wrapper = processWrapper(getTypeReference(PersonCredit.class), url, "person movie credits"); + TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); + results.copyWrapper(wrapper); + return results; } /** - * This method is used to retrieve all of the profile images for a person. + * Get the TV credits for a specific person id. + * + * To get the expanded details for each record, call the /credit method with the provided credit_id. + * + * This will provide details about which episode and/or season the credit is for. + * + * @param personId + * @param language + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public TmdbResultsList getPersonTVCredits(int personId, String language, String... appendToResponse) throws MovieDbException { + return null; + } + + /** + * Get the combined (movie and TV) credits for a specific person id. + * + * To get the expanded details for each TV record, call the /credit method with the provided credit_id. + * + * This will provide details about which episode and/or season the credit is for. + * + * @param personId + * @param language + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public TmdbResultsList getPersonCombinedCredits(int personId, String language, String... appendToResponse) throws MovieDbException { + return null; + } + + /** + * Get the external ids for a specific person id. + * + * @param personId + * @return + * @throws MovieDbException + */ + public TmdbResultsList getPersonExternalIds(int personId) throws MovieDbException { + return null; + } + + /** + * Get the images for a specific person id. * * @param personId * @return @@ -132,6 +170,40 @@ public class TmdbPeople extends AbstractMethod { } } + /** + * Get the images that have been tagged with a specific person id. + * + * We return all of the image results with a media object mapped for each image. + * + * @param personId + * @param page + * @param language + * @return + */ + public TmdbResultsList getPersonTaggedImages(int personId, Integer page, String language) { + return null; + } + + /** + * Get the changes for a specific person id. + * + * Changes are grouped by key, and ordered by date in descending order. + * + * 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 language is present on fields that are translatable. + * + * @param persondId + * @param startDate + * @param endDate + * @return + */ + public TmdbResultsList getPersonChanges(int persondId, String startDate, String endDate) { + return null; + } + /** * Get the list of popular people on The Movie Database. * @@ -141,7 +213,7 @@ public class TmdbPeople extends AbstractMethod { * @return * @throws MovieDbException */ - public TmdbResultsList getPersonPopular(int page) throws MovieDbException { + public TmdbResultsList getPersonPopular(Integer page) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.PAGE, page); @@ -175,8 +247,4 @@ public class TmdbPeople extends AbstractMethod { } } - int getPersonMovieCredits(int ID_BRUCE_WILLIS, String LANGUAGE_DEFAULT) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - } diff --git a/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java b/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java index d8b73dfda..96615675a 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java @@ -30,6 +30,7 @@ public enum MethodSub { CHANGES("changes"), CLEAR("clear"), COLLECTION("collection"), + COMBINED_CREDITS("combined_credits"), COMPANY("company"), CREDITS("credits"), FAVORITE("favorite"), @@ -45,6 +46,7 @@ public enum MethodSub { LISTS("lists"), MOVIE("movie"), MOVIES("movies"), + MOVIE_CREDITS("movie_credits"), MOVIE_LIST("movie/list"), MULTI("multi"), NOW_PLAYING("now-playing"), @@ -64,6 +66,7 @@ public enum MethodSub { TOP_RATED("top-rated"), TRANSLATIONS("translations"), TV("tv"), + TV_CREDITS("tv_credits"), TV_LIST("tv/list"), UPCOMING("upcoming"), VIDEOS("videos"), From 46a50703d70d5f2b459b9839237dd1c7931992ab Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Sun, 1 Mar 2015 19:25:47 +0000 Subject: [PATCH 043/100] People (partial) --- .../omertron/themoviedbapi/TheMovieDbApi.java | 74 +------ .../enumeration/ArtworkType.java | 39 +++- .../themoviedbapi/enumeration/CreditType.java | 30 +++ .../themoviedbapi/enumeration/MediaType.java | 27 ++- .../themoviedbapi/methods/AbstractMethod.java | 2 +- .../methods/TmdbCollections.java | 2 +- .../themoviedbapi/methods/TmdbMovies.java | 2 +- .../themoviedbapi/methods/TmdbPeople.java | 112 ++++++++--- .../themoviedbapi/methods/TmdbSearch.java | 5 + .../themoviedbapi/methods/_Method_List.txt | 2 +- .../omertron/themoviedbapi/model/MovieDb.java | 1 + .../themoviedbapi/model/person/Person.java | 7 +- .../{model => model2/artwork}/Artwork.java | 88 +++++---- .../model2/artwork/ArtworkMedia.java | 74 +++++++ .../model2/person/CreditBasic.java | 126 ++++++++++++ .../model2/person/CreditMovieBasic.java | 77 ++++++++ .../model2/person/CreditTVBasic.java | 77 ++++++++ .../model2/person/ExternalID.java | 82 ++++++++ .../themoviedbapi/model2/person/Person.java | 133 +++++++++++++ .../model2/person/PersonCredits.java | 63 ++++++ .../model2/tv/TVEpisodeBasic.java | 14 +- .../themoviedbapi/tools/MethodSub.java | 2 + .../themoviedbapi/tools/TmdbParameters.java | 4 +- .../themoviedbapi/wrapper/WrapperImages.java | 4 +- .../methods/TmdbCollectionsTest.java | 2 +- .../themoviedbapi/methods/TmdbMoviesTest.java | 2 +- .../themoviedbapi/methods/TmdbPeopleTest.java | 184 +++++++++++++++--- 27 files changed, 1051 insertions(+), 184 deletions(-) create mode 100644 src/main/java/com/omertron/themoviedbapi/enumeration/CreditType.java rename src/main/java/com/omertron/themoviedbapi/{model => model2/artwork}/Artwork.java (94%) create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/artwork/ArtworkMedia.java create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/person/CreditBasic.java create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/person/CreditMovieBasic.java create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/person/CreditTVBasic.java create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/person/ExternalID.java create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/person/Person.java create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/person/PersonCredits.java diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 666148b9f..0ae73f0a3 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -41,7 +41,7 @@ import com.omertron.themoviedbapi.methods.TmdbSearch; import com.omertron.themoviedbapi.methods.TmdbTV; import com.omertron.themoviedbapi.model2.account.Account; import com.omertron.themoviedbapi.model.AlternativeTitle; -import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.model.Certification; import com.omertron.themoviedbapi.model.change.ChangedMedia; import com.omertron.themoviedbapi.model2.collection.Collection; @@ -57,7 +57,6 @@ import com.omertron.themoviedbapi.model.MovieDb; import com.omertron.themoviedbapi.model2.list.ListItem; import com.omertron.themoviedbapi.model.MovieList; import com.omertron.themoviedbapi.model.person.Person; -import com.omertron.themoviedbapi.model.person.PersonCredit; import com.omertron.themoviedbapi.model.ReleaseInfo; import com.omertron.themoviedbapi.model2.review.Review; import com.omertron.themoviedbapi.model2.StatusCode; @@ -1155,79 +1154,10 @@ public class TheMovieDbApi { // // - /** - * This method is used to retrieve all of the basic person information. - * - * It will return the single highest rated profile image. - * - * @param personId - * @param appendToResponse - * @return - * @throws MovieDbException - */ - public Person getPersonInfo(int personId, String... appendToResponse) throws MovieDbException { - return tmdbPeople.getPersonInfo(personId, appendToResponse); - } - /** - * 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. - * - * @param personId - * @param appendToResponse - * @return - * @throws MovieDbException - */ - public TmdbResultsList getPersonCredits(int personId, String... appendToResponse) throws MovieDbException { - return tmdbPeople.getPersonCredits(personId, appendToResponse); - } + null; - /** - * This method is used to retrieve all of the profile images for a person. - * - * @param personId - * @return - * @throws MovieDbException - */ - public TmdbResultsList getPersonImages(int personId) throws MovieDbException { - return tmdbPeople.getPersonImages(personId); - } - /** - * Get the list of popular people on The Movie Database. - * - * This list refreshes every day. - * - * @return - * @throws MovieDbException - */ - public TmdbResultsList getPersonPopular() throws MovieDbException { - return tmdbPeople.getPersonPopular(0); - } - - /** - * Get the list of popular people on The Movie Database. - * - * This list refreshes every day. - * - * @param page - * @return - * @throws MovieDbException - */ - public TmdbResultsList getPersonPopular(int page) throws MovieDbException { - return tmdbPeople.getPersonPopular(page); - } - - /** - * Get the latest person id. - * - * @return - * @throws MovieDbException - */ - public Person getPersonLatest() throws MovieDbException { - return tmdbPeople.getPersonLatest(); - } // // diff --git a/src/main/java/com/omertron/themoviedbapi/enumeration/ArtworkType.java b/src/main/java/com/omertron/themoviedbapi/enumeration/ArtworkType.java index 373dd9886..3ade5fcb8 100644 --- a/src/main/java/com/omertron/themoviedbapi/enumeration/ArtworkType.java +++ b/src/main/java/com/omertron/themoviedbapi/enumeration/ArtworkType.java @@ -19,15 +19,46 @@ */ package com.omertron.themoviedbapi.enumeration; +import org.apache.commons.lang3.StringUtils; + /** * ArtworkType enum List of the artwork types that are available */ public enum ArtworkType { - // Poster artwork + /** + * Poster artwork + */ POSTER, - // Fanart/backdrop + /** + * Fanart/backdrop + */ BACKDROP, - // Person image - PROFILE + /** + * Person image + */ + PROFILE, + /** + * Still (Video image) + */ + STILL; + + /** + * Convert a string into an Enum type + * + * @param artworkType + * @return + * @throws IllegalArgumentException If type is not recognised + * + */ + public static ArtworkType fromString(String artworkType) { + if (StringUtils.isNotBlank(artworkType)) { + try { + return ArtworkType.valueOf(artworkType.trim().toUpperCase()); + } catch (IllegalArgumentException ex) { + throw new IllegalArgumentException("ArtworkType " + artworkType + " does not exist.", ex); + } + } + throw new IllegalArgumentException("ArtworkType must not be null"); + } } diff --git a/src/main/java/com/omertron/themoviedbapi/enumeration/CreditType.java b/src/main/java/com/omertron/themoviedbapi/enumeration/CreditType.java new file mode 100644 index 000000000..72ffd3b31 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/enumeration/CreditType.java @@ -0,0 +1,30 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.enumeration; + +/** + * + * @author Stuart + */ +public enum CreditType { + + CAST, + CREW; +} diff --git a/src/main/java/com/omertron/themoviedbapi/enumeration/MediaType.java b/src/main/java/com/omertron/themoviedbapi/enumeration/MediaType.java index 015ec5e2b..839a41ed6 100644 --- a/src/main/java/com/omertron/themoviedbapi/enumeration/MediaType.java +++ b/src/main/java/com/omertron/themoviedbapi/enumeration/MediaType.java @@ -19,6 +19,8 @@ */ package com.omertron.themoviedbapi.enumeration; +import org.apache.commons.lang3.StringUtils; + /** * Media type options * @@ -33,5 +35,28 @@ public enum MediaType { /** * TV Show media type */ - TV; + TV, + /** + * TV Episode media type + */ + EPISODE; + + /** + * Convert a string into an Enum type + * + * @param mediaType + * @return + * @throws IllegalArgumentException If type is not recognised + * + */ + public static MediaType fromString(String mediaType) { + if (StringUtils.isNotBlank(mediaType)) { + try { + return MediaType.valueOf(mediaType.trim().toUpperCase()); + } catch (IllegalArgumentException ex) { + throw new IllegalArgumentException("MediaType " + mediaType + " does not exist.", ex); + } + } + throw new IllegalArgumentException("MediaType must not be null"); + } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java index f94fe5c83..71d25bdaf 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java @@ -53,7 +53,7 @@ public class AbstractMethod { protected static final TypeReference> TR_TV_BASIC = getTypeReference(TVBasic.class); protected static final TypeReference> TR_USER_LIST = getTypeReference(UserList.class); - protected static TypeReference getTypeReference(T Class) { + private static TypeReference getTypeReference(T Class) { return new TypeReference>() { }; } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCollections.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCollections.java index 49c1cafaf..baac02a1f 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCollections.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCollections.java @@ -20,7 +20,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.enumeration.ArtworkType; import com.omertron.themoviedbapi.model2.collection.CollectionInfo; import com.omertron.themoviedbapi.results.TmdbResultsList; diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java index 19333b55f..b17fbb1f6 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java @@ -21,7 +21,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model.AlternativeTitle; -import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.model.MovieDb; import com.omertron.themoviedbapi.model.MovieList; import com.omertron.themoviedbapi.model.ReleaseInfo; diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java index b0ca3158a..c0b46b2e2 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java @@ -19,12 +19,16 @@ */ package com.omertron.themoviedbapi.methods; +import com.fasterxml.jackson.core.type.TypeReference; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.enumeration.ArtworkType; -import static com.omertron.themoviedbapi.methods.AbstractMethod.getTypeReference; -import com.omertron.themoviedbapi.model.person.Person; -import com.omertron.themoviedbapi.model.person.PersonCredit; +import com.omertron.themoviedbapi.model2.artwork.ArtworkMedia; +import com.omertron.themoviedbapi.model2.person.CreditMovieBasic; +import com.omertron.themoviedbapi.model2.person.CreditTVBasic; +import com.omertron.themoviedbapi.model2.person.ExternalID; +import com.omertron.themoviedbapi.model2.person.Person; +import com.omertron.themoviedbapi.model2.person.PersonCredits; import com.omertron.themoviedbapi.results.TmdbResultsList; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; @@ -88,17 +92,21 @@ public class TmdbPeople extends AbstractMethod { * @return * @throws MovieDbException */ - public TmdbResultsList getPersonMovieCredits(int personId, String language, String... appendToResponse) throws MovieDbException { + public PersonCredits getPersonMovieCredits(int personId, String language, String... appendToResponse) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.ID, personId); parameters.add(Param.LANGUAGE, language); parameters.add(Param.APPEND, appendToResponse); - URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.MOVIE_CREDITS).buildUrl(parameters); - WrapperGenericList wrapper = processWrapper(getTypeReference(PersonCredit.class), url, "person movie credits"); - TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); - results.copyWrapper(wrapper); - return results; + URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.MOVIE_CREDITS).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, new TypeReference>() { + }); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person movie credits", url, ex); + } } /** @@ -114,8 +122,21 @@ public class TmdbPeople extends AbstractMethod { * @return * @throws MovieDbException */ - public TmdbResultsList getPersonTVCredits(int personId, String language, String... appendToResponse) throws MovieDbException { - return null; + public PersonCredits getPersonTVCredits(int personId, String language, String... appendToResponse) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, personId); + parameters.add(Param.LANGUAGE, language); + parameters.add(Param.APPEND, appendToResponse); + + URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.TV_CREDITS).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, new TypeReference>() { + }); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person movie credits", url, ex); + } } /** @@ -131,8 +152,21 @@ public class TmdbPeople extends AbstractMethod { * @return * @throws MovieDbException */ - public TmdbResultsList getPersonCombinedCredits(int personId, String language, String... appendToResponse) throws MovieDbException { - return null; + public PersonCredits getPersonCombinedCredits(int personId, String language, String... appendToResponse) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, personId); + parameters.add(Param.LANGUAGE, language); + parameters.add(Param.APPEND, appendToResponse); + + URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.COMBINED_CREDITS).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, new TypeReference>() { + }); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person movie credits", url, ex); + } } /** @@ -142,8 +176,18 @@ public class TmdbPeople extends AbstractMethod { * @return * @throws MovieDbException */ - public TmdbResultsList getPersonExternalIds(int personId) throws MovieDbException { - return null; + public ExternalID getPersonExternalIds(int personId) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, personId); + + URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.EXTERNAL_IDS).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, ExternalID.class); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person movie credits", url, ex); + } } /** @@ -179,9 +223,28 @@ public class TmdbPeople extends AbstractMethod { * @param page * @param language * @return + * @throws com.omertron.themoviedbapi.MovieDbException */ - public TmdbResultsList getPersonTaggedImages(int personId, Integer page, String language) { - return null; + public TmdbResultsList getPersonTaggedImages(int personId, Integer page, String language) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, personId); + + URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.TAGGED_IMAGES).buildUrl(parameters); + + WrapperGenericList wrapper; + + String webpage = httpTools.getRequest(url); + try { + TypeReference tr = new TypeReference>() { + }; + wrapper = MAPPER.readValue(webpage, tr); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get tagged images", url, ex); + } + + TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); + results.copyWrapper(wrapper); + return results; } /** @@ -199,9 +262,10 @@ public class TmdbPeople extends AbstractMethod { * @param startDate * @param endDate * @return + * @throws com.omertron.themoviedbapi.MovieDbException */ - public TmdbResultsList getPersonChanges(int persondId, String startDate, String endDate) { - return null; + public TmdbResultsList getPersonChanges(int persondId, String startDate, String endDate) throws MovieDbException { + throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not done"); } /** @@ -222,9 +286,10 @@ public class TmdbPeople extends AbstractMethod { try { WrapperPersonList wrapper = MAPPER.readValue(webpage, WrapperPersonList.class); - TmdbResultsList results = new TmdbResultsList(wrapper.getPersonList()); - results.copyWrapper(wrapper); - return results; +// TmdbResultsList results = new TmdbResultsList(wrapper.getPersonList()); +// results.copyWrapper(wrapper); +// return results; + return null; } catch (IOException ex) { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get popular person", url, ex); } @@ -246,5 +311,4 @@ public class TmdbPeople extends AbstractMethod { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get latest person", url, ex); } } - } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java index bde166555..e8c24d0dd 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java @@ -19,6 +19,7 @@ */ package com.omertron.themoviedbapi.methods; +import com.fasterxml.jackson.core.type.TypeReference; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.SearchType; import com.omertron.themoviedbapi.model2.collection.Collection; @@ -264,4 +265,8 @@ public class TmdbSearch extends AbstractMethod { return results; } + private static TypeReference getTypeReference(T Class) { + return new TypeReference>() { + }; + } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt index 0e2023986..20c105b60 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt +++ b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt @@ -94,7 +94,7 @@ People /person/{id} Get the general person information for a specific id /person/{id}/movie_credits Get the movie credits for a specific person id. /person/{id}/tv_credits Get the TV credits for a specific person id. -/person/{id}/combined_credits Get the combined (movie and TV) credits for a specific person id. +*** /person/{id}/combined_credits Get the combined (movie and TV) credits for a specific person id. /person/{id}/external_ids Get the external ids for a specific person id. /person/{id}/images Get the images for a specific person id. /person/{id}/tagged_images Get the images that have been tagged with a specific person id diff --git a/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java b/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java index fa9b9cbed..5a6226bea 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java +++ b/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java @@ -19,6 +19,7 @@ */ package com.omertron.themoviedbapi.model; +import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.model2.review.Review; import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.omertron.themoviedbapi.model2.collection.Collection; diff --git a/src/main/java/com/omertron/themoviedbapi/model/person/Person.java b/src/main/java/com/omertron/themoviedbapi/model/person/Person.java index b76ffe852..f3d99b4a5 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/person/Person.java +++ b/src/main/java/com/omertron/themoviedbapi/model/person/Person.java @@ -34,15 +34,10 @@ public class Person extends AbstractJsonMapping { private static final long serialVersionUID = 1L; - /* - * Static fields for default cast information - */ private static final String CAST_DEPARTMENT = "acting"; private static final String CAST_JOB = "actor"; private static final String DEFAULT_STRING = ""; - /* - * Properties - */ + // Properties @JsonProperty("id") private int id = -1; @JsonProperty("name") diff --git a/src/main/java/com/omertron/themoviedbapi/model/Artwork.java b/src/main/java/com/omertron/themoviedbapi/model2/artwork/Artwork.java similarity index 94% rename from src/main/java/com/omertron/themoviedbapi/model/Artwork.java rename to src/main/java/com/omertron/themoviedbapi/model2/artwork/Artwork.java index a60009016..19bb4f91b 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/Artwork.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/artwork/Artwork.java @@ -17,11 +17,12 @@ * along with TheMovieDB API. If not, see . * */ -package com.omertron.themoviedbapi.model; +package com.omertron.themoviedbapi.model2.artwork; import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.omertron.themoviedbapi.enumeration.ArtworkType; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; @@ -54,84 +55,89 @@ public class Artwork extends AbstractJsonMapping { private String flag; private ArtworkType artworkType = ArtworkType.POSTER; - public ArtworkType getArtworkType() { - return artworkType; + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; } public float getAspectRatio() { return aspectRatio; } - public String getFilePath() { - return filePath; - } - - public int getHeight() { - return height; - } - - public String getLanguage() { - return language; - } - - public int getWidth() { - return width; - } - - public float getVoteAverage() { - return voteAverage; - } - - public int getVoteCount() { - return voteCount; - } - - public String getFlag() { - return flag; - } - - public String getId() { - return id; - } - - public void setArtworkType(ArtworkType artworkType) { - this.artworkType = artworkType; - } - public void setAspectRatio(float aspectRatio) { this.aspectRatio = aspectRatio; } + public String getFilePath() { + return filePath; + } + public void setFilePath(String filePath) { this.filePath = filePath; } + public int getHeight() { + return height; + } + public void setHeight(int height) { this.height = height; } + public String getLanguage() { + return language; + } + public void setLanguage(String language) { this.language = language; } + public int getWidth() { + return width; + } + public void setWidth(int width) { this.width = width; } + public float getVoteAverage() { + return voteAverage; + } + public void setVoteAverage(float voteAverage) { this.voteAverage = voteAverage; } + public int getVoteCount() { + return voteCount; + } + public void setVoteCount(int voteCount) { this.voteCount = voteCount; } + public String getFlag() { + return flag; + } + public void setFlag(String flag) { this.flag = flag; } - public void setId(String id) { - this.id = id; + public ArtworkType getArtworkType() { + return artworkType; + } + + public void setArtworkType(ArtworkType artworkType) { + this.artworkType = artworkType; + } + + @JsonSetter("image_type") + public void setArtworkType(String artworkType){ + this.artworkType=ArtworkType.fromString(artworkType); } @Override diff --git a/src/main/java/com/omertron/themoviedbapi/model2/artwork/ArtworkMedia.java b/src/main/java/com/omertron/themoviedbapi/model2/artwork/ArtworkMedia.java new file mode 100644 index 000000000..5905ea6f9 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/artwork/ArtworkMedia.java @@ -0,0 +1,74 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model2.artwork; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.omertron.themoviedbapi.enumeration.MediaType; +import com.omertron.themoviedbapi.model2.MediaBasic; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; +import com.omertron.themoviedbapi.model2.tv.TVBasic; +import com.omertron.themoviedbapi.model2.tv.TVEpisodeBasic; + +/** + * + * @author Stuart + */ +public class ArtworkMedia extends Artwork { + + private MediaType mediaType; + @JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.EXTERNAL_PROPERTY, + property = "media_type", + defaultImpl = MediaBasic.class + ) + @JsonSubTypes({ + @JsonSubTypes.Type(value = MovieBasic.class, name = "movie"), + @JsonSubTypes.Type(value = TVBasic.class, name = "tv"), + @JsonSubTypes.Type(value = TVEpisodeBasic.class, name = "episode") + }) + @JsonProperty("media") + private MediaBasic media; + + public MediaType getMediaType() { + return mediaType; + } + + public void setMediaType(MediaType mediaType) { + this.mediaType = mediaType; + } + + @JsonSetter("media_type") + public void setMediaType(String mediaType) { + this.mediaType = MediaType.fromString(mediaType); + } + + public MediaBasic getMedia() { + return media; + } + + public void setMedia(MediaBasic media) { + this.media = media; + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/person/CreditBasic.java b/src/main/java/com/omertron/themoviedbapi/model2/person/CreditBasic.java new file mode 100644 index 000000000..eebf5f736 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/person/CreditBasic.java @@ -0,0 +1,126 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model2.person; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.omertron.themoviedbapi.enumeration.CreditType; +import com.omertron.themoviedbapi.enumeration.MediaType; +import com.omertron.themoviedbapi.model2.AbstractJsonMapping; + +/** + * @author stuart.boston + */ +public class CreditBasic extends AbstractJsonMapping { + + private static final long serialVersionUID = 1L; + + private CreditType creditType; + private MediaType mediaType; + + @JsonProperty("credit_id") + private String creditId; + @JsonProperty("id") + private int id; + @JsonProperty("poster_path") + private String posterPath; + + //cast + @JsonProperty("character") + private String character; + //crew + @JsonProperty("department") + private String department; + @JsonProperty("job") + private String job; + + public CreditType getCreditType() { + return creditType; + } + + public void setCreditType(CreditType creditType) { + this.creditType = creditType; + } + + public MediaType getMediaType() { + return mediaType; + } + + @JsonSetter("media_type") + public void setMediaType(String mediaType) { + this.mediaType = MediaType.fromString(mediaType); + } + + public void setMediaType(MediaType mediaType) { + this.mediaType = mediaType; + } + + public String getCreditId() { + return creditId; + } + + public void setCreditId(String creditId) { + this.creditId = creditId; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getPosterPath() { + return posterPath; + } + + public void setPosterPath(String posterPath) { + this.posterPath = posterPath; + } + + public String getCharacter() { + return character; + } + + public void setCharacter(String character) { + this.character = character; + setCreditType(CreditType.CAST); + } + + public String getDepartment() { + return department; + } + + public void setDepartment(String department) { + this.department = department; + setCreditType(CreditType.CREW); + } + + public String getJob() { + return job; + } + + public void setJob(String job) { + this.job = job; + setCreditType(CreditType.CREW); + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/person/CreditMovieBasic.java b/src/main/java/com/omertron/themoviedbapi/model2/person/CreditMovieBasic.java new file mode 100644 index 000000000..b160c18b3 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/person/CreditMovieBasic.java @@ -0,0 +1,77 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model2.person; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.enumeration.MediaType; + +/** + * @author stuart.boston + */ +public class CreditMovieBasic extends CreditBasic { + + private static final long serialVersionUID = 1L; + + @JsonProperty("adult") + private boolean adult; + @JsonProperty("original_title") + private String originalTitle; + @JsonProperty("release_date") + private String releaseDate; + @JsonProperty("title") + private String title; + + public CreditMovieBasic() { + setMediaType(MediaType.MOVIE); + } + + public boolean isAdult() { + return adult; + } + + public void setAdult(boolean adult) { + this.adult = adult; + } + + public String getOriginalTitle() { + return originalTitle; + } + + public void setOriginalTitle(String originalTitle) { + this.originalTitle = originalTitle; + } + + public String getReleaseDate() { + return releaseDate; + } + + public void setReleaseDate(String releaseDate) { + this.releaseDate = releaseDate; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/person/CreditTVBasic.java b/src/main/java/com/omertron/themoviedbapi/model2/person/CreditTVBasic.java new file mode 100644 index 000000000..3d055ac19 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/person/CreditTVBasic.java @@ -0,0 +1,77 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model2.person; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.enumeration.MediaType; + +/** + * @author stuart.boston + */ +public class CreditTVBasic extends CreditBasic { + + private static final long serialVersionUID = 1L; + + @JsonProperty("episode_count") + private int episodeCount; + @JsonProperty("first_air_date") + private String firstAirDate; + @JsonProperty("name") + private String name; + @JsonProperty("original_name") + private String originalName; + + public CreditTVBasic() { + setMediaType(MediaType.TV); + } + + public int getEpisodeCount() { + return episodeCount; + } + + public void setEpisodeCount(int episodeCount) { + this.episodeCount = episodeCount; + } + + public String getFirstAirDate() { + return firstAirDate; + } + + public void setFirstAirDate(String firstAirDate) { + this.firstAirDate = firstAirDate; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getOriginalName() { + return originalName; + } + + public void setOriginalName(String originalName) { + this.originalName = originalName; + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/person/ExternalID.java b/src/main/java/com/omertron/themoviedbapi/model2/person/ExternalID.java new file mode 100644 index 000000000..805163069 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/person/ExternalID.java @@ -0,0 +1,82 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model2.person; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model2.AbstractJsonMapping; + +/** + * + * @author Stuart + */ +public class ExternalID extends AbstractJsonMapping { + + @JsonProperty("id") + private String id; + @JsonProperty("imdb_id") + private String imdbId; + @JsonProperty("freebase_mid") + private String freebaseMid; + @JsonProperty("freebase_id") + private String freebaseId; + @JsonProperty("tvrage_id") + private String tvrageId; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getImdbId() { + return imdbId; + } + + public void setImdbId(String imdbId) { + this.imdbId = imdbId; + } + + public String getFreebaseMid() { + return freebaseMid; + } + + public void setFreebaseMid(String freebaseMid) { + this.freebaseMid = freebaseMid; + } + + public String getFreebaseId() { + return freebaseId; + } + + public void setFreebaseId(String freebaseId) { + this.freebaseId = freebaseId; + } + + public String getTvrageId() { + return tvrageId; + } + + public void setTvrageId(String tvrageId) { + this.tvrageId = tvrageId; + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/person/Person.java b/src/main/java/com/omertron/themoviedbapi/model2/person/Person.java new file mode 100644 index 000000000..63f1a0d79 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/person/Person.java @@ -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 . + * + */ +package com.omertron.themoviedbapi.model2.person; + +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; + +/** + * @author stuart.boston + */ +public class Person extends PersonBasic { + + private static final long serialVersionUID = 1L; + + @JsonProperty("adult") + private boolean adult; + @JsonProperty("also_known_as") + private List alsoKnownAs; + @JsonProperty("biography") + private String biography; + @JsonProperty("birthday") + private String birthday; + @JsonProperty("deathday") + private String deathday; + @JsonProperty("homepage") + private String homepage; + @JsonProperty("imdb_id") + private String imdbId; + @JsonProperty("place_of_birth") + private String placeOfBirth; + @JsonProperty("popularity") + private float popularity; + @JsonProperty("profile_path") + private String profilePath; + + public boolean isAdult() { + return adult; + } + + public void setAdult(boolean adult) { + this.adult = adult; + } + + public List getAlsoKnownAs() { + return alsoKnownAs; + } + + public void setAlsoKnownAs(List alsoKnownAs) { + this.alsoKnownAs = alsoKnownAs; + } + + public String getBiography() { + return biography; + } + + public void setBiography(String biography) { + this.biography = biography; + } + + public String getBirthday() { + return birthday; + } + + public void setBirthday(String birthday) { + this.birthday = birthday; + } + + public String getDeathday() { + return deathday; + } + + public void setDeathday(String deathday) { + this.deathday = deathday; + } + + public String getHomepage() { + return homepage; + } + + public void setHomepage(String homepage) { + this.homepage = homepage; + } + + public String getImdbId() { + return imdbId; + } + + public void setImdbId(String imdbId) { + this.imdbId = imdbId; + } + + public String getPlaceOfBirth() { + return placeOfBirth; + } + + public void setPlaceOfBirth(String placeOfBirth) { + this.placeOfBirth = placeOfBirth; + } + + public float getPopularity() { + return popularity; + } + + public void setPopularity(float popularity) { + this.popularity = popularity; + } + + public String getProfilePath() { + return profilePath; + } + + public void setProfilePath(String profilePath) { + this.profilePath = profilePath; + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/person/PersonCredits.java b/src/main/java/com/omertron/themoviedbapi/model2/person/PersonCredits.java new file mode 100644 index 000000000..29c3fbfe5 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/person/PersonCredits.java @@ -0,0 +1,63 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model2.person; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model2.AbstractJsonMapping; +import java.util.List; + +/** + * @author stuart.boston + */ +public class PersonCredits extends AbstractJsonMapping { + + private static final long serialVersionUID = 1L; + + @JsonProperty("id") + private int id; + @JsonProperty("cast") + private List cast; + @JsonProperty("crew") + private List crew; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public List getCast() { + return cast; + } + + public void setCast(List cast) { + this.cast = cast; + } + + public List getCrew() { + return crew; + } + + public void setCrew(List crew) { + this.crew = crew; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/tv/TVEpisodeBasic.java b/src/main/java/com/omertron/themoviedbapi/model2/tv/TVEpisodeBasic.java index 7af9f79ec..9854bf559 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/tv/TVEpisodeBasic.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/tv/TVEpisodeBasic.java @@ -19,15 +19,15 @@ */ package com.omertron.themoviedbapi.model2.tv; -import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model2.MediaBasic; /** * TV Favorite information * * @author stuart.boston */ -public class TVEpisodeBasic extends AbstractJsonMapping { +public class TVEpisodeBasic extends MediaBasic { @JsonProperty("air_date") private String airDate; @@ -41,6 +41,8 @@ public class TVEpisodeBasic extends AbstractJsonMapping { private String overview; @JsonProperty("still_path") private String stillPath; + @JsonProperty("show_id") + private String showId; public String getAirDate() { return airDate; @@ -90,4 +92,12 @@ public class TVEpisodeBasic extends AbstractJsonMapping { this.stillPath = stillPath; } + public String getShowId() { + return showId; + } + + public void setShowId(String showId) { + this.showId = showId; + } + } diff --git a/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java b/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java index 96615675a..b015f7f29 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java @@ -33,6 +33,7 @@ public enum MethodSub { COMBINED_CREDITS("combined_credits"), COMPANY("company"), CREDITS("credits"), + EXTERNAL_IDS("external_ids"), FAVORITE("favorite"), FAVORITE_MOVIES("favorite/movies"), FAVORITE_TV("favorite/tv"), @@ -61,6 +62,7 @@ public enum MethodSub { REVIEWS("reviews"), SESSION_NEW("session/new"), SIMILAR_MOVIES("similar_movies"), + TAGGED_IMAGES("tagged_images"), TOKEN_NEW("token/new"), TOKEN_VALIDATE("token/validate_with_login"), TOP_RATED("top-rated"), diff --git a/src/main/java/com/omertron/themoviedbapi/tools/TmdbParameters.java b/src/main/java/com/omertron/themoviedbapi/tools/TmdbParameters.java index d063ea6dc..efedeebbf 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/TmdbParameters.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/TmdbParameters.java @@ -57,7 +57,9 @@ public class TmdbParameters { * @param value The array value to use (will be converted into a comma separated list) */ public void add(final Param key, final String[] value) { - parameters.put(key, toList(value)); + if (value != null && value.length > 0) { + parameters.put(key, toList(value)); + } } /** diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperImages.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperImages.java index f2243153c..98e7a660e 100644 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperImages.java +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperImages.java @@ -20,7 +20,7 @@ package com.omertron.themoviedbapi.wrapper; import com.fasterxml.jackson.annotation.JsonProperty; -import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.enumeration.ArtworkType; import java.io.Serializable; import java.util.ArrayList; @@ -96,7 +96,7 @@ public class WrapperImages extends AbstractWrapperAll implements Serializable { artwork.addAll(backdrops); } - // Add all the backdrops to the list + // Add all the profiles to the list if (types.contains(ArtworkType.PROFILE)) { updateArtworkType(profiles, ArtworkType.PROFILE); artwork.addAll(profiles); diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java index a50a3e4ff..3a64526e1 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCollectionsTest.java @@ -21,7 +21,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.model2.collection.CollectionInfo; import com.omertron.themoviedbapi.results.TmdbResultsList; import org.junit.AfterClass; diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java index 828efd858..c0a3c2140 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java @@ -22,7 +22,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model.AlternativeTitle; -import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.MovieDb; import com.omertron.themoviedbapi.model.MovieList; diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java index deac5be78..645a72cc0 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java @@ -21,14 +21,25 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.Artwork; -import com.omertron.themoviedbapi.model.person.Person; +import com.omertron.themoviedbapi.TestID; +import com.omertron.themoviedbapi.enumeration.ArtworkType; +import com.omertron.themoviedbapi.model2.artwork.Artwork; +import com.omertron.themoviedbapi.model2.artwork.ArtworkMedia; +import com.omertron.themoviedbapi.model2.person.CreditMovieBasic; +import com.omertron.themoviedbapi.model2.person.CreditTVBasic; +import com.omertron.themoviedbapi.model2.person.ExternalID; +import com.omertron.themoviedbapi.model2.person.Person; +import com.omertron.themoviedbapi.model2.person.PersonCredits; import com.omertron.themoviedbapi.results.TmdbResultsList; +import java.util.ArrayList; +import java.util.List; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; import org.junit.After; import org.junit.AfterClass; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.junit.Before; @@ -45,6 +56,7 @@ public class TmdbPeopleTest extends AbstractTests { private static final int ID_BRUCE_WILLIS = 62; private static final int ID_SEAN_BEAN = 48; private static final int ID_DICK_WOLF = 117443; + private static final List testIDs = new ArrayList(); public TmdbPeopleTest() { } @@ -53,6 +65,8 @@ public class TmdbPeopleTest extends AbstractTests { public static void setUpClass() throws MovieDbException { doConfiguration(); instance = new TmdbPeople(getApiKey(), getHttpTools()); + testIDs.add(new TestID("Bruce Willis", "nm0000246", 62)); + testIDs.add(new TestID("Will Smith", "nm0000226", 2888)); } @AfterClass @@ -75,33 +89,150 @@ public class TmdbPeopleTest extends AbstractTests { // @Test public void testGetPersonInfo() throws MovieDbException { LOG.info("getPersonInfo"); - Person result = instance.getPersonInfo(ID_BRUCE_WILLIS); - assertTrue("Wrong actor returned", result.getId() == ID_BRUCE_WILLIS); - assertTrue("Missing bio", StringUtils.isNotBlank(result.getBiography())); - assertTrue("Missing birthday", StringUtils.isNotBlank(result.getBirthday())); - assertTrue("Missing homepage", StringUtils.isNotBlank(result.getHomepage())); - assertTrue("Missing IMDB", StringUtils.isNotBlank(result.getImdbId())); - assertTrue("Missing name", StringUtils.isNotBlank(result.getName())); - assertTrue("Missing birth place", StringUtils.isNotBlank(result.getBirthplace())); - assertTrue("Missing artwork", StringUtils.isNotBlank(result.getProfilePath())); - assertTrue("Missing bio", result.getPopularity() > 0F); + Person result; + + for (TestID test : testIDs) { + result = instance.getPersonInfo(test.getTmdb()); + assertEquals("Wrong actor returned", test.getTmdb(), result.getId()); + assertTrue("Missing bio", StringUtils.isNotBlank(result.getBiography())); + assertTrue("Missing birthday", StringUtils.isNotBlank(result.getBirthday())); + assertTrue("Missing homepage", StringUtils.isNotBlank(result.getHomepage())); + assertEquals("Missing IMDB", test.getImdb(), result.getImdbId()); + assertTrue("Missing name", StringUtils.isNotBlank(result.getName())); + assertTrue("Missing birth place", StringUtils.isNotBlank(result.getPlaceOfBirth())); + assertTrue("Missing artwork", StringUtils.isNotBlank(result.getProfilePath())); + assertTrue("Missing bio", result.getPopularity() > 0F); + } } /** - * Test of getPersonMovieOldImages method, of class TheMovieDbApi. + * Test of getPersonMovieCredits method, of class TmdbPeople. * - * @throws MovieDbException + * @throws com.omertron.themoviedbapi.MovieDbException + */ +// @Test + public void testGetPersonMovieCredits() throws MovieDbException { + LOG.info("getPersonMovieCredits"); + String language = LANGUAGE_DEFAULT; + String[] appendToResponse = null; + + for (TestID test : testIDs) { + PersonCredits result = instance.getPersonMovieCredits(test.getTmdb(), language, appendToResponse); + LOG.info("ID: {}, # Cast: {}, # Crew: {}", result.getId(), result.getCast().size(), result.getCrew().size()); + assertEquals("Incorrect ID", test.getTmdb(), result.getId()); + assertFalse("No cast", result.getCast().isEmpty()); + assertFalse("No crew", result.getCrew().isEmpty()); + } + } + + /** + * Test of getPersonTVCredits method, of class TmdbPeople. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ +// @Test + public void testGetPersonTVCredits() throws MovieDbException { + LOG.info("getPersonTVCredits"); + String language = LANGUAGE_DEFAULT; + String[] appendToResponse = null; + + for (TestID test : testIDs) { + PersonCredits result = instance.getPersonTVCredits(test.getTmdb(), language, appendToResponse); + LOG.info("ID: {}, # Cast: {}, # Crew: {}", result.getId(), result.getCast().size(), result.getCrew().size()); + assertEquals("Incorrect ID", test.getTmdb(), result.getId()); + assertFalse("No cast", result.getCast().isEmpty()); + assertFalse("No crew", result.getCrew().isEmpty()); + } + } + + /** + * Test of getPersonCombinedCredits method, of class TmdbPeople. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ +// @Test + public void testGetPersonCombinedCredits() throws MovieDbException { + LOG.info("getPersonCombinedCredits"); + String language = LANGUAGE_DEFAULT; + String[] appendToResponse = null; + + for (TestID test : testIDs) { + PersonCredits result = instance.getPersonCombinedCredits(test.getTmdb(), language, appendToResponse); + LOG.info("ID: {}, # Cast: {}, # Crew: {}", result.getId(), result.getCast().size(), result.getCrew().size()); + assertEquals("Incorrect ID", test.getTmdb(), result.getId()); + assertFalse("No cast", result.getCast().isEmpty()); + assertFalse("No crew", result.getCrew().isEmpty()); + } + fail("Not working"); + } + + /** + * Test of getPersonExternalIds method, of class TmdbPeople. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ +// @Test + public void testGetPersonExternalIds() throws MovieDbException { + LOG.info("getPersonExternalIds"); + + for (TestID test : testIDs) { + ExternalID result = instance.getPersonExternalIds(test.getTmdb()); + assertEquals("Wrong IMDB ID", test.getImdb(), result.getImdbId()); + } + } + + /** + * Test of getPersonImages method, of class TmdbPeople. + * + * @throws com.omertron.themoviedbapi.MovieDbException */ // @Test public void testGetPersonImages() throws MovieDbException { LOG.info("getPersonImages"); - TmdbResultsList result = instance.getPersonImages(ID_BRUCE_WILLIS); - assertTrue("No cast information", result.getResults().size() > 0); - for (Artwork artwork : result.getResults()) { - assertTrue("Artwork is blank", StringUtils.isNotBlank(artwork.getFilePath())); + for (TestID test : testIDs) { + TmdbResultsList result = instance.getPersonImages(test.getTmdb()); + assertFalse("No artwork", result.isEmpty()); + assertEquals("Wrong artwork type", ArtworkType.PROFILE, result.getResults().get(0).getArtworkType()); } + } + /** + * Test of getPersonTaggedImages method, of class TmdbPeople. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ +// @Test + public void testGetPersonTaggedImages() throws MovieDbException { + LOG.info("getPersonTaggedImages"); + Integer page = null; + String language = LANGUAGE_DEFAULT; + + for (TestID test : testIDs) { + TmdbResultsList result = instance.getPersonTaggedImages(test.getTmdb(), page, language); + for (ArtworkMedia am : result.getResults()) { + LOG.info("{}", ToStringBuilder.reflectionToString(am, ToStringStyle.DEFAULT_STYLE)); + } + } + } + + /** + * Test of getPersonChanges method, of class TmdbPeople. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + //@Test + public void testGetPersonChanges() throws MovieDbException { + LOG.info("getPersonChanges"); + int persondId = 0; + String startDate = ""; + String endDate = ""; + + TmdbResultsList expResult = null; + TmdbResultsList result = instance.getPersonChanges(persondId, startDate, endDate); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); } /** @@ -112,9 +243,12 @@ public class TmdbPeopleTest extends AbstractTests { @Test public void testGetPersonPopular() throws MovieDbException { LOG.info("getPersonPopular"); - int page = 0; + Integer page = null; + + TmdbResultsList expResult = null; TmdbResultsList result = instance.getPersonPopular(page); - assertFalse("No popular people", result.getResults().isEmpty()); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); } @@ -123,14 +257,14 @@ public class TmdbPeopleTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test +// @Test public void testGetPersonLatest() throws MovieDbException { LOG.info("getPersonLatest"); + Person expResult = null; Person result = instance.getPersonLatest(); - - assertNotNull("No results found", result); - assertTrue("No results found", StringUtils.isNotBlank(result.getName())); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. fail("The test case is a prototype."); } From 7c193d996bef47c90acbb4b5dfa9d35a8d14d95f Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Sun, 1 Mar 2015 21:53:32 +0000 Subject: [PATCH 044/100] partial --- .../themoviedbapi/methods/TmdbFind.java | 4 +--- .../themoviedbapi/methods/TmdbPeople.java | 18 +++++++++------- .../themoviedbapi/model2/MediaTypeMixIn.java | 4 +++- .../model2/person/PersonFind.java | 21 ++++++++++++++++++- .../themoviedbapi/methods/TmdbFindTest.java | 4 ++-- .../themoviedbapi/methods/TmdbPeopleTest.java | 19 ++++++++++------- 6 files changed, 47 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java index 6fc6c702c..43ea08827 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbFind.java @@ -22,8 +22,6 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.ExternalSource; import com.omertron.themoviedbapi.model2.FindResults; -import com.omertron.themoviedbapi.model2.MediaBasic; -import com.omertron.themoviedbapi.model2.MediaTypeMixIn; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; @@ -48,7 +46,7 @@ public class TmdbFind extends AbstractMethod { */ public TmdbFind(String apiKey, HttpTools httpTools) { super(apiKey, httpTools); - MAPPER.addMixIn(MediaBasic.class, MediaTypeMixIn.class); +// MAPPER.addMixIn(MediaBasic.class, MediaTypeMixIn.class); } /** diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java index c0b46b2e2..1a2639493 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java @@ -29,6 +29,7 @@ import com.omertron.themoviedbapi.model2.person.CreditTVBasic; import com.omertron.themoviedbapi.model2.person.ExternalID; import com.omertron.themoviedbapi.model2.person.Person; import com.omertron.themoviedbapi.model2.person.PersonCredits; +import com.omertron.themoviedbapi.model2.person.PersonFind; import com.omertron.themoviedbapi.results.TmdbResultsList; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; @@ -38,7 +39,6 @@ import com.omertron.themoviedbapi.tools.Param; import com.omertron.themoviedbapi.tools.TmdbParameters; import com.omertron.themoviedbapi.wrapper.WrapperGenericList; import com.omertron.themoviedbapi.wrapper.WrapperImages; -import com.omertron.themoviedbapi.wrapper.WrapperPersonList; import java.io.IOException; import java.net.URL; import org.yamj.api.common.exception.ApiExceptionType; @@ -277,21 +277,23 @@ public class TmdbPeople extends AbstractMethod { * @return * @throws MovieDbException */ - public TmdbResultsList getPersonPopular(Integer page) throws MovieDbException { + public TmdbResultsList getPersonPopular(Integer page) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.PAGE, page); URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.POPULAR).buildUrl(parameters); String webpage = httpTools.getRequest(url); + WrapperGenericList wrapper; try { - WrapperPersonList wrapper = MAPPER.readValue(webpage, WrapperPersonList.class); -// TmdbResultsList results = new TmdbResultsList(wrapper.getPersonList()); -// results.copyWrapper(wrapper); -// return results; - return null; + TypeReference tr = new TypeReference>() { + }; + wrapper = MAPPER.readValue(webpage, tr); + TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); + results.copyWrapper(wrapper); + return results; } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get popular person", url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get tagged images", url, ex); } } diff --git a/src/main/java/com/omertron/themoviedbapi/model2/MediaTypeMixIn.java b/src/main/java/com/omertron/themoviedbapi/model2/MediaTypeMixIn.java index f74bd886d..1a169baa7 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/MediaTypeMixIn.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/MediaTypeMixIn.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.omertron.themoviedbapi.model2.movie.MovieBasic; import com.omertron.themoviedbapi.model2.tv.TVBasic; +import com.omertron.themoviedbapi.model2.tv.TVEpisodeBasic; @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, @@ -13,7 +14,8 @@ import com.omertron.themoviedbapi.model2.tv.TVBasic; ) @JsonSubTypes({ @JsonSubTypes.Type(value = MovieBasic.class, name = "movie"), - @JsonSubTypes.Type(value = TVBasic.class, name = "tv") + @JsonSubTypes.Type(value = TVBasic.class, name = "tv"), + @JsonSubTypes.Type(value = TVEpisodeBasic.class, name = "episode") }) public class MediaTypeMixIn { diff --git a/src/main/java/com/omertron/themoviedbapi/model2/person/PersonFind.java b/src/main/java/com/omertron/themoviedbapi/model2/person/PersonFind.java index 506a972c0..cbf3a9484 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/person/PersonFind.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/person/PersonFind.java @@ -20,7 +20,13 @@ package com.omertron.themoviedbapi.model2.person; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.omertron.themoviedbapi.model2.MediaBasic; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; +import com.omertron.themoviedbapi.model2.tv.TVBasic; +import com.omertron.themoviedbapi.model2.tv.TVEpisodeBasic; import java.util.List; /** @@ -35,7 +41,7 @@ public class PersonFind extends PersonBasic { private Float popularity; @JsonProperty("profile_path") private String profilePath; - @JsonProperty("known_for") +// @JsonProperty("known_for") private List knownFor; public Boolean getAdult() { @@ -66,6 +72,19 @@ public class PersonFind extends PersonBasic { return knownFor; } + @JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, +// include = JsonTypeInfo.As.EXTERNAL_PROPERTY, + include = JsonTypeInfo.As.PROPERTY, + property = "media_type", + defaultImpl = MediaBasic.class + ) + @JsonSubTypes({ + @JsonSubTypes.Type(value = MovieBasic.class, name = "movie"), + @JsonSubTypes.Type(value = TVBasic.class, name = "tv"), + @JsonSubTypes.Type(value = TVEpisodeBasic.class, name = "episode") + }) + @JsonSetter("known_for") public void setKnownFor(List knownFor) { this.knownFor = knownFor; } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java index cf7b3faa3..2c9d78b50 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java @@ -84,7 +84,7 @@ public class TmdbFindTest extends AbstractTests { * * @throws MovieDbException */ -// @Test + @Test public void testFindMoviesImdbID() throws MovieDbException { LOG.info("findMoviesImdbID"); FindResults result; @@ -109,7 +109,7 @@ public class TmdbFindTest extends AbstractTests { * @throws MovieDbException * @throws IOException */ -// @Test + @Test public void testFindPersonImdbID() throws MovieDbException, IOException { LOG.info("findPersonImdbID"); FindResults result; diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java index 645a72cc0..39fd86041 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java @@ -23,6 +23,7 @@ import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.TestID; import com.omertron.themoviedbapi.enumeration.ArtworkType; +import com.omertron.themoviedbapi.model2.MediaBasic; import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.model2.artwork.ArtworkMedia; import com.omertron.themoviedbapi.model2.person.CreditMovieBasic; @@ -30,6 +31,7 @@ import com.omertron.themoviedbapi.model2.person.CreditTVBasic; import com.omertron.themoviedbapi.model2.person.ExternalID; import com.omertron.themoviedbapi.model2.person.Person; import com.omertron.themoviedbapi.model2.person.PersonCredits; +import com.omertron.themoviedbapi.model2.person.PersonFind; import com.omertron.themoviedbapi.results.TmdbResultsList; import java.util.ArrayList; import java.util.List; @@ -53,8 +55,6 @@ import org.junit.Test; public class TmdbPeopleTest extends AbstractTests { private static TmdbPeople instance; - private static final int ID_BRUCE_WILLIS = 62; - private static final int ID_SEAN_BEAN = 48; private static final int ID_DICK_WOLF = 117443; private static final List testIDs = new ArrayList(); @@ -244,12 +244,15 @@ public class TmdbPeopleTest extends AbstractTests { public void testGetPersonPopular() throws MovieDbException { LOG.info("getPersonPopular"); Integer page = null; - - TmdbResultsList expResult = null; - TmdbResultsList result = instance.getPersonPopular(page); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); + TmdbResultsList result = instance.getPersonPopular(page); + assertFalse("No results", result.isEmpty()); + assertTrue("No results", result.getResults().size() > 0); + for (PersonFind p : result.getResults()) { + LOG.info("{} ({}) = {}", p.getName(), p.getId(), p.getKnownFor().size()); + for (MediaBasic k : p.getKnownFor()) { + LOG.info(" {}", k.toString()); + } + } } /** From 9c473bf24ba0784fab2edb52a3664ed805b37c90 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 2 Mar 2015 13:10:06 +0000 Subject: [PATCH 045/100] Update tests --- .../omertron/themoviedbapi/TheMovieDbApi.java | 46 +++++++++---------- .../methods/TmdbConfigurationTest.java | 6 +-- .../methods/TmdbDiscoverTest.java | 2 +- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 0ae73f0a3..a774036e2 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -19,7 +19,10 @@ */ package com.omertron.themoviedbapi; +import com.omertron.themoviedbapi.enumeration.ExternalSource; import com.omertron.themoviedbapi.enumeration.MediaType; +import com.omertron.themoviedbapi.enumeration.SearchType; +import com.omertron.themoviedbapi.enumeration.SortBy; import com.omertron.themoviedbapi.methods.TmdbAccount; import com.omertron.themoviedbapi.methods.TmdbAuthentication; import com.omertron.themoviedbapi.methods.TmdbCertifications; @@ -39,40 +42,37 @@ import com.omertron.themoviedbapi.methods.TmdbPeople; import com.omertron.themoviedbapi.methods.TmdbReviews; import com.omertron.themoviedbapi.methods.TmdbSearch; import com.omertron.themoviedbapi.methods.TmdbTV; -import com.omertron.themoviedbapi.model2.account.Account; import com.omertron.themoviedbapi.model.AlternativeTitle; -import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.model.Certification; +import com.omertron.themoviedbapi.model.Genre; +import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.model.MovieList; +import com.omertron.themoviedbapi.model.ReleaseInfo; +import com.omertron.themoviedbapi.model.Translation; +import com.omertron.themoviedbapi.model.Video; import com.omertron.themoviedbapi.model.change.ChangedMedia; +import com.omertron.themoviedbapi.model.keyword.Keyword; +import com.omertron.themoviedbapi.model.keyword.KeywordMovie; +import com.omertron.themoviedbapi.model.person.Person; +import com.omertron.themoviedbapi.model2.FindResults; +import com.omertron.themoviedbapi.model2.StatusCode; +import com.omertron.themoviedbapi.model2.account.Account; +import com.omertron.themoviedbapi.model2.artwork.Artwork; +import com.omertron.themoviedbapi.model2.authentication.TokenAuthorisation; +import com.omertron.themoviedbapi.model2.authentication.TokenSession; import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.collection.CollectionInfo; import com.omertron.themoviedbapi.model2.company.Company; import com.omertron.themoviedbapi.model2.config.Configuration; -import com.omertron.themoviedbapi.model2.discover.Discover; -import com.omertron.themoviedbapi.model.Genre; import com.omertron.themoviedbapi.model2.config.JobDepartment; -import com.omertron.themoviedbapi.model.keyword.Keyword; -import com.omertron.themoviedbapi.model.keyword.KeywordMovie; -import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.model2.discover.Discover; import com.omertron.themoviedbapi.model2.list.ListItem; -import com.omertron.themoviedbapi.model.MovieList; -import com.omertron.themoviedbapi.model.person.Person; -import com.omertron.themoviedbapi.model.ReleaseInfo; -import com.omertron.themoviedbapi.model2.review.Review; -import com.omertron.themoviedbapi.model2.StatusCode; -import com.omertron.themoviedbapi.enumeration.ExternalSource; -import com.omertron.themoviedbapi.enumeration.SearchType; -import com.omertron.themoviedbapi.enumeration.SortBy; -import com.omertron.themoviedbapi.model2.FindResults; +import com.omertron.themoviedbapi.model2.list.UserList; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; import com.omertron.themoviedbapi.model2.network.Network; import com.omertron.themoviedbapi.model2.person.CreditInfo; -import com.omertron.themoviedbapi.model2.authentication.TokenAuthorisation; -import com.omertron.themoviedbapi.model2.authentication.TokenSession; -import com.omertron.themoviedbapi.model.Translation; -import com.omertron.themoviedbapi.model.Video; -import com.omertron.themoviedbapi.model2.movie.MovieBasic; +import com.omertron.themoviedbapi.model2.review.Review; import com.omertron.themoviedbapi.model2.tv.TVBasic; -import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.results.TmdbResultsList; import com.omertron.themoviedbapi.results.TmdbResultsMap; import com.omertron.themoviedbapi.tools.HttpTools; @@ -1155,7 +1155,7 @@ public class TheMovieDbApi { // - null; + //TODO: Methods here // diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbConfigurationTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbConfigurationTest.java index 324e34800..f7e06ce9e 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbConfigurationTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbConfigurationTest.java @@ -70,7 +70,7 @@ public class TmdbConfigurationTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ -// @Test + @Test public void testGetConfig() throws MovieDbException { LOG.info("getConfig"); Configuration result = instance.getConfig(); @@ -88,7 +88,7 @@ public class TmdbConfigurationTest extends AbstractTests { * * @throws MovieDbException */ -// @Test + @Test public void testCreateImageUrl() throws MovieDbException { LOG.info("createImageUrl"); Configuration config = instance.getConfig(); @@ -102,7 +102,7 @@ public class TmdbConfigurationTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ -// @Test + @Test public void testGetJobs() throws MovieDbException { LOG.info("getJobs"); TmdbResultsList result = instance.getJobs(); diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbDiscoverTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbDiscoverTest.java index e99443916..2462d02c2 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbDiscoverTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbDiscoverTest.java @@ -66,7 +66,7 @@ public class TmdbDiscoverTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ -// @Test + @Test public void testGetDiscoverMovie() throws MovieDbException { LOG.info("getDiscoverMovie"); Discover discover = new Discover(); From c93600fff55a69fa63886a38705b656c6860edd2 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 2 Mar 2015 13:35:36 +0000 Subject: [PATCH 046/100] Remove generic TypeReference builder --- .../themoviedbapi/methods/AbstractMethod.java | 23 +++++++++++------ .../themoviedbapi/methods/TmdbAccount.java | 20 +++++++-------- .../themoviedbapi/methods/TmdbCompanies.java | 2 +- .../themoviedbapi/methods/TmdbDiscover.java | 4 +-- .../themoviedbapi/methods/TmdbGenres.java | 2 +- .../themoviedbapi/methods/TmdbSearch.java | 11 +++----- .../methods/TmdbAccountTest.java | 25 ++++++++++--------- 7 files changed, 46 insertions(+), 41 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java index 71d25bdaf..05234d57a 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java @@ -22,14 +22,16 @@ package com.omertron.themoviedbapi.methods; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.model2.movie.MovieBasic; import com.omertron.themoviedbapi.model2.tv.TVBasic; -import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.wrapper.WrapperGenericList; import java.io.IOException; import java.net.URL; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.yamj.api.common.exception.ApiExceptionType; @@ -49,13 +51,20 @@ public class AbstractMethod { protected static final ObjectMapper MAPPER = new ObjectMapper(); // Logger protected static final Logger LOG = LoggerFactory.getLogger(TmdbAccount.class); - protected static final TypeReference> TR_MOVIE_BASIC = getTypeReference(MovieBasic.class); - protected static final TypeReference> TR_TV_BASIC = getTypeReference(TVBasic.class); - protected static final TypeReference> TR_USER_LIST = getTypeReference(UserList.class); - private static TypeReference getTypeReference(T Class) { - return new TypeReference>() { - }; + private static final Map TYPE_REFS = new HashMap(); + + static { + TYPE_REFS.put(MovieBasic.class, new TypeReference>() { + }); + TYPE_REFS.put(TVBasic.class, new TypeReference>() { + }); + TYPE_REFS.put(UserList.class, new TypeReference>() { + }); + } + + protected static TypeReference getTypeReference(Class aClass) { + return TYPE_REFS.get(aClass); } /** diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java index 1f6188dd6..19545d7dd 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java @@ -22,11 +22,11 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.MediaType; import com.omertron.themoviedbapi.enumeration.SortBy; -import com.omertron.themoviedbapi.model2.account.Account; import com.omertron.themoviedbapi.model2.StatusCode; +import com.omertron.themoviedbapi.model2.account.Account; +import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.model2.movie.MovieBasic; import com.omertron.themoviedbapi.model2.tv.TVBasic; -import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; @@ -92,7 +92,7 @@ public class TmdbAccount extends AbstractMethod { parameters.add(Param.ID, accountId); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.LISTS).buildUrl(parameters); - return processWrapperList(TR_USER_LIST, url, "user list"); + return processWrapperList(getTypeReference(UserList.class), url, "user list"); } /** @@ -109,7 +109,7 @@ public class TmdbAccount extends AbstractMethod { parameters.add(Param.ID, accountId); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.FAVORITE_MOVIES).buildUrl(parameters); - return processWrapperList(TR_MOVIE_BASIC, url, "favorite movies"); + return processWrapperList(getTypeReference(MovieBasic.class), url, "favorite movies"); } /** @@ -126,7 +126,7 @@ public class TmdbAccount extends AbstractMethod { parameters.add(Param.ID, accountId); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.FAVORITE_TV).buildUrl(parameters); - return processWrapperList(TR_TV_BASIC, url, "favorite TV shows"); + return processWrapperList(getTypeReference(TVBasic.class), url, "favorite TV shows"); } /** @@ -181,7 +181,7 @@ public class TmdbAccount extends AbstractMethod { parameters.add(Param.LANGUAGE, language); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.RATED_MOVIES).buildUrl(parameters); - return processWrapperList(TR_MOVIE_BASIC, url, "rated movies"); + return processWrapperList(getTypeReference(MovieBasic.class), url, "rated movies"); } /** @@ -204,7 +204,7 @@ public class TmdbAccount extends AbstractMethod { parameters.add(Param.LANGUAGE, language); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.RATED_TV).buildUrl(parameters); - return processWrapperList(TR_TV_BASIC, url, "rated TV shows"); + return processWrapperList(getTypeReference(TVBasic.class), url, "rated TV shows"); } /** @@ -227,7 +227,7 @@ public class TmdbAccount extends AbstractMethod { parameters.add(Param.LANGUAGE, language); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.WATCHLIST_MOVIES).buildUrl(parameters); - return processWrapperList(TR_MOVIE_BASIC, url, "movie watch list"); + return processWrapperList(getTypeReference(MovieBasic.class), url, "movie watch list"); } /** @@ -250,7 +250,7 @@ public class TmdbAccount extends AbstractMethod { parameters.add(Param.LANGUAGE, language); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.WATCHLIST_TV).buildUrl(parameters); - return processWrapperList(TR_TV_BASIC, url, "TV watch list"); + return processWrapperList(getTypeReference(TVBasic.class), url, "TV watch list"); } /** @@ -306,6 +306,6 @@ public class TmdbAccount extends AbstractMethod { } URL url = new ApiUrl(apiKey, MethodBase.GUEST_SESSION).setSubMethod(MethodSub.RATED_MOVIES_GUEST).buildUrl(parameters); - return processWrapperList(TR_MOVIE_BASIC, url, "Guest Session Movies"); + return processWrapperList(getTypeReference(MovieBasic.class), url, "Guest Session Movies"); } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java index d03571ccd..bee2aa559 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCompanies.java @@ -92,7 +92,7 @@ public class TmdbCompanies extends AbstractMethod { URL url = new ApiUrl(apiKey, MethodBase.COMPANY).setSubMethod(MethodSub.MOVIES).buildUrl(parameters); String webpage = httpTools.getRequest(url); - return processWrapperList(TR_MOVIE_BASIC, url, webpage); + return processWrapperList(getTypeReference(MovieBasic.class), url, webpage); } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbDiscover.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbDiscover.java index 44313a679..48d1e8209 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbDiscover.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbDiscover.java @@ -57,7 +57,7 @@ public class TmdbDiscover extends AbstractMethod { public List getDiscoverMovies(Discover discover) throws MovieDbException { URL url = new ApiUrl(apiKey, MethodBase.DISCOVER).setSubMethod(MethodSub.MOVIE).buildUrl(discover.getParams()); String webpage = httpTools.getRequest(url); - return processWrapperList(TR_MOVIE_BASIC, url, webpage); + return processWrapperList(getTypeReference(MovieBasic.class), url, webpage); } /** @@ -70,6 +70,6 @@ public class TmdbDiscover extends AbstractMethod { public List getDiscoverTV(Discover discover) throws MovieDbException { URL url = new ApiUrl(apiKey, MethodBase.DISCOVER).setSubMethod(MethodSub.TV).buildUrl(discover.getParams()); String webpage = httpTools.getRequest(url); - return processWrapperList(TR_TV_BASIC, url, webpage); + return processWrapperList(getTypeReference(TVBasic.class), url, webpage); } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbGenres.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbGenres.java index 3937ec2cf..4c860b5df 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbGenres.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbGenres.java @@ -122,6 +122,6 @@ public class TmdbGenres extends AbstractMethod { URL url = new ApiUrl(apiKey, MethodBase.GENRE).setSubMethod(MethodSub.MOVIES).buildUrl(parameters); String webpage = httpTools.getRequest(url); - return processWrapperList(TR_MOVIE_BASIC, url, webpage); + return processWrapperList(getTypeReference(MovieBasic.class), url, webpage); } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java index e8c24d0dd..6ad84b4a8 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java @@ -19,14 +19,13 @@ */ package com.omertron.themoviedbapi.methods; -import com.fasterxml.jackson.core.type.TypeReference; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.SearchType; +import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.model.keyword.Keyword; +import com.omertron.themoviedbapi.model.person.Person; import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.company.Company; -import com.omertron.themoviedbapi.model.keyword.Keyword; -import com.omertron.themoviedbapi.model.MovieDb; -import com.omertron.themoviedbapi.model.person.Person; import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.model2.tv.TVBasic; import com.omertron.themoviedbapi.results.TmdbResultsList; @@ -265,8 +264,4 @@ public class TmdbSearch extends AbstractMethod { return results; } - private static TypeReference getTypeReference(T Class) { - return new TypeReference>() { - }; - } } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java index 1da8fadc3..16e8bc85e 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java @@ -23,12 +23,12 @@ import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.MediaType; import com.omertron.themoviedbapi.enumeration.SortBy; -import com.omertron.themoviedbapi.model2.account.Account; import com.omertron.themoviedbapi.model2.StatusCode; +import com.omertron.themoviedbapi.model2.account.Account; import com.omertron.themoviedbapi.model2.authentication.TokenSession; +import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.model2.movie.MovieBasic; import com.omertron.themoviedbapi.model2.tv.TVBasic; -import com.omertron.themoviedbapi.model2.list.UserList; import java.util.List; import org.junit.After; import org.junit.AfterClass; @@ -39,6 +39,7 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; /** @@ -78,7 +79,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + @Ignore public void testGetAccount() throws MovieDbException { LOG.info("getAccount"); Account result = instance.getAccount(getSessionId()); @@ -92,7 +93,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + @Ignore public void testGetUserLists() throws MovieDbException { LOG.info("getUserLists"); List results = instance.getUserLists(getSessionId(), getAccountId()); @@ -108,7 +109,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + @Ignore public void testGetFavoriteMovies() throws MovieDbException { LOG.info("getFavoriteMovies"); List results = instance.getFavoriteMovies(getSessionId(), getAccountId()); @@ -124,7 +125,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + @Ignore public void testGetFavoriteTv() throws MovieDbException { LOG.info("getFavoriteTv"); List results = instance.getFavoriteTv(getSessionId(), getAccountId()); @@ -140,7 +141,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + @Ignore public void testModifyFavoriteStatus() throws MovieDbException { LOG.info("modifyFavoriteStatus"); @@ -170,7 +171,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + @Ignore public void testGetRatedMovies() throws MovieDbException { LOG.info("getRatedMovies"); List results = instance.getRatedMovies(getSessionId(), getAccountId(), null, null, null); @@ -183,7 +184,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + @Ignore public void testGetRatedTV() throws MovieDbException { LOG.info("getRatedTV"); List results = instance.getRatedTV(getSessionId(), getAccountId(), null, null, null); @@ -199,7 +200,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + @Ignore public void testGetWatchListMovie() throws MovieDbException { LOG.info("getWatchListMovie"); List results = instance.getWatchListMovie(getSessionId(), getAccountId(), null, null, null); @@ -231,7 +232,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + @Ignore public void testModifyWatchList() throws MovieDbException { LOG.info("modifyWatchList"); @@ -261,7 +262,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + @Ignore public void testGetGuestRatedMovies() throws MovieDbException { LOG.info("getGuestRatedMovies"); From 4efc282eeddc0d26b41f14922b86882dc6394ca8 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 2 Mar 2015 13:37:20 +0000 Subject: [PATCH 047/100] Uncomment tests --- .../methods/TmdbAccountTest.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java index 16e8bc85e..b78efd4a1 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java @@ -39,7 +39,6 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.junit.Before; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; /** @@ -79,7 +78,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Ignore + @Test public void testGetAccount() throws MovieDbException { LOG.info("getAccount"); Account result = instance.getAccount(getSessionId()); @@ -93,7 +92,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Ignore + @Test public void testGetUserLists() throws MovieDbException { LOG.info("getUserLists"); List results = instance.getUserLists(getSessionId(), getAccountId()); @@ -109,7 +108,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Ignore + @Test public void testGetFavoriteMovies() throws MovieDbException { LOG.info("getFavoriteMovies"); List results = instance.getFavoriteMovies(getSessionId(), getAccountId()); @@ -125,7 +124,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Ignore + @Test public void testGetFavoriteTv() throws MovieDbException { LOG.info("getFavoriteTv"); List results = instance.getFavoriteTv(getSessionId(), getAccountId()); @@ -141,7 +140,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Ignore + @Test public void testModifyFavoriteStatus() throws MovieDbException { LOG.info("modifyFavoriteStatus"); @@ -171,7 +170,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Ignore + @Test public void testGetRatedMovies() throws MovieDbException { LOG.info("getRatedMovies"); List results = instance.getRatedMovies(getSessionId(), getAccountId(), null, null, null); @@ -184,7 +183,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Ignore + @Test public void testGetRatedTV() throws MovieDbException { LOG.info("getRatedTV"); List results = instance.getRatedTV(getSessionId(), getAccountId(), null, null, null); @@ -200,7 +199,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Ignore + @Test public void testGetWatchListMovie() throws MovieDbException { LOG.info("getWatchListMovie"); List results = instance.getWatchListMovie(getSessionId(), getAccountId(), null, null, null); @@ -232,7 +231,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Ignore + @Test public void testModifyWatchList() throws MovieDbException { LOG.info("modifyWatchList"); @@ -262,7 +261,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Ignore + @Test public void testGetGuestRatedMovies() throws MovieDbException { LOG.info("getGuestRatedMovies"); From 0143f31bbcd8e3333f79ca2e14b4ff0022ecbc9f Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 2 Mar 2015 15:46:07 +0000 Subject: [PATCH 048/100] Person --- .../omertron/themoviedbapi/TheMovieDbApi.java | 8 +- .../themoviedbapi/methods/TmdbChanges.java | 25 +++--- .../themoviedbapi/methods/TmdbPeople.java | 39 +++++--- .../model2/change/ChangeKeyItem.java | 51 +++++++++++ .../model2/change/ChangeListItem.java | 49 ++++++++++ .../model2/change/ChangedItem.java | 89 +++++++++++++++++++ .../themoviedbapi/wrapper/WrapperChanges.java | 19 +--- .../methods/TmdbChangesTest.java | 16 ++-- .../themoviedbapi/methods/TmdbPeopleTest.java | 56 +++++++----- 9 files changed, 277 insertions(+), 75 deletions(-) create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/change/ChangeKeyItem.java create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/change/ChangeListItem.java create mode 100644 src/main/java/com/omertron/themoviedbapi/model2/change/ChangedItem.java diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index a774036e2..5b0d9a9d4 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -50,7 +50,6 @@ import com.omertron.themoviedbapi.model.MovieList; import com.omertron.themoviedbapi.model.ReleaseInfo; import com.omertron.themoviedbapi.model.Translation; import com.omertron.themoviedbapi.model.Video; -import com.omertron.themoviedbapi.model.change.ChangedMedia; import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.keyword.KeywordMovie; import com.omertron.themoviedbapi.model.person.Person; @@ -60,6 +59,7 @@ import com.omertron.themoviedbapi.model2.account.Account; import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.model2.authentication.TokenAuthorisation; import com.omertron.themoviedbapi.model2.authentication.TokenSession; +import com.omertron.themoviedbapi.model2.change.ChangeListItem; import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.collection.CollectionInfo; import com.omertron.themoviedbapi.model2.company.Company; @@ -529,7 +529,7 @@ public class TheMovieDbApi { * @return List of changed movie * @throws MovieDbException */ - public TmdbResultsList getMovieChangeList(int page, String startDate, String endDate) throws MovieDbException { + public List getMovieChangeList(int page, String startDate, String endDate) throws MovieDbException { return tmdbChanges.getChangeList(MethodBase.MOVIE, page, startDate, endDate); } @@ -544,7 +544,7 @@ public class TheMovieDbApi { * @return List of changed movie * @throws MovieDbException */ - public TmdbResultsList getTvChangeList(int page, String startDate, String endDate) throws MovieDbException { + public List getTvChangeList(int page, String startDate, String endDate) throws MovieDbException { return tmdbChanges.getChangeList(MethodBase.TV, page, startDate, endDate); } @@ -559,7 +559,7 @@ public class TheMovieDbApi { * @return List of changed movie * @throws MovieDbException */ - public TmdbResultsList getPersonChangeList(int page, String startDate, String endDate) throws MovieDbException { + public List getPersonChangeList(int page, String startDate, String endDate) throws MovieDbException { return tmdbChanges.getChangeList(MethodBase.PERSON, page, startDate, endDate); } // diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbChanges.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbChanges.java index 66067077a..7869aface 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbChanges.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbChanges.java @@ -19,19 +19,18 @@ */ package com.omertron.themoviedbapi.methods; +import com.fasterxml.jackson.core.type.TypeReference; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.change.ChangedMedia; -import com.omertron.themoviedbapi.results.TmdbResultsList; +import com.omertron.themoviedbapi.model2.change.ChangeListItem; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; import com.omertron.themoviedbapi.tools.MethodSub; import com.omertron.themoviedbapi.tools.Param; import com.omertron.themoviedbapi.tools.TmdbParameters; -import com.omertron.themoviedbapi.wrapper.WrapperMediaChanges; -import java.io.IOException; +import com.omertron.themoviedbapi.wrapper.WrapperGenericList; import java.net.URL; -import org.yamj.api.common.exception.ApiExceptionType; +import java.util.List; /** * Class to hold the Change Methods @@ -53,7 +52,8 @@ public class TmdbChanges extends AbstractMethod { /** * Get a list of Media IDs that have been edited. * - * You can then use the movie/TV/person changes API to get the actual data that has been changed. + * You can then use the movie/TV/person changes API to get the actual data + * that has been changed. * * @param method The method base to get * @param page @@ -62,7 +62,7 @@ public class TmdbChanges extends AbstractMethod { * @return List of changed movie * @throws MovieDbException */ - public TmdbResultsList getChangeList(MethodBase method, Integer page, String startDate, String endDate) throws MovieDbException { + public List getChangeList(MethodBase method, Integer page, String startDate, String endDate) throws MovieDbException { TmdbParameters params = new TmdbParameters(); params.add(Param.PAGE, page); params.add(Param.START_DATE, startDate); @@ -71,15 +71,10 @@ public class TmdbChanges extends AbstractMethod { URL url = new ApiUrl(apiKey, method).setSubMethod(MethodSub.CHANGES).buildUrl(params); String webpage = httpTools.getRequest(url); - try { - WrapperMediaChanges wrapper = MAPPER.readValue(webpage, WrapperMediaChanges.class); + TypeReference tr = new TypeReference>() { + }; - TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); - results.copyWrapper(wrapper); - return results; - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get changes", url, ex); - } + return processWrapperList(tr, url, "changes"); } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java index 1a2639493..b23ea75fa 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java @@ -21,8 +21,8 @@ package com.omertron.themoviedbapi.methods; import com.fasterxml.jackson.core.type.TypeReference; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.enumeration.ArtworkType; +import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.model2.artwork.ArtworkMedia; import com.omertron.themoviedbapi.model2.person.CreditMovieBasic; import com.omertron.themoviedbapi.model2.person.CreditTVBasic; @@ -37,6 +37,7 @@ import com.omertron.themoviedbapi.tools.MethodBase; import com.omertron.themoviedbapi.tools.MethodSub; import com.omertron.themoviedbapi.tools.Param; import com.omertron.themoviedbapi.tools.TmdbParameters; +import com.omertron.themoviedbapi.wrapper.WrapperChanges; import com.omertron.themoviedbapi.wrapper.WrapperGenericList; import com.omertron.themoviedbapi.wrapper.WrapperImages; import java.io.IOException; @@ -112,9 +113,11 @@ public class TmdbPeople extends AbstractMethod { /** * Get the TV credits for a specific person id. * - * To get the expanded details for each record, call the /credit method with the provided credit_id. + * To get the expanded details for each record, call the /credit method with + * the provided credit_id. * - * This will provide details about which episode and/or season the credit is for. + * This will provide details about which episode and/or season the credit is + * for. * * @param personId * @param language @@ -142,9 +145,11 @@ public class TmdbPeople extends AbstractMethod { /** * Get the combined (movie and TV) credits for a specific person id. * - * To get the expanded details for each TV record, call the /credit method with the provided credit_id. + * To get the expanded details for each TV record, call the /credit method + * with the provided credit_id. * - * This will provide details about which episode and/or season the credit is for. + * This will provide details about which episode and/or season the credit is + * for. * * @param personId * @param language @@ -217,7 +222,8 @@ public class TmdbPeople extends AbstractMethod { /** * Get the images that have been tagged with a specific person id. * - * We return all of the image results with a media object mapped for each image. + * We return all of the image results with a media object mapped for each + * image. * * @param personId * @param page @@ -254,18 +260,31 @@ public class TmdbPeople extends AbstractMethod { * * 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. * - * @param persondId + * @param personId * @param startDate * @param endDate * @return * @throws com.omertron.themoviedbapi.MovieDbException */ - public TmdbResultsList getPersonChanges(int persondId, String startDate, String endDate) throws MovieDbException { - throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not done"); + public WrapperChanges getPersonChanges(int personId, String startDate, String endDate) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, personId); + parameters.add(Param.START_DATE, startDate); + parameters.add(Param.END_DATE, endDate); + + URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.CHANGES).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + return MAPPER.readValue(webpage, WrapperChanges.class); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person changes", url, ex); + } } /** diff --git a/src/main/java/com/omertron/themoviedbapi/model2/change/ChangeKeyItem.java b/src/main/java/com/omertron/themoviedbapi/model2/change/ChangeKeyItem.java new file mode 100644 index 000000000..62e32f6e4 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/change/ChangeKeyItem.java @@ -0,0 +1,51 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model2.change; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model2.AbstractJsonMapping; +import java.util.ArrayList; +import java.util.List; + +public class ChangeKeyItem extends AbstractJsonMapping { + + private static final long serialVersionUID = 1L; + @JsonProperty("key") + private String key; + @JsonProperty("items") + private List changedItems = new ArrayList(); + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public List getChangedItems() { + return changedItems; + } + + public void setChangedItems(List changes) { + this.changedItems = changes; + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/change/ChangeListItem.java b/src/main/java/com/omertron/themoviedbapi/model2/change/ChangeListItem.java new file mode 100644 index 000000000..5f7a8d04c --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/change/ChangeListItem.java @@ -0,0 +1,49 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model2.change; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model2.AbstractJsonMapping; + +public class ChangeListItem extends AbstractJsonMapping { + + private static final long serialVersionUID = 1L; + + @JsonProperty("id") + private int id; + @JsonProperty("adult") + private boolean adult; + + public int getId() { + return id; + } + + public boolean isAdult() { + return adult; + } + + public void setId(int id) { + this.id = id; + } + + public void setAdult(boolean adult) { + this.adult = adult; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model2/change/ChangedItem.java b/src/main/java/com/omertron/themoviedbapi/model2/change/ChangedItem.java new file mode 100644 index 000000000..7c4c58e37 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model2/change/ChangedItem.java @@ -0,0 +1,89 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model2.change; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model2.AbstractJsonMapping; + +public class ChangedItem extends AbstractJsonMapping { + + private static final long serialVersionUID = 1L; + @JsonProperty("id") + private String id; + @JsonProperty("action") + private String action; + @JsonProperty("time") + private String time; + @JsonProperty("iso_639_1") + private String language; + @JsonProperty("value") + private Object value; + @JsonProperty("original_value") + private Object originalValue; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getAction() { + return action; + } + + public void setAction(String action) { + this.action = action; + } + + public String getTime() { + return time; + } + + public void setTime(String time) { + this.time = time; + } + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } + + public Object getOriginalValue() { + return originalValue; + } + + public void setOriginalValue(Object originalValue) { + this.originalValue = originalValue; + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperChanges.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperChanges.java index 073a8dac0..e45751a55 100644 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperChanges.java +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperChanges.java @@ -19,22 +19,17 @@ */ package com.omertron.themoviedbapi.wrapper; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonProperty; -import com.omertron.themoviedbapi.model.change.ChangeKeyItem; +import com.omertron.themoviedbapi.model2.change.ChangeKeyItem; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; -public class WrapperChanges { +public class WrapperChanges extends AbstractWrapper{ @JsonProperty("changes") private List changedItems = new ArrayList(); - private final Map newItems = new HashMap(); public List getChangedItems() { return changedItems; @@ -44,16 +39,6 @@ public class WrapperChanges { this.changedItems = changes; } - @JsonAnyGetter - public Map getNewItems() { - return this.newItems; - } - - @JsonAnySetter - public void setNewItems(String name, Object value) { - this.newItems.put(name, value); - } - @Override public String toString() { return ToStringBuilder.reflectionToString(this, ToStringStyle.DEFAULT_STYLE); diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbChangesTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbChangesTest.java index ca539e21e..51443a2b4 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbChangesTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbChangesTest.java @@ -21,9 +21,9 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.change.ChangedMedia; -import com.omertron.themoviedbapi.results.TmdbResultsList; +import com.omertron.themoviedbapi.model2.change.ChangeListItem; import com.omertron.themoviedbapi.tools.MethodBase; +import java.util.List; import org.junit.AfterClass; import static org.junit.Assert.assertFalse; import org.junit.BeforeClass; @@ -60,8 +60,8 @@ public class TmdbChangesTest extends AbstractTests { @Test public void testGetMovieChangesList() throws MovieDbException { LOG.info("getMovieChangesList"); - TmdbResultsList result = instance.getChangeList(MethodBase.MOVIE, null, null, null); - assertFalse("No movie changes.", result.getResults().isEmpty()); + List result = instance.getChangeList(MethodBase.MOVIE, null, null, null); + assertFalse("No movie changes.", result.isEmpty()); } /** @@ -72,8 +72,8 @@ public class TmdbChangesTest extends AbstractTests { @Ignore("Not ready yet") public void testGetPersonChangesList() throws MovieDbException { LOG.info("getPersonChangesList"); - TmdbResultsList result = instance.getChangeList(MethodBase.PERSON, null, null, null); - assertFalse("No Person changes.", result.getResults().isEmpty()); + List result = instance.getChangeList(MethodBase.PERSON, null, null, null); + assertFalse("No Person changes.", result.isEmpty()); } /** @@ -84,7 +84,7 @@ public class TmdbChangesTest extends AbstractTests { @Ignore("Not ready yet") public void testGetTVChangesList() throws MovieDbException { LOG.info("getPersonChangesList"); - TmdbResultsList result = instance.getChangeList(MethodBase.PERSON, null, null, null); - assertFalse("No TV changes.", result.getResults().isEmpty()); + List result = instance.getChangeList(MethodBase.PERSON, null, null, null); + assertFalse("No TV changes.", result.isEmpty()); } } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java index 39fd86041..268623f4b 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java @@ -23,9 +23,10 @@ import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.TestID; import com.omertron.themoviedbapi.enumeration.ArtworkType; -import com.omertron.themoviedbapi.model2.MediaBasic; import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.model2.artwork.ArtworkMedia; +import com.omertron.themoviedbapi.model2.change.ChangeKeyItem; +import com.omertron.themoviedbapi.model2.change.ChangeListItem; import com.omertron.themoviedbapi.model2.person.CreditMovieBasic; import com.omertron.themoviedbapi.model2.person.CreditTVBasic; import com.omertron.themoviedbapi.model2.person.ExternalID; @@ -33,15 +34,19 @@ import com.omertron.themoviedbapi.model2.person.Person; import com.omertron.themoviedbapi.model2.person.PersonCredits; import com.omertron.themoviedbapi.model2.person.PersonFind; import com.omertron.themoviedbapi.results.TmdbResultsList; +import com.omertron.themoviedbapi.tools.MethodBase; +import com.omertron.themoviedbapi.wrapper.WrapperChanges; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.List; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; +import org.apache.commons.lang3.time.DateUtils; import org.junit.After; import org.junit.AfterClass; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import org.junit.Before; @@ -55,7 +60,6 @@ import org.junit.Test; public class TmdbPeopleTest extends AbstractTests { private static TmdbPeople instance; - private static final int ID_DICK_WOLF = 117443; private static final List testIDs = new ArrayList(); public TmdbPeopleTest() { @@ -210,8 +214,10 @@ public class TmdbPeopleTest extends AbstractTests { for (TestID test : testIDs) { TmdbResultsList result = instance.getPersonTaggedImages(test.getTmdb(), page, language); + assertFalse("No images", result.isEmpty()); for (ArtworkMedia am : result.getResults()) { - LOG.info("{}", ToStringBuilder.reflectionToString(am, ToStringStyle.DEFAULT_STYLE)); + assertTrue("No ID", StringUtils.isNotBlank(am.getId())); + assertTrue("No file path", StringUtils.isNotBlank(am.getFilePath())); } } } @@ -221,18 +227,30 @@ public class TmdbPeopleTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - //@Test + @Test public void testGetPersonChanges() throws MovieDbException { LOG.info("getPersonChanges"); - int persondId = 0; - String startDate = ""; + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + String startDate = sdf.format(DateUtils.addDays(new Date(), -14)); String endDate = ""; + int maxCheck = 5; - TmdbResultsList expResult = null; - TmdbResultsList result = instance.getPersonChanges(persondId, startDate, endDate); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); + TmdbChanges chgs = new TmdbChanges(getApiKey(), getHttpTools()); + List changeList = chgs.getChangeList(MethodBase.PERSON, null, null, null); + LOG.info("Found {} person changes to check", changeList.size()); + + int count = 1; + WrapperChanges result; + for (ChangeListItem item : changeList) { + result = instance.getPersonChanges(item.getId(), startDate, endDate); + for (ChangeKeyItem ci : result.getChangedItems()) { + assertNotNull("Null changes",ci); + } + + if (count++ > maxCheck) { + break; + } + } } /** @@ -240,7 +258,7 @@ public class TmdbPeopleTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test +// @Test public void testGetPersonPopular() throws MovieDbException { LOG.info("getPersonPopular"); Integer page = null; @@ -248,10 +266,8 @@ public class TmdbPeopleTest extends AbstractTests { assertFalse("No results", result.isEmpty()); assertTrue("No results", result.getResults().size() > 0); for (PersonFind p : result.getResults()) { + assertFalse("No known for entries", p.getKnownFor().isEmpty()); LOG.info("{} ({}) = {}", p.getName(), p.getId(), p.getKnownFor().size()); - for (MediaBasic k : p.getKnownFor()) { - LOG.info(" {}", k.toString()); - } } } @@ -264,11 +280,9 @@ public class TmdbPeopleTest extends AbstractTests { public void testGetPersonLatest() throws MovieDbException { LOG.info("getPersonLatest"); - Person expResult = null; Person result = instance.getPersonLatest(); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); + assertTrue("No ID", result.getId() > 0); + assertTrue("No name!", StringUtils.isNotBlank(result.getName())); } } From ed987dd051e6b17c5894c03631c7a58e9d765189 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 2 Mar 2015 15:47:16 +0000 Subject: [PATCH 049/100] Tests & notes --- .../themoviedbapi/methods/_Method_List.txt | 4 ++-- .../themoviedbapi/methods/TmdbPeopleTest.java | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt index 20c105b60..a5b914583 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt +++ b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt @@ -90,11 +90,11 @@ Movies Networks (Done) /network/{id} This method is used to retrieve the basic information about a TV network. -People +People (Done) /person/{id} Get the general person information for a specific id /person/{id}/movie_credits Get the movie credits for a specific person id. /person/{id}/tv_credits Get the TV credits for a specific person id. -*** /person/{id}/combined_credits Get the combined (movie and TV) credits for a specific person id. +/person/{id}/combined_credits Get the combined (movie and TV) credits for a specific person id. /person/{id}/external_ids Get the external ids for a specific person id. /person/{id}/images Get the images for a specific person id. /person/{id}/tagged_images Get the images that have been tagged with a specific person id diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java index 268623f4b..37696d629 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java @@ -90,7 +90,7 @@ public class TmdbPeopleTest extends AbstractTests { * * @throws MovieDbException */ -// @Test + @Test public void testGetPersonInfo() throws MovieDbException { LOG.info("getPersonInfo"); Person result; @@ -114,7 +114,7 @@ public class TmdbPeopleTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ -// @Test + @Test public void testGetPersonMovieCredits() throws MovieDbException { LOG.info("getPersonMovieCredits"); String language = LANGUAGE_DEFAULT; @@ -134,7 +134,7 @@ public class TmdbPeopleTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ -// @Test + @Test public void testGetPersonTVCredits() throws MovieDbException { LOG.info("getPersonTVCredits"); String language = LANGUAGE_DEFAULT; @@ -154,7 +154,7 @@ public class TmdbPeopleTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ -// @Test + @Test public void testGetPersonCombinedCredits() throws MovieDbException { LOG.info("getPersonCombinedCredits"); String language = LANGUAGE_DEFAULT; @@ -175,7 +175,7 @@ public class TmdbPeopleTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ -// @Test + @Test public void testGetPersonExternalIds() throws MovieDbException { LOG.info("getPersonExternalIds"); @@ -190,7 +190,7 @@ public class TmdbPeopleTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ -// @Test + @Test public void testGetPersonImages() throws MovieDbException { LOG.info("getPersonImages"); @@ -206,7 +206,7 @@ public class TmdbPeopleTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ -// @Test + @Test public void testGetPersonTaggedImages() throws MovieDbException { LOG.info("getPersonTaggedImages"); Integer page = null; @@ -258,7 +258,7 @@ public class TmdbPeopleTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ -// @Test + @Test public void testGetPersonPopular() throws MovieDbException { LOG.info("getPersonPopular"); Integer page = null; @@ -276,7 +276,7 @@ public class TmdbPeopleTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ -// @Test + @Test public void testGetPersonLatest() throws MovieDbException { LOG.info("getPersonLatest"); From 3ebdce3c3507e9dd1ca35cd63ec5828935db4f8c Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 2 Mar 2015 16:00:29 +0000 Subject: [PATCH 050/100] Fix search --- .../themoviedbapi/methods/AbstractMethod.java | 15 +++++++++++++++ .../themoviedbapi/methods/TmdbSearchTest.java | 6 +++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java index 05234d57a..fbe77808c 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java @@ -22,6 +22,11 @@ package com.omertron.themoviedbapi.methods; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.model.keyword.Keyword; +import com.omertron.themoviedbapi.model.person.Person; +import com.omertron.themoviedbapi.model2.collection.Collection; +import com.omertron.themoviedbapi.model2.company.Company; import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.model2.movie.MovieBasic; import com.omertron.themoviedbapi.model2.tv.TVBasic; @@ -61,6 +66,16 @@ public class AbstractMethod { }); TYPE_REFS.put(UserList.class, new TypeReference>() { }); + TYPE_REFS.put(Company.class, new TypeReference>() { + }); + TYPE_REFS.put(Collection.class, new TypeReference>() { + }); + TYPE_REFS.put(Keyword.class, new TypeReference>() { + }); + TYPE_REFS.put(MovieDb.class, new TypeReference>() { + }); + TYPE_REFS.put(Person.class, new TypeReference>() { + }); } protected static TypeReference getTypeReference(Class aClass) { diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java index 193513409..113ee72d6 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java @@ -22,11 +22,11 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.SearchType; +import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.model.keyword.Keyword; +import com.omertron.themoviedbapi.model.person.Person; import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.company.Company; -import com.omertron.themoviedbapi.model.keyword.Keyword; -import com.omertron.themoviedbapi.model.MovieDb; -import com.omertron.themoviedbapi.model.person.Person; import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.model2.tv.TVBasic; import com.omertron.themoviedbapi.results.TmdbResultsList; From df11f93ed70d0b9ec7e163b89a6470974d5eddab Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 2 Mar 2015 19:47:19 +0000 Subject: [PATCH 051/100] Move some stuff --- .../omertron/themoviedbapi/TheMovieDbApi.java | 152 +++++++++++++++++- .../themoviedbapi/methods/AbstractMethod.java | 2 +- .../methods/TmdbCertifications.java | 2 +- .../themoviedbapi/methods/TmdbChanges.java | 3 - .../themoviedbapi/methods/TmdbKeywords.java | 2 +- .../themoviedbapi/methods/TmdbMovies.java | 2 +- .../themoviedbapi/methods/TmdbSearch.java | 4 +- .../omertron/themoviedbapi/model/MovieDb.java | 2 +- .../{model => model2}/Certification.java | 2 +- .../{model => model2}/keyword/Keyword.java | 2 +- .../wrapper/WrapperKeywords.java | 2 +- .../wrapper/WrapperMovieKeywords.java | 2 +- .../methods/TmdbCertificationsTest.java | 2 +- .../methods/TmdbKeywordsTest.java | 2 +- .../themoviedbapi/methods/TmdbMoviesTest.java | 2 +- .../themoviedbapi/methods/TmdbSearchTest.java | 2 +- 16 files changed, 162 insertions(+), 23 deletions(-) rename src/main/java/com/omertron/themoviedbapi/{model => model2}/Certification.java (97%) rename src/main/java/com/omertron/themoviedbapi/{model => model2}/keyword/Keyword.java (95%) diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 5b0d9a9d4..b92aaa491 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -43,20 +43,20 @@ import com.omertron.themoviedbapi.methods.TmdbReviews; import com.omertron.themoviedbapi.methods.TmdbSearch; import com.omertron.themoviedbapi.methods.TmdbTV; import com.omertron.themoviedbapi.model.AlternativeTitle; -import com.omertron.themoviedbapi.model.Certification; +import com.omertron.themoviedbapi.model2.Certification; import com.omertron.themoviedbapi.model.Genre; import com.omertron.themoviedbapi.model.MovieDb; import com.omertron.themoviedbapi.model.MovieList; import com.omertron.themoviedbapi.model.ReleaseInfo; import com.omertron.themoviedbapi.model.Translation; import com.omertron.themoviedbapi.model.Video; -import com.omertron.themoviedbapi.model.keyword.Keyword; +import com.omertron.themoviedbapi.model2.keyword.Keyword; import com.omertron.themoviedbapi.model.keyword.KeywordMovie; -import com.omertron.themoviedbapi.model.person.Person; import com.omertron.themoviedbapi.model2.FindResults; import com.omertron.themoviedbapi.model2.StatusCode; import com.omertron.themoviedbapi.model2.account.Account; import com.omertron.themoviedbapi.model2.artwork.Artwork; +import com.omertron.themoviedbapi.model2.artwork.ArtworkMedia; import com.omertron.themoviedbapi.model2.authentication.TokenAuthorisation; import com.omertron.themoviedbapi.model2.authentication.TokenSession; import com.omertron.themoviedbapi.model2.change.ChangeListItem; @@ -71,12 +71,19 @@ import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.model2.movie.MovieBasic; import com.omertron.themoviedbapi.model2.network.Network; import com.omertron.themoviedbapi.model2.person.CreditInfo; +import com.omertron.themoviedbapi.model2.person.CreditMovieBasic; +import com.omertron.themoviedbapi.model2.person.CreditTVBasic; +import com.omertron.themoviedbapi.model2.person.ExternalID; +import com.omertron.themoviedbapi.model2.person.Person; +import com.omertron.themoviedbapi.model2.person.PersonCredits; +import com.omertron.themoviedbapi.model2.person.PersonFind; import com.omertron.themoviedbapi.model2.review.Review; import com.omertron.themoviedbapi.model2.tv.TVBasic; import com.omertron.themoviedbapi.results.TmdbResultsList; import com.omertron.themoviedbapi.results.TmdbResultsMap; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; +import com.omertron.themoviedbapi.wrapper.WrapperChanges; import java.net.URL; import java.util.List; import java.util.Map; @@ -945,7 +952,7 @@ public class TheMovieDbApi { * @return * @throws MovieDbException */ - public TmdbResultsList getMovieCasts(int movieId, String... appendToResponse) throws MovieDbException { + public TmdbResultsList getMovieCasts(int movieId, String... appendToResponse) throws MovieDbException { return tmdbMovies.getMovieCasts(movieId, appendToResponse); } @@ -1154,10 +1161,145 @@ public class TheMovieDbApi { // // + /** + * Get the general person information for a specific id. + * + * @param personId + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public Person getPersonInfo(int personId, String... appendToResponse) throws MovieDbException { + return tmdbPeople.getPersonInfo(personId, appendToResponse); + } - //TODO: Methods here + /** + * Get the movie credits for a specific person id. + * + * @param personId + * @param language + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public PersonCredits getPersonMovieCredits(int personId, String language, String... appendToResponse) throws MovieDbException { + return tmdbPeople.getPersonMovieCredits(personId, language, appendToResponse); + } + /** + * Get the TV credits for a specific person id. + * + * To get the expanded details for each record, call the /credit method with the provided credit_id. + * + * This will provide details about which episode and/or season the credit is for. + * + * @param personId + * @param language + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public PersonCredits getPersonTVCredits(int personId, String language, String... appendToResponse) throws MovieDbException { + return tmdbPeople.getPersonTVCredits(personId, language, appendToResponse); + } + /** + * Get the combined (movie and TV) credits for a specific person id. + * + * To get the expanded details for each TV record, call the /credit method with the provided credit_id. + * + * This will provide details about which episode and/or season the credit is for. + * + * @param personId + * @param language + * @param appendToResponse + * @return + * @throws MovieDbException + */ + public PersonCredits getPersonCombinedCredits(int personId, String language, String... appendToResponse) throws MovieDbException { + return tmdbPeople.getPersonCombinedCredits(personId, language, appendToResponse); + } + + /** + * Get the external ids for a specific person id. + * + * @param personId + * @return + * @throws MovieDbException + */ + public ExternalID getPersonExternalIds(int personId) throws MovieDbException { + return tmdbPeople.getPersonExternalIds(personId); + } + + /** + * Get the images for a specific person id. + * + * @param personId + * @return + * @throws MovieDbException + */ + public TmdbResultsList getPersonImages(int personId) throws MovieDbException { + return tmdbPeople.getPersonImages(personId); + } + + /** + * Get the images that have been tagged with a specific person id. + * + * We return all of the image results with a media object mapped for each image. + * + * @param personId + * @param page + * @param language + * @return + * @throws com.omertron.themoviedbapi.MovieDbException + */ + public TmdbResultsList getPersonTaggedImages(int personId, Integer page, String language) throws MovieDbException { + return tmdbPeople.getPersonTaggedImages(personId, page, language); + } + + /** + * Get the changes for a specific person id. + * + * Changes are grouped by key, and ordered by date in descending order. + * + * 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 language is present on fields that are translatable. + * + * @param personId + * @param startDate + * @param endDate + * @return + * @throws com.omertron.themoviedbapi.MovieDbException + */ + public WrapperChanges getPersonChanges(int personId, String startDate, String endDate) throws MovieDbException { + return tmdbPeople.getPersonChanges(personId, startDate, endDate); + } + + /** + * Get the list of popular people on The Movie Database. + * + * This list refreshes every day. + * + * @param page + * @return + * @throws MovieDbException + */ + public TmdbResultsList getPersonPopular(Integer page) throws MovieDbException { + return tmdbPeople.getPersonPopular(page); + } + + /** + * Get the latest person id. + * + * @return + * @throws MovieDbException + */ + public Person getPersonLatest() throws MovieDbException { + return tmdbPeople.getPersonLatest(); + } // // diff --git a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java index fbe77808c..ce864bf8a 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java @@ -23,7 +23,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model.MovieDb; -import com.omertron.themoviedbapi.model.keyword.Keyword; +import com.omertron.themoviedbapi.model2.keyword.Keyword; import com.omertron.themoviedbapi.model.person.Person; import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.company.Company; diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCertifications.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCertifications.java index f17ab64ee..31596d0ea 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbCertifications.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbCertifications.java @@ -25,7 +25,7 @@ import com.omertron.themoviedbapi.tools.HttpTools; import java.util.List; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonNode; -import com.omertron.themoviedbapi.model.Certification; +import com.omertron.themoviedbapi.model2.Certification; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.MethodBase; import com.omertron.themoviedbapi.tools.MethodSub; diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbChanges.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbChanges.java index 7869aface..81b39fc78 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbChanges.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbChanges.java @@ -69,11 +69,8 @@ public class TmdbChanges extends AbstractMethod { params.add(Param.END_DATE, endDate); URL url = new ApiUrl(apiKey, method).setSubMethod(MethodSub.CHANGES).buildUrl(params); - String webpage = httpTools.getRequest(url); - TypeReference tr = new TypeReference>() { }; - return processWrapperList(tr, url, "changes"); } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbKeywords.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbKeywords.java index 83a262f6e..5b04f11dc 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbKeywords.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbKeywords.java @@ -20,7 +20,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.keyword.Keyword; +import com.omertron.themoviedbapi.model2.keyword.Keyword; import com.omertron.themoviedbapi.model.keyword.KeywordMovie; import com.omertron.themoviedbapi.results.TmdbResultsList; import com.omertron.themoviedbapi.tools.ApiUrl; diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java index b17fbb1f6..a0cc63299 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java @@ -28,7 +28,7 @@ import com.omertron.themoviedbapi.model.ReleaseInfo; import com.omertron.themoviedbapi.model2.StatusCode; import com.omertron.themoviedbapi.model.Translation; import com.omertron.themoviedbapi.model.Video; -import com.omertron.themoviedbapi.model.keyword.Keyword; +import com.omertron.themoviedbapi.model2.keyword.Keyword; import com.omertron.themoviedbapi.model.person.Person; import com.omertron.themoviedbapi.results.TmdbResultsList; import com.omertron.themoviedbapi.tools.ApiUrl; diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java index 6ad84b4a8..8fbc76df1 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java @@ -22,8 +22,8 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.SearchType; import com.omertron.themoviedbapi.model.MovieDb; -import com.omertron.themoviedbapi.model.keyword.Keyword; -import com.omertron.themoviedbapi.model.person.Person; +import com.omertron.themoviedbapi.model2.keyword.Keyword; +import com.omertron.themoviedbapi.model2.person.Person; import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.company.Company; import com.omertron.themoviedbapi.model2.list.UserList; diff --git a/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java b/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java index 5a6226bea..35ae03da9 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java +++ b/src/main/java/com/omertron/themoviedbapi/model/MovieDb.java @@ -23,7 +23,7 @@ import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.model2.review.Review; import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.omertron.themoviedbapi.model2.collection.Collection; -import com.omertron.themoviedbapi.model.keyword.Keyword; +import com.omertron.themoviedbapi.model2.keyword.Keyword; import com.omertron.themoviedbapi.model.person.PersonCast; import com.omertron.themoviedbapi.model.person.PersonCrew; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/main/java/com/omertron/themoviedbapi/model/Certification.java b/src/main/java/com/omertron/themoviedbapi/model2/Certification.java similarity index 97% rename from src/main/java/com/omertron/themoviedbapi/model/Certification.java rename to src/main/java/com/omertron/themoviedbapi/model2/Certification.java index c794d9155..b6e885fcf 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/Certification.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/Certification.java @@ -17,7 +17,7 @@ * along with TheMovieDB API. If not;private see . * */ -package com.omertron.themoviedbapi.model; +package com.omertron.themoviedbapi.model2; import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/main/java/com/omertron/themoviedbapi/model/keyword/Keyword.java b/src/main/java/com/omertron/themoviedbapi/model2/keyword/Keyword.java similarity index 95% rename from src/main/java/com/omertron/themoviedbapi/model/keyword/Keyword.java rename to src/main/java/com/omertron/themoviedbapi/model2/keyword/Keyword.java index 00a6b6184..c6006b431 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/keyword/Keyword.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/keyword/Keyword.java @@ -17,7 +17,7 @@ * along with TheMovieDB API. If not, see . * */ -package com.omertron.themoviedbapi.model.keyword; +package com.omertron.themoviedbapi.model2.keyword; import com.fasterxml.jackson.annotation.JsonRootName; import com.omertron.themoviedbapi.model.AbstractIdName; diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperKeywords.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperKeywords.java index 7b6bc4547..c734c60fe 100644 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperKeywords.java +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperKeywords.java @@ -20,7 +20,7 @@ package com.omertron.themoviedbapi.wrapper; import com.fasterxml.jackson.annotation.JsonProperty; -import com.omertron.themoviedbapi.model.keyword.Keyword; +import com.omertron.themoviedbapi.model2.keyword.Keyword; import java.util.List; /** diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovieKeywords.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovieKeywords.java index a52a4955e..f15e62a93 100644 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovieKeywords.java +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMovieKeywords.java @@ -20,7 +20,7 @@ package com.omertron.themoviedbapi.wrapper; import com.fasterxml.jackson.annotation.JsonProperty; -import com.omertron.themoviedbapi.model.keyword.Keyword; +import com.omertron.themoviedbapi.model2.keyword.Keyword; import java.io.Serializable; import java.util.List; diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCertificationsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCertificationsTest.java index fe7f220ea..5909474a1 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCertificationsTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCertificationsTest.java @@ -22,7 +22,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import static com.omertron.themoviedbapi.AbstractTests.doConfiguration; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.Certification; +import com.omertron.themoviedbapi.model2.Certification; import com.omertron.themoviedbapi.results.TmdbResultsMap; import java.util.List; import java.util.Map; diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbKeywordsTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbKeywordsTest.java index 2e163fdb0..810611460 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbKeywordsTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbKeywordsTest.java @@ -21,7 +21,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; -import com.omertron.themoviedbapi.model.keyword.Keyword; +import com.omertron.themoviedbapi.model2.keyword.Keyword; import com.omertron.themoviedbapi.model.keyword.KeywordMovie; import com.omertron.themoviedbapi.results.TmdbResultsList; import org.junit.After; diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java index c0a3c2140..cde79704f 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java @@ -23,7 +23,7 @@ import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model.AlternativeTitle; import com.omertron.themoviedbapi.model2.artwork.Artwork; -import com.omertron.themoviedbapi.model.keyword.Keyword; +import com.omertron.themoviedbapi.model2.keyword.Keyword; import com.omertron.themoviedbapi.model.MovieDb; import com.omertron.themoviedbapi.model.MovieList; import com.omertron.themoviedbapi.model.ReleaseInfo; diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java index 113ee72d6..997ebf9a3 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java @@ -23,7 +23,7 @@ import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.SearchType; import com.omertron.themoviedbapi.model.MovieDb; -import com.omertron.themoviedbapi.model.keyword.Keyword; +import com.omertron.themoviedbapi.model2.keyword.Keyword; import com.omertron.themoviedbapi.model.person.Person; import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.company.Company; From 173792dc2e5fb2fcae66a8ba9213ace64b8e9efc Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 2 Mar 2015 19:53:21 +0000 Subject: [PATCH 052/100] Tests --- .../java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java index 997ebf9a3..054e3b412 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java @@ -24,7 +24,7 @@ import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.SearchType; import com.omertron.themoviedbapi.model.MovieDb; import com.omertron.themoviedbapi.model2.keyword.Keyword; -import com.omertron.themoviedbapi.model.person.Person; +import com.omertron.themoviedbapi.model2.person.Person; import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.company.Company; import com.omertron.themoviedbapi.model2.list.UserList; From e118f56f99b51bfefc636991ecd42e5122219c4c Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 2 Mar 2015 20:14:59 +0000 Subject: [PATCH 053/100] fixed Search --- .../omertron/themoviedbapi/methods/AbstractMethod.java | 8 ++++++-- .../omertron/themoviedbapi/methods/TmdbSearchTest.java | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java index ce864bf8a..0a12e1a9a 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java @@ -24,7 +24,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model.MovieDb; import com.omertron.themoviedbapi.model2.keyword.Keyword; -import com.omertron.themoviedbapi.model.person.Person; +import com.omertron.themoviedbapi.model2.person.Person; import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.company.Company; import com.omertron.themoviedbapi.model2.list.UserList; @@ -79,7 +79,11 @@ public class AbstractMethod { } protected static TypeReference getTypeReference(Class aClass) { - return TYPE_REFS.get(aClass); + if (TYPE_REFS.containsKey(aClass)) { + return TYPE_REFS.get(aClass); + } else { + throw new RuntimeException("Class type reference for '" + aClass.getSimpleName() + "' not found!"); + } } /** diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java index 054e3b412..2dc6c1891 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java @@ -47,7 +47,6 @@ import org.junit.Test; */ public class TmdbSearchTest extends AbstractTests { - // API private static TmdbSearch instance; private static final String COMPANY_NAME = "Marvel Studios"; From e850ba15894e994825f4a856783186e6b9bebbb8 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 2 Mar 2015 20:24:43 +0000 Subject: [PATCH 054/100] fixed SearchPerson --- .../omertron/themoviedbapi/methods/AbstractMethod.java | 3 +++ .../com/omertron/themoviedbapi/methods/TmdbSearch.java | 8 ++++---- .../omertron/themoviedbapi/model2/person/PersonFind.java | 2 -- .../omertron/themoviedbapi/methods/TmdbSearchTest.java | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java index 0a12e1a9a..23c6a00ec 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java @@ -29,6 +29,7 @@ import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.company.Company; import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.model2.movie.MovieBasic; +import com.omertron.themoviedbapi.model2.person.PersonFind; import com.omertron.themoviedbapi.model2.tv.TVBasic; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.wrapper.WrapperGenericList; @@ -76,6 +77,8 @@ public class AbstractMethod { }); TYPE_REFS.put(Person.class, new TypeReference>() { }); + TYPE_REFS.put(PersonFind.class, new TypeReference>() { + }); } protected static TypeReference getTypeReference(Class aClass) { diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java index 8fbc76df1..570e6365c 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java @@ -23,10 +23,10 @@ import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.SearchType; import com.omertron.themoviedbapi.model.MovieDb; import com.omertron.themoviedbapi.model2.keyword.Keyword; -import com.omertron.themoviedbapi.model2.person.Person; import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.company.Company; import com.omertron.themoviedbapi.model2.list.UserList; +import com.omertron.themoviedbapi.model2.person.PersonFind; import com.omertron.themoviedbapi.model2.tv.TVBasic; import com.omertron.themoviedbapi.results.TmdbResultsList; import com.omertron.themoviedbapi.tools.ApiUrl; @@ -220,7 +220,7 @@ public class TmdbSearch extends AbstractMethod { * @return * @throws MovieDbException */ - public TmdbResultsList searchPeople(String query, Integer page, Boolean includeAdult, SearchType searchType) throws MovieDbException { + public TmdbResultsList searchPeople(String query, Integer page, Boolean includeAdult, SearchType searchType) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.QUERY, query); parameters.add(Param.ADULT, includeAdult); @@ -230,8 +230,8 @@ public class TmdbSearch extends AbstractMethod { } URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.PERSON).buildUrl(parameters); - WrapperGenericList wrapper = processWrapper(getTypeReference(Person.class), url, "person"); - TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); + WrapperGenericList wrapper = processWrapper(getTypeReference(PersonFind.class), url, "person"); + TmdbResultsList results = new TmdbResultsList(wrapper.getResults()); results.copyWrapper(wrapper); return results; } diff --git a/src/main/java/com/omertron/themoviedbapi/model2/person/PersonFind.java b/src/main/java/com/omertron/themoviedbapi/model2/person/PersonFind.java index cbf3a9484..879226e51 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/person/PersonFind.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/person/PersonFind.java @@ -41,7 +41,6 @@ public class PersonFind extends PersonBasic { private Float popularity; @JsonProperty("profile_path") private String profilePath; -// @JsonProperty("known_for") private List knownFor; public Boolean getAdult() { @@ -74,7 +73,6 @@ public class PersonFind extends PersonBasic { @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, -// include = JsonTypeInfo.As.EXTERNAL_PROPERTY, include = JsonTypeInfo.As.PROPERTY, property = "media_type", defaultImpl = MediaBasic.class diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java index 2dc6c1891..33f92fbfb 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java @@ -24,10 +24,10 @@ import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.SearchType; import com.omertron.themoviedbapi.model.MovieDb; import com.omertron.themoviedbapi.model2.keyword.Keyword; -import com.omertron.themoviedbapi.model2.person.Person; import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.company.Company; import com.omertron.themoviedbapi.model2.list.UserList; +import com.omertron.themoviedbapi.model2.person.PersonFind; import com.omertron.themoviedbapi.model2.tv.TVBasic; import com.omertron.themoviedbapi.results.TmdbResultsList; import org.junit.After; @@ -183,7 +183,7 @@ public class TmdbSearchTest extends AbstractTests { public void testSearchPeople() throws MovieDbException { LOG.info("searchPeople"); String personName = "Bruce Willis"; - TmdbResultsList result = instance.searchPeople(personName, null, null, SearchType.PHRASE); + TmdbResultsList result = instance.searchPeople(personName, null, null, SearchType.PHRASE); assertNotNull("Null results", result); assertNotNull("Null people", result.getResults()); assertFalse("Empty people", result.isEmpty()); From e9945654c97a218992e570e40f27daadf78d1e55 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 2 Mar 2015 22:03:06 +0000 Subject: [PATCH 055/100] Fixed Multi search --- .../omertron/themoviedbapi/TheMovieDbApi.java | 5 +- .../themoviedbapi/methods/TmdbSearch.java | 21 ++++++- .../wrapper/WrapperMultiSearch.java | 59 +++++++++++++++++++ .../themoviedbapi/methods/TmdbSearchTest.java | 26 ++++---- 4 files changed, 92 insertions(+), 19 deletions(-) create mode 100644 src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMultiSearch.java diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index b92aaa491..9a11ca3ac 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -53,6 +53,7 @@ import com.omertron.themoviedbapi.model.Video; import com.omertron.themoviedbapi.model2.keyword.Keyword; import com.omertron.themoviedbapi.model.keyword.KeywordMovie; import com.omertron.themoviedbapi.model2.FindResults; +import com.omertron.themoviedbapi.model2.MediaBasic; import com.omertron.themoviedbapi.model2.StatusCode; import com.omertron.themoviedbapi.model2.account.Account; import com.omertron.themoviedbapi.model2.artwork.Artwork; @@ -1406,7 +1407,7 @@ public class TheMovieDbApi { * @return * @throws MovieDbException */ - public String searchMulti(String query, Integer page, String language, Boolean includeAdult) throws MovieDbException { + public TmdbResultsList searchMulti(String query, Integer page, String language, Boolean includeAdult) throws MovieDbException { return tmdbSearch.searchMulti(query, page, language, includeAdult); } @@ -1422,7 +1423,7 @@ public class TheMovieDbApi { * @return * @throws MovieDbException */ - public TmdbResultsList searchPeople(String query, Integer page, Boolean includeAdult, SearchType searchType) throws MovieDbException { + public TmdbResultsList searchPeople(String query, Integer page, Boolean includeAdult, SearchType searchType) throws MovieDbException { return tmdbSearch.searchPeople(query, page, includeAdult, searchType); } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java index 570e6365c..3770b8dda 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java @@ -21,7 +21,9 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.SearchType; +import static com.omertron.themoviedbapi.methods.AbstractMethod.MAPPER; import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.model2.MediaBasic; import com.omertron.themoviedbapi.model2.keyword.Keyword; import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.company.Company; @@ -36,7 +38,10 @@ import com.omertron.themoviedbapi.tools.MethodSub; import com.omertron.themoviedbapi.tools.Param; import com.omertron.themoviedbapi.tools.TmdbParameters; import com.omertron.themoviedbapi.wrapper.WrapperGenericList; +import com.omertron.themoviedbapi.wrapper.WrapperMultiSearch; +import java.io.IOException; import java.net.URL; +import java.util.List; import org.yamj.api.common.exception.ApiExceptionType; /** @@ -197,7 +202,7 @@ public class TmdbSearch extends AbstractMethod { * @return * @throws MovieDbException */ - public String searchMulti(String query, Integer page, String language, Boolean includeAdult) throws MovieDbException { + public TmdbResultsList searchMulti(String query, Integer page, String language, Boolean includeAdult) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.QUERY, query); parameters.add(Param.PAGE, page); @@ -205,8 +210,18 @@ public class TmdbSearch extends AbstractMethod { parameters.add(Param.ADULT, includeAdult); URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.MULTI).buildUrl(parameters); - throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not implemented yet"); - } + String webpage = httpTools.getRequest(url); + + try { + WrapperMultiSearch wrapper = MAPPER.readValue(webpage, WrapperMultiSearch.class); + TmdbResultsList results = new TmdbResultsList(null); + List x = wrapper.getResults(); + results.getResults().addAll(wrapper.getResults()); + results.copyWrapper(wrapper); + return results; + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get multi search", url, ex); + } } /** * This is a good starting point to start finding people on TMDb. diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMultiSearch.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMultiSearch.java new file mode 100644 index 000000000..a4dde1eb1 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMultiSearch.java @@ -0,0 +1,59 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.omertron.themoviedbapi.model2.MediaBasic; +import com.omertron.themoviedbapi.model2.movie.MovieBasic; +import com.omertron.themoviedbapi.model2.tv.TVBasic; +import com.omertron.themoviedbapi.model2.tv.TVEpisodeBasic; +import java.util.List; + +/** + * + * @author stuart.boston + */ +public class WrapperMultiSearch extends AbstractWrapperAll { + + private List results; + + public List getResults() { + return results; + } + + @JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.PROPERTY, + property = "media_type", + defaultImpl = MediaBasic.class + ) + @JsonSubTypes({ + @JsonSubTypes.Type(value = MovieBasic.class, name = "movie"), + @JsonSubTypes.Type(value = TVBasic.class, name = "tv"), + @JsonSubTypes.Type(value = TVEpisodeBasic.class, name = "episode") + }) + @JsonSetter("results") + public void setResults(List results) { + this.results = results; + } + +} diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java index 33f92fbfb..b649a3187 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java @@ -23,6 +23,7 @@ import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.SearchType; import com.omertron.themoviedbapi.model.MovieDb; +import com.omertron.themoviedbapi.model2.MediaBasic; import com.omertron.themoviedbapi.model2.keyword.Keyword; import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.company.Company; @@ -32,11 +33,9 @@ import com.omertron.themoviedbapi.model2.tv.TVBasic; import com.omertron.themoviedbapi.results.TmdbResultsList; import org.junit.After; import org.junit.AfterClass; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -76,7 +75,7 @@ public class TmdbSearchTest extends AbstractTests { * * @throws MovieDbException */ - @Test +// @Test public void testSearchCompanies() throws MovieDbException { LOG.info("searchCompanies"); TmdbResultsList result = instance.searchCompanies(COMPANY_NAME, 0); @@ -90,7 +89,7 @@ public class TmdbSearchTest extends AbstractTests { * * @throws MovieDbException */ - @Test +// @Test public void testSearchCollection() throws MovieDbException { LOG.info("searchCollection"); String query = "batman"; @@ -106,7 +105,7 @@ public class TmdbSearchTest extends AbstractTests { * * @throws MovieDbException */ - @Test +// @Test public void testSearchKeyword() throws MovieDbException { LOG.info("searchKeyword"); String query = "action"; @@ -122,7 +121,7 @@ public class TmdbSearchTest extends AbstractTests { * * @throws MovieDbException */ - @Test +// @Test public void testSearchList() throws MovieDbException { LOG.info("searchList"); String query = "watch"; @@ -138,7 +137,7 @@ public class TmdbSearchTest extends AbstractTests { * * @throws MovieDbException */ - @Test +// @Test public void testSearchMovie() throws MovieDbException { LOG.info("searchMovie"); @@ -167,11 +166,10 @@ public class TmdbSearchTest extends AbstractTests { Integer page = null; String language = ""; Boolean includeAdult = null; - String expResult = ""; - String result = instance.searchMulti(query, page, language, includeAdult); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); + TmdbResultsList result = instance.searchMulti(query, page, language, includeAdult); + for (MediaBasic item : result.getResults()) { + LOG.info("{}", item); + } } /** @@ -179,7 +177,7 @@ public class TmdbSearchTest extends AbstractTests { * * @throws MovieDbException */ - @Test +// @Test public void testSearchPeople() throws MovieDbException { LOG.info("searchPeople"); String personName = "Bruce Willis"; @@ -194,7 +192,7 @@ public class TmdbSearchTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test +// @Test public void testSearchTV() throws MovieDbException { System.out.println("searchTV"); String query = "The Walking Dead"; From dada02db89d4c5181d97b3461f2c3245d320b368 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Tue, 3 Mar 2015 11:38:37 +0000 Subject: [PATCH 056/100] Fixed People Combined Search --- .../themoviedbapi/methods/TmdbPeople.java | 3 +- .../themoviedbapi/methods/TmdbSearch.java | 2 -- .../model2/person/PersonCredits.java | 31 +++++++++++++++++-- .../themoviedbapi/methods/TmdbPeopleTest.java | 7 ++--- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java index b23ea75fa..f46cda45f 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java @@ -24,6 +24,7 @@ import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.ArtworkType; import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.model2.artwork.ArtworkMedia; +import com.omertron.themoviedbapi.model2.person.CreditBasic; import com.omertron.themoviedbapi.model2.person.CreditMovieBasic; import com.omertron.themoviedbapi.model2.person.CreditTVBasic; import com.omertron.themoviedbapi.model2.person.ExternalID; @@ -167,7 +168,7 @@ public class TmdbPeople extends AbstractMethod { String webpage = httpTools.getRequest(url); try { - return MAPPER.readValue(webpage, new TypeReference>() { + return MAPPER.readValue(webpage, new TypeReference>() { }); } catch (IOException ex) { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person movie credits", url, ex); diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java index 3770b8dda..1a25409c7 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java @@ -41,7 +41,6 @@ import com.omertron.themoviedbapi.wrapper.WrapperGenericList; import com.omertron.themoviedbapi.wrapper.WrapperMultiSearch; import java.io.IOException; import java.net.URL; -import java.util.List; import org.yamj.api.common.exception.ApiExceptionType; /** @@ -215,7 +214,6 @@ public class TmdbSearch extends AbstractMethod { try { WrapperMultiSearch wrapper = MAPPER.readValue(webpage, WrapperMultiSearch.class); TmdbResultsList results = new TmdbResultsList(null); - List x = wrapper.getResults(); results.getResults().addAll(wrapper.getResults()); results.copyWrapper(wrapper); return results; diff --git a/src/main/java/com/omertron/themoviedbapi/model2/person/PersonCredits.java b/src/main/java/com/omertron/themoviedbapi/model2/person/PersonCredits.java index 29c3fbfe5..9db75621d 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/person/PersonCredits.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/person/PersonCredits.java @@ -20,11 +20,16 @@ package com.omertron.themoviedbapi.model2.person; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import com.omertron.themoviedbapi.model2.AbstractJsonMapping; +import com.omertron.themoviedbapi.model2.MediaBasic; import java.util.List; /** * @author stuart.boston + * @param */ public class PersonCredits extends AbstractJsonMapping { @@ -32,9 +37,9 @@ public class PersonCredits extends AbstractJsonMapping { @JsonProperty("id") private int id; - @JsonProperty("cast") +// @JsonProperty("cast") private List cast; - @JsonProperty("crew") +// @JsonProperty("crew") private List crew; public int getId() { @@ -49,6 +54,17 @@ public class PersonCredits extends AbstractJsonMapping { return cast; } + @JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.PROPERTY, + property = "media_type", + defaultImpl = MediaBasic.class + ) + @JsonSubTypes({ + @JsonSubTypes.Type(value = CreditMovieBasic.class, name = "movie"), + @JsonSubTypes.Type(value = CreditTVBasic.class, name = "tv") + }) + @JsonSetter("cast") public void setCast(List cast) { this.cast = cast; } @@ -57,6 +73,17 @@ public class PersonCredits extends AbstractJsonMapping { return crew; } + @JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.PROPERTY, + property = "media_type", + defaultImpl = MediaBasic.class + ) + @JsonSubTypes({ + @JsonSubTypes.Type(value = CreditMovieBasic.class, name = "movie"), + @JsonSubTypes.Type(value = CreditTVBasic.class, name = "tv") + }) + @JsonSetter("crew") public void setCrew(List crew) { this.crew = crew; } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java index 37696d629..1b7bfc39b 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java @@ -27,6 +27,7 @@ import com.omertron.themoviedbapi.model2.artwork.Artwork; import com.omertron.themoviedbapi.model2.artwork.ArtworkMedia; import com.omertron.themoviedbapi.model2.change.ChangeKeyItem; import com.omertron.themoviedbapi.model2.change.ChangeListItem; +import com.omertron.themoviedbapi.model2.person.CreditBasic; import com.omertron.themoviedbapi.model2.person.CreditMovieBasic; import com.omertron.themoviedbapi.model2.person.CreditTVBasic; import com.omertron.themoviedbapi.model2.person.ExternalID; @@ -48,7 +49,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -161,13 +161,12 @@ public class TmdbPeopleTest extends AbstractTests { String[] appendToResponse = null; for (TestID test : testIDs) { - PersonCredits result = instance.getPersonCombinedCredits(test.getTmdb(), language, appendToResponse); + PersonCredits result = instance.getPersonCombinedCredits(test.getTmdb(), language, appendToResponse); LOG.info("ID: {}, # Cast: {}, # Crew: {}", result.getId(), result.getCast().size(), result.getCrew().size()); assertEquals("Incorrect ID", test.getTmdb(), result.getId()); assertFalse("No cast", result.getCast().isEmpty()); assertFalse("No crew", result.getCrew().isEmpty()); } - fail("Not working"); } /** @@ -244,7 +243,7 @@ public class TmdbPeopleTest extends AbstractTests { for (ChangeListItem item : changeList) { result = instance.getPersonChanges(item.getId(), startDate, endDate); for (ChangeKeyItem ci : result.getChangedItems()) { - assertNotNull("Null changes",ci); + assertNotNull("Null changes", ci); } if (count++ > maxCheck) { From 4835cd426c5b9b40d77ec7215704ce97d542bd8c Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Tue, 3 Mar 2015 11:52:58 +0000 Subject: [PATCH 057/100] Fixed Find TV test --- .../com/omertron/themoviedbapi/methods/TmdbFindTest.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java index 2c9d78b50..585cba543 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbFindTest.java @@ -26,6 +26,7 @@ import com.omertron.themoviedbapi.enumeration.ExternalSource; import com.omertron.themoviedbapi.model2.FindResults; import com.omertron.themoviedbapi.model2.movie.MovieBasic; import com.omertron.themoviedbapi.model2.person.PersonFind; +import com.omertron.themoviedbapi.model2.tv.TVBasic; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -143,10 +144,10 @@ public class TmdbFindTest extends AbstractTests { for (TestID test : TV_IDS) { result = instance.find(test.getImdb(), ExternalSource.IMDB_ID, LANGUAGE_DEFAULT); - assertFalse("No TV Show for ID: " + test.getName(), result.getPersonResults().isEmpty()); + assertFalse("No TV Show info for ID: " + test.getName(), result.getTvResults().isEmpty()); boolean found = false; - for (PersonFind p : result.getPersonResults()) { - if (p.getId() == test.getTmdb()) { + for (TVBasic tv : result.getTvResults()) { + if (tv.getId() == test.getTmdb()) { found = true; break; } From 2697e3fcf23de4aa83b01d30f15937f548c60cd0 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Tue, 3 Mar 2015 12:26:55 +0000 Subject: [PATCH 058/100] Add missing parameters --- src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java | 6 +++--- .../java/com/omertron/themoviedbapi/methods/TmdbPeople.java | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 9a11ca3ac..1596ac2d2 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -43,15 +43,14 @@ import com.omertron.themoviedbapi.methods.TmdbReviews; import com.omertron.themoviedbapi.methods.TmdbSearch; import com.omertron.themoviedbapi.methods.TmdbTV; import com.omertron.themoviedbapi.model.AlternativeTitle; -import com.omertron.themoviedbapi.model2.Certification; import com.omertron.themoviedbapi.model.Genre; import com.omertron.themoviedbapi.model.MovieDb; import com.omertron.themoviedbapi.model.MovieList; import com.omertron.themoviedbapi.model.ReleaseInfo; import com.omertron.themoviedbapi.model.Translation; import com.omertron.themoviedbapi.model.Video; -import com.omertron.themoviedbapi.model2.keyword.Keyword; import com.omertron.themoviedbapi.model.keyword.KeywordMovie; +import com.omertron.themoviedbapi.model2.Certification; import com.omertron.themoviedbapi.model2.FindResults; import com.omertron.themoviedbapi.model2.MediaBasic; import com.omertron.themoviedbapi.model2.StatusCode; @@ -67,6 +66,7 @@ import com.omertron.themoviedbapi.model2.company.Company; import com.omertron.themoviedbapi.model2.config.Configuration; import com.omertron.themoviedbapi.model2.config.JobDepartment; import com.omertron.themoviedbapi.model2.discover.Discover; +import com.omertron.themoviedbapi.model2.keyword.Keyword; import com.omertron.themoviedbapi.model2.list.ListItem; import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.model2.movie.MovieBasic; @@ -1390,7 +1390,7 @@ public class TheMovieDbApi { Integer searchYear, Integer primaryReleaseYear, SearchType searchType) throws MovieDbException { - return tmdbSearch.searchMovie(query, page, language, includeAdult, searchYear, primaryReleaseYear, SearchType.PHRASE); + return tmdbSearch.searchMovie(query, page, language, includeAdult, searchYear, primaryReleaseYear, searchType); } /** diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java index f46cda45f..aafd4741f 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java @@ -235,6 +235,8 @@ public class TmdbPeople extends AbstractMethod { public TmdbResultsList getPersonTaggedImages(int personId, Integer page, String language) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.ID, personId); + parameters.add(Param.PAGE, page); + parameters.add(Param.LANGUAGE, language); URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.TAGGED_IMAGES).buildUrl(parameters); From d0ec5c3b1897092b1945480d8dfd1668eee81319 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Tue, 3 Mar 2015 12:34:53 +0000 Subject: [PATCH 059/100] minor sonar fixes --- .../themoviedbapi/methods/AbstractMethod.java | 29 ++++++++++++------- .../themoviedbapi/methods/TmdbPeople.java | 8 ++--- .../model2/config/Configuration.java | 3 +- .../model2/config/JobDepartment.java | 2 -- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java index 23c6a00ec..ac5a7ca54 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java @@ -23,12 +23,12 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model.MovieDb; -import com.omertron.themoviedbapi.model2.keyword.Keyword; -import com.omertron.themoviedbapi.model2.person.Person; import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.company.Company; +import com.omertron.themoviedbapi.model2.keyword.Keyword; import com.omertron.themoviedbapi.model2.list.UserList; import com.omertron.themoviedbapi.model2.movie.MovieBasic; +import com.omertron.themoviedbapi.model2.person.Person; import com.omertron.themoviedbapi.model2.person.PersonFind; import com.omertron.themoviedbapi.model2.tv.TVBasic; import com.omertron.themoviedbapi.tools.HttpTools; @@ -56,7 +56,7 @@ public class AbstractMethod { // Jackson JSON configuration protected static final ObjectMapper MAPPER = new ObjectMapper(); // Logger - protected static final Logger LOG = LoggerFactory.getLogger(TmdbAccount.class); + protected static final Logger LOG = LoggerFactory.getLogger(AbstractMethod.class); private static final Map TYPE_REFS = new HashMap(); @@ -81,14 +81,6 @@ public class AbstractMethod { }); } - protected static TypeReference getTypeReference(Class aClass) { - if (TYPE_REFS.containsKey(aClass)) { - return TYPE_REFS.get(aClass); - } else { - throw new RuntimeException("Class type reference for '" + aClass.getSimpleName() + "' not found!"); - } - } - /** * Default constructor for the methods * @@ -100,6 +92,21 @@ public class AbstractMethod { this.httpTools = httpTools; } + /** + * Helper function to get a pre-generated TypeReference for a class + * + * @param aClass + * @return + * @throws MovieDbException + */ + protected static TypeReference getTypeReference(Class aClass) throws MovieDbException { + if (TYPE_REFS.containsKey(aClass)) { + return TYPE_REFS.get(aClass); + } else { + throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Class type reference for '" + aClass.getSimpleName() + "' not found!"); + } + } + /** * Process the wrapper list and return the results * diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java index aafd4741f..9141d4b2e 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java @@ -139,7 +139,7 @@ public class TmdbPeople extends AbstractMethod { return MAPPER.readValue(webpage, new TypeReference>() { }); } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person movie credits", url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person TV credits", url, ex); } } @@ -171,7 +171,7 @@ public class TmdbPeople extends AbstractMethod { return MAPPER.readValue(webpage, new TypeReference>() { }); } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person movie credits", url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person combined credits", url, ex); } } @@ -192,7 +192,7 @@ public class TmdbPeople extends AbstractMethod { try { return MAPPER.readValue(webpage, ExternalID.class); } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person movie credits", url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person external IDs", url, ex); } } @@ -315,7 +315,7 @@ public class TmdbPeople extends AbstractMethod { results.copyWrapper(wrapper); return results; } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get tagged images", url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person popular", url, ex); } } diff --git a/src/main/java/com/omertron/themoviedbapi/model2/config/Configuration.java b/src/main/java/com/omertron/themoviedbapi/model2/config/Configuration.java index 501e04450..cdf25bd39 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/config/Configuration.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/config/Configuration.java @@ -19,7 +19,6 @@ */ package com.omertron.themoviedbapi.model2.config; -import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.fasterxml.jackson.annotation.JsonProperty; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model2.AbstractJsonMapping; @@ -203,7 +202,7 @@ public class Configuration extends AbstractJsonMapping { StringBuilder sb = new StringBuilder(getBaseUrl()); sb.append(requiredSize); sb.append(imagePath); - + try { return new URL(sb.toString()); } catch (MalformedURLException ex) { diff --git a/src/main/java/com/omertron/themoviedbapi/model2/config/JobDepartment.java b/src/main/java/com/omertron/themoviedbapi/model2/config/JobDepartment.java index 403d48584..288f5a1a6 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/config/JobDepartment.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/config/JobDepartment.java @@ -19,10 +19,8 @@ */ package com.omertron.themoviedbapi.model2.config; -import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.fasterxml.jackson.annotation.JsonProperty; import com.omertron.themoviedbapi.model2.AbstractJsonMapping; - import java.util.List; public class JobDepartment extends AbstractJsonMapping { From aa6bb1e252b90a171c058c205acd1fd48ef9f37d Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Tue, 3 Mar 2015 12:38:25 +0000 Subject: [PATCH 060/100] add equals and hashcode to ArtworkMedia --- .../model2/artwork/ArtworkMedia.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/com/omertron/themoviedbapi/model2/artwork/ArtworkMedia.java b/src/main/java/com/omertron/themoviedbapi/model2/artwork/ArtworkMedia.java index 5905ea6f9..75ac96bd6 100644 --- a/src/main/java/com/omertron/themoviedbapi/model2/artwork/ArtworkMedia.java +++ b/src/main/java/com/omertron/themoviedbapi/model2/artwork/ArtworkMedia.java @@ -28,6 +28,8 @@ import com.omertron.themoviedbapi.model2.MediaBasic; import com.omertron.themoviedbapi.model2.movie.MovieBasic; import com.omertron.themoviedbapi.model2.tv.TVBasic; import com.omertron.themoviedbapi.model2.tv.TVEpisodeBasic; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; /** * @@ -71,4 +73,25 @@ public class ArtworkMedia extends Artwork { this.media = media; } + @Override + public int hashCode() { + return new HashCodeBuilder() + .appendSuper(super.hashCode()) + .append(mediaType) + .toHashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof ArtworkMedia) { + final ArtworkMedia other = (ArtworkMedia) obj; + return new EqualsBuilder() + .appendSuper(super.equals(obj)) + .append(mediaType, other.mediaType) + .isEquals(); + } else { + return false; + } + } + } From 5dd6ed7d601eabb4b463ca7ca98511146d5b8923 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Tue, 3 Mar 2015 12:39:28 +0000 Subject: [PATCH 061/100] minor sonar fixes --- .../com/omertron/themoviedbapi/methods/TmdbLists.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbLists.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbLists.java index 4113c547c..f7a5711c4 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbLists.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbLists.java @@ -23,9 +23,9 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model.ListItemStatus; import com.omertron.themoviedbapi.model.MovieDb; -import com.omertron.themoviedbapi.model2.list.ListItem; import com.omertron.themoviedbapi.model.MovieDbListStatus; import com.omertron.themoviedbapi.model2.StatusCode; +import com.omertron.themoviedbapi.model2.list.ListItem; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; @@ -71,7 +71,8 @@ public class TmdbLists extends AbstractMethod { String webpage = httpTools.getRequest(url); try { - return MAPPER.readValue(webpage, new TypeReference>(){}); + return MAPPER.readValue(webpage, new TypeReference>() { + }); } catch (IOException ex) { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get list", url, ex); } @@ -129,7 +130,8 @@ public class TmdbLists extends AbstractMethod { } /** - * 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 @@ -217,7 +219,8 @@ public class TmdbLists extends AbstractMethod { * * This is a irreversible action and should be treated with caution. * - * A valid session id is required. A call without confirm=true will return status code 29. + * A valid session id is required. A call without confirm=true will return + * status code 29. * * @param sessionId * @param listId From 306f6f3cc21a67125bbcb0561febbb0fba817853 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Tue, 3 Mar 2015 13:19:33 +0000 Subject: [PATCH 062/100] stub methods --- .../omertron/themoviedbapi/TheMovieDbApi.java | 210 ++++++---- .../themoviedbapi/methods/TmdbMovies.java | 362 +++++++++++------- .../themoviedbapi/methods/TmdbMoviesTest.java | 23 +- 3 files changed, 370 insertions(+), 225 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 1596ac2d2..56bea5abf 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -95,7 +95,8 @@ import org.yamj.api.common.http.SimpleHttpClientBuilder; /** * The MovieDb API *

- * 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 */ @@ -193,7 +194,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. */ @@ -274,7 +276,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 @@ -440,13 +443,16 @@ public class TheMovieDbApi { // /** - * 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 @@ -456,7 +462,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. * @@ -469,7 +476,8 @@ public class TheMovieDbApi { } /** - * This method is used to generate a session id for user based authentication. User must provide their username and password + * This method is used to generate a session id for user based + * authentication. User must provide their username and password * * A session id is required in order to use any of the write methods. * @@ -486,14 +494,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 @@ -529,7 +541,8 @@ public class TheMovieDbApi { /** * Get a list of Movie IDs that have been edited. * - * You can then use the movie changes API to get the actual data that has been changed. + * You can then use the movie changes API to get the actual data that has + * been changed. * * @param page * @param startDate the start date of the changes, optional @@ -537,14 +550,15 @@ public class TheMovieDbApi { * @return List of changed movie * @throws MovieDbException */ - public List getMovieChangeList(int page, String startDate, String endDate) throws MovieDbException { + public List getMovieChangeList(Integer page, String startDate, String endDate) throws MovieDbException { return tmdbChanges.getChangeList(MethodBase.MOVIE, page, startDate, endDate); } /** * Get a list of TV IDs that have been edited. * - * You can then use the TV changes API to get the actual data that has been changed. + * You can then use the TV changes API to get the actual data that has been + * changed. * * @param page * @param startDate the start date of the changes, optional @@ -552,14 +566,15 @@ public class TheMovieDbApi { * @return List of changed movie * @throws MovieDbException */ - public List getTvChangeList(int page, String startDate, String endDate) throws MovieDbException { + public List getTvChangeList(Integer page, String startDate, String endDate) throws MovieDbException { return tmdbChanges.getChangeList(MethodBase.TV, page, startDate, endDate); } /** * Get a list of Person IDs that have been edited. * - * You can then use the person changes API to get the actual data that has been changed. + * You can then use the person changes API to get the actual data that has + * been changed. * * @param page * @param startDate the start date of the changes, optional @@ -567,16 +582,18 @@ public class TheMovieDbApi { * @return List of changed movie * @throws MovieDbException */ - public List getPersonChangeList(int page, String startDate, String endDate) throws MovieDbException { + public List getPersonChangeList(Integer page, String startDate, String endDate) throws MovieDbException { return tmdbChanges.getChangeList(MethodBase.PERSON, page, startDate, endDate); } // // /** - * 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 @@ -602,7 +619,8 @@ public class TheMovieDbApi { // /** - * 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 @@ -615,7 +633,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 * @@ -625,7 +644,7 @@ public class TheMovieDbApi { * @return * @throws MovieDbException */ - public List getCompanyMovies(int companyId, String language, int page) throws MovieDbException { + public List getCompanyMovies(int companyId, String language, Integer page) throws MovieDbException { return tmdbCompany.getCompanyMovies(companyId, language, page); } // @@ -664,7 +683,8 @@ public class TheMovieDbApi { } /** - * Get the list of supported timezones for the API methods that support them. + * Get the list of supported timezones for the API methods that support + * them. * * @return @throws MovieDbException */ @@ -679,11 +699,14 @@ public class TheMovieDbApi { *

* This is currently only supported with the new credit model found in TV. *
- * These IDs can be found from any TV credit response as well as the TV_credits and combined_credits methods for people.
- * The episodes object returns a list of episodes and are generally going to be guest stars.
+ * These IDs can be found from any TV credit response as well as the + * TV_credits and combined_credits methods for people.
+ * The episodes object returns a list of episodes and are generally going to + * be guest stars.
* The season array will return a list of season numbers.
- * Season credits are credits that were marked with the "add to every season" option in the editing interface and are assumed to - * be "season regulars". + * Season credits are credits that were marked with the "add to every + * season" option in the editing interface and are assumed to be "season + * regulars". * * @param creditId * @param language @@ -697,7 +720,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 @@ -708,7 +732,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 @@ -721,16 +746,18 @@ public class TheMovieDbApi { // /** - * You con use this method to find movies, tv series or persons using external ids. + * You con use this method to find movies, tv series or persons using + * external ids. * * Supported query ids are *

    *
  • Movies: imdb_id
  • *
  • People: imdb_id, freebase_mid, freebase_id, tvrage_id
  • - *
  • TV Series: imdb_id, freebase_mid, freebase_id, tvdb_id, tvrage_id
  • + *
  • TV Series: imdb_id, freebase_mid, freebase_id, tvdb_id, + * tvrage_id
  • *
  • TV Seasons: freebase_mid, freebase_id, tvdb_id, tvrage_id
  • - *
  • TV Episodes: imdb_id, freebase_mid, freebase_id, tvdb_id, tvrage_idimdb_id, freebase_mid, freebase_id, tvrage_id, - * tvdb_id. + *
  • TV Episodes: imdb_id, freebase_mid, freebase_id, tvdb_id, + * tvrage_idimdb_id, freebase_mid, freebase_id, tvrage_id, tvdb_id. *
* * For details see http://docs.themoviedb.apiary.io/#find @@ -772,9 +799,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 @@ -810,7 +839,7 @@ public class TheMovieDbApi { * @return List of movies with the keyword * @throws MovieDbException */ - public TmdbResultsList getKeywordMovies(String keywordId, String language, int page) throws MovieDbException { + public TmdbResultsList getKeywordMovies(String keywordId, String language, Integer page) throws MovieDbException { return tmdbKeywords.getKeywordMovies(keywordId, language, page); } //
@@ -841,7 +870,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 @@ -901,7 +931,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 @@ -918,7 +949,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 @@ -931,7 +963,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 @@ -958,7 +991,8 @@ public class TheMovieDbApi { } /** - * This method should be used when you’re wanting to retrieve all of the images for a particular movie. + * This method should be used when you’re wanting to retrieve all of the + * images for a particular movie. * * @param movieId * @param language @@ -971,7 +1005,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. * @@ -985,7 +1020,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 @@ -998,7 +1034,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. * @@ -1009,11 +1046,12 @@ public class TheMovieDbApi { * @throws MovieDbException */ public TmdbResultsList