clazz) throws TmdbResponseException {
+ String jsonResponse = tmdbApi.getTmdbUrlReader().readUrl(apiUrl.buildUrl(), jsonBody, requestType);
try {
- // check if was error responseStatus
- ResponseStatus responseStatus = jsonMapper.readValue(webpage, ResponseStatus.class);
- // work around the problem that there's no status code for suspected spam names yet
- String suspectedSpam = "Unable to create list because: Description is suspected to be spam.";
- if (webpage.contains(suspectedSpam)) {
- responseStatus = new ResponseStatus(-100, suspectedSpam);
- }
-
- // if null, the json response was not a error responseStatus code, but something else
+ // check if the response was successful. tmdb have their own codes for successful and unsuccessful responses.
+ // some 2xx codes are not successful. See: https://developer.themoviedb.org/docs/errors for more info.
+ ResponseStatus responseStatus = responseStatusReader.readValue(jsonResponse);
Integer statusCode = responseStatus.getStatusCode();
- if (statusCode != null && !SUCCESS_STATUS_CODES.contains(statusCode)) {
- throw new ResponseStatusException(responseStatus);
+
+ if (statusCode != null) {
+ TmdbResponseCode tmdbResponseCode = TmdbResponseCode.fromCode(statusCode);
+
+ if (tmdbResponseCode != null) {
+ if (REQUEST_LIMIT_EXCEEDED == tmdbResponseCode) {
+ Thread.sleep(1000);
+ return mapJsonResult(apiUrl, jsonBody, requestType, clazz);
+ }
+ else if (!tmdbResponseCode.isSuccess()) {
+ throw new TmdbResponseException(tmdbResponseCode);
+ }
+ }
}
- return jsonMapper.readValue(webpage, clazz);
+ return objectMapper.readValue(jsonResponse, clazz);
}
- catch (IOException ex) {
- throw new MovieDbException("mapping failed:\n" + webpage, ex);
+ catch (JsonProcessingException | InterruptedException exception) {
+ throw new TmdbResponseException(exception);
}
}
}
diff --git a/src/main/java/info/movito/themoviedbapi/TmdbAccount.java b/src/main/java/info/movito/themoviedbapi/TmdbAccount.java
index db4bccff..134710d4 100644
--- a/src/main/java/info/movito/themoviedbapi/TmdbAccount.java
+++ b/src/main/java/info/movito/themoviedbapi/TmdbAccount.java
@@ -4,11 +4,13 @@
import info.movito.themoviedbapi.model.config.Account;
import info.movito.themoviedbapi.model.core.AccountID;
import info.movito.themoviedbapi.model.core.MovieResultsPage;
-import info.movito.themoviedbapi.model.core.ResponseStatus;
+import info.movito.themoviedbapi.model.core.responses.ResponseStatus;
import info.movito.themoviedbapi.model.core.ResultsPage;
import info.movito.themoviedbapi.model.core.SessionToken;
+import info.movito.themoviedbapi.model.core.responses.TmdbResponseException;
import info.movito.themoviedbapi.tools.ApiUrl;
import info.movito.themoviedbapi.tools.MovieDbException;
+import info.movito.themoviedbapi.tools.TmdbResponseCode;
import java.util.Collections;
import java.util.HashMap;
@@ -36,7 +38,7 @@ public class TmdbAccount extends AbstractTmdbApi {
/**
* Get the basic information for an account. You will need to have a valid session id.
*/
- public Account getAccount(SessionToken sessionToken) {
+ public Account getAccount(SessionToken sessionToken) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_ACCOUNT);
apiUrl.addPathParam(PARAM_SESSION, sessionToken);
@@ -48,7 +50,7 @@ public Account getAccount(SessionToken sessionToken) {
* Get the lists that as user has created.
*/
public MovieListResultsPage getLists(SessionToken sessionToken, AccountID accountId, String language,
- Integer page) {
+ Integer page) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_ACCOUNT, accountId, "lists");
apiUrl.addPathParam(PARAM_SESSION, sessionToken);
@@ -61,7 +63,7 @@ public MovieListResultsPage getLists(SessionToken sessionToken, AccountID accoun
/**
* Get the rated movies from the account.
*/
- public MovieResultsPage getRatedMovies(SessionToken sessionToken, AccountID accountId, Integer page) {
+ public MovieResultsPage getRatedMovies(SessionToken sessionToken, AccountID accountId, Integer page) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_ACCOUNT, accountId, "rated/movies");
apiUrl.addPathParam(PARAM_SESSION, sessionToken);
@@ -73,7 +75,7 @@ public MovieResultsPage getRatedMovies(SessionToken sessionToken, AccountID acco
/**
* Get the rated tv shows from the account.
*/
- public TvResultsPage getRatedTvSeries(SessionToken sessionToken, AccountID accountId, Integer page) {
+ public TvResultsPage getRatedTvSeries(SessionToken sessionToken, AccountID accountId, Integer page) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_ACCOUNT, accountId, "rated/tv");
apiUrl.addPathParam(PARAM_SESSION, sessionToken);
@@ -85,7 +87,8 @@ public TvResultsPage getRatedTvSeries(SessionToken sessionToken, AccountID accou
/**
* Get the rated tv episodes from the account.
*/
- public TvEpisodesResultsPage getRatedEpisodes(SessionToken sessionToken, AccountID accountId, Integer page) {
+ public TvEpisodesResultsPage getRatedEpisodes(SessionToken sessionToken, AccountID accountId, Integer page)
+ throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_ACCOUNT, accountId, "rated/tv/episodes");
apiUrl.addPathParam(PARAM_SESSION, sessionToken);
@@ -99,7 +102,7 @@ public TvEpisodesResultsPage getRatedEpisodes(SessionToken sessionToken, Account
*
* A valid session id is required.
*/
- public boolean postMovieRating(SessionToken sessionToken, Integer movieId, Integer rating) {
+ public boolean postMovieRating(SessionToken sessionToken, Integer movieId, Integer rating) throws TmdbResponseException {
return postRatingInternal(sessionToken, rating, new ApiUrl(TmdbMovies.TMDB_METHOD_MOVIE, movieId, "rating"));
}
@@ -108,7 +111,7 @@ public boolean postMovieRating(SessionToken sessionToken, Integer movieId, Integ
*
* A valid session id is required.
*/
- public boolean postTvSeriesRating(SessionToken sessionToken, Integer movieId, Integer rating) {
+ public boolean postTvSeriesRating(SessionToken sessionToken, Integer movieId, Integer rating) throws TmdbResponseException {
return postRatingInternal(sessionToken, rating, new ApiUrl(TmdbTV.TMDB_METHOD_TV, movieId, "rating"));
}
@@ -116,7 +119,7 @@ public boolean postTvSeriesRating(SessionToken sessionToken, Integer movieId, In
* This method lets users rate a tv episode.
*/
public boolean postTvExpisodeRating(SessionToken sessionToken, Integer seriesId, Integer seasonNumber,
- Integer episodeNumber, Integer rating) {
+ Integer episodeNumber, Integer rating) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(
TMDB_METHOD_TV, seriesId,
TMDB_METHOD_TV_SEASON, seasonNumber,
@@ -127,22 +130,22 @@ public boolean postTvExpisodeRating(SessionToken sessionToken, Integer seriesId,
return postRatingInternal(sessionToken, rating, apiUrl);
}
- private boolean postRatingInternal(SessionToken sessionToken, Integer rating, ApiUrl apiUrl) {
+ private boolean postRatingInternal(SessionToken sessionToken, Integer rating, ApiUrl apiUrl) throws TmdbResponseException {
apiUrl.addPathParam(PARAM_SESSION, sessionToken);
if (rating < 0 || rating > 10) {
throw new MovieDbException("rating out of range");
}
- String jsonBody = Utils.convertToJson(jsonMapper, Collections.singletonMap("value", rating));
+ String jsonBody = Utils.convertToJson(getObjectMapper(), Collections.singletonMap("value", rating));
- return mapJsonResult(apiUrl, ResponseStatus.class, jsonBody).getStatusCode() == 12;
+ return mapJsonResult(apiUrl, jsonBody, ResponseStatus.class).getStatusCode() == TmdbResponseCode.ITEM_UPDATED.getTmdbCode();
}
/**
* Get favourites movies from the account.
*/
- public MovieResultsPage getFavoriteMovies(SessionToken sessionToken, AccountID accountId) {
+ public MovieResultsPage getFavoriteMovies(SessionToken sessionToken, AccountID accountId) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_ACCOUNT, accountId, "favorite/movies");
apiUrl.addPathParam(PARAM_SESSION, sessionToken);
@@ -152,7 +155,7 @@ public MovieResultsPage getFavoriteMovies(SessionToken sessionToken, AccountID a
/**
* Get the favorite tv shows from the account.
*/
- public TvResultsPage getFavoriteSeries(SessionToken sessionToken, AccountID accountId, Integer page) {
+ public TvResultsPage getFavoriteSeries(SessionToken sessionToken, AccountID accountId, Integer page) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_ACCOUNT, accountId, "favorite/tv");
apiUrl.addPathParam(PARAM_SESSION, sessionToken);
@@ -165,7 +168,7 @@ public TvResultsPage getFavoriteSeries(SessionToken sessionToken, AccountID acco
* Remove a movie from an account's favorites list.
*/
public ResponseStatus addFavorite(SessionToken sessionToken, AccountID accountId, Integer movieId,
- MediaType mediaType) {
+ MediaType mediaType) throws TmdbResponseException {
return changeFavoriteStatus(sessionToken, accountId, movieId, mediaType, true);
}
@@ -173,25 +176,25 @@ public ResponseStatus addFavorite(SessionToken sessionToken, AccountID accountId
* Remove a movie from an account's favorites list.
*/
public ResponseStatus removeFavorite(SessionToken sessionToken, AccountID accountId, Integer movieId,
- MediaType mediaType) {
+ MediaType mediaType) throws TmdbResponseException {
return changeFavoriteStatus(sessionToken, accountId, movieId, mediaType, false);
}
private ResponseStatus changeFavoriteStatus(SessionToken sessionToken, AccountID accountId, Integer movieId,
- MediaType mediaType, boolean isFavorite) {
+ MediaType mediaType, boolean isFavorite) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_ACCOUNT, accountId, "favorite");
apiUrl.addPathParam(PARAM_SESSION, sessionToken);
- HashMap body = new HashMap();
+ HashMap body = new HashMap<>();
body.put("media_type", mediaType.toString());
body.put("media_id", movieId);
body.put("favorite", isFavorite);
- String jsonBody = Utils.convertToJson(jsonMapper, body);
+ String jsonBody = Utils.convertToJson(getObjectMapper(), body);
- return mapJsonResult(apiUrl, ResponseStatus.class, jsonBody);
+ return mapJsonResult(apiUrl, jsonBody, ResponseStatus.class);
}
/**
@@ -199,7 +202,7 @@ private ResponseStatus changeFavoriteStatus(SessionToken sessionToken, AccountID
*
* @return The watchlist of the user
*/
- public MovieResultsPage getWatchListMovies(SessionToken sessionToken, AccountID accountId, Integer page) {
+ public MovieResultsPage getWatchListMovies(SessionToken sessionToken, AccountID accountId, Integer page) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_ACCOUNT, accountId, "watchlist/movies");
apiUrl.addPathParam(PARAM_SESSION, sessionToken);
@@ -213,7 +216,7 @@ public MovieResultsPage getWatchListMovies(SessionToken sessionToken, AccountID
*
* @return The watchlist of the user
*/
- public TvResultsPage getWatchListSeries(SessionToken sessionToken, AccountID accountId, Integer page) {
+ public TvResultsPage getWatchListSeries(SessionToken sessionToken, AccountID accountId, Integer page) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_ACCOUNT, accountId, "watchlist/tv");
apiUrl.addPathParam(PARAM_SESSION, sessionToken);
@@ -226,7 +229,7 @@ public TvResultsPage getWatchListSeries(SessionToken sessionToken, AccountID acc
* Add a movie to an account's watch list.
*/
public ResponseStatus addToWatchList(SessionToken sessionToken, AccountID accountId, Integer movieId,
- MediaType mediaType) {
+ MediaType mediaType) throws TmdbResponseException {
return modifyWatchList(sessionToken, accountId, movieId, mediaType, true);
}
@@ -234,25 +237,25 @@ public ResponseStatus addToWatchList(SessionToken sessionToken, AccountID accoun
* Remove a movie from an account's watch list.
*/
public ResponseStatus removeFromWatchList(SessionToken sessionToken, AccountID accountId, Integer movieId,
- MediaType mediaType) {
+ MediaType mediaType) throws TmdbResponseException {
return modifyWatchList(sessionToken, accountId, movieId, mediaType, false);
}
private ResponseStatus modifyWatchList(SessionToken sessionToken, AccountID accountId, Integer movieId,
- MediaType mediaType, boolean isWatched) {
+ MediaType mediaType, boolean isWatched) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_ACCOUNT, accountId, "watchlist");
apiUrl.addPathParam(PARAM_SESSION, sessionToken);
- HashMap body = new HashMap();
+ HashMap body = new HashMap<>();
body.put("media_type", mediaType.toString());
body.put("media_id", movieId);
body.put("watchlist", isWatched);
- String jsonBody = Utils.convertToJson(jsonMapper, body);
+ String jsonBody = Utils.convertToJson(getObjectMapper(), body);
- return mapJsonResult(apiUrl, ResponseStatus.class, jsonBody);
+ return mapJsonResult(apiUrl, jsonBody, ResponseStatus.class);
}
/**
diff --git a/src/main/java/info/movito/themoviedbapi/TmdbApi.java b/src/main/java/info/movito/themoviedbapi/TmdbApi.java
index e7cf125a..ffc9a12d 100644
--- a/src/main/java/info/movito/themoviedbapi/TmdbApi.java
+++ b/src/main/java/info/movito/themoviedbapi/TmdbApi.java
@@ -2,16 +2,13 @@
import info.movito.themoviedbapi.model.config.Timezone;
import info.movito.themoviedbapi.model.config.TmdbConfiguration;
-import info.movito.themoviedbapi.tools.ApiUrl;
+import info.movito.themoviedbapi.model.core.responses.TmdbResponseException;
import info.movito.themoviedbapi.tools.MovieDbException;
-import info.movito.themoviedbapi.tools.RequestCountLimitException;
-import info.movito.themoviedbapi.tools.RequestType;
-import info.movito.themoviedbapi.tools.UrlReader;
-import info.movito.themoviedbapi.tools.WebBrowser;
+import info.movito.themoviedbapi.tools.TmdbHttpClient;
+import info.movito.themoviedbapi.tools.TmdbUrlReader;
+import lombok.AccessLevel;
import lombok.Getter;
-import org.apache.commons.lang3.StringUtils;
-import java.net.URL;
import java.util.List;
/**
@@ -21,21 +18,14 @@
* @author Holger Brandl.
*/
public class TmdbApi {
- @Getter
- private final String apiKey;
-
- private final TmdbConfiguration tmdbConfig;
-
/**
- * Reader implementation that is used to fetch all websites.
+ * Http client to make requests to the movie database api.
+ * can make certain things static if necessary
*/
- private final UrlReader urlReader;
+ @Getter(AccessLevel.PROTECTED)
+ private final TmdbUrlReader tmdbUrlReader;
- /**
- * Automatically retry after indicated amount of seconds if we hit the request limit. See the
- * documentation for details.
- */
- private final boolean autoRetry;
+ private final TmdbConfiguration tmdbConfig;
/**
* Constructor.
@@ -43,20 +33,16 @@ public class TmdbApi {
* @param apiKey your TMDB api key
*/
public TmdbApi(String apiKey) {
- this(apiKey, new WebBrowser(), true);
+ this(new TmdbHttpClient(apiKey));
}
/**
* Constructor.
*
- * @param apiKey your TMDB api key
- * @param urlReader the reader implementation that is used to fetch all websites
- * @param autoRetry automatically retry after indicated amount of seconds if we hit the request limit.
+ * @param tmdbUrlReader the url reader to use
*/
- public TmdbApi(String apiKey, UrlReader urlReader, boolean autoRetry) {
- this.urlReader = urlReader;
- this.apiKey = apiKey;
- this.autoRetry = autoRetry;
+ public TmdbApi(TmdbUrlReader tmdbUrlReader) {
+ this.tmdbUrlReader = tmdbUrlReader;
try {
tmdbConfig = new TmdbConfig(this).getConfig().getTmdbConfiguration();
@@ -69,43 +55,12 @@ public TmdbApi(String apiKey, UrlReader urlReader, boolean autoRetry) {
}
}
- /**
- * Uses the instance's api key to request information from api.tmdb.org.
- *
- * Depending on the autoRetry
setting this method will stall and internally recurse until the request was successfully
- * processed.
- *
- * @param apiUrl The url to be requested
- * @param jsonBody can be null
- */
- public String requestWebPage(ApiUrl apiUrl, String jsonBody, RequestType requestType) {
- assert StringUtils.isNotBlank(apiKey);
- apiUrl.addPathParam(AbstractTmdbApi.PARAM_API_KEY, getApiKey());
-
- return requestWebPageInternal(apiUrl.buildUrl(), jsonBody, requestType);
- }
-
- private String requestWebPageInternal(URL url, String jsonBody, RequestType requestType) {
- try {
- return urlReader.request(url, jsonBody, requestType);
- }
- catch (RequestCountLimitException rcle) {
- if (autoRetry) {
- Utils.sleep(rcle.getRetryAfter() * 1000);
- return requestWebPageInternal(url, jsonBody, requestType);
- }
- else {
- // just return the orignal json response if autoRetry is disabled. This will cause a ResponseStatusException.
- return rcle.getMessage();
- }
- }
- }
-
public TmdbConfiguration getConfiguration() {
return tmdbConfig;
}
- public List getTimezones() {
+ @SuppressWarnings("checkstyle:MissingJavadocMethod")
+ public List getTimezones() throws TmdbResponseException {
return new TmdbTimezones(this).getTimezones();
}
diff --git a/src/main/java/info/movito/themoviedbapi/TmdbAuthentication.java b/src/main/java/info/movito/themoviedbapi/TmdbAuthentication.java
index 1f578a4f..0566d6c9 100644
--- a/src/main/java/info/movito/themoviedbapi/TmdbAuthentication.java
+++ b/src/main/java/info/movito/themoviedbapi/TmdbAuthentication.java
@@ -2,6 +2,7 @@
import info.movito.themoviedbapi.model.config.TokenAuthorisation;
import info.movito.themoviedbapi.model.config.TokenSession;
+import info.movito.themoviedbapi.model.core.responses.TmdbResponseException;
import info.movito.themoviedbapi.tools.ApiUrl;
import info.movito.themoviedbapi.tools.MovieDbException;
@@ -31,7 +32,7 @@ public class TmdbAuthentication extends AbstractTmdbApi {
* As soon as a valid session id has been created the token will be destroyed.
*/
- public TokenAuthorisation getAuthorisationToken() {
+ public TokenAuthorisation getAuthorisationToken() throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_AUTH, "token/new");
return mapJsonResult(apiUrl, TokenAuthorisation.class);
@@ -42,7 +43,7 @@ public TokenAuthorisation getAuthorisationToken() {
*
* A session id is required in order to use any of the write methods.
*/
- public TokenSession getSessionToken(TokenAuthorisation token) {
+ public TokenSession getSessionToken(TokenAuthorisation token) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_AUTH, "session/new");
if (!token.getSuccess()) {
@@ -63,7 +64,7 @@ public TokenSession getSessionToken(TokenAuthorisation token) {
* @param pwd password
* @return The validated TokenAuthorisation. The same as input with getSuccess()==true
*/
- public TokenAuthorisation getLoginToken(TokenAuthorisation token, String user, String pwd) {
+ public TokenAuthorisation getLoginToken(TokenAuthorisation token, String user, String pwd) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_AUTH, "token/validate_with_login");
apiUrl.addPathParam(PARAM_REQUEST_TOKEN, token.getRequestToken());
@@ -88,7 +89,7 @@ public TokenAuthorisation getLoginToken(TokenAuthorisation token, String user, S
* @return validated TokenSession
* @throws info.movito.themoviedbapi.tools.MovieDbException if the login failed
*/
- public TokenSession getSessionLogin(String username, String password) {
+ public TokenSession getSessionLogin(String username, String password) throws TmdbResponseException {
TokenAuthorisation authToken = getAuthorisationToken();
if (!authToken.getSuccess()) {
@@ -117,7 +118,7 @@ public TokenSession getSessionLogin(String username, String password) {
*
* If a guest session is not used for the first time within 24 hours, it will be automatically discarded.
*/
- public TokenSession getGuestSessionToken() {
+ public TokenSession getGuestSessionToken() throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_AUTH, "guest_session/new");
return mapJsonResult(apiUrl, TokenSession.class);
diff --git a/src/main/java/info/movito/themoviedbapi/TmdbCollections.java b/src/main/java/info/movito/themoviedbapi/TmdbCollections.java
index 684d3e70..fb17df89 100644
--- a/src/main/java/info/movito/themoviedbapi/TmdbCollections.java
+++ b/src/main/java/info/movito/themoviedbapi/TmdbCollections.java
@@ -3,6 +3,7 @@
import info.movito.themoviedbapi.model.Artwork;
import info.movito.themoviedbapi.model.CollectionInfo;
import info.movito.themoviedbapi.model.MovieImages;
+import info.movito.themoviedbapi.model.core.responses.TmdbResponseException;
import info.movito.themoviedbapi.tools.ApiUrl;
import java.util.List;
@@ -29,7 +30,7 @@ public class TmdbCollections extends AbstractTmdbApi {
*
* You can get the ID needed for this method by making a getMovieInfo request for the belongs_to_collection.
*/
- public CollectionInfo getCollectionInfo(int collectionId, String language) {
+ public CollectionInfo getCollectionInfo(int collectionId, String language) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_COLLECTION, collectionId);
apiUrl.addLanguage(language);
@@ -40,7 +41,7 @@ public CollectionInfo getCollectionInfo(int collectionId, String language) {
/**
* Get all of the images for a particular collection by collection id.
*/
- public List getCollectionImages(int collectionId, String language) {
+ public List getCollectionImages(int collectionId, String language) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_COLLECTION, collectionId, "images");
apiUrl.addLanguage(language);
diff --git a/src/main/java/info/movito/themoviedbapi/TmdbCompany.java b/src/main/java/info/movito/themoviedbapi/TmdbCompany.java
index a4f77472..77e48b5b 100644
--- a/src/main/java/info/movito/themoviedbapi/TmdbCompany.java
+++ b/src/main/java/info/movito/themoviedbapi/TmdbCompany.java
@@ -3,6 +3,7 @@
import info.movito.themoviedbapi.model.Collection;
import info.movito.themoviedbapi.model.Company;
import info.movito.themoviedbapi.model.core.ResultsPage;
+import info.movito.themoviedbapi.model.core.responses.TmdbResponseException;
import info.movito.themoviedbapi.tools.ApiUrl;
/**
@@ -22,7 +23,7 @@ public class TmdbCompany extends AbstractTmdbApi {
/**
* This method is used to retrieve the basic information about a production company on TMDb.
*/
- public Company getCompanyInfo(int companyId) {
+ public Company getCompanyInfo(int companyId) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_COMPANY, companyId);
return mapJsonResult(apiUrl, Company.class);
@@ -33,7 +34,7 @@ public Company getCompanyInfo(int companyId) {
*
* These movies are returned in order of most recently released to oldest. The default response will return 20
*/
- public CollectionResultsPage getCompanyMovies(int companyId, String language, Integer page) {
+ public CollectionResultsPage getCompanyMovies(int companyId, String language, Integer page) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_COMPANY, companyId, "movies");
apiUrl.addLanguage(language);
diff --git a/src/main/java/info/movito/themoviedbapi/TmdbConfig.java b/src/main/java/info/movito/themoviedbapi/TmdbConfig.java
index ca976dfd..129d97ef 100644
--- a/src/main/java/info/movito/themoviedbapi/TmdbConfig.java
+++ b/src/main/java/info/movito/themoviedbapi/TmdbConfig.java
@@ -1,6 +1,7 @@
package info.movito.themoviedbapi;
import info.movito.themoviedbapi.model.config.ConfigResults;
+import info.movito.themoviedbapi.model.core.responses.TmdbResponseException;
import info.movito.themoviedbapi.tools.ApiUrl;
/**
@@ -17,7 +18,7 @@ class TmdbConfig extends AbstractTmdbApi {
super(tmdbApi);
}
- public ConfigResults getConfig() {
+ public ConfigResults getConfig() throws TmdbResponseException {
return mapJsonResult(new ApiUrl(TMDB_METHOD_CONFIGURATION), ConfigResults.class);
}
}
diff --git a/src/main/java/info/movito/themoviedbapi/TmdbDiscover.java b/src/main/java/info/movito/themoviedbapi/TmdbDiscover.java
index 5e0c5a0f..c09b56d4 100644
--- a/src/main/java/info/movito/themoviedbapi/TmdbDiscover.java
+++ b/src/main/java/info/movito/themoviedbapi/TmdbDiscover.java
@@ -2,6 +2,7 @@
import info.movito.themoviedbapi.model.Discover;
import info.movito.themoviedbapi.model.core.MovieResultsPage;
+import info.movito.themoviedbapi.model.core.responses.TmdbResponseException;
import info.movito.themoviedbapi.tools.ApiUrl;
/**
@@ -50,7 +51,7 @@ public class TmdbDiscover extends AbstractTmdbApi {
public MovieResultsPage getDiscover(int page, String language, String sortBy, boolean includeAdult, int year, int primaryReleaseYear,
int voteCountGte, float voteAverageGte, String withGenres, String releaseDateGte,
String releaseDateLte, String certificationCountry, String certificationLte,
- String withCompanies) {
+ String withCompanies) throws TmdbResponseException {
Discover discover = new Discover();
discover.page(page)
@@ -77,7 +78,7 @@ public MovieResultsPage getDiscover(int page, String language, String sortBy, bo
* @param discover A discover object containing the search criteria required
* @return the movie results page.
*/
- public MovieResultsPage getDiscover(Discover discover) {
+ public MovieResultsPage getDiscover(Discover discover) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_DISCOVER, "movie");
for (String key : discover.getParams().keySet()) {
@@ -118,7 +119,8 @@ public MovieResultsPage getDiscover(Discover discover) {
*/
public TvResultsPage getDiscoverTV(int page, String language, String sortBy, boolean includeAdult, int year, int primaryReleaseYear,
int voteCountGte, float voteAverageGte, String withGenres, String releaseDateGte,
- String releaseDateLte, String certificationCountry, String certificationLte, String withCompanies) {
+ String releaseDateLte, String certificationCountry, String certificationLte, String withCompanies)
+ throws TmdbResponseException {
Discover discover = new Discover();
discover.page(page)
@@ -145,7 +147,7 @@ public TvResultsPage getDiscoverTV(int page, String language, String sortBy, boo
* @param discover A discover object containing the search criteria required
* @return the tv results page.
*/
- public TvResultsPage getDiscoverTV(Discover discover) {
+ public TvResultsPage getDiscoverTV(Discover discover) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_DISCOVER, "tv");
for (String key : discover.getParams().keySet()) {
diff --git a/src/main/java/info/movito/themoviedbapi/TmdbFind.java b/src/main/java/info/movito/themoviedbapi/TmdbFind.java
index a80482c5..4e4fb018 100644
--- a/src/main/java/info/movito/themoviedbapi/TmdbFind.java
+++ b/src/main/java/info/movito/themoviedbapi/TmdbFind.java
@@ -1,6 +1,7 @@
package info.movito.themoviedbapi;
import info.movito.themoviedbapi.model.FindResults;
+import info.movito.themoviedbapi.model.core.responses.TmdbResponseException;
import info.movito.themoviedbapi.tools.ApiUrl;
/**
@@ -20,7 +21,7 @@ public class TmdbFind extends AbstractTmdbApi {
/**
* Supported query ids are imdb, people, freebase, series. For details see http://docs.themoviedb.apiary.io/#find
*/
- public FindResults find(String id, ExternalSource externalSource, String language) {
+ public FindResults find(String id, ExternalSource externalSource, String language) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_FIND, id);
apiUrl.addPathParam("external_source", externalSource.toString());
diff --git a/src/main/java/info/movito/themoviedbapi/TmdbGenre.java b/src/main/java/info/movito/themoviedbapi/TmdbGenre.java
index b269fd42..01aaf2cd 100644
--- a/src/main/java/info/movito/themoviedbapi/TmdbGenre.java
+++ b/src/main/java/info/movito/themoviedbapi/TmdbGenre.java
@@ -4,6 +4,7 @@
import info.movito.themoviedbapi.model.Genre;
import info.movito.themoviedbapi.model.core.AbstractJsonMapping;
import info.movito.themoviedbapi.model.core.MovieResultsPage;
+import info.movito.themoviedbapi.model.core.responses.TmdbResponseException;
import info.movito.themoviedbapi.tools.ApiUrl;
import java.util.List;
@@ -31,7 +32,7 @@ public TmdbGenre(TmdbApi tmdbApi) {
* @deprecated use {@code getMovieGenreList} as TV shows Genres was added.
*/
@Deprecated
- public List getGenreList(String language) {
+ public List getGenreList(String language) throws TmdbResponseException {
return getMovieGenreList(language);
}
@@ -41,7 +42,7 @@ public List getGenreList(String language) {
*
* These IDs will correspond to those found in movie calls.
*/
- public List getMovieGenreList(String language) {
+ public List getMovieGenreList(String language) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_GENRE, "movie", "list");
apiUrl.addLanguage(language);
@@ -55,7 +56,7 @@ public List getMovieGenreList(String language) {
*
* These IDs will correspond to those found in TV shows calls.
*/
- public List getTvGenreList(String language) {
+ public List getTvGenreList(String language) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_GENRE, "tv", "list");
apiUrl.addLanguage(language);
@@ -70,7 +71,8 @@ public List getTvGenreList(String language) {
*
* This prevents movies from 1 10/10 rating from being listed first and for the first 5 pages.
*/
- public MovieResultsPage getGenreMovies(int genreId, String language, Integer page, boolean includeAllMovies) {
+ public MovieResultsPage getGenreMovies(int genreId, String language, Integer page, boolean includeAllMovies)
+ throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_GENRE, genreId, "movies");
apiUrl.addLanguage(language);
diff --git a/src/main/java/info/movito/themoviedbapi/TmdbKeywords.java b/src/main/java/info/movito/themoviedbapi/TmdbKeywords.java
index d987b46a..e1c39a6e 100644
--- a/src/main/java/info/movito/themoviedbapi/TmdbKeywords.java
+++ b/src/main/java/info/movito/themoviedbapi/TmdbKeywords.java
@@ -2,6 +2,7 @@
import info.movito.themoviedbapi.model.core.MovieResultsPage;
import info.movito.themoviedbapi.model.core.ResultsPage;
+import info.movito.themoviedbapi.model.core.responses.TmdbResponseException;
import info.movito.themoviedbapi.model.keywords.Keyword;
import info.movito.themoviedbapi.tools.ApiUrl;
@@ -22,7 +23,7 @@ public class TmdbKeywords extends AbstractTmdbApi {
/**
* Get the basic information for a specific keyword id.
*/
- public Keyword getKeyword(String keywordId) {
+ public Keyword getKeyword(String keywordId) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_KEYWORD, keywordId);
return mapJsonResult(apiUrl, Keyword.class);
@@ -33,7 +34,7 @@ public Keyword getKeyword(String keywordId) {
*
* @return List of movies with the keyword
*/
- public MovieResultsPage getKeywordMovies(String keywordId, String language, Integer page) {
+ public MovieResultsPage getKeywordMovies(String keywordId, String language, Integer page) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_KEYWORD, keywordId, "movies");
apiUrl.addLanguage(language);
diff --git a/src/main/java/info/movito/themoviedbapi/TmdbLists.java b/src/main/java/info/movito/themoviedbapi/TmdbLists.java
index 70cf94d9..cbbba8fa 100644
--- a/src/main/java/info/movito/themoviedbapi/TmdbLists.java
+++ b/src/main/java/info/movito/themoviedbapi/TmdbLists.java
@@ -3,8 +3,9 @@
import info.movito.themoviedbapi.model.ListItemStatus;
import info.movito.themoviedbapi.model.MovieList;
import info.movito.themoviedbapi.model.MovieListCreationStatus;
-import info.movito.themoviedbapi.model.core.ResponseStatus;
+import info.movito.themoviedbapi.model.core.responses.ResponseStatus;
import info.movito.themoviedbapi.model.core.SessionToken;
+import info.movito.themoviedbapi.model.core.responses.TmdbResponseException;
import info.movito.themoviedbapi.tools.ApiUrl;
import info.movito.themoviedbapi.tools.RequestType;
import org.apache.commons.lang3.StringUtils;
@@ -31,7 +32,7 @@ public TmdbLists(TmdbApi tmdbApi) {
*
* @return The list and its items
*/
- public MovieList getList(String listId) {
+ public MovieList getList(String listId) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_LIST, listId);
return mapJsonResult(apiUrl, MovieList.class);
@@ -42,7 +43,7 @@ public MovieList getList(String listId) {
*
* @return The list id
*/
- public String createList(SessionToken sessionToken, String name, String description) {
+ public String createList(SessionToken sessionToken, String name, String description) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_LIST);
apiUrl.addPathParam(TmdbAccount.PARAM_SESSION, sessionToken);
@@ -51,9 +52,9 @@ public String createList(SessionToken sessionToken, String name, String descript
body.put("name", StringUtils.trimToEmpty(name));
body.put("description", StringUtils.trimToEmpty(description));
- String jsonBody = Utils.convertToJson(jsonMapper, body);
+ String jsonBody = Utils.convertToJson(getObjectMapper(), body);
- return mapJsonResult(apiUrl, MovieListCreationStatus.class, jsonBody).getListId();
+ return mapJsonResult(apiUrl, jsonBody, MovieListCreationStatus.class).getListId();
}
/**
@@ -61,7 +62,7 @@ public String createList(SessionToken sessionToken, String name, String descript
*
* @return true if the movie is on the list
*/
- public boolean isMovieOnList(String listId, Integer movieId) {
+ public boolean isMovieOnList(String listId, Integer movieId) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_LIST, listId, "item_status");
apiUrl.addPathParam("movie_id", movieId);
@@ -74,7 +75,7 @@ public boolean isMovieOnList(String listId, Integer movieId) {
*
* @return true if the movie is on the list
*/
- public ResponseStatus addMovieToList(SessionToken sessionToken, String listId, Integer movieId) {
+ public ResponseStatus addMovieToList(SessionToken sessionToken, String listId, Integer movieId) throws TmdbResponseException {
return modifyMovieList(sessionToken, listId, movieId, "add_item");
}
@@ -83,29 +84,29 @@ public ResponseStatus addMovieToList(SessionToken sessionToken, String listId, I
*
* @return true if the movie is on the list
*/
- public ResponseStatus removeMovieFromList(SessionToken sessionToken, String listId, Integer movieId) {
+ public ResponseStatus removeMovieFromList(SessionToken sessionToken, String listId, Integer movieId) throws TmdbResponseException {
return modifyMovieList(sessionToken, listId, movieId, "remove_item");
}
private ResponseStatus modifyMovieList(SessionToken sessionToken, String listId, Integer movieId,
- String operation) {
+ String operation) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_LIST, listId, operation);
apiUrl.addPathParam(TmdbAccount.PARAM_SESSION, sessionToken);
- String jsonBody = Utils.convertToJson(jsonMapper, Collections.singletonMap("media_id", movieId + ""));
+ String jsonBody = Utils.convertToJson(getObjectMapper(), Collections.singletonMap("media_id", movieId + ""));
- return mapJsonResult(apiUrl, ResponseStatus.class, jsonBody);
+ return mapJsonResult(apiUrl, jsonBody, ResponseStatus.class);
}
/**
* This method lets users delete a list that they created. A valid session id is required.
*/
- public ResponseStatus deleteMovieList(SessionToken sessionToken, String listId) {
+ public ResponseStatus deleteMovieList(SessionToken sessionToken, String listId) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_LIST, listId);
apiUrl.addPathParam(TmdbAccount.PARAM_SESSION, sessionToken);
- return mapJsonResult(apiUrl, ResponseStatus.class, null, RequestType.DELETE);
+ return mapJsonResult(apiUrl, null, RequestType.DELETE, ResponseStatus.class);
}
}
diff --git a/src/main/java/info/movito/themoviedbapi/TmdbMovies.java b/src/main/java/info/movito/themoviedbapi/TmdbMovies.java
index 0790bfaf..97866a7b 100644
--- a/src/main/java/info/movito/themoviedbapi/TmdbMovies.java
+++ b/src/main/java/info/movito/themoviedbapi/TmdbMovies.java
@@ -15,6 +15,7 @@
import info.movito.themoviedbapi.model.core.IdElement;
import info.movito.themoviedbapi.model.core.MovieResultsPage;
import info.movito.themoviedbapi.model.core.SessionToken;
+import info.movito.themoviedbapi.model.core.responses.TmdbResponseException;
import info.movito.themoviedbapi.model.keywords.Keyword;
import info.movito.themoviedbapi.model.providers.ProviderResults;
import info.movito.themoviedbapi.tools.ApiUrl;
@@ -55,7 +56,7 @@ public TmdbMovies(TmdbApi tmdbApi) {
*
* It will return the single highest rated poster and backdrop.
*/
- public MovieDb getMovie(int movieId, String language, MovieMethod... appendToResponse) {
+ public MovieDb getMovie(int movieId, String language, MovieMethod... appendToResponse) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_MOVIE, movieId);
apiUrl.addLanguage(language);
@@ -68,7 +69,7 @@ public MovieDb getMovie(int movieId, String language, MovieMethod... appendToRes
/**
* This method is used to retrieve all the alternative titles we have for a particular movie.
*/
- public List getAlternativeTitles(int movieId, String country) {
+ public List getAlternativeTitles(int movieId, String country) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_MOVIE, movieId, MovieMethod.alternative_titles);
if (StringUtils.isNotBlank(country)) {
@@ -84,7 +85,7 @@ public List getAlternativeTitles(int movieId, String country)
* @param movieId the movies id
* @return the movie credits
*/
- public Credits getCredits(int movieId) {
+ public Credits getCredits(int movieId) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_MOVIE, movieId, MovieMethod.credits);
return mapJsonResult(apiUrl, Credits.class);
@@ -93,7 +94,7 @@ public Credits getCredits(int movieId) {
/**
* This method should be used when you’re wanting to retrieve all of the images for a particular movie.
*/
- public MovieImages getImages(int movieId, String language) {
+ public MovieImages getImages(int movieId, String language) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_MOVIE, movieId, MovieMethod.images);
apiUrl.addLanguage(language);
@@ -106,7 +107,7 @@ public MovieImages getImages(int movieId, String language) {
*
* Currently, only English keywords exist.
*/
- public List getKeywords(int movieId) {
+ public List getKeywords(int movieId) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_MOVIE, movieId, MovieMethod.keywords);
return mapJsonResult(apiUrl, KeywordResults.class).results;
@@ -115,7 +116,7 @@ public List getKeywords(int movieId) {
/**
* This method is used to retrieve all of the release and certification data we have for a specific movie.
*/
- public List getReleaseInfo(int movieId, String language) {
+ public List getReleaseInfo(int movieId, String language) throws TmdbResponseException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_MOVIE, movieId, MovieMethod.release_dates);
apiUrl.addLanguage(language);
@@ -128,7 +129,7 @@ public List getReleaseInfo(int movieId, String language) {
*
* Supported sites are YouTube and QuickTime.
*/
- public List