Add PopularPerson method
This commit is contained in:
@@ -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<Person> getPersonPopular() throws MovieDbException {
|
||||
return getPersonPopular(0);
|
||||
}
|
||||
|
||||
public List<Person> 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.
|
||||
*
|
||||
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
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<Person> personList;
|
||||
|
||||
public WrapperPersonList() {
|
||||
super(LoggerFactory.getLogger(WrapperPersonList.class));
|
||||
}
|
||||
|
||||
public List<Person> getPersonList() {
|
||||
return personList;
|
||||
}
|
||||
|
||||
public void setPersonList(List<Person> personList) {
|
||||
this.personList = personList;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user