diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java
index 5948116ac..8b8afeb7c 100644
--- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java
+++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java
@@ -54,21 +54,9 @@ import com.omertron.themoviedbapi.model.Video;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import com.omertron.themoviedbapi.results.TmdbResultsMap;
import com.omertron.themoviedbapi.tools.ApiUrl;
-import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_ADULT;
-import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_COUNTRY;
-import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_END_DATE;
-import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_ID;
-import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_INCLUDE_ALL_MOVIES;
-import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_LANGUAGE;
-import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_PAGE;
-import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_PASSWORD;
-import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_QUERY;
-import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_SESSION;
-import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_START_DATE;
-import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_TOKEN;
-import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_USERNAME;
-import static com.omertron.themoviedbapi.tools.ApiUrl.PARAM_YEAR;
import com.omertron.themoviedbapi.tools.HttpTools;
+import com.omertron.themoviedbapi.tools.Param;
+import com.omertron.themoviedbapi.tools.TmdbParameters;
import com.omertron.themoviedbapi.wrapper.WrapperAlternativeTitles;
import com.omertron.themoviedbapi.wrapper.WrapperChanges;
import com.omertron.themoviedbapi.wrapper.WrapperCollection;
@@ -110,7 +98,8 @@ import org.yamj.api.common.http.SimpleHttpClientBuilder;
/**
* The MovieDb API
*
- * This is for version 3 of the API as specified here: http://help.themoviedb.org/kb/api/about-3
+ * This is for version 3 of the API as specified here:
+ * http://help.themoviedb.org/kb/api/about-3
*
* @author stuart.boston
*/
@@ -164,8 +153,7 @@ public class TheMovieDbApi {
this.apiKey = apiKey;
this.httpTools = new HttpTools(httpClient);
- ApiUrl apiUrl = new ApiUrl(apiKey, "configuration");
- URL configUrl = apiUrl.buildUrl();
+ URL configUrl = new ApiUrl(apiKey, "configuration").buildUrl();
String webpage = httpTools.getRequest(configUrl);
try {
@@ -194,7 +182,8 @@ public class TheMovieDbApi {
* @param moviedb The moviedb object to compare too
* @param title The title of the movie to compare
* @param year The year of the movie to compare
- * @param maxDistance The Levenshtein Distance between the two titles. 0 = exact match
+ * @param maxDistance The Levenshtein Distance between the two titles. 0 =
+ * exact match
* @param caseSensitive true if the comparison is to be case sensitive
* @return True if there is a match, False otherwise.
*/
@@ -310,21 +299,24 @@ public class TheMovieDbApi {
//
/**
- * This method is used to generate a valid request token for user based authentication.
+ * This method is used to generate a valid request token for user based
+ * authentication.
*
* A request token is required in order to request a session id.
*
- * You can generate any number of request tokens but they will expire after 60 minutes.
+ * You can generate any number of request tokens but they will expire after
+ * 60 minutes.
*
- * As soon as a valid session id has been created the token will be destroyed.
+ * As soon as a valid session id has been created the token will be
+ * destroyed.
*
* @return
* @throws MovieDbException
*/
public TokenAuthorisation getAuthorisationToken() throws MovieDbException {
- ApiUrl apiUrl = new ApiUrl(apiKey, BASE_AUTH, "token/new");
+ TmdbParameters parameters = new TmdbParameters();
+ URL url = new ApiUrl(apiKey, BASE_AUTH).setSubMethod("token/new").buildUrl(parameters);
- URL url = apiUrl.buildUrl();
String webpage = httpTools.getRequest(url);
try {
@@ -336,7 +328,8 @@ public class TheMovieDbApi {
}
/**
- * This method is used to generate a session id for user based authentication.
+ * This method is used to generate a session id for user based
+ * authentication.
*
* A session id is required in order to use any of the write methods.
*
@@ -345,15 +338,15 @@ public class TheMovieDbApi {
* @throws MovieDbException
*/
public TokenSession getSessionToken(TokenAuthorisation token) throws MovieDbException {
- ApiUrl apiUrl = new ApiUrl(apiKey, BASE_AUTH, "session/new");
+ 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!", apiUrl.buildUrl());
+ throw new MovieDbException(ApiExceptionType.AUTH_FAILURE, "Authorisation token was not successful!");
}
- apiUrl.addArgument(PARAM_TOKEN, token.getRequestToken());
- URL url = apiUrl.buildUrl();
+ parameters.add(Param.TOKEN, token.getRequestToken());
+ URL url = new ApiUrl(apiKey, BASE_AUTH).setSubMethod("session/new").buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -365,7 +358,8 @@ public class TheMovieDbApi {
}
/**
- * This method is used to generate a session id for user based authentication. User must provide their username and password
+ * This method is used to generate a session id for user based
+ * authentication. User must provide their username and password
*
* A session id is required in order to use any of the write methods.
*
@@ -376,18 +370,18 @@ public class TheMovieDbApi {
* @throws MovieDbException
*/
public TokenAuthorisation getSessionTokenLogin(TokenAuthorisation token, String username, String password) throws MovieDbException {
- ApiUrl apiUrl = new ApiUrl(apiKey, BASE_AUTH, "token/validate_with_login");
+ 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!", apiUrl.buildUrl());
+ throw new MovieDbException(ApiExceptionType.AUTH_FAILURE, "Authorisation token was not successful!");
}
- apiUrl.addArgument(PARAM_TOKEN, token.getRequestToken());
- apiUrl.addArgument(PARAM_USERNAME, username);
- apiUrl.addArgument(PARAM_PASSWORD, password);
+ parameters.add(Param.TOKEN, token.getRequestToken());
+ parameters.add(Param.USERNAME, username);
+ parameters.add(Param.PASSWORD, password);
- URL url = apiUrl.buildUrl();
+ URL url = new ApiUrl(apiKey, BASE_AUTH).setSubMethod("token/validate_with_login").buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -401,22 +395,24 @@ public class TheMovieDbApi {
/**
* This method is used to generate a guest session id.
*
- * A guest session can be used to rate movies without having a registered TMDb user account.
+ * A guest session can be used to rate movies without having a registered
+ * TMDb user account.
*
- * You should only generate a single guest session per user (or device) as you will be able to attach the ratings to a TMDb user
- * account in the future.
+ * You should only generate a single guest session per user (or device) as
+ * you will be able to attach the ratings to a TMDb user account in the
+ * future.
*
- * There are also IP limits in place so you should always make sure it's the end user doing the guest session actions.
+ * There are also IP limits in place so you should always make sure it's the
+ * end user doing the guest session actions.
*
- * If a guest session is not used for the first time within 24 hours, it will be automatically discarded.
+ * If a guest session is not used for the first time within 24 hours, it
+ * will be automatically discarded.
*
* @return
* @throws MovieDbException
*/
public TokenSession getGuestSessionToken() throws MovieDbException {
- ApiUrl apiUrl = new ApiUrl(apiKey, BASE_AUTH, "guest_session/new");
-
- URL url = apiUrl.buildUrl();
+ URL url = new ApiUrl(apiKey, BASE_AUTH).setSubMethod("guest_session/new").buildUrl();
String webpage = httpTools.getRequest(url);
try {
@@ -428,18 +424,18 @@ public class TheMovieDbApi {
}
/**
- * Get the basic information for an account. You will need to have a valid session id.
+ * Get the basic information for an account. You will need to have a valid
+ * session id.
*
* @param sessionId
* @return
* @throws MovieDbException
*/
public Account getAccount(String sessionId) throws MovieDbException {
- ApiUrl apiUrl = new ApiUrl(apiKey, BASE_ACCOUNT.replace("/", ""));
-
- apiUrl.addArgument(PARAM_SESSION, sessionId);
+ TmdbParameters parameters = new TmdbParameters();
+ parameters.add(Param.SESSION, sessionId);
- URL url = apiUrl.buildUrl();
+ URL url = new ApiUrl(apiKey, BASE_ACCOUNT.replace("/", "")).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -450,11 +446,19 @@ public class TheMovieDbApi {
}
}
+ /**
+ * Get the account favourite movies
+ *
+ * @param sessionId
+ * @param accountId
+ * @return
+ * @throws MovieDbException
+ */
public List getFavoriteMovies(String sessionId, int accountId) throws MovieDbException {
- ApiUrl apiUrl = new ApiUrl(apiKey, BASE_ACCOUNT, accountId + "/favorite_movies");
- apiUrl.addArgument(PARAM_SESSION, sessionId);
+ TmdbParameters parameters = new TmdbParameters();
+ parameters.add(Param.SESSION, sessionId);
- URL url = apiUrl.buildUrl();
+ URL url = new ApiUrl(apiKey, BASE_ACCOUNT).setSubMethod(accountId, "/favorite_movies").buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -466,16 +470,15 @@ public class TheMovieDbApi {
}
public StatusCode changeFavoriteStatus(String sessionId, int accountId, Integer movieId, boolean isFavorite) throws MovieDbException {
- ApiUrl apiUrl = new ApiUrl(apiKey, BASE_ACCOUNT, accountId + "/favorite");
-
- apiUrl.addArgument(PARAM_SESSION, sessionId);
+ 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 = apiUrl.buildUrl();
+ URL url = new ApiUrl(apiKey, BASE_ACCOUNT).setSubMethod(accountId, "/favorite").buildUrl(parameters);
String webpage = httpTools.postRequest(url, jsonBody);
try {
@@ -513,16 +516,15 @@ public class TheMovieDbApi {
}
private StatusCode modifyWatchList(String sessionId, int accountId, Integer movieId, boolean add) throws MovieDbException {
- ApiUrl apiUrl = new ApiUrl(apiKey, BASE_ACCOUNT, accountId + "/movie_watchlist");
-
- apiUrl.addArgument(PARAM_SESSION, sessionId);
+ 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 = apiUrl.buildUrl();
+ URL url = new ApiUrl(apiKey, BASE_ACCOUNT).setSubMethod(accountId, "/movie_watchlist").buildUrl(parameters);
String webpage = httpTools.postRequest(url, jsonBody);
try {
@@ -540,7 +542,8 @@ public class TheMovieDbApi {
*
* It will return the single highest rated poster and backdrop.
*
- * ApiExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies found.
+ * ApiExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies
+ * found.
*
* @param movieId
* @param language
@@ -549,17 +552,12 @@ public class TheMovieDbApi {
* @throws MovieDbException
*/
public MovieDb getMovieInfo(int movieId, String language, String... appendToResponse) throws MovieDbException {
- ApiUrl apiUrl = new ApiUrl(apiKey, BASE_MOVIE);
-
- apiUrl.addArgument(PARAM_ID, movieId);
-
- if (StringUtils.isNotBlank(language)) {
- apiUrl.addArgument(PARAM_LANGUAGE, language);
- }
-
- apiUrl.appendToResponse(appendToResponse);
+ TmdbParameters parameters = new TmdbParameters();
+ parameters.add(Param.ID, movieId);
+ parameters.add(Param.LANGUAGE, language);
+ parameters.add(Param.APPEND, appendToResponse);
- URL url = apiUrl.buildUrl();
+ URL url = new ApiUrl(apiKey, BASE_MOVIE).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
MovieDb movie = mapper.readValue(webpage, MovieDb.class);
@@ -579,7 +577,8 @@ public class TheMovieDbApi {
*
* It will return the single highest rated poster and backdrop.
*
- * ApiExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies found.
+ * ApiExceptionType.MOVIE_ID_NOT_FOUND will be thrown if there are no movies
+ * found.
*
* @param imdbId
* @param language
@@ -588,18 +587,14 @@ public class TheMovieDbApi {
* @throws MovieDbException
*/
public MovieDb getMovieInfoImdb(String imdbId, String language, String... appendToResponse) throws MovieDbException {
- ApiUrl apiUrl = new ApiUrl(apiKey, BASE_MOVIE);
-
- apiUrl.addArgument(PARAM_ID, imdbId);
-
- if (StringUtils.isNotBlank(language)) {
- apiUrl.addArgument(PARAM_LANGUAGE, language);
- }
-
- apiUrl.appendToResponse(appendToResponse);
+ TmdbParameters parameters = new TmdbParameters();
+ parameters.add(Param.ID, imdbId);
+ parameters.add(Param.LANGUAGE, language);
+ parameters.add(Param.APPEND, appendToResponse);
- URL url = apiUrl.buildUrl();
+ URL url = new ApiUrl(apiKey, BASE_MOVIE).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
+
try {
MovieDb movie = mapper.readValue(webpage, MovieDb.class);
if (movie == null || movie.getId() == 0) {
@@ -614,7 +609,8 @@ public class TheMovieDbApi {
}
/**
- * This method is used to retrieve all of the alternative titles we have for a particular movie.
+ * This method is used to retrieve all of the alternative titles we have for
+ * a particular movie.
*
* @param movieId
* @param country
@@ -623,16 +619,12 @@ public class TheMovieDbApi {
* @throws MovieDbException
*/
public TmdbResultsList getMovieAlternativeTitles(int movieId, String country, String... appendToResponse) throws MovieDbException {
- ApiUrl apiUrl = new ApiUrl(apiKey, BASE_MOVIE, "/alternative_titles");
- apiUrl.addArgument(PARAM_ID, movieId);
-
- if (StringUtils.isNotBlank(country)) {
- apiUrl.addArgument(PARAM_COUNTRY, country);
- }
+ TmdbParameters parameters = new TmdbParameters();
+ parameters.add(Param.ID, movieId);
+ parameters.add(Param.COUNTRY, country);
+ parameters.add(Param.APPEND, appendToResponse);
- apiUrl.appendToResponse(appendToResponse);
-
- URL url = apiUrl.buildUrl();
+ URL url = new ApiUrl(apiKey, BASE_MOVIE).setSubMethod("/alternative_titles").buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
WrapperAlternativeTitles wrapper = mapper.readValue(webpage, WrapperAlternativeTitles.class);
@@ -656,12 +648,11 @@ public class TheMovieDbApi {
* @throws MovieDbException
*/
public TmdbResultsList getMovieCasts(int movieId, String... appendToResponse) throws MovieDbException {
- ApiUrl apiUrl = new ApiUrl(apiKey, BASE_MOVIE, "/casts");
- apiUrl.addArgument(PARAM_ID, movieId);
-
- apiUrl.appendToResponse(appendToResponse);
+ TmdbParameters parameters = new TmdbParameters();
+ parameters.add(Param.ID, movieId);
+ parameters.add(Param.APPEND, appendToResponse);
- URL url = apiUrl.buildUrl();
+ URL url = new ApiUrl(apiKey, BASE_MOVIE).setSubMethod("casts").buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -676,7 +667,8 @@ public class TheMovieDbApi {
}
/**
- * This method should be used when you’re wanting to retrieve all of the images for a particular movie.
+ * This method should be used when you’re wanting to retrieve all of the
+ * images for a particular movie.
*
* @param movieId
* @param language
@@ -685,16 +677,12 @@ public class TheMovieDbApi {
* @throws MovieDbException
*/
public TmdbResultsList getMovieImages(int movieId, String language, String... appendToResponse) throws MovieDbException {
- ApiUrl apiUrl = new ApiUrl(apiKey, BASE_MOVIE, URL_IMAGES);
- apiUrl.addArgument(PARAM_ID, movieId);
+ TmdbParameters parameters = new TmdbParameters();
+ parameters.add(Param.ID, movieId);
+ parameters.add(Param.LANGUAGE, language);
+ parameters.add(Param.APPEND, appendToResponse);
- if (StringUtils.isNotBlank(language)) {
- apiUrl.addArgument(PARAM_LANGUAGE, language);
- }
-
- apiUrl.appendToResponse(appendToResponse);
-
- URL url = apiUrl.buildUrl();
+ URL url = new ApiUrl(apiKey, BASE_MOVIE).setSubMethod(URL_IMAGES).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -709,7 +697,8 @@ public class TheMovieDbApi {
}
/**
- * This method is used to retrieve all of the keywords that have been added to a particular movie.
+ * This method is used to retrieve all of the keywords that have been added
+ * to a particular movie.
*
* Currently, only English keywords exist.
*
@@ -719,12 +708,11 @@ public class TheMovieDbApi {
* @throws MovieDbException
*/
public TmdbResultsList getMovieKeywords(int movieId, String... appendToResponse) throws MovieDbException {
- ApiUrl apiUrl = new ApiUrl(apiKey, BASE_MOVIE, "/keywords");
- apiUrl.addArgument(PARAM_ID, movieId);
-
- apiUrl.appendToResponse(appendToResponse);
+ TmdbParameters parameters = new TmdbParameters();
+ parameters.add(Param.ID, movieId);
+ parameters.add(Param.APPEND, appendToResponse);
- URL url = apiUrl.buildUrl();
+ URL url = new ApiUrl(apiKey, BASE_MOVIE).setSubMethod("keywords").buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -739,7 +727,8 @@ public class TheMovieDbApi {
}
/**
- * This method is used to retrieve all of the release and certification data we have for a specific movie.
+ * This method is used to retrieve all of the release and certification data
+ * we have for a specific movie.
*
* @param movieId
* @param language
@@ -748,13 +737,12 @@ public class TheMovieDbApi {
* @throws MovieDbException
*/
public TmdbResultsList getMovieReleaseInfo(int movieId, String language, String... appendToResponse) throws MovieDbException {
- ApiUrl apiUrl = new ApiUrl(apiKey, BASE_MOVIE, "/releases");
- apiUrl.addArgument(PARAM_ID, movieId);
- apiUrl.addArgument(PARAM_LANGUAGE, language);
+ TmdbParameters parameters = new TmdbParameters();
+ parameters.add(Param.ID, movieId);
+ parameters.add(Param.LANGUAGE, language);
+ parameters.add(Param.APPEND, appendToResponse);
- apiUrl.appendToResponse(appendToResponse);
-
- URL url = apiUrl.buildUrl();
+ URL url = new ApiUrl(apiKey, BASE_MOVIE).setSubMethod("releases").buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -769,7 +757,8 @@ public class TheMovieDbApi {
}
/**
- * This method is used to retrieve all of the trailers for a particular movie.
+ * This method is used to retrieve all of the trailers for a particular
+ * movie.
*
* Supported sites are YouTube and QuickTime.
*
@@ -780,16 +769,12 @@ public class TheMovieDbApi {
* @throws MovieDbException
*/
public TmdbResultsList