diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index 0771b00fc..de0dbdb5a 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -69,6 +69,9 @@ import com.omertron.themoviedbapi.model.TokenAuthorisation; import com.omertron.themoviedbapi.model.TokenSession; import com.omertron.themoviedbapi.model.Translation; import com.omertron.themoviedbapi.model.Video; +import com.omertron.themoviedbapi.model.list.MovieFavorite; +import com.omertron.themoviedbapi.model.list.TVFavorite; +import com.omertron.themoviedbapi.model.list.UserList; import com.omertron.themoviedbapi.results.TmdbResultsList; import com.omertron.themoviedbapi.results.TmdbResultsMap; import com.omertron.themoviedbapi.tools.HttpTools; @@ -280,7 +283,7 @@ public class TheMovieDbApi { * @return The lists * @throws MovieDbException */ - public List getUserLists(String sessionId, int accountId) throws MovieDbException { + public List getUserLists(String sessionId, int accountId) throws MovieDbException { return tmdbAccount.getUserLists(sessionId, accountId); } @@ -292,7 +295,7 @@ public class TheMovieDbApi { * @return * @throws MovieDbException */ - public List getFavoriteMovies(String sessionId, int accountId) throws MovieDbException { + public List getFavoriteMovies(String sessionId, int accountId) throws MovieDbException { return tmdbAccount.getFavoriteMovies(sessionId, accountId); } @@ -307,8 +310,8 @@ public class TheMovieDbApi { * @return * @throws MovieDbException */ - public StatusCode changeFavoriteStatus(String sessionId, int accountId, Integer mediaId, MediaType mediaType, boolean isFavorite) throws MovieDbException { - return tmdbAccount.changeFavoriteStatus(sessionId, accountId, mediaId, mediaType, isFavorite); + public StatusCode modifyFavoriteStatus(String sessionId, int accountId, Integer mediaId, MediaType mediaType, boolean isFavorite) throws MovieDbException { + return tmdbAccount.modifyFavoriteStatus(sessionId, accountId, mediaType, mediaId, isFavorite); } /** @@ -316,11 +319,14 @@ public class TheMovieDbApi { * * @param sessionId * @param accountId + * @param page + * @param sortBy + * @param language * @return * @throws MovieDbException */ - public List getRatedMovies(String sessionId, int accountId) throws MovieDbException { - return tmdbAccount.getRatedMovies(sessionId, accountId); + public List getRatedMovies(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { + return tmdbAccount.getRatedMovies(sessionId, accountId, page, sortBy, language); } /** @@ -328,11 +334,14 @@ public class TheMovieDbApi { * * @param sessionId * @param accountId + * @param page + * @param sortBy + * @param language * @return * @throws MovieDbException */ - public List getRatedTV(String sessionId, int accountId) throws MovieDbException { - return tmdbAccount.getRatedTV(sessionId, accountId); + public List getRatedTV(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { + return tmdbAccount.getRatedTV(sessionId, accountId, page, sortBy, language); } /** @@ -340,11 +349,14 @@ public class TheMovieDbApi { * * @param sessionId * @param accountId + * @param page + * @param sortBy + * @param language * @return The watchlist of the user * @throws MovieDbException */ - public List getWatchListMovie(String sessionId, int accountId) throws MovieDbException { - return tmdbAccount.getWatchListMovie(sessionId, accountId); + public List getWatchListMovie(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { + return tmdbAccount.getWatchListMovie(sessionId, accountId, page, sortBy, language); } /** @@ -352,11 +364,14 @@ public class TheMovieDbApi { * * @param sessionId * @param accountId + * @param page + * @param sortBy + * @param language * @return The watchlist of the user * @throws MovieDbException */ - public List getWatchListTV(String sessionId, int accountId) throws MovieDbException { - return tmdbAccount.getWatchListTV(sessionId, accountId); + public List getWatchListTV(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { + return tmdbAccount.getWatchListTV(sessionId, accountId, page, sortBy, language); } /** diff --git a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java index 010b90f36..166bab5f4 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java @@ -19,10 +19,17 @@ */ package com.omertron.themoviedbapi.methods; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.tools.HttpTools; +import com.omertron.themoviedbapi.wrapper.WrapperGenericList; +import java.io.IOException; +import java.net.URL; +import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.yamj.api.common.exception.ApiExceptionType; /** * Abstract methods @@ -51,4 +58,26 @@ public class AbstractMethod { this.httpTools = httpTools; } + /** + * Process the wrapper list and return the results + * + * @param Type of list to process + * @param url URL of the page (Error output only) + * @param errorMessageSuffix Error message to output (Error output only) + * @return + * @throws MovieDbException + */ + public List processWrapperList(URL url, String errorMessageSuffix) throws MovieDbException { + String webpage = httpTools.getRequest(url); + + try { + TypeReference> ref = new TypeReference>() { + }; + WrapperGenericList results = MAPPER.readValue(webpage, ref); + return results.getResults(); + } catch (IOException ex) { + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get " + errorMessageSuffix, url, ex); + } + + } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java index cffa32dd7..adca10b92 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java @@ -19,12 +19,14 @@ */ package com.omertron.themoviedbapi.methods; +import com.fasterxml.jackson.core.type.TypeReference; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.MediaType; import com.omertron.themoviedbapi.model.Account; -import com.omertron.themoviedbapi.model.MovieDb; -import com.omertron.themoviedbapi.model.MovieDbList; import com.omertron.themoviedbapi.model.StatusCode; +import com.omertron.themoviedbapi.model.list.MovieFavorite; +import com.omertron.themoviedbapi.model.list.TVFavorite; +import com.omertron.themoviedbapi.model.list.UserList; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; @@ -33,8 +35,6 @@ import com.omertron.themoviedbapi.tools.Param; import com.omertron.themoviedbapi.tools.PostBody; import com.omertron.themoviedbapi.tools.PostTools; import com.omertron.themoviedbapi.tools.TmdbParameters; -import com.omertron.themoviedbapi.wrapper.WrapperMovie; -import com.omertron.themoviedbapi.wrapper.WrapperMovieDbList; import java.io.IOException; import java.net.URL; import java.util.List; @@ -58,8 +58,7 @@ public class TmdbAccount extends AbstractMethod { } /** - * Get the basic information for an account. You will need to have a valid - * session id. + * Get the basic information for an account. You will need to have a valid session id. * * @param sessionId * @return @@ -80,12 +79,6 @@ public class TmdbAccount extends AbstractMethod { } /* - /account/{id}/lists Get the lists that you have created and marked as a favorite. - /account/{id}/favorite/movies Get the list of favorite movies for an account. - /account/{id}/favorite/tv Get the list of favorite TV series for an account - /account/{id}/favorite Add or remove a movie to an accounts favorite list - /account/{id}/rated/movies Get the list of rated movies (and associated rating) for an account - /account/{id}/rated/tv Get the list of rated TV shows (and associated rating) for an account. /account/{id}/watchlist/movies Get the list of movies on an accounts watchlist /account/{id}/watchlist/tv Get the list of TV series on an accounts watchlist /account/{id}/watchlist Add or remove a movie to an accounts watch list @@ -98,19 +91,13 @@ public class TmdbAccount extends AbstractMethod { * @return The lists * @throws MovieDbException */ - public List getUserLists(String sessionId, int accountId) throws MovieDbException { + public List getUserLists(String sessionId, int accountId) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.SESSION, sessionId); parameters.add(Param.ID, accountId); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.LISTS).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - return MAPPER.readValue(webpage, WrapperMovieDbList.class).getLists(); - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get user list", url, ex); - } + return processWrapperList(url, "user list"); } /** @@ -121,19 +108,13 @@ public class TmdbAccount extends AbstractMethod { * @return * @throws MovieDbException */ - public List getFavoriteMovies(String sessionId, int accountId) throws MovieDbException { + public List getFavoriteMovies(String sessionId, int accountId) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.SESSION, sessionId); parameters.add(Param.ID, accountId); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.FAVORITE_MOVIES).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - return MAPPER.readValue(webpage, WrapperMovie.class).getMovies(); - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get favorite movies", url, ex); - } + return processWrapperList(url, "favorite movies"); } /** @@ -144,15 +125,13 @@ public class TmdbAccount extends AbstractMethod { * @return * @throws MovieDbException */ - public List getFavoriteTv(String sessionId, int accountId) throws MovieDbException { + public List getFavoriteTv(String sessionId, int accountId) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.SESSION, sessionId); parameters.add(Param.ID, accountId); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.FAVORITE_TV).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not implemented yet"); + return processWrapperList(url, "favorite TV shows"); } /** @@ -162,11 +141,11 @@ public class TmdbAccount extends AbstractMethod { * @param accountId * @param mediaType * @param mediaId - * @param isFavorite + * @param setFavorite * @return * @throws MovieDbException */ - public StatusCode changeFavoriteStatus(String sessionId, int accountId, Integer mediaId, MediaType mediaType, boolean isFavorite) throws MovieDbException { + public StatusCode modifyFavoriteStatus(String sessionId, int accountId, MediaType mediaType, int mediaId, boolean setFavorite) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.SESSION, sessionId); parameters.add(Param.ID, accountId); @@ -174,7 +153,7 @@ public class TmdbAccount extends AbstractMethod { String jsonBody = new PostTools() .add(PostBody.MEDIA_TYPE, mediaType.toString().toLowerCase()) .add(PostBody.MEDIA_ID, mediaId) - .add(PostBody.FAVORITE, isFavorite) + .add(PostBody.FAVORITE, setFavorite) .build(); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.FAVORITE).buildUrl(parameters); @@ -183,7 +162,7 @@ public class TmdbAccount extends AbstractMethod { try { return MAPPER.readValue(webpage, StatusCode.class); } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get favorite status", url, ex); + throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to set favorite status", url, ex); } } @@ -192,22 +171,24 @@ public class TmdbAccount extends AbstractMethod { * * @param sessionId * @param accountId + * @param page + * @param sortBy + * @param language * @return * @throws MovieDbException */ - public List getRatedMovies(String sessionId, int accountId) throws MovieDbException { + public List getRatedMovies(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.SESSION, sessionId); parameters.add(Param.ID, accountId); + parameters.add(Param.PAGE, page); + parameters.add(Param.SORT_BY, sortBy); + parameters.add(Param.LANGUAGE, language); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.RATED_MOVIES).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - return MAPPER.readValue(webpage, WrapperMovie.class).getMovies(); - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get rated movies", url, ex); - } + TypeReference ref = new TypeReference() { + }; + return processWrapperList(url, "rated movies"); } /** @@ -215,11 +196,22 @@ public class TmdbAccount extends AbstractMethod { * * @param sessionId * @param accountId + * @param page + * @param sortBy + * @param language * @return * @throws MovieDbException */ - public List getRatedTV(String sessionId, int accountId) throws MovieDbException { - throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not implemented yet"); + public List getRatedTV(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.SESSION, sessionId); + parameters.add(Param.ID, accountId); + parameters.add(Param.PAGE, page); + parameters.add(Param.SORT_BY, sortBy); + parameters.add(Param.LANGUAGE, language); + + URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.RATED_TV).buildUrl(parameters); + return processWrapperList(url, "rated TV shows"); } /** @@ -227,22 +219,22 @@ public class TmdbAccount extends AbstractMethod { * * @param sessionId * @param accountId + * @param page + * @param sortBy + * @param language * @return The watch list of the user * @throws MovieDbException */ - public List getWatchListMovie(String sessionId, int accountId) throws MovieDbException { + public List getWatchListMovie(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.SESSION, sessionId); parameters.add(Param.ID, accountId); + parameters.add(Param.PAGE, page); + parameters.add(Param.SORT_BY, sortBy); + parameters.add(Param.LANGUAGE, language); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.WATCHLIST_MOVIES).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - return MAPPER.readValue(webpage, WrapperMovie.class).getMovies(); - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get Movie watch list", url, ex); - } + return processWrapperList(url, "movie watch list"); } /** @@ -250,22 +242,22 @@ public class TmdbAccount extends AbstractMethod { * * @param sessionId * @param accountId + * @param page + * @param sortBy + * @param language * @return The watch list of the user * @throws MovieDbException */ - public List getWatchListTV(String sessionId, int accountId) throws MovieDbException { + public List getWatchListTV(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.SESSION, sessionId); parameters.add(Param.ID, accountId); + parameters.add(Param.PAGE, page); + parameters.add(Param.SORT_BY, sortBy); + parameters.add(Param.LANGUAGE, language); URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).setSubMethod(MethodSub.WATCHLIST_TV).buildUrl(parameters); - String webpage = httpTools.getRequest(url); - - try { - return MAPPER.readValue(webpage, WrapperMovie.class).getMovies(); - } catch (IOException ex) { - throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get TV watch list", url, ex); - } + return processWrapperList(url, "TV watch list"); } /** diff --git a/src/main/java/com/omertron/themoviedbapi/model/list/MovieFavorite.java b/src/main/java/com/omertron/themoviedbapi/model/list/MovieFavorite.java new file mode 100644 index 000000000..489a91e36 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/list/MovieFavorite.java @@ -0,0 +1,152 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model.list; + +import com.omertron.themoviedbapi.model.*; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Movie Favorite information + * + * @author stuart.boston + */ +public class MovieFavorite extends AbstractJsonMapping { + + @JsonProperty("id") + private int id; + @JsonProperty("adult") + private boolean adult; + @JsonProperty("backdrop_path") + private String backdropPath; + @JsonProperty("original_title") + private String originalTitle; + @JsonProperty("release_date") + private String releaseDate; + @JsonProperty("poster_path") + private String posterPath; + @JsonProperty("popularity") + private float popularity; + @JsonProperty("title") + private String title; + @JsonProperty("video") + private boolean video; + @JsonProperty("vote_average") + private float voteAverage; + @JsonProperty("vote_count") + private int voteCount; + @JsonProperty("rating") + private float rating = -1f; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public boolean isAdult() { + return adult; + } + + public void setAdult(boolean adult) { + this.adult = adult; + } + + public String getBackdropPath() { + return backdropPath; + } + + public void setBackdropPath(String backdropPath) { + this.backdropPath = backdropPath; + } + + public String getOriginalTitle() { + return originalTitle; + } + + public void setOriginalTitle(String originalTitle) { + this.originalTitle = originalTitle; + } + + public String getReleaseDate() { + return releaseDate; + } + + public void setReleaseDate(String releaseDate) { + this.releaseDate = releaseDate; + } + + public String getPosterPath() { + return posterPath; + } + + public void setPosterPath(String posterPath) { + this.posterPath = posterPath; + } + + public float getPopularity() { + return popularity; + } + + public void setPopularity(float popularity) { + this.popularity = popularity; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public boolean isVideo() { + return video; + } + + public void setVideo(boolean video) { + this.video = video; + } + + public float getVoteAverage() { + return voteAverage; + } + + public void setVoteAverage(float voteAverage) { + this.voteAverage = voteAverage; + } + + public int getVoteCount() { + return voteCount; + } + + public void setVoteCount(int voteCount) { + this.voteCount = voteCount; + } + + public float getRating() { + return rating; + } + + public void setRating(float rating) { + this.rating = rating; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/list/TVFavorite.java b/src/main/java/com/omertron/themoviedbapi/model/list/TVFavorite.java new file mode 100644 index 000000000..388c5bdbe --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/list/TVFavorite.java @@ -0,0 +1,144 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model.list; + +import com.omertron.themoviedbapi.model.*; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; + +/** + * TV Favorite information + * + * @author stuart.boston + */ +public class TVFavorite extends AbstractJsonMapping { + + @JsonProperty("id") + private int id; + @JsonProperty("name") + private String name; + @JsonProperty("original_name") + private String originalName; + @JsonProperty("backdrop_path") + private String backdropPath; + @JsonProperty("poster_path") + private String posterPath; + @JsonProperty("vote_average") + private float voteAverage; + @JsonProperty("vote_count") + private int voteCount; + @JsonProperty("first_air_date") + private String firstAirDate; + @JsonProperty("popularity") + private float popularity; + @JsonProperty("origin_country") + private List originCountry; + @JsonProperty("rating") + private float rating = -1f; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getOriginalName() { + return originalName; + } + + public void setOriginalName(String originalName) { + this.originalName = originalName; + } + + public String getBackdropPath() { + return backdropPath; + } + + public void setBackdropPath(String backdropPath) { + this.backdropPath = backdropPath; + } + + public String getPosterPath() { + return posterPath; + } + + public void setPosterPath(String posterPath) { + this.posterPath = posterPath; + } + + public float getVoteAverage() { + return voteAverage; + } + + public void setVoteAverage(float voteAverage) { + this.voteAverage = voteAverage; + } + + public int getVoteCount() { + return voteCount; + } + + public void setVoteCount(int voteCount) { + this.voteCount = voteCount; + } + + public String getFirstAirDate() { + return firstAirDate; + } + + public void setFirstAirDate(String firstAirDate) { + this.firstAirDate = firstAirDate; + } + + public float getPopularity() { + return popularity; + } + + public void setPopularity(float popularity) { + this.popularity = popularity; + } + + public List getOriginCountry() { + return originCountry; + } + + public void setOriginCountry(List originCountry) { + this.originCountry = originCountry; + } + + public float getRating() { + return rating; + } + + public void setRating(float rating) { + this.rating = rating; + } + +} diff --git a/src/main/java/com/omertron/themoviedbapi/model/list/UserList.java b/src/main/java/com/omertron/themoviedbapi/model/list/UserList.java new file mode 100644 index 000000000..36288c303 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/model/list/UserList.java @@ -0,0 +1,112 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.model.list; + +import com.omertron.themoviedbapi.model.*; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Wrapper for the MovieDbList function + * + * @author stuart.boston + */ +public class UserList extends AbstractJsonMapping { + + @JsonProperty("id") + private String id; + @JsonProperty("description") + private String description; + @JsonProperty("favorite_count") + private int favoriteCount; + @JsonProperty("item_count") + private int itemCount; + @JsonProperty("iso_639_1") + private String language; + @JsonProperty("list_type") + private String listType; + @JsonProperty("name") + private String name; + @JsonProperty("poster_path") + private String posterPath; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public int getFavoriteCount() { + return favoriteCount; + } + + public void setFavoriteCount(int favoriteCount) { + this.favoriteCount = favoriteCount; + } + + public int getItemCount() { + return itemCount; + } + + public void setItemCount(int itemCount) { + this.itemCount = itemCount; + } + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + + public String getListType() { + return listType; + } + + public void setListType(String listType) { + this.listType = listType; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPosterPath() { + return posterPath; + } + + public void setPosterPath(String posterPath) { + this.posterPath = posterPath; + } +} diff --git a/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java b/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java index a46c703aa..f8bbda057 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java @@ -49,6 +49,7 @@ public enum MethodSub { PERSON("person"), POPULAR("popular"), RATED_MOVIES("rated/movies"), + RATED_TV("rated/tv"), RATING("rating"), RELEASES("releases"), REMOVE_ITEM("remove_item"), diff --git a/src/main/java/com/omertron/themoviedbapi/tools/Param.java b/src/main/java/com/omertron/themoviedbapi/tools/Param.java index c70471874..137fdedfe 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/Param.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/Param.java @@ -49,9 +49,7 @@ public enum Param { USERNAME("username="), VALUE("value="), YEAR("year="), - /* - * Discover parameters - */ + // Discover parameters CERTIFICATION_COUNTRY("certification_country="), CERTIFICATION_LTE("certification.lte="), PRIMARY_RELEASE_YEAR("primary_release_year="), diff --git a/src/main/java/com/omertron/themoviedbapi/tools/TmdbParameters.java b/src/main/java/com/omertron/themoviedbapi/tools/TmdbParameters.java index 101914b4b..d063ea6dc 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/TmdbParameters.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/TmdbParameters.java @@ -56,7 +56,7 @@ public class TmdbParameters { * @param key Parameter to add * @param value The array value to use (will be converted into a comma separated list) */ - public void add(Param key, String[] value) { + public void add(final Param key, final String[] value) { parameters.put(key, toList(value)); } @@ -66,7 +66,7 @@ public class TmdbParameters { * @param key Parameter to add * @param value The value to add (will be checked to ensure it's valid) */ - public void add(Param key, String value) { + public void add(final Param key, final String value) { if (StringUtils.isNotBlank(value)) { parameters.put(key, value); } @@ -78,8 +78,8 @@ public class TmdbParameters { * @param key Parameter to add * @param value The value to add (will be checked to ensure >0) */ - public void add(Param key, int value) { - if (value > 0f) { + public void add(final Param key, final Integer value) { + if (value != null && value > 0) { parameters.put(key, String.valueOf(value)); } } @@ -90,8 +90,8 @@ public class TmdbParameters { * @param key Parameter to add * @param value The value to add (will be checked to ensure >0) */ - public void add(Param key, float value) { - if (value > 0) { + public void add(final Param key, final Float value) { + if (value != null && value > 0f) { parameters.put(key, String.valueOf(value)); } } @@ -102,8 +102,10 @@ public class TmdbParameters { * @param key Parameter to add * @param value The value to add (will be checked to ensure >0) */ - public void add(Param key, boolean value) { - parameters.put(key, String.valueOf(value)); + public void add(final Param key, final Boolean value) { + if (value != null) { + parameters.put(key, String.valueOf(value)); + } } /** @@ -112,7 +114,7 @@ public class TmdbParameters { * @param key The Parameter to check * @return */ - public boolean has(Param key) { + public boolean has(final Param key) { return parameters.containsKey(key); } @@ -122,7 +124,7 @@ public class TmdbParameters { * @param key The parameter to get * @return */ - public Object get(Param key) { + public Object get(final Param key) { return parameters.get(key); } @@ -131,7 +133,7 @@ public class TmdbParameters { * * @param key */ - public void remove(Param key) { + public void remove(final Param key) { parameters.remove(key); } @@ -159,7 +161,7 @@ public class TmdbParameters { * @param appendToResponse * @return */ - public String toList(String[] appendToResponse) { + public String toList(final String[] appendToResponse) { StringBuilder sb = new StringBuilder(); if (appendToResponse.length > 0) { boolean first = Boolean.TRUE; diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperGenericList.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperGenericList.java new file mode 100644 index 000000000..3be06f981 --- /dev/null +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperGenericList.java @@ -0,0 +1,47 @@ +/* + * 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 . + * + */ +package com.omertron.themoviedbapi.wrapper; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; +import java.util.List; + +/** + * Generic wrapper for result lists + * + * @author Stuart + * @param + */ +public class WrapperGenericList extends AbstractWrapperAll implements Serializable { + + @JsonProperty("results") + private List results; + + public List getResults() { + return results; + } + + @JsonCreator + public void setResults(List results) { + this.results = results; + } + +} diff --git a/src/test/java/com/omertron/themoviedbapi/AbstractTests.java b/src/test/java/com/omertron/themoviedbapi/AbstractTests.java index fce9a3d85..a120649bd 100644 --- a/src/test/java/com/omertron/themoviedbapi/AbstractTests.java +++ b/src/test/java/com/omertron/themoviedbapi/AbstractTests.java @@ -149,9 +149,8 @@ public class AbstractTests { * @throws MovieDbException */ public static final String getSessionId() throws MovieDbException { - LOG.info("Create a session token for the rest of the tests"); - if (tokenSession == null) { + LOG.info("Create a session token for the rest of the tests"); String filename = TokenSession.class.getSimpleName(); // Try to read the object from a file tokenSession = readObject(filename); @@ -181,9 +180,8 @@ public class AbstractTests { * @throws MovieDbException */ public static final int getAccountId() throws MovieDbException { - LOG.info("Getting account information"); - if (account == null) { + LOG.info("Getting account information"); String filename = Account.class.getSimpleName(); // Read the object from a file account = readObject(filename); diff --git a/src/test/java/com/omertron/themoviedbapi/TestAccounts.java b/src/test/java/com/omertron/themoviedbapi/TestAccounts.java index 13699beae..6143fe3c3 100644 --- a/src/test/java/com/omertron/themoviedbapi/TestAccounts.java +++ b/src/test/java/com/omertron/themoviedbapi/TestAccounts.java @@ -26,6 +26,7 @@ import com.omertron.themoviedbapi.model.MovieDbList; import com.omertron.themoviedbapi.model.StatusCode; import com.omertron.themoviedbapi.model.TokenAuthorisation; import com.omertron.themoviedbapi.model.TokenSession; +import com.omertron.themoviedbapi.model.list.MovieFavorite; import java.util.List; import java.util.Random; import static org.junit.Assert.assertEquals; @@ -141,14 +142,14 @@ public class TestAccounts extends AbstractTests { assertTrue(tmdb.getFavoriteMovies(tokenSession.getSessionId(), account.getId()).isEmpty()); // add a movie - tmdb.changeFavoriteStatus(tokenSession.getSessionId(), account.getId(), 550, MediaType.MOVIE, true); + tmdb.modifyFavoriteStatus(tokenSession.getSessionId(), account.getId(), 550, MediaType.MOVIE, true); - List watchList = tmdb.getFavoriteMovies(tokenSession.getSessionId(), account.getId()); + List watchList = tmdb.getFavoriteMovies(tokenSession.getSessionId(), account.getId()); assertNotNull("Empty watch list returned", watchList); assertEquals("Watchlist wrong size", 1, watchList.size()); // clean up again - tmdb.changeFavoriteStatus(tokenSession.getSessionId(), account.getId(), 550, MediaType.MOVIE, false); + tmdb.modifyFavoriteStatus(tokenSession.getSessionId(), account.getId(), 550, MediaType.MOVIE, false); assertTrue(tmdb.getFavoriteMovies(tokenSession.getSessionId(), account.getId()).isEmpty()); } @@ -195,7 +196,7 @@ public class TestAccounts extends AbstractTests { assertTrue("Rating was not added", wasPosted); // get all rated movies - List ratedMovies = tmdb.getRatedMovies(tokenSession.getSessionId(), account.getId()); + List ratedMovies = tmdb.getRatedMovies(tokenSession.getSessionId(), account.getId(), null, null, null); assertTrue("No rated movies", ratedMovies.size() > 0); // We should check that the movie was correctly rated, but the CDN does not update fast enough. diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java index 21efffb37..27d44f8cb 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java @@ -21,13 +21,20 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; +import com.omertron.themoviedbapi.enumeration.MediaType; import com.omertron.themoviedbapi.model.Account; -import com.omertron.themoviedbapi.model.MovieDbList; +import com.omertron.themoviedbapi.model.StatusCode; +import com.omertron.themoviedbapi.model.list.MovieFavorite; +import com.omertron.themoviedbapi.model.list.TVFavorite; +import com.omertron.themoviedbapi.model.list.UserList; import java.util.List; import org.junit.After; import org.junit.AfterClass; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; @@ -41,6 +48,7 @@ public class TmdbAccountTest extends AbstractTests { private static TmdbAccount instance; // Constants private static final int ID_MOVIE_FIGHT_CLUB = 550; + private static final int ID_TV_WALKING_DEAD = 1402; public TmdbAccountTest() { } @@ -68,7 +76,7 @@ public class TmdbAccountTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test +// @Test public void testGetAccount() throws MovieDbException { LOG.info("getAccount"); Account result = instance.getAccount(getSessionId()); @@ -79,11 +87,164 @@ public class TmdbAccountTest extends AbstractTests { /** * Test of getUserLists method, of class TmdbAccount. + * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test +// @Test public void testGetUserLists() throws MovieDbException { LOG.info("getUserLists"); - List result = instance.getUserLists(getSessionId(), getAccountId()); + List results = instance.getUserLists(getSessionId(), getAccountId()); + assertNotNull("No list found", results); + assertFalse("No entries found", results.isEmpty()); + for (UserList r : results) { + LOG.info(" {}", r.toString()); + } + } + + /** + * Test of getFavoriteMovies method, of class TmdbAccount. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ +// @Test + public void testGetFavoriteMovies() throws MovieDbException { + LOG.info("getFavoriteMovies"); + List results = instance.getFavoriteMovies(getSessionId(), getAccountId()); + assertNotNull("No list found", results); + assertFalse("No entries found", results.isEmpty()); + for (MovieFavorite r : results) { + LOG.info(" {}", r.toString()); + } + } + + /** + * Test of getFavoriteTv method, of class TmdbAccount. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ +// @Test + public void testGetFavoriteTv() throws MovieDbException { + LOG.info("getFavoriteTv"); + List results = instance.getFavoriteTv(getSessionId(), getAccountId()); + assertNotNull("No list found", results); + assertFalse("No entries found", results.isEmpty()); + for (TVFavorite r : results) { + LOG.info(" {}", r.toString()); + } + } + + /** + * Test of modifyFavoriteStatus method, of class TmdbAccount. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ +// @Test + public void testModifyFavoriteStatus() throws MovieDbException { + LOG.info("modifyFavoriteStatus"); + + // Add a movie as a favourite + StatusCode result = instance.modifyFavoriteStatus(getSessionId(), getAccountId(), MediaType.MOVIE, ID_MOVIE_FIGHT_CLUB, true); + LOG.info("Result: {}", result); + assertTrue("Incorrect status code", result.getStatusCode() == 1 || result.getStatusCode() == 12); + + // Remove a movie as a favourite + result = instance.modifyFavoriteStatus(getSessionId(), getAccountId(), MediaType.MOVIE, ID_MOVIE_FIGHT_CLUB, false); + LOG.info("Result: {}", result); + assertTrue("Incorrect status code", result.getStatusCode() == 13); + + // Add a TV Show as a favourite + result = instance.modifyFavoriteStatus(getSessionId(), getAccountId(), MediaType.TV, ID_TV_WALKING_DEAD, true); + LOG.info("Result: {}", result); + assertTrue("Incorrect status code", result.getStatusCode() == 1 || result.getStatusCode() == 12); + + // Remove a TV Show as a favourite + result = instance.modifyFavoriteStatus(getSessionId(), getAccountId(), MediaType.TV, ID_TV_WALKING_DEAD, false); + LOG.info("Result: {}", result); + assertTrue("Incorrect status code", result.getStatusCode() == 13); + + } + + /** + * Test of getRatedMovies method, of class TmdbAccount. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetRatedMovies() throws MovieDbException { + LOG.info("getRatedMovies"); + List results = instance.getRatedMovies(getSessionId(), getAccountId(), null, null, null); + assertNotNull("No rated list found", results); + assertFalse("No entries found", results.isEmpty()); + + for(MovieFavorite r: results){ + LOG.info(" {}-{}", r.getClass(),r.toString()); + } + + } + + /** + * Test of getRatedTV method, of class TmdbAccount. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ +// @Test + public void testGetRatedTV() throws MovieDbException { + LOG.info("getRatedTV"); + List results = instance.getRatedTV(getSessionId(), getAccountId(), null, null, null); + assertNotNull("No rated list found", results); + assertFalse("No entries found", results.isEmpty()); + for (TVFavorite r : results) { + LOG.info(" {}", r.toString()); + } + } + + /** + * Test of getWatchListMovie method, of class TmdbAccount. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ +// @Test + public void testGetWatchListMovie() throws MovieDbException { + LOG.info("getWatchListMovie"); + List results = instance.getWatchListMovie(getSessionId(), getAccountId(), null, null, null); + assertNotNull("No rated list found", results); + assertFalse("No entries found", results.isEmpty()); + for (MovieFavorite r : results) { + LOG.info(" {}", r.toString()); + } + } + + /** + * Test of getWatchListTV method, of class TmdbAccount. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ +// @Test + public void testGetWatchListTV() throws MovieDbException { + LOG.info("getWatchListTV"); + List results = instance.getWatchListTV(getSessionId(), getAccountId(), null, null, null); + assertNotNull("No rated list found", results); + assertFalse("No entries found", results.isEmpty()); + for (TVFavorite r : results) { + LOG.info(" {}", r.toString()); + } + } + + /** + * Test of modifyWatchList method, of class TmdbAccount. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ +// @Test + public void testModifyWatchList() throws MovieDbException { + LOG.info("modifyWatchList"); + Integer movieId = null; + MediaType mediaType = null; + boolean addToWatchlist = false; + StatusCode expResult = null; + StatusCode result = instance.modifyWatchList(getSessionId(), getAccountId(), movieId, mediaType, addToWatchlist); + assertEquals(expResult, result); + // TODO review the generated test code and remove the default call to fail. + fail("The test case is a prototype."); } } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java index d6721a145..cf69ab4ea 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbMoviesTest.java @@ -313,7 +313,7 @@ public class TmdbMoviesTest extends AbstractTests { // get all rated movies TmdbAccount account = new TmdbAccount(getApiKey(), getHttpTools()); - List ratedMovies = account.getRatedMovies(getSessionId(), getAccountId()); + List ratedMovies = account.getRatedMovies(getSessionId(), getAccountId(),null,null,null); assertTrue(ratedMovies.size() > 0); // make sure that we find the movie and it is rated correctly