Add PopularPerson method

This commit is contained in:
Stuart Boston
2013-05-15 13:46:59 +01:00
parent c99f60f636
commit 4c682731b6
4 changed files with 151 additions and 20 deletions
@@ -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;