diff --git a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java index 640829b02..a9587fd34 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java @@ -23,6 +23,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model.artwork.ArtworkMedia; +import com.omertron.themoviedbapi.model.change.ChangeKeyItem; import com.omertron.themoviedbapi.model.change.ChangeListItem; import com.omertron.themoviedbapi.model.collection.Collection; import com.omertron.themoviedbapi.model.company.Company; @@ -37,7 +38,14 @@ import com.omertron.themoviedbapi.model.person.PersonFind; import com.omertron.themoviedbapi.model.review.Review; import com.omertron.themoviedbapi.model.tv.TVBasic; import com.omertron.themoviedbapi.model.tv.TVInfo; +import com.omertron.themoviedbapi.results.ResultList; +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.WrapperChanges; import com.omertron.themoviedbapi.wrapper.WrapperGenericList; import java.io.IOException; import java.net.URL; @@ -156,4 +164,33 @@ public class AbstractMethod { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get " + errorMessageSuffix, url, ex); } } + + /** + * + * Look up the media's changes by ID + * + * @param mediaID + * @param startDate + * @param endDate + * @return + * @throws MovieDbException + */ + protected ResultList getMediaChanges(int mediaID, String startDate, String endDate) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, mediaID); + parameters.add(Param.START_DATE, startDate); + parameters.add(Param.END_DATE, endDate); + + URL url = new ApiUrl(apiKey, MethodBase.EPISODE).subMethod(MethodSub.CHANGES).buildUrl(parameters); + String webpage = httpTools.getRequest(url); + + try { + WrapperChanges wrapper = MAPPER.readValue(webpage, WrapperChanges.class); + ResultList results = new ResultList(wrapper.getChangedItems()); + wrapper.setResultProperties(results); + 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/TmdbEpisodes.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbEpisodes.java index f7dc3861a..4ef94d6b2 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbEpisodes.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbEpisodes.java @@ -38,7 +38,6 @@ import com.omertron.themoviedbapi.tools.Param; import com.omertron.themoviedbapi.tools.PostBody; import com.omertron.themoviedbapi.tools.PostTools; import com.omertron.themoviedbapi.tools.TmdbParameters; -import com.omertron.themoviedbapi.wrapper.WrapperChanges; import com.omertron.themoviedbapi.wrapper.WrapperImages; import com.omertron.themoviedbapi.wrapper.WrapperVideos; import java.io.IOException; @@ -66,8 +65,7 @@ public class TmdbEpisodes extends AbstractMethod { } /** - * Get the primary information about a TV episode by combination of a season - * and episode number. + * Get the primary information about a TV episode by combination of a season and episode number. * * @param tvID * @param seasonNumber @@ -106,27 +104,11 @@ public class TmdbEpisodes extends AbstractMethod { * @throws MovieDbException */ public ResultList getEpisodeChanges(int episodeID, String startDate, String endDate) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, episodeID); - parameters.add(Param.START_DATE, startDate); - parameters.add(Param.END_DATE, endDate); - - URL url = new ApiUrl(apiKey, MethodBase.EPISODE).subMethod(MethodSub.CHANGES).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperChanges wrapper = MAPPER.readValue(webpage, WrapperChanges.class); - ResultList results = new ResultList(wrapper.getChangedItems()); - wrapper.setResultProperties(results); - return results; - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get changes", url, ex); - } + return getMediaChanges(episodeID, startDate, endDate); } /** - * This method lets users get the status of whether or not the TV episode - * has been rated. + * This method lets users get the status of whether or not the TV episode has been rated. * * A valid session id is required. * @@ -179,8 +161,7 @@ public class TmdbEpisodes extends AbstractMethod { } /** - * Get the external ids for a TV episode by comabination of a season and - * episode number. + * Get the external ids for a TV episode by comabination of a season and episode number. * * @param tvID * @param seasonNumber @@ -207,8 +188,7 @@ public class TmdbEpisodes extends AbstractMethod { } /** - * Get the images (episode stills) for a TV episode by combination of a - * season and episode number. + * Get the images (episode stills) for a TV episode by combination of a season and episode number. * * @param tvID * @param seasonNumber @@ -236,8 +216,7 @@ public class TmdbEpisodes extends AbstractMethod { } /** - * This method lets users rate a TV episode. A valid session id or guest - * session id is required. + * This method lets users rate a TV episode. A valid session id or guest session id is required. * * @param tvID * @param seasonNumber @@ -274,8 +253,7 @@ public class TmdbEpisodes extends AbstractMethod { } /** - * Get the videos that have been added to a TV episode (teasers, clips, - * etc...) + * Get the videos that have been added to a TV episode (teasers, clips, etc...) * * @param tvID * @param seasonNumber diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java index 693ac5653..b748b37be 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbMovies.java @@ -44,7 +44,6 @@ import com.omertron.themoviedbapi.tools.PostBody; import com.omertron.themoviedbapi.tools.PostTools; import com.omertron.themoviedbapi.tools.TmdbParameters; import com.omertron.themoviedbapi.wrapper.WrapperAlternativeTitles; -import com.omertron.themoviedbapi.wrapper.WrapperChanges; import com.omertron.themoviedbapi.wrapper.WrapperGenericList; import com.omertron.themoviedbapi.wrapper.WrapperImages; import com.omertron.themoviedbapi.wrapper.WrapperMovieKeywords; @@ -442,22 +441,7 @@ public class TmdbMovies extends AbstractMethod { * @throws MovieDbException */ public ResultList getMovieChanges(int movieId, String startDate, String endDate) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, movieId); - parameters.add(Param.START_DATE, startDate); - parameters.add(Param.END_DATE, endDate); - - URL url = new ApiUrl(apiKey, MethodBase.PERSON).subMethod(MethodSub.CHANGES).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperChanges wrapper = MAPPER.readValue(webpage, WrapperChanges.class); - ResultList results = new ResultList(wrapper.getChangedItems()); - wrapper.setResultProperties(results); - return results; - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get changes", url, ex); - } + return getMediaChanges(movieId, startDate, endDate); } /** diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java index 2393e9b3d..ae735bfcc 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java @@ -42,7 +42,6 @@ import com.omertron.themoviedbapi.tools.MethodBase; import com.omertron.themoviedbapi.tools.MethodSub; import com.omertron.themoviedbapi.tools.Param; import com.omertron.themoviedbapi.tools.TmdbParameters; -import com.omertron.themoviedbapi.wrapper.WrapperChanges; import com.omertron.themoviedbapi.wrapper.WrapperGenericList; import com.omertron.themoviedbapi.wrapper.WrapperImages; import java.io.IOException; @@ -271,22 +270,7 @@ public class TmdbPeople extends AbstractMethod { * @throws com.omertron.themoviedbapi.MovieDbException */ public ResultList getPersonChanges(int personId, String startDate, String endDate) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, personId); - parameters.add(Param.START_DATE, startDate); - parameters.add(Param.END_DATE, endDate); - - URL url = new ApiUrl(apiKey, MethodBase.PERSON).subMethod(MethodSub.CHANGES).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperChanges wrapper = MAPPER.readValue(webpage, WrapperChanges.class); - ResultList results = new ResultList(wrapper.getChangedItems()); - wrapper.setResultProperties(results); - return results; - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person changes", url, ex); - } + return getMediaChanges(personId, startDate, endDate); } /** diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSeasons.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSeasons.java index 1b8c6ddbd..a6c138fb4 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSeasons.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSeasons.java @@ -35,7 +35,6 @@ import com.omertron.themoviedbapi.tools.MethodBase; import com.omertron.themoviedbapi.tools.MethodSub; import com.omertron.themoviedbapi.tools.Param; import com.omertron.themoviedbapi.tools.TmdbParameters; -import com.omertron.themoviedbapi.wrapper.WrapperChanges; import com.omertron.themoviedbapi.wrapper.WrapperImages; import com.omertron.themoviedbapi.wrapper.WrapperVideos; import java.io.IOException; @@ -96,22 +95,7 @@ public class TmdbSeasons extends AbstractMethod { * @throws MovieDbException */ public ResultList getSeasonChanges(int tvID, String startDate, String endDate) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, tvID); - parameters.add(Param.START_DATE, startDate); - parameters.add(Param.END_DATE, endDate); - - URL url = new ApiUrl(apiKey, MethodBase.SEASON).subMethod(MethodSub.CHANGES).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperChanges wrapper = MAPPER.readValue(webpage, WrapperChanges.class); - ResultList results = new ResultList(wrapper.getChangedItems()); - wrapper.setResultProperties(results); - return results; - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get changes", url, ex); - } + return getMediaChanges(tvID, startDate, endDate); } /** diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbTV.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbTV.java index 2dd35bd71..5c61b39a7 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbTV.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbTV.java @@ -43,7 +43,6 @@ import com.omertron.themoviedbapi.tools.Param; import com.omertron.themoviedbapi.tools.PostBody; import com.omertron.themoviedbapi.tools.PostTools; import com.omertron.themoviedbapi.tools.TmdbParameters; -import com.omertron.themoviedbapi.wrapper.WrapperChanges; import com.omertron.themoviedbapi.wrapper.WrapperGenericList; import com.omertron.themoviedbapi.wrapper.WrapperImages; import com.omertron.themoviedbapi.wrapper.WrapperTranslations; @@ -148,22 +147,7 @@ public class TmdbTV extends AbstractMethod { * @throws com.omertron.themoviedbapi.MovieDbException */ public ResultList getTVChanges(int tvID, String startDate, String endDate) throws MovieDbException { - TmdbParameters parameters = new TmdbParameters(); - parameters.add(Param.ID, tvID); - parameters.add(Param.START_DATE, startDate); - parameters.add(Param.END_DATE, endDate); - - URL url = new ApiUrl(apiKey, MethodBase.TV).subMethod(MethodSub.CHANGES).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - WrapperChanges wrapper = MAPPER.readValue(webpage, WrapperChanges.class); - ResultList results = new ResultList(wrapper.getChangedItems()); - wrapper.setResultProperties(results); - return results; - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get changes", url, ex); - } + return getMediaChanges(tvID, startDate, endDate); } /**