From 4c682731b6ef1ef01f420e2245efb81515bac05f Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Wed, 15 May 2013 13:46:59 +0100 Subject: [PATCH] Add PopularPerson method --- .../omertron/themoviedbapi/TheMovieDbApi.java | 43 ++++++----- .../wrapper/WrapperPersonList.java | 51 +++++++++++++ .../themoviedbapi/wrapper/WrapperReviews.java | 1 - .../themoviedbapi/TheMovieDbApiTest.java | 76 ++++++++++++++++++- 4 files changed, 151 insertions(+), 20 deletions(-) create mode 100644 src/main/java/com/omertron/themoviedbapi/wrapper/WrapperPersonList.java diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index b0cda7140..ccd28cb91 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -45,12 +45,7 @@ public class TheMovieDbApi { private static final Logger LOG = LoggerFactory.getLogger(TheMovieDbApi.class); private String apiKey; private TmdbConfiguration tmdbConfig; - /* - * API Methods - * - * These are not set to static so that multiple instances of - * the API can co-exist - */ + // API Methods private static final String BASE_MOVIE = "movie/"; private static final String BASE_PERSON = "person/"; private static final String BASE_COMPANY = "company/"; @@ -61,18 +56,7 @@ public class TheMovieDbApi { private static final String BASE_SEARCH = "search/"; private static final String BASE_LIST = "list/"; private static final String BASE_KEYWORD = "keyword/"; - // Account - /* - private final ApiUrl tmdbAccount = new ApiUrl(apiKey, BASE_ACCOUNT); - private final ApiUrl tmdbFavouriteMovies = new ApiUrl(apiKey, BASE_ACCOUNT, "/favorite_movies"); - private final ApiUrl tmdbPostFavourite = new ApiUrl(apiKey, BASE_ACCOUNT, "/favorite"); - private final ApiUrl tmdbRatedMovies = new ApiUrl(apiKey, BASE_ACCOUNT, "/rated_movies"); - private final ApiUrl tmdbMovieWatchList = new ApiUrl(apiKey, BASE_ACCOUNT, "/movie_watchlist"); - private final ApiUrl tmdbPostMovieWatchList = new ApiUrl(apiKey, BASE_ACCOUNT, "/movie_watchlist"); - */ - /* - * Jackson JSON configuration - */ + // Jackson JSON configuration private static ObjectMapper mapper = new ObjectMapper(); /** @@ -1090,6 +1074,29 @@ public class TheMovieDbApi { throw new MovieDbException(MovieDbExceptionType.UNKNOWN_CAUSE, "Not implemented yet"); } + public List getPersonPopular() throws MovieDbException { + return getPersonPopular(0); + } + + public List getPersonPopular(int page) throws MovieDbException{ + ApiUrl apiUrl = new ApiUrl(apiKey, BASE_PERSON, "/popular"); + + if(page>0) { + apiUrl.addArgument(PARAM_PAGE, page); + } + + URL url = apiUrl.buildUrl(); + String webpage = WebBrowser.request(url); + + try { + WrapperPersonList wrapper = mapper.readValue(webpage, WrapperPersonList.class); + return wrapper.getPersonList(); + } catch (IOException ex) { + LOG.warn("Failed to get person images: {}", ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); + } + } + /** * Get the latest person id. * diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperPersonList.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperPersonList.java new file mode 100644 index 000000000..195efb144 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperPersonList.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2004-2013 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.JsonProperty; +import com.omertron.themoviedbapi.model.MovieList; +import com.omertron.themoviedbapi.model.Person; +import java.util.List; +import org.slf4j.LoggerFactory; + +/** + * + * @author Stuart + */ +public class WrapperPersonList extends WrapperBase { + /* + * Properties + */ + + @JsonProperty("results") + private List personList; + + public WrapperPersonList() { + super(LoggerFactory.getLogger(WrapperPersonList.class)); + } + + public List getPersonList() { + return personList; + } + + public void setPersonList(List personList) { + this.personList = personList; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperReviews.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperReviews.java index f9fc7a001..fa450f2aa 100644 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperReviews.java +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperReviews.java @@ -20,7 +20,6 @@ package com.omertron.themoviedbapi.wrapper; import com.fasterxml.jackson.annotation.JsonProperty; -import com.omertron.themoviedbapi.model.Collection; import com.omertron.themoviedbapi.model.Reviews; import java.util.List; import org.slf4j.LoggerFactory; diff --git a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java index b5d8efc71..1d7b232ff 100644 --- a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java +++ b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java @@ -609,6 +609,7 @@ public class TheMovieDbApiTest { * * TODO: Cannot be tested without a HTTP authorisation: http://help.themoviedb.org/kb/api/user-authentication */ + @Ignore("Not ready yet") public void testPostMovieRating() throws Exception { LOG.info("postMovieRating"); String sessionId = ""; @@ -623,8 +624,8 @@ public class TheMovieDbApiTest { /** * Test of getPersonChanges method, of class TheMovieDbApi. * - * TODO: Fix the method before testing */ + @Ignore("Not ready yet") public void testGetPersonChanges() throws Exception { LOG.info("getPersonChanges"); String startDate = ""; @@ -676,4 +677,77 @@ public class TheMovieDbApiTest { assertFalse("No reviews found", result.isEmpty()); } + /** + * Test of compareMovies method, of class TheMovieDbApi. + */ + @Ignore("Not required") + public void testCompareMovies_3args() { + } + + /** + * Test of compareMovies method, of class TheMovieDbApi. + */ + @Ignore("Not required") + public void testCompareMovies_4args() { + } + + /** + * Test of getPersonPopular method, of class TheMovieDbApi. + */ + @Ignore("Not required") + public void testGetPersonPopular_0args() throws Exception { + } + + /** + * Test of getPersonPopular method, of class TheMovieDbApi. + */ + @Ignore + public void testGetPersonPopular_int() throws Exception { + LOG.info("getPersonPopular"); + int page = 0; + List result = tmdb.getPersonPopular(page); + assertFalse("No popular people", result.isEmpty()); + } + + /** + * Test of getGenreMovies method, of class TheMovieDbApi. + */ + @Ignore("Not required") + public void testGetGenreMovies_3args() throws Exception { + } + + /** + * Test of getGenreMovies method, of class TheMovieDbApi. + */ + @Ignore("Not required") + public void testGetGenreMovies_4args() throws Exception { + } + + /** + * Test of getMovieChangesList method, of class TheMovieDbApi. + */ + @Ignore("Not ready yet") + public void testGetMovieChangesList() throws Exception { + LOG.info("getMovieChangesList"); + int page = 0; + String startDate = ""; + String endDate = ""; + tmdb.getMovieChangesList(page, startDate, endDate); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } + + /** + * Test of getPersonChangesList method, of class TheMovieDbApi. + */ + @Ignore("Not ready yet") + public void testGetPersonChangesList() throws Exception { + LOG.info("getPersonChangesList"); + int page = 0; + String startDate = ""; + String endDate = ""; + tmdb.getPersonChangesList(page, startDate, endDate); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); + } }