Simplify ApiUrl

This commit is contained in:
Stuart Boston
2015-03-04 09:37:59 +00:00
parent 3828eca965
commit dd3e04e6d1
16 changed files with 155 additions and 116 deletions
@@ -91,7 +91,7 @@ public class TmdbAccount extends AbstractMethod {
parameters.add(Param.SESSION, sessionId);
parameters.add(Param.ID, accountId);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.LISTS).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).subMethod(MethodSub.LISTS).buildUrl(parameters);
return processWrapperList(getTypeReference(UserList.class), url, "user list");
}
@@ -108,7 +108,7 @@ public class TmdbAccount extends AbstractMethod {
parameters.add(Param.SESSION, sessionId);
parameters.add(Param.ID, accountId);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.FAVORITE_MOVIES).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).subMethod(MethodSub.FAVORITE_MOVIES).buildUrl(parameters);
return processWrapperList(getTypeReference(MovieBasic.class), url, "favorite movies");
}
@@ -125,7 +125,7 @@ public class TmdbAccount extends AbstractMethod {
parameters.add(Param.SESSION, sessionId);
parameters.add(Param.ID, accountId);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.FAVORITE_TV).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).subMethod(MethodSub.FAVORITE_TV).buildUrl(parameters);
return processWrapperList(getTypeReference(TVBasic.class), url, "favorite TV shows");
}
@@ -151,7 +151,7 @@ public class TmdbAccount extends AbstractMethod {
.add(PostBody.FAVORITE, setFavorite)
.build();
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.FAVORITE).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).subMethod(MethodSub.FAVORITE).buildUrl(parameters);
String webpage = httpTools.postRequest(url, jsonBody);
try {
@@ -180,7 +180,7 @@ public class TmdbAccount extends AbstractMethod {
parameters.add(Param.SORT_BY, sortBy);
parameters.add(Param.LANGUAGE, language);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.RATED_MOVIES).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).subMethod(MethodSub.RATED_MOVIES).buildUrl(parameters);
return processWrapperList(getTypeReference(MovieBasic.class), url, "rated movies");
}
@@ -203,7 +203,7 @@ public class TmdbAccount extends AbstractMethod {
parameters.add(Param.SORT_BY, sortBy);
parameters.add(Param.LANGUAGE, language);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.RATED_TV).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).subMethod(MethodSub.RATED_TV).buildUrl(parameters);
return processWrapperList(getTypeReference(TVBasic.class), url, "rated TV shows");
}
@@ -226,7 +226,7 @@ public class TmdbAccount extends AbstractMethod {
parameters.add(Param.SORT_BY, sortBy);
parameters.add(Param.LANGUAGE, language);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.WATCHLIST_MOVIES).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).subMethod(MethodSub.WATCHLIST_MOVIES).buildUrl(parameters);
return processWrapperList(getTypeReference(MovieBasic.class), url, "movie watch list");
}
@@ -249,7 +249,7 @@ public class TmdbAccount extends AbstractMethod {
parameters.add(Param.SORT_BY, sortBy);
parameters.add(Param.LANGUAGE, language);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.WATCHLIST_TV).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).subMethod(MethodSub.WATCHLIST_TV).buildUrl(parameters);
return processWrapperList(getTypeReference(TVBasic.class), url, "TV watch list");
}
@@ -275,7 +275,7 @@ public class TmdbAccount extends AbstractMethod {
.add(PostBody.WATCHLIST, addToWatchlist)
.build();
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.WATCHLIST).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).subMethod(MethodSub.WATCHLIST).buildUrl(parameters);
String webpage = httpTools.postRequest(url, jsonBody);
try {
@@ -305,7 +305,7 @@ public class TmdbAccount extends AbstractMethod {
parameters.add(Param.SORT_BY, sortBy.getPropertyString());
}
URL url = new ApiUrl(apiKey, MethodBase.GUEST_SESSION).setSubMethod(MethodSub.RATED_MOVIES_GUEST).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.GUEST_SESSION).subMethod(MethodSub.RATED_MOVIES_GUEST).buildUrl(parameters);
return processWrapperList(getTypeReference(MovieBasic.class), url, "Guest Session Movies");
}
}
@@ -63,7 +63,7 @@ public class TmdbAuthentication extends AbstractMethod {
*/
public TokenAuthorisation getAuthorisationToken() throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
URL url = new ApiUrl(apiKey, MethodBase.AUTH).setSubMethod(MethodSub.TOKEN_NEW).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.AUTH).subMethod(MethodSub.TOKEN_NEW).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
@@ -91,7 +91,7 @@ public class TmdbAuthentication extends AbstractMethod {
}
parameters.add(Param.TOKEN, token.getRequestToken());
URL url = new ApiUrl(apiKey, MethodBase.AUTH).setSubMethod(MethodSub.SESSION_NEW).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.AUTH).subMethod(MethodSub.SESSION_NEW).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -123,7 +123,7 @@ public class TmdbAuthentication extends AbstractMethod {
parameters.add(Param.USERNAME, username);
parameters.add(Param.PASSWORD, password);
URL url = new ApiUrl(apiKey, MethodBase.AUTH).setSubMethod(MethodSub.TOKEN_VALIDATE).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.AUTH).subMethod(MethodSub.TOKEN_VALIDATE).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -149,7 +149,7 @@ public class TmdbAuthentication extends AbstractMethod {
* @throws MovieDbException
*/
public TokenSession getGuestSessionToken() throws MovieDbException {
URL url = new ApiUrl(apiKey, MethodBase.AUTH).setSubMethod(MethodSub.GUEST_SESSION).buildUrl();
URL url = new ApiUrl(apiKey, MethodBase.AUTH).subMethod(MethodSub.GUEST_SESSION).buildUrl();
String webpage = httpTools.getRequest(url);
try {
@@ -58,7 +58,7 @@ public class TmdbCertifications extends AbstractMethod {
* @throws MovieDbException
*/
public TmdbResultsMap<String, List<Certification>> getMoviesCertification() throws MovieDbException {
URL url = new ApiUrl(apiKey, MethodBase.CERTIFICATION).setSubMethod(MethodSub.MOVIE_LIST).buildUrl();
URL url = new ApiUrl(apiKey, MethodBase.CERTIFICATION).subMethod(MethodSub.MOVIE_LIST).buildUrl();
String webpage = httpTools.getRequest(url);
try {
@@ -78,7 +78,7 @@ public class TmdbCertifications extends AbstractMethod {
* @throws MovieDbException
*/
public TmdbResultsMap<String, List<Certification>> getTvCertification() throws MovieDbException {
URL url = new ApiUrl(apiKey, MethodBase.CERTIFICATION).setSubMethod(MethodSub.TV_LIST).buildUrl();
URL url = new ApiUrl(apiKey, MethodBase.CERTIFICATION).subMethod(MethodSub.TV_LIST).buildUrl();
String webpage = httpTools.getRequest(url);
try {
@@ -68,7 +68,7 @@ public class TmdbChanges extends AbstractMethod {
params.add(Param.START_DATE, startDate);
params.add(Param.END_DATE, endDate);
URL url = new ApiUrl(apiKey, method).setSubMethod(MethodSub.CHANGES).buildUrl(params);
URL url = new ApiUrl(apiKey, method).subMethod(MethodSub.CHANGES).buildUrl(params);
TypeReference tr = new TypeReference<WrapperGenericList<ChangeListItem>>() {
};
return processWrapperList(tr, url, "changes");
@@ -92,7 +92,7 @@ public class TmdbCollections extends AbstractMethod {
parameters.add(Param.ID, collectionId);
parameters.add(Param.LANGUAGE, language);
URL url = new ApiUrl(apiKey, MethodBase.COLLECTION).setSubMethod(MethodSub.IMAGES).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.COLLECTION).subMethod(MethodSub.IMAGES).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -88,7 +88,7 @@ public class TmdbCompanies extends AbstractMethod {
parameters.add(Param.LANGUAGE, language);
parameters.add(Param.PAGE, page);
URL url = new ApiUrl(apiKey, MethodBase.COMPANY).setSubMethod(MethodSub.MOVIES).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.COMPANY).subMethod(MethodSub.MOVIES).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
return processWrapperList(getTypeReference(MovieBasic.class), url, webpage);
}
@@ -90,7 +90,7 @@ public class TmdbConfiguration extends AbstractMethod {
* @throws MovieDbException
*/
public TmdbResultsList<JobDepartment> getJobs() throws MovieDbException {
URL url = new ApiUrl(apiKey, MethodBase.JOB).setSubMethod(MethodSub.LIST).buildUrl();
URL url = new ApiUrl(apiKey, MethodBase.JOB).subMethod(MethodSub.LIST).buildUrl();
String webpage = httpTools.getRequest(url);
try {
@@ -104,7 +104,7 @@ public class TmdbConfiguration extends AbstractMethod {
}
public Map<String, List<String>> getTimezones() throws MovieDbException {
URL url = new ApiUrl(apiKey, MethodBase.TIMEZONES).setSubMethod(MethodSub.LIST).buildUrl();
URL url = new ApiUrl(apiKey, MethodBase.TIMEZONES).subMethod(MethodSub.LIST).buildUrl();
String webpage = httpTools.getRequest(url);
List<Map<String, List<String>>> tzList;
@@ -55,7 +55,7 @@ public class TmdbDiscover extends AbstractMethod {
* @throws MovieDbException
*/
public List<MovieBasic> getDiscoverMovies(Discover discover) throws MovieDbException {
URL url = new ApiUrl(apiKey, MethodBase.DISCOVER).setSubMethod(MethodSub.MOVIE).buildUrl(discover.getParams());
URL url = new ApiUrl(apiKey, MethodBase.DISCOVER).subMethod(MethodSub.MOVIE).buildUrl(discover.getParams());
String webpage = httpTools.getRequest(url);
return processWrapperList(getTypeReference(MovieBasic.class), url, webpage);
}
@@ -68,7 +68,7 @@ public class TmdbDiscover extends AbstractMethod {
* @throws MovieDbException
*/
public List<TVBasic> getDiscoverTV(Discover discover) throws MovieDbException {
URL url = new ApiUrl(apiKey, MethodBase.DISCOVER).setSubMethod(MethodSub.TV).buildUrl(discover.getParams());
URL url = new ApiUrl(apiKey, MethodBase.DISCOVER).subMethod(MethodSub.TV).buildUrl(discover.getParams());
String webpage = httpTools.getRequest(url);
return processWrapperList(getTypeReference(TVBasic.class), url, webpage);
}
@@ -85,7 +85,7 @@ public class TmdbGenres extends AbstractMethod {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.LANGUAGE, language);
URL url = new ApiUrl(apiKey, MethodBase.GENRE).setSubMethod(sub).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.GENRE).subMethod(sub).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -119,7 +119,7 @@ public class TmdbGenres extends AbstractMethod {
parameters.add(Param.INCLUDE_ALL_MOVIES, includeAllMovies);
parameters.add(Param.INCLUDE_ADULT, includeAdult);
URL url = new ApiUrl(apiKey, MethodBase.GENRE).setSubMethod(MethodSub.MOVIES).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.GENRE).subMethod(MethodSub.MOVIES).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
return processWrapperList(getTypeReference(MovieBasic.class), url, webpage);
@@ -88,7 +88,7 @@ public class TmdbKeywords extends AbstractMethod {
parameters.add(Param.LANGUAGE, language);
parameters.add(Param.PAGE, page);
URL url = new ApiUrl(apiKey, MethodBase.KEYWORD).setSubMethod(MethodSub.MOVIES).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.KEYWORD).subMethod(MethodSub.MOVIES).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -91,7 +91,7 @@ public class TmdbLists extends AbstractMethod {
parameters.add(Param.ID, listId);
parameters.add(Param.MOVIE_ID, mediaId);
URL url = new ApiUrl(apiKey, MethodBase.LIST).setSubMethod(MethodSub.ITEM_STATUS).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.LIST).subMethod(MethodSub.ITEM_STATUS).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -173,7 +173,7 @@ public class TmdbLists extends AbstractMethod {
.add(PostBody.MEDIA_ID, movieId)
.build();
URL url = new ApiUrl(apiKey, MethodBase.LIST).setSubMethod(operation).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.LIST).subMethod(operation).buildUrl(parameters);
String webpage = httpTools.postRequest(url, jsonBody);
try {
@@ -232,7 +232,7 @@ public class TmdbLists extends AbstractMethod {
parameters.add(Param.ID, listId);
parameters.add(Param.CONFIRM, confirm);
URL url = new ApiUrl(apiKey, MethodBase.LIST).setSubMethod(MethodSub.CLEAR).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.LIST).subMethod(MethodSub.CLEAR).buildUrl(parameters);
String webpage = httpTools.postRequest(url, "");
try {
@@ -156,7 +156,7 @@ public class TmdbMovies extends AbstractMethod {
parameters.add(Param.ID, movieId);
parameters.add(Param.SESSION, sessionId);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.ACCOUNT_STATES).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.ACCOUNT_STATES).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -181,7 +181,7 @@ public class TmdbMovies extends AbstractMethod {
parameters.add(Param.COUNTRY, country);
parameters.add(Param.APPEND, appendToResponse);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.ALT_TITLES).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.ALT_TITLES).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
WrapperAlternativeTitles wrapper = MAPPER.readValue(webpage, WrapperAlternativeTitles.class);
@@ -206,7 +206,7 @@ public class TmdbMovies extends AbstractMethod {
parameters.add(Param.ID, movieId);
parameters.add(Param.APPEND, appendToResponse);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.CREDITS).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.CREDITS).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
return MAPPER.readValue(webpage, MediaCreditList.class);
@@ -230,7 +230,7 @@ public class TmdbMovies extends AbstractMethod {
parameters.add(Param.LANGUAGE, language);
parameters.add(Param.APPEND, appendToResponse);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.IMAGES).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.IMAGES).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -258,7 +258,7 @@ public class TmdbMovies extends AbstractMethod {
parameters.add(Param.ID, movieId);
parameters.add(Param.APPEND, appendToResponse);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.KEYWORDS).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.KEYWORDS).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -286,7 +286,7 @@ public class TmdbMovies extends AbstractMethod {
parameters.add(Param.LANGUAGE, language);
parameters.add(Param.APPEND, appendToResponse);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.RELEASES).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.RELEASES).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -316,7 +316,7 @@ public class TmdbMovies extends AbstractMethod {
parameters.add(Param.LANGUAGE, language);
parameters.add(Param.APPEND, appendToResponse);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.VIDEOS).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.VIDEOS).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -342,7 +342,7 @@ public class TmdbMovies extends AbstractMethod {
parameters.add(Param.ID, movieId);
parameters.add(Param.APPEND, appendToResponse);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.TRANSLATIONS).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.TRANSLATIONS).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -376,7 +376,7 @@ public class TmdbMovies extends AbstractMethod {
parameters.add(Param.PAGE, page);
parameters.add(Param.APPEND, appendToResponse);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.SIMILAR_MOVIES).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.SIMILAR_MOVIES).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -406,7 +406,7 @@ public class TmdbMovies extends AbstractMethod {
parameters.add(Param.LANGUAGE, language);
parameters.add(Param.APPEND, appendToResponse);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.REVIEWS).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.REVIEWS).buildUrl(parameters);
WrapperGenericList<Review> wrapper = processWrapper(getTypeReference(Review.class), url, "review");
TmdbResultsList<Review> results = new TmdbResultsList<Review>(null);
results.getResults().addAll(wrapper.getResults());
@@ -431,7 +431,7 @@ public class TmdbMovies extends AbstractMethod {
parameters.add(Param.PAGE, page);
parameters.add(Param.APPEND, appendToResponse);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.LISTS).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.LISTS).buildUrl(parameters);
List<UserList> wrapper = processWrapperList(getTypeReference(UserList.class), url, "movie lists");
TmdbResultsList<UserList> results = new TmdbResultsList<UserList>(null);
results.getResults().addAll(wrapper);
@@ -461,7 +461,7 @@ public class TmdbMovies extends AbstractMethod {
parameters.add(Param.START_DATE, startDate);
parameters.add(Param.END_DATE, endDate);
URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.CHANGES).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.PERSON).subMethod(MethodSub.CHANGES).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -493,7 +493,7 @@ public class TmdbMovies extends AbstractMethod {
parameters.add(Param.SESSION, sessionId);
parameters.add(Param.GUEST_SESSION_ID, guestSessionId);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.RATING).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.RATING).buildUrl(parameters);
String jsonBody = new PostTools()
.add(PostBody.VALUE, rating)
@@ -514,7 +514,7 @@ public class TmdbMovies extends AbstractMethod {
* @throws MovieDbException
*/
public MovieDb getLatestMovie() throws MovieDbException {
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.LATEST).buildUrl();
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.LATEST).buildUrl();
String webpage = httpTools.getRequest(url);
try {
@@ -541,7 +541,7 @@ public class TmdbMovies extends AbstractMethod {
parameters.add(Param.LANGUAGE, language);
parameters.add(Param.PAGE, page);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.UPCOMING).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.UPCOMING).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -570,7 +570,7 @@ public class TmdbMovies extends AbstractMethod {
parameters.add(Param.LANGUAGE, language);
parameters.add(Param.PAGE, page);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.NOW_PLAYING).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.NOW_PLAYING).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -598,7 +598,7 @@ public class TmdbMovies extends AbstractMethod {
parameters.add(Param.LANGUAGE, language);
parameters.add(Param.PAGE, page);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.POPULAR).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.POPULAR).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -626,7 +626,7 @@ public class TmdbMovies extends AbstractMethod {
parameters.add(Param.LANGUAGE, language);
parameters.add(Param.PAGE, page);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.TOP_RATED).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).subMethod(MethodSub.TOP_RATED).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -97,7 +97,7 @@ public class TmdbPeople extends AbstractMethod {
parameters.add(Param.LANGUAGE, language);
parameters.add(Param.APPEND, appendToResponse);
URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.MOVIE_CREDITS).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.PERSON).subMethod(MethodSub.MOVIE_CREDITS).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -128,7 +128,7 @@ public class TmdbPeople extends AbstractMethod {
parameters.add(Param.LANGUAGE, language);
parameters.add(Param.APPEND, appendToResponse);
URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.TV_CREDITS).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.PERSON).subMethod(MethodSub.TV_CREDITS).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -159,7 +159,7 @@ public class TmdbPeople extends AbstractMethod {
parameters.add(Param.LANGUAGE, language);
parameters.add(Param.APPEND, appendToResponse);
URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.COMBINED_CREDITS).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.PERSON).subMethod(MethodSub.COMBINED_CREDITS).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -180,7 +180,7 @@ public class TmdbPeople extends AbstractMethod {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.ID, personId);
URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.EXTERNAL_IDS).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.PERSON).subMethod(MethodSub.EXTERNAL_IDS).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -201,7 +201,7 @@ public class TmdbPeople extends AbstractMethod {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.ID, personId);
URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.IMAGES).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.PERSON).subMethod(MethodSub.IMAGES).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -232,7 +232,7 @@ public class TmdbPeople extends AbstractMethod {
parameters.add(Param.PAGE, page);
parameters.add(Param.LANGUAGE, language);
URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.TAGGED_IMAGES).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.PERSON).subMethod(MethodSub.TAGGED_IMAGES).buildUrl(parameters);
WrapperGenericList<ArtworkMedia> wrapper;
@@ -274,7 +274,7 @@ public class TmdbPeople extends AbstractMethod {
parameters.add(Param.START_DATE, startDate);
parameters.add(Param.END_DATE, endDate);
URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.CHANGES).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.PERSON).subMethod(MethodSub.CHANGES).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -297,7 +297,7 @@ public class TmdbPeople extends AbstractMethod {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.PAGE, page);
URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.POPULAR).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.PERSON).subMethod(MethodSub.POPULAR).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
WrapperGenericList<PersonFind> wrapper;
@@ -320,7 +320,7 @@ public class TmdbPeople extends AbstractMethod {
* @throws MovieDbException
*/
public Person getPersonLatest() throws MovieDbException {
URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.LATEST).buildUrl();
URL url = new ApiUrl(apiKey, MethodBase.PERSON).subMethod(MethodSub.LATEST).buildUrl();
String webpage = httpTools.getRequest(url);
try {
@@ -78,7 +78,7 @@ public class TmdbSearch extends AbstractMethod {
parameters.add(Param.QUERY, query);
parameters.add(Param.PAGE, page);
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.COMPANY).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).subMethod(MethodSub.COMPANY).buildUrl(parameters);
WrapperGenericList<Company> wrapper = processWrapper(getTypeReference(Company.class), url, "company");
TmdbResultsList<Company> results = new TmdbResultsList<Company>(wrapper.getResults());
results.copyWrapper(wrapper);
@@ -100,7 +100,7 @@ public class TmdbSearch extends AbstractMethod {
parameters.add(Param.PAGE, page);
parameters.add(Param.LANGUAGE, language);
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.COLLECTION).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).subMethod(MethodSub.COLLECTION).buildUrl(parameters);
WrapperGenericList<Collection> wrapper = processWrapper(getTypeReference(Collection.class), url, "collection");
TmdbResultsList<Collection> results = new TmdbResultsList<Collection>(wrapper.getResults());
results.copyWrapper(wrapper);
@@ -120,7 +120,7 @@ public class TmdbSearch extends AbstractMethod {
parameters.add(Param.QUERY, query);
parameters.add(Param.PAGE, page);
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.KEYWORD).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).subMethod(MethodSub.KEYWORD).buildUrl(parameters);
WrapperGenericList<Keyword> wrapper = processWrapper(getTypeReference(Keyword.class), url, "keyword");
TmdbResultsList<Keyword> results = new TmdbResultsList<Keyword>(wrapper.getResults());
results.copyWrapper(wrapper);
@@ -142,7 +142,7 @@ public class TmdbSearch extends AbstractMethod {
parameters.add(Param.PAGE, page);
parameters.add(Param.INCLUDE_ADULT, includeAdult);
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.LIST).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).subMethod(MethodSub.LIST).buildUrl(parameters);
WrapperGenericList<UserList> wrapper = processWrapper(getTypeReference(UserList.class), url, "list");
TmdbResultsList<UserList> results = new TmdbResultsList<UserList>(wrapper.getResults());
results.copyWrapper(wrapper);
@@ -179,7 +179,7 @@ public class TmdbSearch extends AbstractMethod {
if (searchType != null) {
parameters.add(Param.SEARCH_TYPE, searchType.getPropertyString());
}
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.MOVIE).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).subMethod(MethodSub.MOVIE).buildUrl(parameters);
WrapperGenericList<MovieDb> wrapper = processWrapper(getTypeReference(MovieDb.class), url, "movie");
TmdbResultsList<MovieDb> results = new TmdbResultsList<MovieDb>(wrapper.getResults());
@@ -208,7 +208,7 @@ public class TmdbSearch extends AbstractMethod {
parameters.add(Param.LANGUAGE, language);
parameters.add(Param.ADULT, includeAdult);
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.MULTI).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).subMethod(MethodSub.MULTI).buildUrl(parameters);
String webpage = httpTools.getRequest(url);
try {
@@ -241,7 +241,7 @@ public class TmdbSearch extends AbstractMethod {
if (searchType != null) {
parameters.add(Param.SEARCH_TYPE, searchType.getPropertyString());
}
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.PERSON).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).subMethod(MethodSub.PERSON).buildUrl(parameters);
WrapperGenericList<PersonFind> wrapper = processWrapper(getTypeReference(PersonFind.class), url, "person");
TmdbResultsList<PersonFind> results = new TmdbResultsList<PersonFind>(wrapper.getResults());
@@ -269,7 +269,7 @@ public class TmdbSearch extends AbstractMethod {
if (searchType != null) {
parameters.add(Param.SEARCH_TYPE, searchType.getPropertyString());
}
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.MOVIE).buildUrl(parameters);
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).subMethod(MethodSub.MOVIE).buildUrl(parameters);
WrapperGenericList<TVBasic> wrapper = processWrapper(getTypeReference(TVBasic.class), url, "TV Show");
TmdbResultsList<TVBasic> results = new TmdbResultsList<TVBasic>(wrapper.getResults());
@@ -40,7 +40,6 @@ public class ApiUrl {
private static final Logger LOG = LoggerFactory.getLogger(ApiUrl.class);
// TheMovieDbApi API Base URL
private static final String TMDB_API_BASE = "http://api.themoviedb.org/3/";
// private static final String TMDB_API_BASE = "http://private-639f-themoviedb.apiary-proxy.com/3/";
// Parameter configuration
private static final String DELIMITER_FIRST = "?";
private static final String DELIMITER_SUBSEQUENT = "&";
@@ -66,7 +65,7 @@ public class ApiUrl {
* @param submethod
* @return
*/
public ApiUrl setSubMethod(MethodSub submethod) {
public ApiUrl subMethod(MethodSub submethod) {
this.submethod = submethod.getValue();
return this;
}
@@ -95,48 +94,95 @@ public class ApiUrl {
// Get the start of the URL
urlString.append(method);
// We have either a queury, or a direct request
// We have either a queury, or a ID request
if (params.has(Param.QUERY)) {
// Append the suffix of the API URL
if (StringUtils.isNotBlank(submethod)) {
urlString.append("/").append(submethod);
}
// Append the key information
urlString.append(DELIMITER_FIRST)
.append(Param.API_KEY.getValue())
.append(apiKey);
// Append the search term
urlString.append(DELIMITER_SUBSEQUENT);
urlString.append(Param.QUERY.getValue());
String query = (String) params.get(Param.QUERY);
try {
urlString.append(URLEncoder.encode(query, "UTF-8"));
} catch (UnsupportedEncodingException ex) {
LOG.trace("Unable to encode query: '{}' trying raw.", query, ex);
// If we can't encode it, try it raw
urlString.append(query);
}
urlString.append(queryProcessing(params));
} else {
// Append the ID if provided
if (params.has(Param.ID)) {
urlString.append("/").append(params.get(Param.ID));
}
if (StringUtils.isNotBlank(submethod)) {
urlString.append("/").append(submethod);
}
// Append the key information
urlString.append(DELIMITER_FIRST)
.append(Param.API_KEY.getValue())
.append(apiKey);
urlString.append(idProcessing(params));
}
// Append remaining parameters
urlString.append(otherProcessing(params));
try {
LOG.trace("URL: {}", urlString.toString());
return new URL(urlString.toString());
} catch (MalformedURLException ex) {
LOG.warn("Failed to create URL {} - {}", urlString.toString(), ex.getMessage());
return null;
}
}
/**
* Create the query based URL portion
*
* @param params
* @return
*/
private StringBuilder queryProcessing(TmdbParameters params) {
StringBuilder urlString = new StringBuilder();
// Append the suffix of the API URL
if (StringUtils.isNotBlank(submethod)) {
urlString.append("/").append(submethod);
}
// Append the key information
urlString.append(DELIMITER_FIRST)
.append(Param.API_KEY.getValue())
.append(apiKey);
// Append the search term
urlString.append(DELIMITER_SUBSEQUENT);
urlString.append(Param.QUERY.getValue());
String query = (String) params.get(Param.QUERY);
try {
urlString.append(URLEncoder.encode(query, "UTF-8"));
} catch (UnsupportedEncodingException ex) {
LOG.trace("Unable to encode query: '{}' trying raw.", query, ex);
// If we can't encode it, try it raw
urlString.append(query);
}
return urlString;
}
/**
* Create the ID based URL portion
*
* @param params
* @return
*/
private StringBuilder idProcessing(final TmdbParameters params) {
StringBuilder urlString = new StringBuilder();
// Append the ID
if (params.has(Param.ID)) {
urlString.append("/").append(params.get(Param.ID));
}
if (StringUtils.isNotBlank(submethod)) {
urlString.append("/").append(submethod);
}
// Append the key information
urlString.append(DELIMITER_FIRST)
.append(Param.API_KEY.getValue())
.append(apiKey);
return urlString;
}
/**
* Create a string of the remaining parameters
*
* @param params
* @return
*/
private StringBuilder otherProcessing(final TmdbParameters params) {
StringBuilder urlString = new StringBuilder();
for (Map.Entry<Param, String> argEntry : params.getEntries()) {
// Skip the ID an QUERY params
if (argEntry.getKey() == Param.ID || argEntry.getKey() == Param.QUERY) {
@@ -147,13 +193,6 @@ public class ApiUrl {
.append(argEntry.getKey().getValue())
.append(argEntry.getValue());
}
try {
LOG.trace("URL: {}", urlString.toString());
return new URL(urlString.toString());
} catch (MalformedURLException ex) {
LOG.warn("Failed to create URL {} - {}", urlString.toString(), ex.getMessage());
return null;
}
return urlString;
}
}
@@ -86,7 +86,7 @@ public class ApiUrlTest {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.QUERY, "query");
URL result = new ApiUrl(APIKEY, MethodBase.MOVIE).setSubMethod(MethodSub.LATEST).buildUrl(parameters);
URL result = new ApiUrl(APIKEY, MethodBase.MOVIE).subMethod(MethodSub.LATEST).buildUrl(parameters);
String expResult = "http://api.themoviedb.org/3/movie/latest?api_key=APIKEY&query=query";
assertEquals("Wrong Query-Sub URL", expResult, result.toString());
}
@@ -99,7 +99,7 @@ public class ApiUrlTest {
parameters.add(Param.PAGE, 1);
parameters.add(Param.LANGUAGE, "lang");
URL result = new ApiUrl(APIKEY, MethodBase.MOVIE).setSubMethod(MethodSub.LATEST).buildUrl(parameters);
URL result = new ApiUrl(APIKEY, MethodBase.MOVIE).subMethod(MethodSub.LATEST).buildUrl(parameters);
String expResult = "http://api.themoviedb.org/3/movie/latest?api_key=APIKEY&query=query&language=lang&page=1";
assertEquals("Wrong Query Extra URL", expResult, result.toString());
}
@@ -121,7 +121,7 @@ public class ApiUrlTest {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.ID, "ID");
URL result = new ApiUrl(APIKEY, MethodBase.MOVIE).setSubMethod(MethodSub.LATEST).buildUrl(parameters);
URL result = new ApiUrl(APIKEY, MethodBase.MOVIE).subMethod(MethodSub.LATEST).buildUrl(parameters);
String expResult = "http://api.themoviedb.org/3/movie/ID/latest?api_key=APIKEY";
assertEquals("Wrong ID-Sub URL", expResult, result.toString());
}
@@ -134,7 +134,7 @@ public class ApiUrlTest {
parameters.add(Param.PAGE, 1);
parameters.add(Param.LANGUAGE, "lang");
URL result = new ApiUrl(APIKEY, MethodBase.MOVIE).setSubMethod(MethodSub.LATEST).buildUrl(parameters);
URL result = new ApiUrl(APIKEY, MethodBase.MOVIE).subMethod(MethodSub.LATEST).buildUrl(parameters);
String expResult = "http://api.themoviedb.org/3/movie/ID/latest?api_key=APIKEY&language=lang&page=1";
assertEquals("Wrong Query Extra URL", expResult, result.toString());
}