Skip to content

Commit

Permalink
People api (#173)
Browse files Browse the repository at this point in the history
* update people api

* test people api
  • Loading branch information
c-eg authored Feb 25, 2024
1 parent 2658c35 commit c343fc8
Show file tree
Hide file tree
Showing 63 changed files with 10,169 additions and 576 deletions.
8 changes: 4 additions & 4 deletions src/main/java/info/movito/themoviedbapi/TmdbCollections.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import info.movito.themoviedbapi.model.Artwork;
import info.movito.themoviedbapi.model.ArtworkType;
import info.movito.themoviedbapi.model.CollectionInfo;
import info.movito.themoviedbapi.model.Translation;
import info.movito.themoviedbapi.model.Translations;
import info.movito.themoviedbapi.model.core.image.CollectionImage;
import info.movito.themoviedbapi.model.collections.Translation;
import info.movito.themoviedbapi.model.collections.Translations;
import info.movito.themoviedbapi.model.core.image.CollectionImages;
import info.movito.themoviedbapi.tools.ApiUrl;
import info.movito.themoviedbapi.tools.TmdbException;

Expand Down Expand Up @@ -54,7 +54,7 @@ public List<Artwork> getImages(Integer collectionId, String language, String...
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_COLLECTION, collectionId, "images");
apiUrl.addLanguage(language);
apiUrl.addQueryParamCommandSeparated("include_image_language", includeImageLanguage);
return mapJsonResult(apiUrl, CollectionImage.class).getAll(ArtworkType.POSTER, ArtworkType.BACKDROP);
return mapJsonResult(apiUrl, CollectionImages.class).getAll(ArtworkType.POSTER, ArtworkType.BACKDROP);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/info/movito/themoviedbapi/TmdbDiscover.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class TmdbDiscover extends AbstractTmdbApi {
*/
public MovieResultsPage getMovie(DiscoverMovieParamBuilder builder) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_DISCOVER, TMDB_METHOD_MOVIE);
apiUrl.addParams(builder);
apiUrl.addPathParams(builder);
return mapJsonResult(apiUrl, MovieResultsPage.class);
}

Expand All @@ -45,7 +45,7 @@ public MovieResultsPage getMovie(DiscoverMovieParamBuilder builder) throws TmdbE
*/
public TvSeriesResultsPage getTv(DiscoverTvParamBuilder builder) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_DISCOVER, TMDB_METHOD_TV);
apiUrl.addParams(builder);
apiUrl.addPathParams(builder);
return mapJsonResult(apiUrl, TvSeriesResultsPage.class);
}
}
27 changes: 13 additions & 14 deletions src/main/java/info/movito/themoviedbapi/TmdbMovies.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import info.movito.themoviedbapi.model.AlternativeTitle;
import info.movito.themoviedbapi.model.Credits;
import info.movito.themoviedbapi.model.ExternalIds;
import info.movito.themoviedbapi.model.MovieDb;
import info.movito.themoviedbapi.model.MovieImages;
import info.movito.themoviedbapi.model.MovieListResultsPage;
import info.movito.themoviedbapi.model.Translations;
import info.movito.themoviedbapi.model.MoviesAlternativeTitles;
import info.movito.themoviedbapi.model.ReleaseInfo;
import info.movito.themoviedbapi.model.Translation;
import info.movito.themoviedbapi.model.collections.Translation;
import info.movito.themoviedbapi.model.collections.Translations;
import info.movito.themoviedbapi.model.Video;
import info.movito.themoviedbapi.model.movies.changes.ChangesItems;
import info.movito.themoviedbapi.model.core.IdElement;
import info.movito.themoviedbapi.model.core.MovieDbResultsPage;
import info.movito.themoviedbapi.model.core.SessionToken;
import info.movito.themoviedbapi.model.core.image.CollectionImages;
import info.movito.themoviedbapi.model.keywords.Keyword;
import info.movito.themoviedbapi.model.movies.changes.ChangeResults;
import info.movito.themoviedbapi.model.people.ExternalIds;
import info.movito.themoviedbapi.model.people.PersonCredits;
import info.movito.themoviedbapi.model.providers.ProviderResults;
import info.movito.themoviedbapi.tools.ApiUrl;
import info.movito.themoviedbapi.tools.TmdbException;
Expand All @@ -26,7 +26,6 @@

import static info.movito.themoviedbapi.TmdbAccount.PARAM_SESSION;
import static info.movito.themoviedbapi.TmdbMovies.MovieMethod.videos;
import static info.movito.themoviedbapi.util.Utils.asStringArray;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

