diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java index e5c14be42..b2e9f9317 100644 --- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java +++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java @@ -62,6 +62,7 @@ import com.omertron.themoviedbapi.model.ReleaseInfo; import com.omertron.themoviedbapi.model.Reviews; import com.omertron.themoviedbapi.model2.StatusCode; import com.omertron.themoviedbapi.enumeration.ExternalSource; +import com.omertron.themoviedbapi.enumeration.SortBy; import com.omertron.themoviedbapi.model2.FindResults; import com.omertron.themoviedbapi.model.TBD_Network; import com.omertron.themoviedbapi.model2.person.CreditInfo; @@ -413,6 +414,20 @@ public class TheMovieDbApi { public List getFavoriteTv(String sessionId, int accountId) throws MovieDbException { return tmdbAccount.getFavoriteTv(sessionId, accountId); } + + /** + * Get a list of rated movies for a specific guest session id. + * + * @param guestSessionId + * @param language + * @param page + * @param sortBy only CREATED_AT_ASC or CREATED_AT_DESC is supported + * @return + * @throws MovieDbException + */ + public List getGuestRatedMovies(String guestSessionId, String language, Integer page, SortBy sortBy) throws MovieDbException { + return tmdbAccount.getGuestRatedMovies(guestSessionId, language, page, sortBy); + } // // @@ -716,16 +731,25 @@ public class TheMovieDbApi { // /** - * You can use this method to retrieve the list of genres used on TMDb. + * Get the list of Movie genres. * - * These IDs will correspond to those found in movie calls. + * @param language + * @return + * @throws MovieDbException + */ + public TmdbResultsList getGenreMovieList(String language) throws MovieDbException { + return tmdbGenre.getGenreMovieList(language); + } + + /** + * Get the list of TV genres.. * * @param language * @return * @throws MovieDbException */ - public TmdbResultsList getGenreList(String language) throws MovieDbException { - return tmdbGenre.getGenreList(language); + public TmdbResultsList getGenreTVList(String language) throws MovieDbException { + return tmdbGenre.getGenreTVList(language); } /** @@ -739,11 +763,12 @@ public class TheMovieDbApi { * @param language * @param page * @param includeAllMovies + * @param includeAdult * @return * @throws MovieDbException */ - public TmdbResultsList getGenreMovies(int genreId, String language, int page, boolean includeAllMovies) throws MovieDbException { - return tmdbGenre.getGenreMovies(genreId, language, page, includeAllMovies); + public List getGenreMovies(int genreId, String language, Integer page, Boolean includeAllMovies, Boolean includeAdult) throws MovieDbException { + return tmdbGenre.getGenreMovies(genreId, language, page, includeAllMovies, includeAdult); } // diff --git a/src/main/java/com/omertron/themoviedbapi/enumeration/SortBy.java b/src/main/java/com/omertron/themoviedbapi/enumeration/SortBy.java index b023362e1..78e62a63d 100644 --- a/src/main/java/com/omertron/themoviedbapi/enumeration/SortBy.java +++ b/src/main/java/com/omertron/themoviedbapi/enumeration/SortBy.java @@ -2,6 +2,8 @@ package com.omertron.themoviedbapi.enumeration; public enum SortBy { + CREATED_AT_ASC, + CREATED_AT_DESC, POPULARITY_ASC, POPULARITY_DESC, RELEASE_DATE_ASC, diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java index 22574f209..1f6188dd6 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbAccount.java @@ -21,6 +21,7 @@ package com.omertron.themoviedbapi.methods; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.enumeration.MediaType; +import com.omertron.themoviedbapi.enumeration.SortBy; import com.omertron.themoviedbapi.model2.account.Account; import com.omertron.themoviedbapi.model2.StatusCode; import com.omertron.themoviedbapi.model2.movie.MovieBasic; @@ -283,4 +284,28 @@ public class TmdbAccount extends AbstractMethod { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to modify watch list", url, ex); } } + + /** + * Get a list of rated movies for a specific guest session id. + * + * @param guestSessionId + * @param language + * @param page + * @param sortBy only CREATED_AT_ASC or CREATED_AT_DESC is supported + * @return + * @throws MovieDbException + */ + public List getGuestRatedMovies(String guestSessionId, String language, Integer page, SortBy sortBy) throws MovieDbException { + TmdbParameters parameters = new TmdbParameters(); + parameters.add(Param.ID, guestSessionId); + parameters.add(Param.LANGUAGE, language); + parameters.add(Param.PAGE, page); + //TODO: Test this works + if (sortBy != null) { + parameters.add(Param.SORT_BY, sortBy.getPropertyString()); + } + + URL url = new ApiUrl(apiKey, MethodBase.GUEST_SESSION).setSubMethod(MethodSub.RATED_MOVIES_GUEST).buildUrl(parameters); + return processWrapperList(TR_MOVIE_BASIC, url, "Guest Session Movies"); + } } diff --git a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt index ee326d7ad..86852bedb 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt +++ b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt @@ -43,7 +43,7 @@ Discover (Done) Find /find/{id} The find method makes it easy to search for objects in our database by an external id. -Genres +Genres (Done) /genre/movie/list Get the list of movie genres. /genre/tv/list Get the list of TV genres. /genre/{id}/movies Get the list of movies for a particular genre by id. diff --git a/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java b/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java index c3894b7c2..3c2a38a7d 100644 --- a/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java +++ b/src/main/java/com/omertron/themoviedbapi/tools/MethodBase.java @@ -34,6 +34,7 @@ public enum MethodBase { DISCOVER("discover"), FIND("find"), GENRE("genre"), + GUEST_SESSION("guest_session"), JOB("job"), KEYWORD("keyword"), LIST("list"), diff --git a/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java b/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java index f8bbda057..767adce11 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_MOVIES_GUEST("rated_movies"), RATED_TV("rated/tv"), RATING("rating"), RELEASES("releases"), diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java index 229807fa3..1da8fadc3 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAccountTest.java @@ -22,8 +22,10 @@ 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.enumeration.SortBy; import com.omertron.themoviedbapi.model2.account.Account; import com.omertron.themoviedbapi.model2.StatusCode; +import com.omertron.themoviedbapi.model2.authentication.TokenSession; import com.omertron.themoviedbapi.model2.movie.MovieBasic; import com.omertron.themoviedbapi.model2.tv.TVBasic; import com.omertron.themoviedbapi.model2.list.UserList; @@ -34,6 +36,7 @@ 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; @@ -252,4 +255,26 @@ public class TmdbAccountTest extends AbstractTests { LOG.info("Result: {}", result); assertTrue("Incorrect status code", result.getStatusCode() == 13); } + + /** + * Test of getGuestRatedMovies method, of class TmdbAccount. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetGuestRatedMovies() throws MovieDbException { + LOG.info("getGuestRatedMovies"); + + //TODO: Need to use rated movies with the guest session to add some movies to get + TmdbAuthentication auth = new TmdbAuthentication(getApiKey(), getHttpTools()); + TokenSession guestToken = auth.getGuestSessionToken(); + TmdbMovies tmdbM = new TmdbMovies(getApiKey(), getHttpTools()); + + String language = LANGUAGE_DEFAULT; + Integer page = null; + SortBy sortBy = null; + List result = instance.getGuestRatedMovies(guestToken.getGuestSessionId(), language, page, sortBy); + LOG.info("{}", result); + fail("Need rated movies"); + } } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAuthenticationTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAuthenticationTest.java index c8e74f4b0..68bfa7ff3 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbAuthenticationTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbAuthenticationTest.java @@ -23,9 +23,13 @@ import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model2.authentication.TokenAuthorisation; import com.omertron.themoviedbapi.model2.authentication.TokenSession; +import org.apache.commons.lang3.StringUtils; +import org.junit.After; import org.junit.AfterClass; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Ignore; import org.junit.Test; @@ -34,7 +38,7 @@ import org.junit.Test; * * @author stuart.boston */ -public class TmdbAuthenticationTest extends AbstractTests{ +public class TmdbAuthenticationTest extends AbstractTests { private static TmdbAuthentication instance; @@ -44,13 +48,21 @@ public class TmdbAuthenticationTest extends AbstractTests{ @BeforeClass public static void setUpClass() throws MovieDbException { doConfiguration(); - instance = new TmdbAuthentication(getApiKey(),getHttpTools()); + instance = new TmdbAuthentication(getApiKey(), getHttpTools()); } @AfterClass public static void tearDownClass() { } + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + /** * Test of getAuthorisationToken method, of class TmdbAuthentication. * @@ -94,4 +106,18 @@ public class TmdbAuthenticationTest extends AbstractTests{ assertTrue("Failed to get guest session", result.getSuccess()); } + /** + * Test of getSessionTokenLogin method, of class TmdbAuthentication. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testGetSessionTokenLogin() throws MovieDbException { + System.out.println("getSessionTokenLogin"); + TokenAuthorisation token = instance.getAuthorisationToken(); + TokenAuthorisation result = instance.getSessionTokenLogin(token, getUsername(), getPassword()); + assertNotNull("Null token returned", result); + assertTrue("Empty token", StringUtils.isNotBlank(result.getRequestToken())); + } + }