Guest session (partial)

master
Stuart Boston 11 years ago
parent 6231130d46
commit 50820a437f

@ -62,6 +62,7 @@ import com.omertron.themoviedbapi.model.ReleaseInfo;
import com.omertron.themoviedbapi.model.Reviews; import com.omertron.themoviedbapi.model.Reviews;
import com.omertron.themoviedbapi.model2.StatusCode; import com.omertron.themoviedbapi.model2.StatusCode;
import com.omertron.themoviedbapi.enumeration.ExternalSource; import com.omertron.themoviedbapi.enumeration.ExternalSource;
import com.omertron.themoviedbapi.enumeration.SortBy;
import com.omertron.themoviedbapi.model2.FindResults; import com.omertron.themoviedbapi.model2.FindResults;
import com.omertron.themoviedbapi.model.TBD_Network; import com.omertron.themoviedbapi.model.TBD_Network;
import com.omertron.themoviedbapi.model2.person.CreditInfo; import com.omertron.themoviedbapi.model2.person.CreditInfo;
@ -413,6 +414,20 @@ public class TheMovieDbApi {
public List getFavoriteTv(String sessionId, int accountId) throws MovieDbException { public List getFavoriteTv(String sessionId, int accountId) throws MovieDbException {
return tmdbAccount.getFavoriteTv(sessionId, accountId); 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<MovieBasic> getGuestRatedMovies(String guestSessionId, String language, Integer page, SortBy sortBy) throws MovieDbException {
return tmdbAccount.getGuestRatedMovies(guestSessionId, language, page, sortBy);
}
//</editor-fold> //</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Authentication"> //<editor-fold defaultstate="collapsed" desc="Authentication">
@ -716,16 +731,25 @@ public class TheMovieDbApi {
//<editor-fold defaultstate="collapsed" desc="Genres"> //<editor-fold defaultstate="collapsed" desc="Genres">
/** /**
* 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<Genre> getGenreMovieList(String language) throws MovieDbException {
return tmdbGenre.getGenreMovieList(language);
}
/**
* Get the list of TV genres..
* *
* @param language * @param language
* @return * @return
* @throws MovieDbException * @throws MovieDbException
*/ */
public TmdbResultsList<Genre> getGenreList(String language) throws MovieDbException { public TmdbResultsList<Genre> getGenreTVList(String language) throws MovieDbException {
return tmdbGenre.getGenreList(language); return tmdbGenre.getGenreTVList(language);
} }
/** /**
@ -739,11 +763,12 @@ public class TheMovieDbApi {
* @param language * @param language
* @param page * @param page
* @param includeAllMovies * @param includeAllMovies
* @param includeAdult
* @return * @return
* @throws MovieDbException * @throws MovieDbException
*/ */
public TmdbResultsList<MovieDb> getGenreMovies(int genreId, String language, int page, boolean includeAllMovies) throws MovieDbException { public List<MovieBasic> getGenreMovies(int genreId, String language, Integer page, Boolean includeAllMovies, Boolean includeAdult) throws MovieDbException {
return tmdbGenre.getGenreMovies(genreId, language, page, includeAllMovies); return tmdbGenre.getGenreMovies(genreId, language, page, includeAllMovies, includeAdult);
} }
//</editor-fold> //</editor-fold>

@ -2,6 +2,8 @@ package com.omertron.themoviedbapi.enumeration;
public enum SortBy { public enum SortBy {
CREATED_AT_ASC,
CREATED_AT_DESC,
POPULARITY_ASC, POPULARITY_ASC,
POPULARITY_DESC, POPULARITY_DESC,
RELEASE_DATE_ASC, RELEASE_DATE_ASC,

@ -21,6 +21,7 @@ package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.enumeration.MediaType; import com.omertron.themoviedbapi.enumeration.MediaType;
import com.omertron.themoviedbapi.enumeration.SortBy;
import com.omertron.themoviedbapi.model2.account.Account; import com.omertron.themoviedbapi.model2.account.Account;
import com.omertron.themoviedbapi.model2.StatusCode; import com.omertron.themoviedbapi.model2.StatusCode;
import com.omertron.themoviedbapi.model2.movie.MovieBasic; 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); 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<MovieBasic> 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");
}
} }

@ -43,7 +43,7 @@ Discover (Done)
Find Find
/find/{id} The find method makes it easy to search for objects in our database by an external id. /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/movie/list Get the list of movie genres.
/genre/tv/list Get the list of TV genres. /genre/tv/list Get the list of TV genres.
/genre/{id}/movies Get the list of movies for a particular genre by id. /genre/{id}/movies Get the list of movies for a particular genre by id.

@ -34,6 +34,7 @@ public enum MethodBase {
DISCOVER("discover"), DISCOVER("discover"),
FIND("find"), FIND("find"),
GENRE("genre"), GENRE("genre"),
GUEST_SESSION("guest_session"),
JOB("job"), JOB("job"),
KEYWORD("keyword"), KEYWORD("keyword"),
LIST("list"), LIST("list"),

@ -49,6 +49,7 @@ public enum MethodSub {
PERSON("person"), PERSON("person"),
POPULAR("popular"), POPULAR("popular"),
RATED_MOVIES("rated/movies"), RATED_MOVIES("rated/movies"),
RATED_MOVIES_GUEST("rated_movies"),
RATED_TV("rated/tv"), RATED_TV("rated/tv"),
RATING("rating"), RATING("rating"),
RELEASES("releases"), RELEASES("releases"),

@ -22,8 +22,10 @@ package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests; import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.enumeration.MediaType; import com.omertron.themoviedbapi.enumeration.MediaType;
import com.omertron.themoviedbapi.enumeration.SortBy;
import com.omertron.themoviedbapi.model2.account.Account; import com.omertron.themoviedbapi.model2.account.Account;
import com.omertron.themoviedbapi.model2.StatusCode; 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.movie.MovieBasic;
import com.omertron.themoviedbapi.model2.tv.TVBasic; import com.omertron.themoviedbapi.model2.tv.TVBasic;
import com.omertron.themoviedbapi.model2.list.UserList; 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.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -252,4 +255,26 @@ public class TmdbAccountTest extends AbstractTests {
LOG.info("Result: {}", result); LOG.info("Result: {}", result);
assertTrue("Incorrect status code", result.getStatusCode() == 13); 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<MovieBasic> result = instance.getGuestRatedMovies(guestToken.getGuestSessionId(), language, page, sortBy);
LOG.info("{}", result);
fail("Need rated movies");
}
} }

@ -23,9 +23,13 @@ import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.model2.authentication.TokenAuthorisation; import com.omertron.themoviedbapi.model2.authentication.TokenAuthorisation;
import com.omertron.themoviedbapi.model2.authentication.TokenSession; import com.omertron.themoviedbapi.model2.authentication.TokenSession;
import org.apache.commons.lang3.StringUtils;
import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
@ -51,6 +55,14 @@ public class TmdbAuthenticationTest extends AbstractTests{
public static void tearDownClass() { public static void tearDownClass() {
} }
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
/** /**
* Test of getAuthorisationToken method, of class TmdbAuthentication. * Test of getAuthorisationToken method, of class TmdbAuthentication.
* *
@ -94,4 +106,18 @@ public class TmdbAuthenticationTest extends AbstractTests{
assertTrue("Failed to get guest session", result.getSuccess()); 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()));
}
} }

Loading…
Cancel
Save