diff --git a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java
index 3a89e695b..9213f5573 100644
--- a/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java
+++ b/src/main/java/com/omertron/themoviedbapi/TheMovieDbApi.java
@@ -69,7 +69,8 @@ import org.apache.log4j.Logger;
/**
* The MovieDb API
*
- * This is for version 3 of the API as specified here: http://help.themoviedb.org/kb/api/about-3
+ * This is for version 3 of the API as specified here:
+ * http://help.themoviedb.org/kb/api/about-3
*
* @author stuart.boston
*/
@@ -174,7 +175,8 @@ public class TheMovieDbApi {
* @param moviedb The moviedb object to compare too
* @param title The title of the movie to compare
* @param year The year of the movie to compare
- * @param maxDistance The Levenshtein Distance between the two titles. 0 = exact match
+ * @param maxDistance The Levenshtein Distance between the two titles. 0 =
+ * exact match
* @return True if there is a match, False otherwise.
*/
public static boolean compareMovies(MovieDb moviedb, String title, String year, int maxDistance) {
@@ -268,13 +270,16 @@ public class TheMovieDbApi {
//
//
/**
- * This method is used to generate a valid request token for user based authentication.
+ * This method is used to generate a valid request token for user based
+ * authentication.
*
* A request token is required in order to request a session id.
*
- * You can generate any number of request tokens but they will expire after 60 minutes.
+ * You can generate any number of request tokens but they will expire after
+ * 60 minutes.
*
- * As soon as a valid session id has been created the token will be destroyed.
+ * As soon as a valid session id has been created the token will be
+ * destroyed.
*
* @return
* @throws MovieDbException
@@ -294,7 +299,8 @@ public class TheMovieDbApi {
}
/**
- * This method is used to generate a session id for user based authentication.
+ * This method is used to generate a session id for user based
+ * authentication.
*
* A session id is required in order to use any of the write methods.
*
@@ -322,6 +328,39 @@ public class TheMovieDbApi {
}
}
+ /**
+ * This method is used to generate a guest session id.
+ *
+ * A guest session can be used to rate movies without having a registered
+ * TMDb user account.
+ *
+ * You should only generate a single guest session per user (or device) as
+ * you will be able to attach the ratings to a TMDb user account in the
+ * future.
+ *
+ * There are also IP limits in place so you should always make sure it's the
+ * end user doing the guest session actions.
+ *
+ * If a guest session is not used for the first time within 24 hours, it
+ * will be automatically discarded.
+ *
+ * @return
+ * @throws MovieDbException
+ */
+ public TokenSession getGuestSessionToken() throws MovieDbException {
+ ApiUrl apiUrl = new ApiUrl(this, BASE_AUTH, "guest_session/new");
+
+ URL url = apiUrl.buildUrl();
+ String webpage = WebBrowser.request(url);
+
+ try {
+ return mapper.readValue(webpage, TokenSession.class);
+ } catch (IOException ex) {
+ logger.warn("Failed to get Session Token: " + ex.getMessage());
+ throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex);
+ }
+ }
+
//
//
//
@@ -387,7 +426,8 @@ public class TheMovieDbApi {
}
/**
- * This method is used to retrieve all of the alternative titles we have for a particular movie.
+ * This method is used to retrieve all of the alternative titles we have for
+ * a particular movie.
*
* @param movieId
* @param country
@@ -455,7 +495,8 @@ public class TheMovieDbApi {
}
/**
- * This method should be used when you’re wanting to retrieve all of the images for a particular movie.
+ * This method should be used when you’re wanting to retrieve all of the
+ * images for a particular movie.
*
* @param movieId
* @param language
@@ -496,7 +537,8 @@ public class TheMovieDbApi {
}
/**
- * This method is used to retrieve all of the keywords that have been added to a particular movie.
+ * This method is used to retrieve all of the keywords that have been added
+ * to a particular movie.
*
* Currently, only English keywords exist.
*
@@ -521,7 +563,8 @@ public class TheMovieDbApi {
}
/**
- * This method is used to retrieve all of the release and certification data we have for a specific movie.
+ * This method is used to retrieve all of the release and certification data
+ * we have for a specific movie.
*
* @param movieId
* @param language
@@ -546,7 +589,8 @@ public class TheMovieDbApi {
}
/**
- * This method is used to retrieve all of the trailers for a particular movie.
+ * This method is used to retrieve all of the trailers for a particular
+ * movie.
*
* Supported sites are YouTube and QuickTime.
*
@@ -589,7 +633,8 @@ public class TheMovieDbApi {
}
/**
- * This method is used to retrieve a list of the available translations for a specific movie.
+ * This method is used to retrieve a list of the available translations for
+ * a specific movie.
*
* @param movieId
* @return
@@ -612,9 +657,11 @@ public class TheMovieDbApi {
}
/**
- * The similar movies method will let you retrieve the similar movies for a particular movie.
+ * The similar movies method will let you retrieve the similar movies for a
+ * particular movie.
*
- * This data is created dynamically but with the help of users votes on TMDb.
+ * This data is created dynamically but with the help of users votes on
+ * TMDb.
*
* The data is much better with movies that have more keywords
*
@@ -703,7 +750,8 @@ public class TheMovieDbApi {
/**
* This method is used to retrieve the movies currently in theatres.
*
- * This is a curated list that will normally contain 100 movies. The default response will return 20 movies.
+ * This is a curated list that will normally contain 100 movies. The default
+ * response will return 20 movies.
*
* TODO: Implement more than 20 movies
*
@@ -771,7 +819,8 @@ public class TheMovieDbApi {
}
/**
- * This method is used to retrieve the top rated movies that have over 10 votes on TMDb.
+ * This method is used to retrieve the top rated movies that have over 10
+ * votes on TMDb.
*
* The default response will return 20 movies.
*
@@ -828,9 +877,11 @@ public class TheMovieDbApi {
//
//
/**
- * This method is used to retrieve all of the basic information about a movie collection.
+ * This method is used to retrieve all of the basic information about a
+ * movie collection.
*
- * You can get the ID needed for this method by making a getMovieInfo request for the belongs_to_collection.
+ * You can get the ID needed for this method by making a getMovieInfo
+ * request for the belongs_to_collection.
*
* @param collectionId
* @param language
@@ -928,7 +979,8 @@ public class TheMovieDbApi {
}
/**
- * This method is used to retrieve all of the cast & crew information for the person.
+ * 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.
*
@@ -1002,7 +1054,8 @@ public class TheMovieDbApi {
//
//
/**
- * This method is used to retrieve the basic information about a production company on TMDb.
+ * This method is used to retrieve the basic information about a production
+ * company on TMDb.
*
* @param companyId
* @return
@@ -1027,8 +1080,8 @@ public class TheMovieDbApi {
/**
* This method is used to retrieve the movies associated with a company.
*
- * These movies are returned in order of most recently released to oldest. The default response will return 20
- * movies per page.
+ * These movies are returned in order of most recently released to oldest.
+ * The default response will return 20 movies per page.
*
* TODO: Implement more than 20 movies
*
@@ -1093,9 +1146,11 @@ public class TheMovieDbApi {
/**
* Get a list of movies per genre.
*
- * It is important to understand that only movies with more than 10 votes get listed.
+ * It is important to understand that only movies with more than 10 votes
+ * get listed.
*
- * This prevents movies from 1 10/10 rating from being listed first and for the first 5 pages.
+ * This prevents movies from 1 10/10 rating from being listed first and for
+ * the first 5 pages.
*
* @param genreId
* @param language
@@ -1130,13 +1185,16 @@ public class TheMovieDbApi {
//
/**
- * Search Movies This is a good starting point to start finding movies on TMDb.
+ * Search Movies This is a good starting point to start finding movies on
+ * TMDb.
*
* @param movieName
- * @param searchYear Limit the search to the provided year. Zero (0) will get all years
+ * @param searchYear Limit the search to the provided year. Zero (0) will
+ * get all years
* @param language The language to include. Can be blank/null.
* @param includeAdult true or false to include adult titles in the search
- * @param page The page of results to return. 0 to get the default (first page)
+ * @param page The page of results to return. 0 to get the default (first
+ * page)
* @return
* @throws MovieDbException
*/
@@ -1176,8 +1234,8 @@ public class TheMovieDbApi {
/**
* Search Companies.
*
- * You can use this method to search for production companies that are part of TMDb. The company IDs will map to
- * those returned on movie calls.
+ * You can use this method to search for production companies that are part
+ * of TMDb. The company IDs will map to those returned on movie calls.
*
* http://help.themoviedb.org/kb/api/search-companies
*
@@ -1208,7 +1266,8 @@ public class TheMovieDbApi {
/**
* This is a good starting point to start finding people on TMDb.
*
- * The idea is to be a quick and light method so you can iterate through people quickly.
+ * The idea is to be a quick and light method so you can iterate through
+ * people quickly.
*
* TODO: Fix allResults
*
diff --git a/src/main/java/com/omertron/themoviedbapi/model/TokenSession.java b/src/main/java/com/omertron/themoviedbapi/model/TokenSession.java
index 5dfd38a0d..6863afd03 100644
--- a/src/main/java/com/omertron/themoviedbapi/model/TokenSession.java
+++ b/src/main/java/com/omertron/themoviedbapi/model/TokenSession.java
@@ -27,6 +27,7 @@ public class TokenSession {
/*
* Logger
*/
+
private static final Logger logger = Logger.getLogger(TokenSession.class);
/*
* Properties
@@ -39,6 +40,10 @@ public class TokenSession {
private String statusCode;
@JsonProperty("status_message")
private String statusMessage;
+ @JsonProperty("guest_session_id")
+ private String guestSessionId;
+ @JsonProperty("expires_at")
+ private String expiresAt;
//
public String getSessionId() {
@@ -56,6 +61,14 @@ public class TokenSession {
public String getStatusMessage() {
return statusMessage;
}
+
+ public String getGuestSessionId() {
+ return guestSessionId;
+ }
+
+ public String getExpiresAt() {
+ return expiresAt;
+ }
//
//
@@ -74,6 +87,15 @@ public class TokenSession {
public void setStatusMessage(String statusMessage) {
this.statusMessage = statusMessage;
}
+
+ public void setGuestSessionId(String guestSessionId) {
+ this.guestSessionId = guestSessionId;
+ }
+
+ public void setExpiresAt(String expiresAt) {
+ this.expiresAt = expiresAt;
+ }
+
//
/**
@@ -92,7 +114,6 @@ public class TokenSession {
@Override
public String toString() {
- return "TokenSession{" + "sessionId=" + sessionId + ", success=" + success + ", statusCode=" + statusCode + ", statusMessage=" + statusMessage + '}';
+ return "TokenSession{" + "sessionId=" + sessionId + ", success=" + success + ", statusCode=" + statusCode + ", statusMessage=" + statusMessage + ", guestSessionId=" + guestSessionId + ", expiresAt=" + expiresAt + '}';
}
-
}
diff --git a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java
index bc00ac44f..c16c870a5 100644
--- a/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java
+++ b/src/test/java/com/omertron/themoviedbapi/TheMovieDbApiTest.java
@@ -242,6 +242,7 @@ public class TheMovieDbApiTest {
/**
* Test of createImageUrl method, of class TheMovieDbApi.
+ *
* @throws MovieDbException
*/
@Test
@@ -479,7 +480,7 @@ public class TheMovieDbApiTest {
/**
* Test of getAuthorisationToken method, of class TheMovieDbApi.
*/
-// @Test
+ @Test
public void testGetAuthorisationToken() throws Exception {
logger.info("getAuthorisationToken");
TokenAuthorisation result = tmdb.getAuthorisationToken();
@@ -491,7 +492,7 @@ public class TheMovieDbApiTest {
/**
* Test of getSessionToken method, of class TheMovieDbApi.
*/
-// @Test
+ @Test
public void testGetSessionToken() throws Exception {
logger.info("getSessionToken");
TokenAuthorisation token = tmdb.getAuthorisationToken();
@@ -504,4 +505,15 @@ public class TheMovieDbApiTest {
assertTrue("Session token is not valid", result.getSuccess());
logger.info(result.toString());
}
+
+ /**
+ * Test of getGuestSessionToken method, of class TheMovieDbApi.
+ */
+ @Test
+ public void testGetGuestSessionToken() throws Exception {
+ logger.info("getGuestSessionToken");
+ TokenSession result = tmdb.getGuestSessionToken();
+
+ assertTrue("Failed to get guest session", result.getSuccess());
+ }
}