Add Enum URL methods
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -54,9 +54,9 @@ public class ApiUrl {
|
||||
* @param apiKey
|
||||
* @param method
|
||||
*/
|
||||
public ApiUrl(String apiKey, String method) {
|
||||
public ApiUrl(String apiKey, MethodBase method) {
|
||||
this.apiKey = apiKey;
|
||||
this.method = method;
|
||||
this.method = method.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,8 +65,8 @@ public class ApiUrl {
|
||||
* @param submethod
|
||||
* @return
|
||||
*/
|
||||
public ApiUrl setSubMethod(String submethod) {
|
||||
this.submethod = submethod;
|
||||
public ApiUrl setSubMethod(MethodSub submethod) {
|
||||
this.submethod = submethod.getValue();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -77,8 +77,8 @@ public class ApiUrl {
|
||||
* @param submethod
|
||||
* @return
|
||||
*/
|
||||
public ApiUrl setSubMethod(int someId, String submethod) {
|
||||
this.submethod = someId + submethod;
|
||||
public ApiUrl setSubMethod(int someId, MethodSub submethod) {
|
||||
this.submethod = someId + submethod.getValue();
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -89,8 +89,8 @@ public class ApiUrl {
|
||||
* @param submethod
|
||||
* @return
|
||||
*/
|
||||
public ApiUrl setSubMethod(String someId, String submethod) {
|
||||
this.submethod = someId + submethod;
|
||||
public ApiUrl setSubMethod(String someId, MethodSub submethod) {
|
||||
this.submethod = someId + submethod.getValue();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2004-2015 Stuart Boston
|
||||
*
|
||||
* This file is part of TheMovieDB API.
|
||||
*
|
||||
* TheMovieDB API is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* TheMovieDB API is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with TheMovieDB API. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.omertron.themoviedbapi.tools;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public enum MethodBase {
|
||||
|
||||
ACCOUNT("account"),
|
||||
AUTH("authentication"),
|
||||
COLLECTION("collection"),
|
||||
COMPANY("company"),
|
||||
CONFIGURATION("configuration"),
|
||||
DISCOVER("discover"),
|
||||
GENRE("genre"),
|
||||
JOB("job"),
|
||||
KEYWORD("keyword"),
|
||||
LIST("list"),
|
||||
MOVIE("movie"),
|
||||
PERSON("person"),
|
||||
SEARCH("search");
|
||||
|
||||
private final String value;
|
||||
|
||||
private MethodBase(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL parameter to use
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string into an Enum type
|
||||
*
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public static MethodBase fromString(String value) {
|
||||
if (StringUtils.isNotBlank(value)) {
|
||||
for (final MethodBase method : EnumSet.allOf(MethodBase.class)) {
|
||||
if (value.equalsIgnoreCase(method.value)) {
|
||||
return method;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We've not found the type!
|
||||
throw new IllegalArgumentException("Method '" + value + "' not recognised");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (c) 2004-2015 Stuart Boston
|
||||
*
|
||||
* This file is part of TheMovieDB API.
|
||||
*
|
||||
* TheMovieDB API is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* TheMovieDB API is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with TheMovieDB API. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.omertron.themoviedbapi.tools;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public enum MethodSub {
|
||||
|
||||
ALT_TITLES("alternative_titles"),
|
||||
CASTS("casts"),
|
||||
CHANGES("changes"),
|
||||
COLLECTION("collection"),
|
||||
COMPANY("company"),
|
||||
CREDITS("credits"),
|
||||
FAVORITE("favorite"),
|
||||
FAVORITE_MOVIES("favorite_movies"),
|
||||
GUEST_SESSION("guest_session/new"),
|
||||
IMAGES("images"),
|
||||
ITEM_STATUS("item_status"),
|
||||
KEYWORD("keyword"),
|
||||
KEYWORDS("keywords"),
|
||||
LATEST("latest"),
|
||||
LIST("list"),
|
||||
LISTS("lists"),
|
||||
MOVIE("movie"),
|
||||
MOVIES("movies"),
|
||||
MOVIE_WATCHLIST("movie_watchlist"),
|
||||
NOW_PLAYING("now-playing"),
|
||||
PERSON("person"),
|
||||
POPULAR("popular"),
|
||||
RATED_MOVIES("rated/movies"),
|
||||
RATING("rating"),
|
||||
RELEASES("releases"),
|
||||
REVIEWS("reviews"),
|
||||
SESSION_NEW("session/new"),
|
||||
SIMILAR_MOVIES("similar_movies"),
|
||||
TOKEN_NEW("token/new"),
|
||||
TOKEN_VALIDATE("token/validate_with_login"),
|
||||
TOP_RATED("top-rated"),
|
||||
TRANSLATIONS("translations"),
|
||||
UPCOMING("upcoming"),
|
||||
VIDEOS("videos"),
|
||||
ADD_ITEM("add_item"),
|
||||
REMOVE_ITEM("remove_item");
|
||||
|
||||
private final String value;
|
||||
|
||||
private MethodSub(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL parameter to use
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string into an Enum type
|
||||
*
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public static MethodSub fromString(String value) {
|
||||
if (StringUtils.isNotBlank(value)) {
|
||||
for (final MethodSub method : EnumSet.allOf(MethodSub.class)) {
|
||||
if (value.equalsIgnoreCase(method.value)) {
|
||||
return method;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We've not found the type!
|
||||
throw new IllegalArgumentException("Method '" + value + "' not recognised");
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,7 @@ public class ApiUrlTest {
|
||||
public void testConfiguration() {
|
||||
LOG.info("Configuration Test");
|
||||
|
||||
URL result = new ApiUrl(APIKEY, "configuration").buildUrl();
|
||||
URL result = new ApiUrl(APIKEY, MethodBase.CONFIGURATION).buildUrl();
|
||||
String expResult = "http://api.themoviedb.org/3/configuration?api_key=APIKEY";
|
||||
assertEquals("Wrong config URL", expResult, result.toString());
|
||||
}
|
||||
@@ -75,8 +75,8 @@ public class ApiUrlTest {
|
||||
TmdbParameters parameters = new TmdbParameters();
|
||||
parameters.add(Param.QUERY, "query");
|
||||
|
||||
URL result = new ApiUrl(APIKEY, "method").buildUrl(parameters);
|
||||
String expResult = "http://api.themoviedb.org/3/method?api_key=APIKEY&query=query";
|
||||
URL result = new ApiUrl(APIKEY, MethodBase.MOVIE).buildUrl(parameters);
|
||||
String expResult = "http://api.themoviedb.org/3/movie?api_key=APIKEY&query=query";
|
||||
assertEquals("Wrong Query URL", expResult, result.toString());
|
||||
}
|
||||
|
||||
@@ -86,8 +86,8 @@ public class ApiUrlTest {
|
||||
TmdbParameters parameters = new TmdbParameters();
|
||||
parameters.add(Param.QUERY, "query");
|
||||
|
||||
URL result = new ApiUrl(APIKEY, "method").setSubMethod("sub").buildUrl(parameters);
|
||||
String expResult = "http://api.themoviedb.org/3/method/sub?api_key=APIKEY&query=query";
|
||||
URL result = new ApiUrl(APIKEY, MethodBase.MOVIE).setSubMethod(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,8 +99,8 @@ public class ApiUrlTest {
|
||||
parameters.add(Param.PAGE, 1);
|
||||
parameters.add(Param.LANGUAGE, "lang");
|
||||
|
||||
URL result = new ApiUrl(APIKEY, "method").setSubMethod("sub").buildUrl(parameters);
|
||||
String expResult = "http://api.themoviedb.org/3/method/sub?api_key=APIKEY&query=query&language=lang&page=1";
|
||||
URL result = new ApiUrl(APIKEY, MethodBase.MOVIE).setSubMethod(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());
|
||||
}
|
||||
|
||||
@@ -110,8 +110,8 @@ public class ApiUrlTest {
|
||||
TmdbParameters parameters = new TmdbParameters();
|
||||
parameters.add(Param.ID, "ID");
|
||||
|
||||
URL result = new ApiUrl(APIKEY, "method").buildUrl(parameters);
|
||||
String expResult = "http://api.themoviedb.org/3/method/ID?api_key=APIKEY";
|
||||
URL result = new ApiUrl(APIKEY, MethodBase.MOVIE).buildUrl(parameters);
|
||||
String expResult = "http://api.themoviedb.org/3/movie/ID?api_key=APIKEY";
|
||||
assertEquals("Wrong ID URL", expResult, result.toString());
|
||||
}
|
||||
|
||||
@@ -121,8 +121,8 @@ public class ApiUrlTest {
|
||||
TmdbParameters parameters = new TmdbParameters();
|
||||
parameters.add(Param.ID, "ID");
|
||||
|
||||
URL result = new ApiUrl(APIKEY, "method").setSubMethod("sub").buildUrl(parameters);
|
||||
String expResult = "http://api.themoviedb.org/3/method/ID/sub?api_key=APIKEY";
|
||||
URL result = new ApiUrl(APIKEY, MethodBase.MOVIE).setSubMethod(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,8 +134,8 @@ public class ApiUrlTest {
|
||||
parameters.add(Param.PAGE, 1);
|
||||
parameters.add(Param.LANGUAGE, "lang");
|
||||
|
||||
URL result = new ApiUrl(APIKEY, "method").setSubMethod("sub").buildUrl(parameters);
|
||||
String expResult = "http://api.themoviedb.org/3/method/ID/sub?api_key=APIKEY&language=lang&page=1";
|
||||
URL result = new ApiUrl(APIKEY, MethodBase.MOVIE).setSubMethod(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());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user