/**
Expand Down Expand Up @@ -62,7 +61,7 @@ public MovieDb getMovie(int movieId, String language, MovieMethod... appendToRes

apiUrl.addLanguage(language);

apiUrl.appendToResponse(asStringArray(appendToResponse));
//apiUrl.addAppendToResponses(asStringArray(appendToResponse)); todo fix me

return mapJsonResult(apiUrl, MovieDb.class);
}
Expand All @@ -86,21 +85,21 @@ public List<AlternativeTitle> getAlternativeTitles(int movieId, String country)
* @param movieId the movies id
* @return the movie credits
*/
public Credits getCredits(int movieId) throws TmdbException {
public PersonCredits getCredits(int movieId) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_MOVIE, movieId, MovieMethod.credits);

return mapJsonResult(apiUrl, Credits.class);
return mapJsonResult(apiUrl, PersonCredits.class);
}

/**
* This method should be used when you’re wanting to retrieve all of the images for a particular movie.
*/
public MovieImages getImages(int movieId, String language) throws TmdbException {
public CollectionImages getImages(int movieId, String language) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_MOVIE, movieId, MovieMethod.images);

apiUrl.addLanguage(language);

return mapJsonResult(apiUrl, MovieImages.class);
return mapJsonResult(apiUrl, CollectionImages.class);
}

/**
Expand Down Expand Up @@ -213,7 +212,7 @@ public MovieListResultsPage getListsContaining(int movieId, SessionToken session
* @param startDate the start date of the changes, optional
* @param endDate the end date of the changes, optional
*/
public ChangesItems getChanges(int movieId, String startDate, String endDate) throws TmdbException {
public ChangeResults getChanges(int movieId, String startDate, String endDate) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_MOVIE, movieId, MovieMethod.changes);

if (StringUtils.isNotBlank(startDate)) {
Expand All @@ -224,7 +223,7 @@ public ChangesItems getChanges(int movieId, String startDate, String endDate) th
apiUrl.addPathParam(PARAM_END_DATE, endDate);
}

return mapJsonResult(apiUrl, ChangesItems.class);
return mapJsonResult(apiUrl, ChangeResults.class);
}

/**
Expand Down
155 changes: 109 additions & 46 deletions src/main/java/info/movito/themoviedbapi/TmdbPeople.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
package info.movito.themoviedbapi;

import info.movito.themoviedbapi.model.Artwork;
import info.movito.themoviedbapi.model.ArtworkType;
import info.movito.themoviedbapi.model.MovieImages;
import info.movito.themoviedbapi.model.core.ResultsPage;
import info.movito.themoviedbapi.model.people.Person;
import info.movito.themoviedbapi.model.people.PersonCredits;
import info.movito.themoviedbapi.model.people.PersonPeople;
import info.movito.themoviedbapi.model.movies.changes.ChangeResults;
import info.movito.themoviedbapi.model.people.ExternalIds;
import info.movito.themoviedbapi.model.people.PersonDb;
import info.movito.themoviedbapi.model.people.PersonImages;
import info.movito.themoviedbapi.model.people.Translations;
import info.movito.themoviedbapi.model.people.credits.CombinedPersonCredits;
import info.movito.themoviedbapi.model.people.credits.MovieCredits;
import info.movito.themoviedbapi.model.people.credits.Person;
import info.movito.themoviedbapi.model.people.credits.TvCredits;
import info.movito.themoviedbapi.tools.ApiUrl;
import info.movito.themoviedbapi.tools.MovieDbException;
import info.movito.themoviedbapi.tools.TmdbException;

import java.util.List;
import info.movito.themoviedbapi.tools.appendtoresponse.PersonAppendToResponse;

/**
* The movie database api for people. See the
* <a href="https://developer.themoviedb.org/reference/person-details">documentation</a> for more info.
*/
public class TmdbPeople extends AbstractTmdbApi {
public static final String TMDB_METHOD_PERSON = "person";
protected static final String TMDB_METHOD_PERSON = "person";

/**
* Create a new TmdbPeople instance to call the people related TMDb API methods.
Expand All @@ -28,73 +29,135 @@ public class TmdbPeople extends AbstractTmdbApi {
}

/**
* This method is used to retrieve all of the basic person information.
* <p>Query the top level details of a person.</p>
* <p>See the <a href="https://developer.themoviedb.org/reference/person-details">documentation</a> for more info.</p>
*
* It will return the single highest rated profile image.
* @param personId The TMDb id of the person.
* @param language optional - The language to query the results in. Default: en-US.
* @param appendToResponse optional - additional namespaces to append to the result (20 max).
* @return The person details.
* @throws TmdbException If there was an error making the request or mapping the response.
*/
public PersonPeople getPersonInfo(int personId, String... appendToResponse) throws TmdbException {
public PersonDb getDetails(int personId, String language, PersonAppendToResponse... appendToResponse) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_PERSON, personId);
apiUrl.addLanguage(language);
apiUrl.addAppendToResponses(appendToResponse);
return mapJsonResult(apiUrl, PersonDb.class);
}

