diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 54a138d7e..2aec5a543 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -24,6 +24,7 @@ import com.omertron.themoviedbapi.MovieDbException.MovieDbExceptionType; import com.omertron.themoviedbapi.model.AlternativeTitle; import com.omertron.themoviedbapi.model.Artwork; import com.omertron.themoviedbapi.model.ArtworkType; +import com.omertron.themoviedbapi.model.Collection; import com.omertron.themoviedbapi.model.CollectionInfo; import com.omertron.themoviedbapi.model.Company; import com.omertron.themoviedbapi.model.Genre; @@ -48,6 +49,7 @@ import com.omertron.themoviedbapi.tools.FilteringLayout; import com.omertron.themoviedbapi.tools.WebBrowser; import com.omertron.themoviedbapi.wrapper.WrapperAlternativeTitles; import com.omertron.themoviedbapi.wrapper.WrapperChanges; +import com.omertron.themoviedbapi.wrapper.WrapperCollection; import com.omertron.themoviedbapi.wrapper.WrapperCompany; import com.omertron.themoviedbapi.wrapper.WrapperCompanyMovies; import com.omertron.themoviedbapi.wrapper.WrapperConfig; @@ -1332,33 +1334,37 @@ public class TheMovieDbApi { } /** - * 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 + * Search for collections by name. * - * @param companyName + * @param query + * @param language * @param page * @return * @throws MovieDbException */ - public List searchCompanies(String companyName, int page) throws MovieDbException { - ApiUrl apiUrl = new ApiUrl(this, BASE_SEARCH, "company"); - apiUrl.addArgument(PARAM_QUERY, companyName); + public List searchCollection(String query, String language, int page) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_SEARCH, "collections"); + + if (StringUtils.isNotBlank(query)) { + apiUrl.addArgument(PARAM_QUERY, query); + } + + if (StringUtils.isNotBlank(language)) { + apiUrl.addArgument(PARAM_LANGUAGE, language); + } if (page > 0) { - apiUrl.addArgument(PARAM_PAGE, page); + apiUrl.addArgument(PARAM_PAGE, Integer.toString(page)); } URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); try { - WrapperCompany wrapper = mapper.readValue(webpage, WrapperCompany.class); + WrapperCollection wrapper = mapper.readValue(webpage, WrapperCollection.class); return wrapper.getResults(); } catch (IOException ex) { - logger.warn("Failed to find company: " + ex.getMessage()); + logger.warn("Failed to find collection: " + ex.getMessage()); throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); } } @@ -1395,5 +1401,78 @@ public class TheMovieDbApi { throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); } } + + /** + * Search for lists by name and description. + * + * @param query + * @param language + * @param page + * @throws MovieDbException + */ + public List searchList(String query, String language, int page) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_SEARCH, "list"); + + if (StringUtils.isNotBlank(query)) { + apiUrl.addArgument(PARAM_QUERY, query); + } + + if (StringUtils.isNotBlank(language)) { + apiUrl.addArgument(PARAM_LANGUAGE, language); + } + + if (page > 0) { + apiUrl.addArgument(PARAM_PAGE, Integer.toString(page)); + } + + URL url = apiUrl.buildUrl(); + + String webpage = WebBrowser.request(url); + try { + WrapperMovieList wrapper = mapper.readValue(webpage, WrapperMovieList.class); + return wrapper.getMovieList(); + } catch (IOException ex) { + logger.warn("Failed to find list: " + ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, 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 List searchCompanies(String companyName, int page) throws MovieDbException { + ApiUrl apiUrl = new ApiUrl(this, BASE_SEARCH, "company"); + apiUrl.addArgument(PARAM_QUERY, companyName); + + if (page > 0) { + apiUrl.addArgument(PARAM_PAGE, page); + } + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + try { + WrapperCompany wrapper = mapper.readValue(webpage, WrapperCompany.class); + return wrapper.getResults(); + } catch (IOException ex) { + logger.warn("Failed to find company: " + ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + + public void searchKeyword() { + } // + // + // List Functions + // Keywords Functions } diff --git a/src/main/java/com/omertron/themoviedbapi/model/MovieList.java b/src/main/java/com/omertron/themoviedbapi/model/MovieList.java index 29f2fac3b..540ba3a3e 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/MovieList.java +++ b/src/main/java/com/omertron/themoviedbapi/model/MovieList.java @@ -53,6 +53,8 @@ public class MovieList implements Serializable { private String name; @JsonProperty("poster_path") private String posterPath; + @JsonProperty("list_type") + private String listType; // public String getDescription() { @@ -83,6 +85,9 @@ public class MovieList implements Serializable { return posterPath; } + public String getListType() { + return listType; + } // // @@ -114,6 +119,9 @@ public class MovieList implements Serializable { this.posterPath = posterPath; } + public void setListType(String listType) { + this.listType = listType; + } // /** diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCollection.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCollection.java new file mode 100644 index 000000000..f7b2a49ce --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperCollection.java @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2004-2012 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 . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.model.Collection; +import com.omertron.themoviedbapi.model.MovieChanges; +import java.util.List; +import org.apache.log4j.Logger; + +/** + * + * @author stuart.boston + */ +public class WrapperCollection { + /* + * Logger + */ + + private static final Logger logger = Logger.getLogger(WrapperCollection.class); + /* + * Properties + */ + @JsonProperty("page") + private int page; + @JsonProperty("results") + private List results; + @JsonProperty("total_pages") + private int totalPages; + @JsonProperty("total_results") + private int totalResults; + + // + public int getPage() { + return page; + } + + public List getResults() { + return results; + } + + public int getTotalPages() { + return totalPages; + } + + public int getTotalResults() { + return totalResults; + } + // + + // + public void setPage(int page) { + this.page = page; + } + + public void setResults(List results) { + this.results = results; + } + + public void setTotalPages(int totalPages) { + this.totalPages = totalPages; + } + + public void setTotalResults(int totalResults) { + this.totalResults = totalResults; + } + // + + /** + * Handle unknown properties and print a message + * + * @param key + * @param value + */ + @JsonAnySetter + public void handleUnknown(String key, Object value) { + StringBuilder sb = new StringBuilder(); + sb.append("Unknown property: '").append(key); + sb.append("' value: '").append(value).append("'"); + logger.trace(sb.toString()); + } +} diff --git a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java index 3ef0e6e28..a16718099 100644 --- a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java +++ b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java @@ -21,6 +21,7 @@ package com.omertron.themoviedbapi; import com.omertron.themoviedbapi.model.AlternativeTitle; import com.omertron.themoviedbapi.model.Artwork; +import com.omertron.themoviedbapi.model.Collection; import com.omertron.themoviedbapi.model.CollectionInfo; import com.omertron.themoviedbapi.model.Company; import com.omertron.themoviedbapi.model.Genre; @@ -93,7 +94,7 @@ public class TheMovieDbApiTest { /** * Test of getConfiguration method, of class TheMovieDbApi. */ - @Test + //@Test public void testConfiguration() throws IOException { logger.info("Test Configuration"); @@ -109,7 +110,7 @@ public class TheMovieDbApiTest { /** * Test of searchMovie method, of class TheMovieDbApi. */ - @Test + //@Test public void testSearchMovie() throws MovieDbException { logger.info("searchMovie"); @@ -130,7 +131,7 @@ public class TheMovieDbApiTest { /** * Test of getMovieInfo method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetMovieInfo() throws MovieDbException { logger.info("getMovieInfo"); String language = "en"; @@ -141,7 +142,7 @@ public class TheMovieDbApiTest { /** * Test of getMovieAlternativeTitles method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetMovieAlternativeTitles() throws MovieDbException { logger.info("getMovieAlternativeTitles"); String country = ""; @@ -157,7 +158,7 @@ public class TheMovieDbApiTest { /** * Test of getMovieCasts method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetMovieCasts() throws MovieDbException { logger.info("getMovieCasts"); List people = tmdb.getMovieCasts(ID_MOVIE_BLADE_RUNNER); @@ -184,7 +185,7 @@ public class TheMovieDbApiTest { /** * Test of getMovieImages method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetMovieImages() throws MovieDbException { logger.info("getMovieImages"); String language = ""; @@ -195,7 +196,7 @@ public class TheMovieDbApiTest { /** * Test of getMovieKeywords method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetMovieKeywords() throws MovieDbException { logger.info("getMovieKeywords"); List result = tmdb.getMovieKeywords(ID_MOVIE_BLADE_RUNNER); @@ -205,7 +206,7 @@ public class TheMovieDbApiTest { /** * Test of getMovieReleaseInfo method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetMovieReleaseInfo() throws MovieDbException { logger.info("getMovieReleaseInfo"); List result = tmdb.getMovieReleaseInfo(ID_MOVIE_BLADE_RUNNER, ""); @@ -215,7 +216,7 @@ public class TheMovieDbApiTest { /** * Test of getMovieTrailers method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetMovieTrailers() throws MovieDbException { logger.info("getMovieTrailers"); List result = tmdb.getMovieTrailers(ID_MOVIE_BLADE_RUNNER, ""); @@ -225,7 +226,7 @@ public class TheMovieDbApiTest { /** * Test of getMovieTranslations method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetMovieTranslations() throws MovieDbException { logger.info("getMovieTranslations"); List result = tmdb.getMovieTranslations(ID_MOVIE_BLADE_RUNNER); @@ -235,7 +236,7 @@ public class TheMovieDbApiTest { /** * Test of getCollectionInfo method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetCollectionInfo() throws MovieDbException { logger.info("getCollectionInfo"); String language = ""; @@ -248,7 +249,7 @@ public class TheMovieDbApiTest { * * @throws MovieDbException */ - @Test + //@Test public void testCreateImageUrl() throws MovieDbException { logger.info("createImageUrl"); MovieDb movie = tmdb.getMovieInfo(ID_MOVIE_BLADE_RUNNER, ""); @@ -259,7 +260,7 @@ public class TheMovieDbApiTest { /** * Test of getMovieInfoImdb method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetMovieInfoImdb() throws MovieDbException { logger.info("getMovieInfoImdb"); MovieDb result = tmdb.getMovieInfoImdb("tt0076759", "en-US"); @@ -269,7 +270,7 @@ public class TheMovieDbApiTest { /** * Test of getApiKey method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetApiKey() { // Not required } @@ -277,7 +278,7 @@ public class TheMovieDbApiTest { /** * Test of getApiBase method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetApiBase() { // Not required } @@ -285,7 +286,7 @@ public class TheMovieDbApiTest { /** * Test of getConfiguration method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetConfiguration() { // Not required } @@ -293,7 +294,7 @@ public class TheMovieDbApiTest { /** * Test of searchPeople method, of class TheMovieDbApi. */ - @Test + //@Test public void testSearchPeople() throws MovieDbException { logger.info("searchPeople"); String personName = "Bruce Willis"; @@ -305,7 +306,7 @@ public class TheMovieDbApiTest { /** * Test of getPersonInfo method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetPersonInfo() throws MovieDbException { logger.info("getPersonInfo"); Person result = tmdb.getPersonInfo(ID_PERSON_BRUCE_WILLIS); @@ -315,7 +316,7 @@ public class TheMovieDbApiTest { /** * Test of getPersonCredits method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetPersonCredits() throws MovieDbException { logger.info("getPersonCredits"); @@ -326,7 +327,7 @@ public class TheMovieDbApiTest { /** * Test of getPersonImages method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetPersonImages() throws MovieDbException { logger.info("getPersonImages"); @@ -337,7 +338,7 @@ public class TheMovieDbApiTest { /** * Test of getLatestMovie method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetLatestMovie() throws MovieDbException { logger.info("getLatestMovie"); MovieDb result = tmdb.getLatestMovie(); @@ -348,7 +349,7 @@ public class TheMovieDbApiTest { /** * Test of compareMovies method, of class TheMovieDbApi. */ - @Test + //@Test public void testCompareMovies() { // Not required } @@ -356,7 +357,7 @@ public class TheMovieDbApiTest { /** * Test of setProxy method, of class TheMovieDbApi. */ - @Test + //@Test public void testSetProxy() { // Not required } @@ -364,7 +365,7 @@ public class TheMovieDbApiTest { /** * Test of setTimeout method, of class TheMovieDbApi. */ - @Test + //@Test public void testSetTimeout() { // Not required } @@ -372,7 +373,7 @@ public class TheMovieDbApiTest { /** * Test of getNowPlayingMovies method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetNowPlayingMovies() throws MovieDbException { logger.info("getNowPlayingMovies"); List results = tmdb.getNowPlayingMovies("", 0); @@ -382,7 +383,7 @@ public class TheMovieDbApiTest { /** * Test of getPopularMovieList method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetPopularMovieList() throws MovieDbException { logger.info("getPopularMovieList"); List results = tmdb.getPopularMovieList("", 0); @@ -392,7 +393,7 @@ public class TheMovieDbApiTest { /** * Test of getTopRatedMovies method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetTopRatedMovies() throws MovieDbException { logger.info("getTopRatedMovies"); List results = tmdb.getTopRatedMovies("", 0); @@ -402,7 +403,7 @@ public class TheMovieDbApiTest { /** * Test of getCompanyInfo method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetCompanyInfo() throws MovieDbException { logger.info("getCompanyInfo"); Company company = tmdb.getCompanyInfo(ID_COMPANY_LUCASFILM); @@ -412,7 +413,7 @@ public class TheMovieDbApiTest { /** * Test of getCompanyMovies method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetCompanyMovies() throws MovieDbException { logger.info("getCompanyMovies"); List results = tmdb.getCompanyMovies(ID_COMPANY_LUCASFILM, "", 0); @@ -422,7 +423,7 @@ public class TheMovieDbApiTest { /** * Test of searchCompanies method, of class TheMovieDbApi. */ - @Test + //@Test public void testSearchCompanies() throws MovieDbException { logger.info("searchCompanies"); List results = tmdb.searchCompanies(COMPANY_NAME, 0); @@ -432,7 +433,7 @@ public class TheMovieDbApiTest { /** * Test of getSimilarMovies method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetSimilarMovies() throws MovieDbException { logger.info("getSimilarMovies"); List results = tmdb.getSimilarMovies(ID_MOVIE_BLADE_RUNNER, "", 0); @@ -442,7 +443,7 @@ public class TheMovieDbApiTest { /** * Test of getGenreList method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetGenreList() throws MovieDbException { logger.info("getGenreList"); List results = tmdb.getGenreList(""); @@ -452,7 +453,7 @@ public class TheMovieDbApiTest { /** * Test of getGenreMovies method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetGenreMovies() throws MovieDbException { logger.info("getGenreMovies"); List results = tmdb.getGenreMovies(ID_GENRE_ACTION, "", 0); @@ -462,7 +463,7 @@ public class TheMovieDbApiTest { /** * Test of getUpcoming method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetUpcoming() throws Exception { logger.info("getUpcoming"); List results = tmdb.getUpcoming("", 0); @@ -472,7 +473,7 @@ public class TheMovieDbApiTest { /** * Test of getCollectionImages method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetCollectionImages() throws Exception { logger.info("getCollectionImages"); String language = ""; @@ -483,7 +484,7 @@ public class TheMovieDbApiTest { /** * Test of getAuthorisationToken method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetAuthorisationToken() throws Exception { logger.info("getAuthorisationToken"); TokenAuthorisation result = tmdb.getAuthorisationToken(); @@ -496,7 +497,7 @@ public class TheMovieDbApiTest { * Test of getSessionToken method, of class TheMovieDbApi. */ // Cannot be tested without a HTTP authorisation: http://help.themoviedb.org/kb/api/user-authentication -// @Test +// //@Test public void testGetSessionToken() throws Exception { logger.info("getSessionToken"); TokenAuthorisation token = tmdb.getAuthorisationToken(); @@ -513,7 +514,7 @@ public class TheMovieDbApiTest { /** * Test of getGuestSessionToken method, of class TheMovieDbApi. */ - @Test + //@Test public void testGetGuestSessionToken() throws Exception { logger.info("getGuestSessionToken"); TokenSession result = tmdb.getGuestSessionToken(); @@ -521,7 +522,7 @@ public class TheMovieDbApiTest { assertTrue("Failed to get guest session", result.getSuccess()); } - @Test + //@Test public void testGetMovieLists() throws Exception { logger.info("getMovieLists"); String language = "en"; @@ -531,7 +532,6 @@ public class TheMovieDbApiTest { } // Do not test this until it is fixed -// @Test public void testGetMovieChanges() throws Exception { logger.info("getMovieChanges"); @@ -550,7 +550,7 @@ public class TheMovieDbApiTest { assertTrue("No results found", results.size() > 0); } - @Test + //@Test public void testGetPersonLatest() throws Exception { logger.info("getPersonLatest"); @@ -559,4 +559,44 @@ public class TheMovieDbApiTest { assertNotNull("No results found", result); assertTrue("No results found", StringUtils.isNotBlank(result.getName())); } + + /** + * Test of searchCollection method, of class TheMovieDbApi. + */ + //@Test + public void testSearchCollection() throws Exception { + logger.info("searchCollection"); + String query = "batman"; + String language = ""; + int page = 0; + List result = tmdb.searchCollection(query, language, page); + assertFalse("No collections found", result == null); + assertTrue("No collections found", result.size() > 0); + } + + /** + * Test of searchList method, of class TheMovieDbApi. + */ + //@Test + public void testSearchList() throws Exception { + System.out.println("searchList"); + String query = "watch"; + String language = ""; + int page = 0; + List result = tmdb.searchList(query, language, page); + assertFalse("No lists found", result == null); + assertTrue("No lists found", result.size() > 0); + } + + /** + * Test of searchKeyword method, of class TheMovieDbApi. + */ + @Test + public void testSearchKeyword() { + System.out.println("searchKeyword"); + TheMovieDbApi instance = null; + instance.searchKeyword(); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } }