Make changes generic
This commit is contained in:
@@ -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<ChangeKeyItem> 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<ChangeKeyItem> results = new ResultList<ChangeKeyItem>(wrapper.getChangedItems());
|
||||
wrapper.setResultProperties(results);
|
||||
return results;
|
||||
} catch (IOException ex) {
|
||||
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get changes", url, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<ChangeKeyItem> 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<ChangeKeyItem> results = new ResultList<ChangeKeyItem>(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
|
||||
|
||||
@@ -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<ChangeKeyItem> 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<ChangeKeyItem> results = new ResultList<ChangeKeyItem>(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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<ChangeKeyItem> 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<ChangeKeyItem> results = new ResultList<ChangeKeyItem>(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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<ChangeKeyItem> 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<ChangeKeyItem> results = new ResultList<ChangeKeyItem>(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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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<ChangeKeyItem> 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<ChangeKeyItem> results = new ResultList<ChangeKeyItem>(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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user