apiUrl.appendToResponse(appendToResponse);

return mapJsonResult(apiUrl, PersonPeople.class);
/**
* <p>Get the recent changes for a person.</p>
* <p>See the <a href="https://developer.themoviedb.org/reference/person-changes">documentation</a> for more info.</p>
*
* @param personId The TMDb id of the person.
* @param startDate optional - The start date, in format: YYYY-MM-DD.
* @param endDate optional - The end date, in format: YYYY-MM-DD.
* @param page optional - The page of results to return. Default: 1.
* @return The person changes.
* @throws TmdbException If there was an error making the request or mapping the response.
*/
public ChangeResults getChanges(int personId, String startDate, String endDate, Integer page) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_PERSON, personId, "changes");
apiUrl.addQueryParam("start_date", startDate);
apiUrl.addQueryParam("end_date", endDate);
apiUrl.addPage(page);
return mapJsonResult(apiUrl, ChangeResults.class);
}

/**
* This method is used to retrieve all of the cast &amp; crew information for the person.
* <p>Get the combined movie and TV credits that belong to a person.</p>
* <p>See the <a href="https://developer.themoviedb.org/reference/person-combined-credits">documentation</a> for more info.</p>
*
* It will return the single highest rated poster for each movie record.
* @param personId The TMDb id of the person.
* @param language optional - The language to query the results in. Default: en-US.
* @return The combined person credits.
* @throws TmdbException If there was an error making the request or mapping the response.
*/
public PersonCredits getCombinedPersonCredits(int personId) throws TmdbException {
public CombinedPersonCredits getCombinedCredits(int personId, String language) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_PERSON, personId, "combined_credits");
apiUrl.addLanguage(language);
return mapJsonResult(apiUrl, CombinedPersonCredits.class);
}

return mapJsonResult(apiUrl, PersonCredits.class);
/**
* <p>Get the external ID's that belong to a person.</p>
* <p>See the <a href="https://developer.themoviedb.org/reference/person-external-ids">documentation</a> for more info.</p>
*
* @param personId The TMDb id of the person.
* @return The external IDs.
* @throws TmdbException If there was an error making the request or mapping the response.
*/
public ExternalIds getExternalIds(int personId) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_PERSON, personId, "external_ids");
return mapJsonResult(apiUrl, ExternalIds.class);
}

/**
* This method is used to retrieve all of the profile images for a person.
* <p>Get the profile images that belong to a person.</p>
* <p>See the <a href="https://developer.themoviedb.org/reference/person-images">documentation</a> for more info.</p>
*
* @param personId The TMDb id of the person.
* @return The profile images.
* @throws TmdbException If there was an error making the request or mapping the response.
*/
public List<Artwork> getPersonImages(int personId) throws TmdbException {
public PersonImages getImages(int personId) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_PERSON, personId, "images");

return mapJsonResult(apiUrl, MovieImages.class).getAll(ArtworkType.PROFILE);
return mapJsonResult(apiUrl, PersonImages.class);
}

/**
* Get the changes for a specific person id.
* <p>Get the newest created person. This is a live response and will continuously change.</p>
* <p>See the <a href="https://developer.themoviedb.org/reference/person-latest-id">documentation</a> for more info.</p>
*
* Changes are grouped by key, and ordered by date in descending order.
*
* By default, only the last 24 hours of changes are returned.
*
* The maximum number of days that can be returned in a single request is 14.
*
* The language is present on fields that are translatable.
* @return The latest person.
* @throws TmdbException If there was an error making the request or mapping the response.
*/
public void getPersonChanges(int personId, String startDate, String endDate) {
throw new MovieDbException("Not implemented yet");
public PersonDb getLatest() throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_PERSON, "latest");
return mapJsonResult(apiUrl, PersonDb.class);
}

