You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
183 lines
6.7 KiB
Java
183 lines
6.7 KiB
Java
/*
|
|
* 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.methods;
|
|
|
|
import com.omertron.themoviedbapi.MovieDbException;
|
|
import com.omertron.themoviedbapi.model.Artwork;
|
|
import com.omertron.themoviedbapi.model.ArtworkType;
|
|
import com.omertron.themoviedbapi.model.Person;
|
|
import com.omertron.themoviedbapi.model.PersonCredit;
|
|
import com.omertron.themoviedbapi.results.TmdbResultsList;
|
|
import com.omertron.themoviedbapi.tools.ApiUrl;
|
|
import com.omertron.themoviedbapi.tools.HttpTools;
|
|
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.WrapperImages;
|
|
import com.omertron.themoviedbapi.wrapper.WrapperPersonCredits;
|
|
import com.omertron.themoviedbapi.wrapper.WrapperPersonList;
|
|
import java.io.IOException;
|
|
import java.net.URL;
|
|
import org.yamj.api.common.exception.ApiExceptionType;
|
|
|
|
/**
|
|
* Class to hold the People Methods
|
|
*
|
|
* @author stuart.boston
|
|
*/
|
|
public class TmdbPeople extends AbstractMethod {
|
|
|
|
/**
|
|
* Constructor
|
|
*
|
|
* @param apiKey
|
|
* @param httpTools
|
|
*/
|
|
public TmdbPeople(String apiKey, HttpTools httpTools) {
|
|
super(apiKey, httpTools);
|
|
}
|
|
|
|
/**
|
|
* This method is used to retrieve all of the basic person information.
|
|
*
|
|
* It will return the single highest rated profile image.
|
|
*
|
|
* @param personId
|
|
* @param appendToResponse
|
|
* @return
|
|
* @throws MovieDbException
|
|
*/
|
|
public Person getPersonInfo(int personId, String... appendToResponse) throws MovieDbException {
|
|
TmdbParameters parameters = new TmdbParameters();
|
|
parameters.add(Param.ID, personId);
|
|
parameters.add(Param.APPEND, appendToResponse);
|
|
|
|
URL url = new ApiUrl(apiKey, MethodBase.PERSON).buildUrl(parameters);
|
|
String webpage = httpTools.getRequest(url);
|
|
|
|
try {
|
|
return MAPPER.readValue(webpage, Person.class);
|
|
} catch (IOException ex) {
|
|
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person info", url, ex);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* This method is used to retrieve all of the cast & crew information for the person.
|
|
*
|
|
* It will return the single highest rated poster for each movie record.
|
|
*
|
|
* @param personId
|
|
* @param appendToResponse
|
|
* @return
|
|
* @throws MovieDbException
|
|
*/
|
|
public TmdbResultsList<PersonCredit> getPersonCredits(int personId, String... appendToResponse) throws MovieDbException {
|
|
TmdbParameters parameters = new TmdbParameters();
|
|
parameters.add(Param.ID, personId);
|
|
parameters.add(Param.APPEND, appendToResponse);
|
|
|
|
URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.CREDITS).buildUrl(parameters);
|
|
String webpage = httpTools.getRequest(url);
|
|
|
|
try {
|
|
WrapperPersonCredits wrapper = MAPPER.readValue(webpage, WrapperPersonCredits.class);
|
|
TmdbResultsList<PersonCredit> results = new TmdbResultsList<PersonCredit>(wrapper.getAll());
|
|
results.copyWrapper(wrapper);
|
|
return results;
|
|
} catch (IOException ex) {
|
|
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person credits", url, ex);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* This method is used to retrieve all of the profile images for a person.
|
|
*
|
|
* @param personId
|
|
* @return
|
|
* @throws MovieDbException
|
|
*/
|
|
public TmdbResultsList<Artwork> getPersonImages(int personId) throws MovieDbException {
|
|
TmdbParameters parameters = new TmdbParameters();
|
|
parameters.add(Param.ID, personId);
|
|
|
|
URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.IMAGES).buildUrl(parameters);
|
|
String webpage = httpTools.getRequest(url);
|
|
|
|
try {
|
|
WrapperImages wrapper = MAPPER.readValue(webpage, WrapperImages.class);
|
|
TmdbResultsList<Artwork> results = new TmdbResultsList<Artwork>(wrapper.getAll(ArtworkType.PROFILE));
|
|
results.copyWrapper(wrapper);
|
|
return results;
|
|
} catch (IOException ex) {
|
|
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person images", url, ex);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the list of popular people on The Movie Database.
|
|
*
|
|
* This list refreshes every day.
|
|
*
|
|
* @param page
|
|
* @return
|
|
* @throws MovieDbException
|
|
*/
|
|
public TmdbResultsList<Person> getPersonPopular(int page) throws MovieDbException {
|
|
TmdbParameters parameters = new TmdbParameters();
|
|
parameters.add(Param.PAGE, page);
|
|
|
|
URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.POPULAR).buildUrl(parameters);
|
|
String webpage = httpTools.getRequest(url);
|
|
|
|
try {
|
|
WrapperPersonList wrapper = MAPPER.readValue(webpage, WrapperPersonList.class);
|
|
TmdbResultsList<Person> results = new TmdbResultsList<Person>(wrapper.getPersonList());
|
|
results.copyWrapper(wrapper);
|
|
return results;
|
|
} catch (IOException ex) {
|
|
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get popular person", url, ex);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the latest person id.
|
|
*
|
|
* @return
|
|
* @throws MovieDbException
|
|
*/
|
|
public Person getPersonLatest() throws MovieDbException {
|
|
URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.LATEST).buildUrl();
|
|
String webpage = httpTools.getRequest(url);
|
|
|
|
try {
|
|
return MAPPER.readValue(webpage, Person.class);
|
|
} catch (IOException ex) {
|
|
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get latest person", url, ex);
|
|
}
|
|
}
|
|
|
|
int getPersonMovieCredits(int ID_BRUCE_WILLIS, String LANGUAGE_DEFAULT) {
|
|
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
|
}
|
|
|
|
}
|