Search (Partial - missing multi)
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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.enumeration;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stuart
|
||||
*/
|
||||
public enum SearchType {
|
||||
|
||||
PHRASE,
|
||||
NGRAM;
|
||||
|
||||
public String getPropertyString() {
|
||||
return this.name().toLowerCase();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +1,22 @@
|
||||
/*
|
||||
* 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.enumeration;
|
||||
|
||||
public enum SortBy {
|
||||
|
||||
@@ -49,12 +49,14 @@ public class AbstractMethod {
|
||||
protected static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
// Logger
|
||||
protected static final Logger LOG = LoggerFactory.getLogger(TmdbAccount.class);
|
||||
protected static final TypeReference<WrapperGenericList<MovieBasic>> TR_MOVIE_BASIC = new TypeReference<WrapperGenericList<MovieBasic>>() {
|
||||
};
|
||||
protected static final TypeReference<WrapperGenericList<TVBasic>> TR_TV_BASIC = new TypeReference<WrapperGenericList<TVBasic>>() {
|
||||
};
|
||||
protected static final TypeReference<WrapperGenericList<UserList>> TR_USER_LIST = new TypeReference<WrapperGenericList<UserList>>() {
|
||||
};
|
||||
protected static final TypeReference<WrapperGenericList<MovieBasic>> TR_MOVIE_BASIC = getTypeReference(MovieBasic.class);
|
||||
protected static final TypeReference<WrapperGenericList<TVBasic>> TR_TV_BASIC = getTypeReference(TVBasic.class);
|
||||
protected static final TypeReference<WrapperGenericList<UserList>> TR_USER_LIST = getTypeReference(UserList.class);
|
||||
|
||||
protected static <T> TypeReference getTypeReference(T Class) {
|
||||
return new TypeReference<WrapperGenericList<T>>() {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor for the methods
|
||||
@@ -78,16 +80,28 @@ public class AbstractMethod {
|
||||
* @throws MovieDbException
|
||||
*/
|
||||
public <T> List<T> processWrapperList(TypeReference typeRef, URL url, String errorMessageSuffix) throws MovieDbException {
|
||||
WrapperGenericList<T> val = processWrapper(typeRef, url, errorMessageSuffix);
|
||||
return val.getResults();
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the wrapper list and return the whole wrapper
|
||||
*
|
||||
* @param <T> Type of list to process
|
||||
* @param typeRef
|
||||
* @param url URL of the page (Error output only)
|
||||
* @param errorMessageSuffix Error message to output (Error output only)
|
||||
* @return
|
||||
* @throws MovieDbException
|
||||
*/
|
||||
public <T> WrapperGenericList<T> processWrapper(TypeReference typeRef, URL url, String errorMessageSuffix) throws MovieDbException {
|
||||
String webpage = httpTools.getRequest(url);
|
||||
try {
|
||||
// Due to type erasure, this doesn't work
|
||||
// TypeReference<WrapperGenericList<T>> typeRef = new TypeReference<WrapperGenericList<T>>() {};
|
||||
WrapperGenericList<T> results = MAPPER.readValue(webpage, typeRef);
|
||||
return results.getResults();
|
||||
return MAPPER.readValue(webpage, typeRef);
|
||||
} catch (IOException ex) {
|
||||
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get " + errorMessageSuffix, url, ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,12 +20,14 @@
|
||||
package com.omertron.themoviedbapi.methods;
|
||||
|
||||
import com.omertron.themoviedbapi.MovieDbException;
|
||||
import com.omertron.themoviedbapi.enumeration.SearchType;
|
||||
import com.omertron.themoviedbapi.model2.collection.Collection;
|
||||
import com.omertron.themoviedbapi.model2.company.Company;
|
||||
import com.omertron.themoviedbapi.model.keyword.Keyword;
|
||||
import com.omertron.themoviedbapi.model.MovieDb;
|
||||
import com.omertron.themoviedbapi.model.MovieList;
|
||||
import com.omertron.themoviedbapi.model.person.Person;
|
||||
import com.omertron.themoviedbapi.model2.list.UserList;
|
||||
import com.omertron.themoviedbapi.model2.tv.TVBasic;
|
||||
import com.omertron.themoviedbapi.results.TmdbResultsList;
|
||||
import com.omertron.themoviedbapi.tools.ApiUrl;
|
||||
import com.omertron.themoviedbapi.tools.HttpTools;
|
||||
@@ -33,13 +35,7 @@ import com.omertron.themoviedbapi.tools.MethodBase;
|
||||
import com.omertron.themoviedbapi.tools.MethodSub;
|
||||
import com.omertron.themoviedbapi.tools.Param;
|
||||
import com.omertron.themoviedbapi.tools.TmdbParameters;
|
||||
import com.omertron.themoviedbapi.wrapper.WrapperCollection;
|
||||
import com.omertron.themoviedbapi.wrapper.WrapperCompany;
|
||||
import com.omertron.themoviedbapi.wrapper.WrapperKeywords;
|
||||
import com.omertron.themoviedbapi.wrapper.WrapperMovie;
|
||||
import com.omertron.themoviedbapi.wrapper.WrapperMovieList;
|
||||
import com.omertron.themoviedbapi.wrapper.WrapperPerson;
|
||||
import java.io.IOException;
|
||||
import com.omertron.themoviedbapi.wrapper.WrapperGenericList;
|
||||
import java.net.URL;
|
||||
import org.yamj.api.common.exception.ApiExceptionType;
|
||||
|
||||
@@ -61,36 +57,28 @@ public class TmdbSearch extends AbstractMethod {
|
||||
}
|
||||
|
||||
/**
|
||||
* Search Movies This is a good starting point to start finding movies on TMDb.
|
||||
* Search Companies.
|
||||
*
|
||||
* @param movieName
|
||||
* @param searchYear Limit the search to the provided year. Zero (0) will get all years
|
||||
* @param language The language to include. Can be blank/null.
|
||||
* @param includeAdult true or false to include adult titles in the search
|
||||
* @param page The page of results to return. 0 to get the default (first page)
|
||||
* You can use this method to search for production companies that are part of TMDb. The company IDs will map to those returned
|
||||
* on movie calls.
|
||||
*
|
||||
* http://help.themoviedb.org/kb/api/search-companies
|
||||
*
|
||||
* @param query
|
||||
* @param page
|
||||
* @return
|
||||
* @throws MovieDbException
|
||||
*/
|
||||
public TmdbResultsList<MovieDb> searchMovie(String movieName, int searchYear, String language, boolean includeAdult, int page) throws MovieDbException {
|
||||
public TmdbResultsList<Company> searchCompanies(String query, Integer page) throws MovieDbException {
|
||||
TmdbParameters parameters = new TmdbParameters();
|
||||
parameters.add(Param.QUERY, movieName);
|
||||
parameters.add(Param.YEAR, searchYear);
|
||||
parameters.add(Param.LANGUAGE, language);
|
||||
parameters.add(Param.ADULT, includeAdult);
|
||||
parameters.add(Param.QUERY, query);
|
||||
parameters.add(Param.PAGE, page);
|
||||
|
||||
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.MOVIE).buildUrl(parameters);
|
||||
String webpage = httpTools.getRequest(url);
|
||||
|
||||
try {
|
||||
WrapperMovie wrapper = MAPPER.readValue(webpage, WrapperMovie.class);
|
||||
TmdbResultsList<MovieDb> results = new TmdbResultsList<MovieDb>(wrapper.getMovies());
|
||||
results.copyWrapper(wrapper);
|
||||
return results;
|
||||
} catch (IOException ex) {
|
||||
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find movie", url, ex);
|
||||
}
|
||||
|
||||
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.COMPANY).buildUrl(parameters);
|
||||
WrapperGenericList<Company> wrapper = processWrapper(getTypeReference(Company.class), url, "company");
|
||||
TmdbResultsList<Company> results = new TmdbResultsList<Company>(wrapper.getResults());
|
||||
results.copyWrapper(wrapper);
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,112 +90,17 @@ public class TmdbSearch extends AbstractMethod {
|
||||
* @return
|
||||
* @throws MovieDbException
|
||||
*/
|
||||
public TmdbResultsList<Collection> searchCollection(String query, String language, int page) throws MovieDbException {
|
||||
public TmdbResultsList<Collection> searchCollection(String query, Integer page, String language) throws MovieDbException {
|
||||
TmdbParameters parameters = new TmdbParameters();
|
||||
parameters.add(Param.QUERY, query);
|
||||
parameters.add(Param.LANGUAGE, language);
|
||||
parameters.add(Param.PAGE, page);
|
||||
parameters.add(Param.LANGUAGE, language);
|
||||
|
||||
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.COLLECTION).buildUrl(parameters);
|
||||
String webpage = httpTools.getRequest(url);
|
||||
|
||||
try {
|
||||
WrapperCollection wrapper = MAPPER.readValue(webpage, WrapperCollection.class);
|
||||
TmdbResultsList<Collection> results = new TmdbResultsList<Collection>(wrapper.getResults());
|
||||
results.copyWrapper(wrapper);
|
||||
return results;
|
||||
} catch (IOException ex) {
|
||||
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find collection", url, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a good starting point to start finding people on TMDb.
|
||||
*
|
||||
* The idea is to be a quick and light method so you can iterate through people quickly.
|
||||
*
|
||||
* @param personName
|
||||
* @param includeAdult
|
||||
* @param page
|
||||
* @return
|
||||
* @throws MovieDbException
|
||||
*/
|
||||
public TmdbResultsList<Person> searchPeople(String personName, boolean includeAdult, int page) throws MovieDbException {
|
||||
TmdbParameters parameters = new TmdbParameters();
|
||||
parameters.add(Param.QUERY, personName);
|
||||
parameters.add(Param.ADULT, includeAdult);
|
||||
parameters.add(Param.PAGE, page);
|
||||
|
||||
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.PERSON).buildUrl(parameters);
|
||||
String webpage = httpTools.getRequest(url);
|
||||
|
||||
try {
|
||||
WrapperPerson wrapper = MAPPER.readValue(webpage, WrapperPerson.class);
|
||||
TmdbResultsList<Person> results = new TmdbResultsList<Person>(wrapper.getResults());
|
||||
results.copyWrapper(wrapper);
|
||||
return results;
|
||||
} catch (IOException ex) {
|
||||
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find person", url, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for lists by name and description.
|
||||
*
|
||||
* @param query
|
||||
* @param language
|
||||
* @param page
|
||||
* @return
|
||||
* @throws MovieDbException
|
||||
*/
|
||||
public TmdbResultsList<MovieList> searchList(String query, String language, int page) throws MovieDbException {
|
||||
TmdbParameters parameters = new TmdbParameters();
|
||||
parameters.add(Param.QUERY, query);
|
||||
parameters.add(Param.LANGUAGE, language);
|
||||
parameters.add(Param.PAGE, page);
|
||||
|
||||
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.LIST).buildUrl(parameters);
|
||||
String webpage = httpTools.getRequest(url);
|
||||
|
||||
try {
|
||||
WrapperMovieList wrapper = MAPPER.readValue(webpage, WrapperMovieList.class);
|
||||
TmdbResultsList<MovieList> results = new TmdbResultsList<MovieList>(wrapper.getMovieList());
|
||||
results.copyWrapper(wrapper);
|
||||
return results;
|
||||
} catch (IOException ex) {
|
||||
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find list", url, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Search Companies.
|
||||
*
|
||||
* You can use this method to search for production companies that are part of TMDb. The company IDs will map to those returned
|
||||
* on movie calls.
|
||||
*
|
||||
* http://help.themoviedb.org/kb/api/search-companies
|
||||
*
|
||||
* @param companyName
|
||||
* @param page
|
||||
* @return
|
||||
* @throws MovieDbException
|
||||
*/
|
||||
public TmdbResultsList<Company> searchCompanies(String companyName, int page) throws MovieDbException {
|
||||
TmdbParameters parameters = new TmdbParameters();
|
||||
parameters.add(Param.QUERY, companyName);
|
||||
parameters.add(Param.PAGE, page);
|
||||
|
||||
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.COMPANY).buildUrl(parameters);
|
||||
String webpage = httpTools.getRequest(url);
|
||||
|
||||
try {
|
||||
WrapperCompany wrapper = MAPPER.readValue(webpage, WrapperCompany.class);
|
||||
TmdbResultsList<Company> results = new TmdbResultsList<Company>(wrapper.getResults());
|
||||
results.copyWrapper(wrapper);
|
||||
return results;
|
||||
} catch (IOException ex) {
|
||||
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find company", url, ex);
|
||||
}
|
||||
WrapperGenericList<Collection> wrapper = processWrapper(getTypeReference(Collection.class), url, "collection");
|
||||
TmdbResultsList<Collection> results = new TmdbResultsList<Collection>(wrapper.getResults());
|
||||
results.copyWrapper(wrapper);
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,22 +111,158 @@ public class TmdbSearch extends AbstractMethod {
|
||||
* @return
|
||||
* @throws MovieDbException
|
||||
*/
|
||||
public TmdbResultsList<Keyword> searchKeyword(String query, int page) throws MovieDbException {
|
||||
public TmdbResultsList<Keyword> searchKeyword(String query, Integer page) throws MovieDbException {
|
||||
TmdbParameters parameters = new TmdbParameters();
|
||||
parameters.add(Param.QUERY, query);
|
||||
parameters.add(Param.PAGE, page);
|
||||
|
||||
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.KEYWORD).buildUrl(parameters);
|
||||
String webpage = httpTools.getRequest(url);
|
||||
WrapperGenericList<Keyword> wrapper = processWrapper(getTypeReference(Keyword.class), url, "keyword");
|
||||
TmdbResultsList<Keyword> results = new TmdbResultsList<Keyword>(wrapper.getResults());
|
||||
results.copyWrapper(wrapper);
|
||||
return results;
|
||||
}
|
||||
|
||||
try {
|
||||
WrapperKeywords wrapper = MAPPER.readValue(webpage, WrapperKeywords.class);
|
||||
TmdbResultsList<Keyword> results = new TmdbResultsList<Keyword>(wrapper.getResults());
|
||||
results.copyWrapper(wrapper);
|
||||
return results;
|
||||
} catch (IOException ex) {
|
||||
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find keyword", url, ex);
|
||||
/**
|
||||
* Search for lists by name and description.
|
||||
*
|
||||
* @param query
|
||||
* @param language
|
||||
* @param includeAdult
|
||||
* @param page
|
||||
* @return
|
||||
* @throws MovieDbException
|
||||
*/
|
||||
public TmdbResultsList<UserList> searchList(String query, Integer page, Boolean includeAdult) throws MovieDbException {
|
||||
TmdbParameters parameters = new TmdbParameters();
|
||||
parameters.add(Param.QUERY, query);
|
||||
parameters.add(Param.PAGE, page);
|
||||
parameters.add(Param.INCLUDE_ADULT, includeAdult);
|
||||
|
||||
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.LIST).buildUrl(parameters);
|
||||
WrapperGenericList<UserList> wrapper = processWrapper(getTypeReference(UserList.class), url, "list");
|
||||
TmdbResultsList<UserList> results = new TmdbResultsList<UserList>(wrapper.getResults());
|
||||
results.copyWrapper(wrapper);
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search Movies This is a good starting point to start finding movies on TMDb.
|
||||
*
|
||||
* @param query
|
||||
* @param searchYear Limit the search to the provided year. Zero (0) will get all years
|
||||
* @param language The language to include. Can be blank/null.
|
||||
* @param includeAdult true or false to include adult titles in the search
|
||||
* @param page The page of results to return. 0 to get the default (first page)
|
||||
* @param primaryReleaseYear
|
||||
* @param searchType
|
||||
* @return
|
||||
* @throws MovieDbException
|
||||
*/
|
||||
public TmdbResultsList<MovieDb> searchMovie(String query,
|
||||
Integer page,
|
||||
String language,
|
||||
Boolean includeAdult,
|
||||
Integer searchYear,
|
||||
Integer primaryReleaseYear,
|
||||
SearchType searchType) throws MovieDbException {
|
||||
TmdbParameters parameters = new TmdbParameters();
|
||||
parameters.add(Param.QUERY, query);
|
||||
parameters.add(Param.PAGE, page);
|
||||
parameters.add(Param.LANGUAGE, language);
|
||||
parameters.add(Param.ADULT, includeAdult);
|
||||
parameters.add(Param.YEAR, searchYear);
|
||||
parameters.add(Param.PRIMARY_RELEASE_YEAR, primaryReleaseYear);
|
||||
if (searchType != null) {
|
||||
parameters.add(Param.SEARCH_TYPE, searchType.getPropertyString());
|
||||
}
|
||||
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.MOVIE).buildUrl(parameters);
|
||||
|
||||
WrapperGenericList<MovieDb> wrapper = processWrapper(getTypeReference(MovieDb.class), url, "movie");
|
||||
TmdbResultsList<MovieDb> results = new TmdbResultsList<MovieDb>(wrapper.getResults());
|
||||
results.copyWrapper(wrapper);
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search the movie, tv show and person collections with a single query.
|
||||
*
|
||||
* Each item returned in the result array has a media_type field that maps to either movie, tv or person.
|
||||
*
|
||||
* Each mapped result is the same response you would get from each independent search
|
||||
*
|
||||
* @param query
|
||||
* @param page
|
||||
* @param language
|
||||
* @param includeAdult
|
||||
* @return
|
||||
* @throws MovieDbException
|
||||
*/
|
||||
public String searchMulti(String query, Integer page, String language, Boolean includeAdult) throws MovieDbException {
|
||||
TmdbParameters parameters = new TmdbParameters();
|
||||
parameters.add(Param.QUERY, query);
|
||||
parameters.add(Param.PAGE, page);
|
||||
parameters.add(Param.LANGUAGE, language);
|
||||
parameters.add(Param.ADULT, includeAdult);
|
||||
|
||||
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.MULTI).buildUrl(parameters);
|
||||
throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not implemented yet");
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a good starting point to start finding people on TMDb.
|
||||
*
|
||||
* The idea is to be a quick and light method so you can iterate through people quickly.
|
||||
*
|
||||
* @param query
|
||||
* @param includeAdult
|
||||
* @param page
|
||||
* @param searchType
|
||||
* @return
|
||||
* @throws MovieDbException
|
||||
*/
|
||||
public TmdbResultsList<Person> searchPeople(String query, Integer page, Boolean includeAdult, SearchType searchType) throws MovieDbException {
|
||||
TmdbParameters parameters = new TmdbParameters();
|
||||
parameters.add(Param.QUERY, query);
|
||||
parameters.add(Param.ADULT, includeAdult);
|
||||
parameters.add(Param.PAGE, page);
|
||||
if (searchType != null) {
|
||||
parameters.add(Param.SEARCH_TYPE, searchType.getPropertyString());
|
||||
}
|
||||
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.PERSON).buildUrl(parameters);
|
||||
|
||||
WrapperGenericList<Person> wrapper = processWrapper(getTypeReference(Person.class), url, "person");
|
||||
TmdbResultsList<Person> results = new TmdbResultsList<Person>(wrapper.getResults());
|
||||
results.copyWrapper(wrapper);
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for TV shows by title.
|
||||
*
|
||||
* @param query
|
||||
* @param page
|
||||
* @param language
|
||||
* @param firstAirDateYear
|
||||
* @param searchType
|
||||
* @return
|
||||
* @throws com.omertron.themoviedbapi.MovieDbException
|
||||
*/
|
||||
public TmdbResultsList<TVBasic> searchTV(String query, Integer page, String language, Integer firstAirDateYear, SearchType searchType) throws MovieDbException {
|
||||
TmdbParameters parameters = new TmdbParameters();
|
||||
parameters.add(Param.QUERY, query);
|
||||
parameters.add(Param.PAGE, page);
|
||||
parameters.add(Param.LANGUAGE, language);
|
||||
parameters.add(Param.FIRST_AIR_DATE_YEAR, firstAirDateYear);
|
||||
if (searchType != null) {
|
||||
parameters.add(Param.SEARCH_TYPE, searchType.getPropertyString());
|
||||
}
|
||||
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.MOVIE).buildUrl(parameters);
|
||||
|
||||
WrapperGenericList<TVBasic> wrapper = processWrapper(getTypeReference(TVBasic.class), url, "TV Show");
|
||||
TmdbResultsList<TVBasic> results = new TmdbResultsList<TVBasic>(wrapper.getResults());
|
||||
results.copyWrapper(wrapper);
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -105,13 +105,13 @@ People
|
||||
Reviews (Done)
|
||||
/review/{id} Get the full details of a review by ID.
|
||||
|
||||
Search
|
||||
Search (Partial - multi search to do)
|
||||
/search/company Search for companies by name.
|
||||
/search/collection Search for collections by name.
|
||||
/search/keyword Search for keywords by name.
|
||||
/search/list Search for lists by name and description.
|
||||
/search/movie Search for movies by title.
|
||||
/search/multi Search the movie, tv show and person collections with a single query.
|
||||
*** /search/multi Search the movie, tv show and person collections with a single query.
|
||||
/search/person Search for people by name.
|
||||
/search/tv Search for TV shows by title.
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ public enum MethodSub {
|
||||
MOVIE("movie"),
|
||||
MOVIES("movies"),
|
||||
MOVIE_LIST("movie/list"),
|
||||
MULTI("multi"),
|
||||
NOW_PLAYING("now-playing"),
|
||||
PERSON("person"),
|
||||
POPULAR("popular"),
|
||||
|
||||
@@ -46,6 +46,7 @@ public enum Param {
|
||||
PAGE("page="),
|
||||
PASSWORD("password="),
|
||||
QUERY("query="),
|
||||
SEARCH_TYPE("search_type="),
|
||||
SESSION("session_id="),
|
||||
START_DATE("start_date="),
|
||||
TOKEN("request_token="),
|
||||
|
||||
@@ -21,16 +21,23 @@ package com.omertron.themoviedbapi.methods;
|
||||
|
||||
import com.omertron.themoviedbapi.AbstractTests;
|
||||
import com.omertron.themoviedbapi.MovieDbException;
|
||||
import com.omertron.themoviedbapi.enumeration.SearchType;
|
||||
import com.omertron.themoviedbapi.model2.collection.Collection;
|
||||
import com.omertron.themoviedbapi.model2.company.Company;
|
||||
import com.omertron.themoviedbapi.model.keyword.Keyword;
|
||||
import com.omertron.themoviedbapi.model.MovieDb;
|
||||
import com.omertron.themoviedbapi.model.MovieList;
|
||||
import com.omertron.themoviedbapi.model.person.Person;
|
||||
import com.omertron.themoviedbapi.model2.list.UserList;
|
||||
import com.omertron.themoviedbapi.model2.tv.TVBasic;
|
||||
import com.omertron.themoviedbapi.results.TmdbResultsList;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -57,27 +64,26 @@ public class TmdbSearchTest extends AbstractTests {
|
||||
public static void tearDownClass() {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of searchMovie method, of class TheMovieDbApi.
|
||||
* Test of searchCompanies method, of class TheMovieDbApi.
|
||||
*
|
||||
* @throws MovieDbException
|
||||
*/
|
||||
@Test
|
||||
public void testSearchMovie() throws MovieDbException {
|
||||
LOG.info("searchMovie");
|
||||
|
||||
// Try a movie with less than 1 page of results
|
||||
TmdbResultsList<MovieDb> movieList = instance.searchMovie("Blade Runner", 0, "", true, 0);
|
||||
// List<MovieDb> movieList = tmdb.searchMovie("Blade Runner", "", true);
|
||||
assertTrue("No movies found, should be at least 1", movieList.getResults().size() > 0);
|
||||
|
||||
// Try a russian langugage movie
|
||||
movieList = instance.searchMovie("О чём говорят мужчины", 0, LANGUAGE_RUSSIAN, true, 0);
|
||||
assertTrue("No 'RU' movies found, should be at least 1", movieList.getResults().size() > 0);
|
||||
|
||||
// Try a movie with more than 20 results
|
||||
movieList = instance.searchMovie("Star Wars", 0, LANGUAGE_ENGLISH, false, 0);
|
||||
assertTrue("Not enough movies found, should be over 15, found " + movieList.getResults().size(), movieList.getResults().size() >= 15);
|
||||
public void testSearchCompanies() throws MovieDbException {
|
||||
LOG.info("searchCompanies");
|
||||
TmdbResultsList<Company> result = instance.searchCompanies(COMPANY_NAME, 0);
|
||||
assertNotNull("Null results", result);
|
||||
assertNotNull("Null company", result.getResults());
|
||||
assertFalse("Empty company", result.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,50 +96,10 @@ public class TmdbSearchTest extends AbstractTests {
|
||||
LOG.info("searchCollection");
|
||||
String query = "batman";
|
||||
int page = 0;
|
||||
TmdbResultsList<Collection> result = instance.searchCollection(query, LANGUAGE_DEFAULT, page);
|
||||
assertFalse("No collections found", result == null);
|
||||
assertTrue("No collections found", result.getResults().size() > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of searchPeople method, of class TheMovieDbApi.
|
||||
*
|
||||
* @throws MovieDbException
|
||||
*/
|
||||
@Test
|
||||
public void testSearchPeople() throws MovieDbException {
|
||||
LOG.info("searchPeople");
|
||||
String personName = "Bruce Willis";
|
||||
boolean includeAdult = false;
|
||||
TmdbResultsList<Person> result = instance.searchPeople(personName, includeAdult, 0);
|
||||
assertTrue("Couldn't find the person", result.getResults().size() > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of searchList method, of class TheMovieDbApi.
|
||||
*
|
||||
* @throws MovieDbException
|
||||
*/
|
||||
@Test
|
||||
public void testSearchList() throws MovieDbException {
|
||||
LOG.info("searchList");
|
||||
String query = "watch";
|
||||
int page = 0;
|
||||
TmdbResultsList<MovieList> result = instance.searchList(query, LANGUAGE_DEFAULT, page);
|
||||
assertFalse("No lists found", result.getResults() == null);
|
||||
assertTrue("No lists found", result.getResults().size() > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of searchCompanies method, of class TheMovieDbApi.
|
||||
*
|
||||
* @throws MovieDbException
|
||||
*/
|
||||
@Test
|
||||
public void testSearchCompanies() throws MovieDbException {
|
||||
LOG.info("searchCompanies");
|
||||
TmdbResultsList<Company> result = instance.searchCompanies(COMPANY_NAME, 0);
|
||||
assertTrue("No company information found", !result.getResults().isEmpty());
|
||||
TmdbResultsList<Collection> result = instance.searchCollection(query, page, LANGUAGE_DEFAULT);
|
||||
assertNotNull("Null results", result);
|
||||
assertNotNull("Null collection", result.getResults());
|
||||
assertFalse("Empty collection", result.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -147,8 +113,100 @@ public class TmdbSearchTest extends AbstractTests {
|
||||
String query = "action";
|
||||
int page = 0;
|
||||
TmdbResultsList<Keyword> result = instance.searchKeyword(query, page);
|
||||
assertFalse("No keywords found", result.getResults() == null);
|
||||
assertTrue("No keywords found", result.getResults().size() > 0);
|
||||
assertNotNull("Null results", result);
|
||||
assertNotNull("Null keyword", result.getResults());
|
||||
assertFalse("Empty keyword", result.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of searchList method, of class TheMovieDbApi.
|
||||
*
|
||||
* @throws MovieDbException
|
||||
*/
|
||||
@Test
|
||||
public void testSearchList() throws MovieDbException {
|
||||
LOG.info("searchList");
|
||||
String query = "watch";
|
||||
int page = 0;
|
||||
TmdbResultsList<UserList> result = instance.searchList(query, page, null);
|
||||
assertNotNull("Null results", result);
|
||||
assertNotNull("Null list", result.getResults());
|
||||
assertFalse("Empty list", result.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of searchMovie method, of class TheMovieDbApi.
|
||||
*
|
||||
* @throws MovieDbException
|
||||
*/
|
||||
@Test
|
||||
public void testSearchMovie() throws MovieDbException {
|
||||
LOG.info("searchMovie");
|
||||
|
||||
// Try a movie with less than 1 page of results
|
||||
TmdbResultsList<MovieDb> movieList = instance.searchMovie("Blade Runner", 0, "", null, 0, 0, SearchType.PHRASE);
|
||||
assertTrue("No movies found, should be at least 1", movieList.getResults().size() > 0);
|
||||
|
||||
// Try a russian langugage movie
|
||||
movieList = instance.searchMovie("О чём говорят мужчины", 0, LANGUAGE_RUSSIAN, null, 0, 0, SearchType.PHRASE);
|
||||
assertTrue("No 'RU' movies found, should be at least 1", movieList.getResults().size() > 0);
|
||||
|
||||
// Try a movie with more than 20 results
|
||||
movieList = instance.searchMovie("Star Wars", 0, LANGUAGE_ENGLISH, null, 0, 0, SearchType.PHRASE);
|
||||
assertTrue("Not enough movies found, should be over 15, found " + movieList.getResults().size(), movieList.getResults().size() >= 15);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of searchMulti method, of class TmdbSearch.
|
||||
*
|
||||
* @throws com.omertron.themoviedbapi.MovieDbException
|
||||
*/
|
||||
@Test
|
||||
public void testSearchMulti() throws MovieDbException {
|
||||
System.out.println("searchMulti");
|
||||
String query = "j";
|
||||
Integer page = null;
|
||||
String language = "";
|
||||
Boolean includeAdult = null;
|
||||
String expResult = "";
|
||||
String result = instance.searchMulti(query, page, language, includeAdult);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of searchPeople method, of class TheMovieDbApi.
|
||||
*
|
||||
* @throws MovieDbException
|
||||
*/
|
||||
@Test
|
||||
public void testSearchPeople() throws MovieDbException {
|
||||
LOG.info("searchPeople");
|
||||
String personName = "Bruce Willis";
|
||||
TmdbResultsList<Person> result = instance.searchPeople(personName, null, null, SearchType.PHRASE);
|
||||
assertNotNull("Null results", result);
|
||||
assertNotNull("Null people", result.getResults());
|
||||
assertFalse("Empty people", result.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of searchTV method, of class TmdbSearch.
|
||||
*
|
||||
* @throws com.omertron.themoviedbapi.MovieDbException
|
||||
*/
|
||||
@Test
|
||||
public void testSearchTV() throws MovieDbException {
|
||||
System.out.println("searchTV");
|
||||
String query = "The Walking Dead";
|
||||
Integer page = null;
|
||||
String language = LANGUAGE_ENGLISH;
|
||||
Integer firstAirDateYear = null;
|
||||
SearchType searchType = SearchType.PHRASE;
|
||||
TmdbResultsList<TVBasic> result = instance.searchTV(query, page, language, firstAirDateYear, searchType);
|
||||
assertNotNull("Null results", result);
|
||||
assertNotNull("Null TV", result.getResults());
|
||||
assertFalse("Empty TV", result.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user