/**
* Get the list of popular people on The Movie Database.
* <p>Get the movie credits for a person.</p>
* <p>See the <a href="https://developer.themoviedb.org/reference/person-movie-credits">documentation</a> for more info.</p>
*
* This list refreshes every day.
* @param personId The TMDb id of the person.
* @param language optional - The language to query the results in. Default: en-US.
* @return The movie credits.
* @throws TmdbException If there was an error making the request or mapping the response.
*/
public PersonResultsPage getPersonPopular(Integer page) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_PERSON, "popular");

apiUrl.addPage(page);

return mapJsonResult(apiUrl, PersonResultsPage.class);
public MovieCredits getMovieCredits(int personId, String language) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_PERSON, personId, "movie_credits");
apiUrl.addLanguage(language);
return mapJsonResult(apiUrl, MovieCredits.class);
}

/**
* Get the latest person id.
* <p>Get the TV credits that belong to a person..</p>
* <p>See the <a href="https://developer.themoviedb.org/reference/person-tv-credits">documentation</a> for more info.</p>
*
* @param personId The TMDb id of the person.
* @param language optional - The language to query the results in. Default: en-US.
* @return The TV credits.
* @throws TmdbException If there was an error making the request or mapping the response.
*/
public PersonPeople getPersonLatest() throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_PERSON, "latest");
public TvCredits getTvCredits(int personId, String language) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_PERSON, personId, "tv_credits");
apiUrl.addLanguage(language);
return mapJsonResult(apiUrl, TvCredits.class);
}

return mapJsonResult(apiUrl, PersonPeople.class);
/**
* <p>Get the translations that belong to a person.</p>
* <p>See the <a href="https://developer.themoviedb.org/reference/translations">documentation</a> for more info.</p>
*
* @param personId The TMDb id of the person.
* @return The translations.
* @throws TmdbException If there was an error making the request or mapping the response.
*/
public Translations getTranslations(int personId) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_PERSON, personId, "translations");
return mapJsonResult(apiUrl, Translations.class);
}

@SuppressWarnings("checkstyle:MissingJavadocType")
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/info/movito/themoviedbapi/TmdbTV.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package info.movito.themoviedbapi;

import info.movito.themoviedbapi.model.ContentRating;
import info.movito.themoviedbapi.model.Credits;
import info.movito.themoviedbapi.model.MovieImages;
import info.movito.themoviedbapi.model.config.Timezone;
import info.movito.themoviedbapi.model.core.TvKeywords;
import info.movito.themoviedbapi.model.core.TvSeriesDbResultsPage;
import info.movito.themoviedbapi.model.core.image.CollectionImages;
import info.movito.themoviedbapi.model.people.PersonCredits;
import info.movito.themoviedbapi.model.tv.TvSeriesDb;
import info.movito.themoviedbapi.tools.ApiUrl;
import info.movito.themoviedbapi.tools.TmdbException;

import static info.movito.themoviedbapi.util.Utils.asStringArray;

/**
* The movie database api for tv series. See the
* <a href="https://developer.themoviedb.org/reference/tv-series-details">documentation</a> for more info.
Expand Down Expand Up @@ -50,7 +48,7 @@ public TvSeriesDb getSeries(int seriesId, String language, TvMethod... appendToR

apiUrl.addLanguage(language);

apiUrl.appendToResponse(asStringArray(appendToResponse));
//apiUrl.addAppendToResponses(asStringArray(appendToResponse)); todo fix me

return mapJsonResult(apiUrl, TvSeriesDb.class);
}
Expand All @@ -62,11 +60,11 @@ public TvSeriesDb getSeries(int seriesId, String language, TvMethod... appendToR
* @param language the language
* @return the show's credits
*/
public Credits getCredits(int seriesId, String language) throws TmdbException {
public PersonCredits getCredits(int seriesId, String language) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_TV, seriesId, TMDB_METHOD_CREDITS);

apiUrl.addLanguage(language);
return mapJsonResult(apiUrl, Credits.class);
return mapJsonResult(apiUrl, PersonCredits.class);
}

/**
Expand Down Expand Up @@ -145,12 +143,12 @@ public TvSeriesDbResultsPage getTopRated(String language, Integer page) throws T
* @param language the language
* @return the series
*/
public MovieImages getImages(int seriesId, String language) throws TmdbException {
public CollectionImages getImages(int seriesId, String language) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_TV, seriesId, TvMethod.images);

apiUrl.addLanguage(language);

return mapJsonResult(apiUrl, MovieImages.class);
return mapJsonResult(apiUrl, CollectionImages.class);
}

/**
Expand Down
Loading

0 comments on commit c343fc8

Please sign in to comment.