From bbda0eec727b26d04a1e834150b2e45181854654 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Mon, 16 Feb 2015 08:50:11 +0000 Subject: [PATCH] Inital commit for release 4.0 Signed-off-by: Stuart Boston --- .../omertron/themoviedbapi/TheMovieDbApi.java | 942 +++++++++--------- .../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, 2251 insertions(+), 487 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; @@ -1200,30 +969,9 @@ 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. + * Get the list of popular people on The Movie Database. * - * 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. - * - * This list refreshes every day. + * This list refreshes every day. * * @return * @throws MovieDbException @@ -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()); }