Movie
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
package com.omertron.themoviedbapi.methods;
|
||||
|
||||
import com.omertron.themoviedbapi.MovieDbException;
|
||||
import static com.omertron.themoviedbapi.methods.AbstractMethod.MAPPER;
|
||||
import com.omertron.themoviedbapi.model2.movie.MovieDb;
|
||||
import com.omertron.themoviedbapi.model2.movie.ReleaseInfo;
|
||||
import com.omertron.themoviedbapi.model2.movie.Translation;
|
||||
@@ -41,6 +42,7 @@ import com.omertron.themoviedbapi.tools.PostBody;
|
||||
import com.omertron.themoviedbapi.tools.PostTools;
|
||||
import com.omertron.themoviedbapi.tools.TmdbParameters;
|
||||
import com.omertron.themoviedbapi.wrapper.WrapperAlternativeTitles;
|
||||
import com.omertron.themoviedbapi.wrapper.WrapperChanges;
|
||||
import com.omertron.themoviedbapi.wrapper.WrapperImages;
|
||||
import com.omertron.themoviedbapi.wrapper.WrapperMovie;
|
||||
import com.omertron.themoviedbapi.wrapper.WrapperMovieKeywords;
|
||||
@@ -60,7 +62,6 @@ import org.yamj.api.common.exception.ApiExceptionType;
|
||||
public class TmdbMovies extends AbstractMethod {
|
||||
|
||||
private static final int RATING_MAX = 10;
|
||||
private static final int POST_SUCCESS_STATUS_CODE = 12;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -449,36 +450,43 @@ public class TmdbMovies extends AbstractMethod {
|
||||
* @return
|
||||
* @throws MovieDbException
|
||||
*/
|
||||
public String getMovieChanges(int movieId, String startDate, String endDate) throws MovieDbException {
|
||||
public WrapperChanges getMovieChanges(int movieId, String startDate, String endDate) throws MovieDbException {
|
||||
TmdbParameters parameters = new TmdbParameters();
|
||||
parameters.add(Param.ID, movieId);
|
||||
parameters.add(Param.START_DATE, startDate);
|
||||
parameters.add(Param.END_DATE, endDate);
|
||||
|
||||
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).buildUrl(parameters);
|
||||
URL url = new ApiUrl(apiKey, MethodBase.PERSON).setSubMethod(MethodSub.CHANGES).buildUrl(parameters);
|
||||
String webpage = httpTools.getRequest(url);
|
||||
return null;
|
||||
|
||||
try {
|
||||
return MAPPER.readValue(webpage, WrapperChanges.class);
|
||||
} catch (IOException ex) {
|
||||
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get movie changes", url, ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method lets users rate a movie.
|
||||
*
|
||||
* A valid session id is required.
|
||||
* A valid session id or guest session id is required.
|
||||
*
|
||||
* @param sessionId
|
||||
* @param movieId
|
||||
* @param rating
|
||||
* @param guestSessionId
|
||||
* @return
|
||||
* @throws MovieDbException
|
||||
*/
|
||||
public boolean postMovieRating(String sessionId, Integer movieId, Integer rating) throws MovieDbException {
|
||||
public StatusCode postMovieRating(int movieId, int rating, String sessionId, String guestSessionId) throws MovieDbException {
|
||||
if (rating < 0 || rating > RATING_MAX) {
|
||||
throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Rating out of range");
|
||||
}
|
||||
|
||||
TmdbParameters parameters = new TmdbParameters();
|
||||
parameters.add(Param.SESSION, sessionId);
|
||||
parameters.add(Param.ID, movieId);
|
||||
parameters.add(Param.SESSION, sessionId);
|
||||
parameters.add(Param.GUEST_SESSION_ID, guestSessionId);
|
||||
|
||||
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.RATING).buildUrl(parameters);
|
||||
|
||||
@@ -488,10 +496,7 @@ public class TmdbMovies extends AbstractMethod {
|
||||
String webpage = httpTools.postRequest(url, jsonBody);
|
||||
|
||||
try {
|
||||
StatusCode status = MAPPER.readValue(webpage, StatusCode.class);
|
||||
LOG.info("Status: {}", status);
|
||||
int code = status.getStatusCode();
|
||||
return code == POST_SUCCESS_STATUS_CODE;
|
||||
return MAPPER.readValue(webpage, StatusCode.class);
|
||||
} catch (IOException ex) {
|
||||
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to post movie rating", url, ex);
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ public enum Param {
|
||||
END_DATE("end_date="),
|
||||
EXTERNAL_SOURCE("external_source="),
|
||||
FAVORITE("favorite="),
|
||||
GUEST_SESSION_ID("guest_session_id="),
|
||||
ID("id="),
|
||||
INCLUDE_ALL_MOVIES("include_all_movies="),
|
||||
INCLUDE_ADULT("include_adult="),
|
||||
|
||||
@@ -23,10 +23,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.omertron.themoviedbapi.model2.change.ChangeKeyItem;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
|
||||
public class WrapperChanges extends AbstractWrapper{
|
||||
public class WrapperChanges extends AbstractWrapper {
|
||||
|
||||
@JsonProperty("changes")
|
||||
private List<ChangeKeyItem> changedItems = new ArrayList<ChangeKeyItem>();
|
||||
@@ -39,8 +37,4 @@ public class WrapperChanges extends AbstractWrapper{
|
||||
this.changedItems = changes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this, ToStringStyle.DEFAULT_STYLE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,14 +20,19 @@
|
||||
package com.omertron.themoviedbapi.methods;
|
||||
|
||||
import com.omertron.themoviedbapi.AbstractTests;
|
||||
import static com.omertron.themoviedbapi.AbstractTests.getApiKey;
|
||||
import static com.omertron.themoviedbapi.AbstractTests.getHttpTools;
|
||||
import com.omertron.themoviedbapi.MovieDbException;
|
||||
import com.omertron.themoviedbapi.TestID;
|
||||
import com.omertron.themoviedbapi.enumeration.ArtworkType;
|
||||
import com.omertron.themoviedbapi.model2.StatusCode;
|
||||
import com.omertron.themoviedbapi.model2.movie.MovieDb;
|
||||
import com.omertron.themoviedbapi.model2.movie.ReleaseInfo;
|
||||
import com.omertron.themoviedbapi.model2.movie.Translation;
|
||||
import com.omertron.themoviedbapi.model2.movie.Video;
|
||||
import com.omertron.themoviedbapi.model2.artwork.Artwork;
|
||||
import com.omertron.themoviedbapi.model2.change.ChangeKeyItem;
|
||||
import com.omertron.themoviedbapi.model2.change.ChangeListItem;
|
||||
import com.omertron.themoviedbapi.model2.keyword.Keyword;
|
||||
import com.omertron.themoviedbapi.model2.list.UserList;
|
||||
import com.omertron.themoviedbapi.model2.media.MediaCreditCast;
|
||||
@@ -35,9 +40,15 @@ import com.omertron.themoviedbapi.model2.media.MediaCreditList;
|
||||
import com.omertron.themoviedbapi.model2.media.MediaState;
|
||||
import com.omertron.themoviedbapi.model2.movie.AlternativeTitle;
|
||||
import com.omertron.themoviedbapi.results.TmdbResultsList;
|
||||
import com.omertron.themoviedbapi.tools.MethodBase;
|
||||
import com.omertron.themoviedbapi.wrapper.WrapperChanges;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.time.DateUtils;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -331,7 +342,7 @@ public class TmdbMoviesTest extends AbstractTests {
|
||||
for (TestID test : FILM_IDS) {
|
||||
TmdbResultsList<UserList> result = instance.getMovieLists(test.getTmdb(), page, language, appendToResponse);
|
||||
assertFalse("Empty list", result.isEmpty());
|
||||
assertTrue(result.getTotalResults()>0);
|
||||
assertTrue(result.getTotalResults() > 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -343,15 +354,27 @@ public class TmdbMoviesTest extends AbstractTests {
|
||||
@Test
|
||||
public void testGetMovieChanges() throws MovieDbException {
|
||||
LOG.info("getMovieChanges");
|
||||
|
||||
String startDate = "";
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
String startDate = sdf.format(DateUtils.addDays(new Date(), -14));
|
||||
String endDate = "";
|
||||
int maxCheck = 5;
|
||||
|
||||
for (TestID test : FILM_IDS) {
|
||||
String result = instance.getMovieChanges(test.getTmdb(), startDate, endDate);
|
||||
TmdbChanges chgs = new TmdbChanges(getApiKey(), getHttpTools());
|
||||
List<ChangeListItem> changeList = chgs.getChangeList(MethodBase.PERSON, null, null, null);
|
||||
LOG.info("Found {} person changes to check", changeList.size());
|
||||
|
||||
int count = 1;
|
||||
WrapperChanges result;
|
||||
for (ChangeListItem item : changeList) {
|
||||
result = instance.getMovieChanges(item.getId(), startDate, endDate);
|
||||
for (ChangeKeyItem ci : result.getChangedItems()) {
|
||||
assertNotNull("Null changes", ci);
|
||||
}
|
||||
|
||||
if (count++ > maxCheck) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -365,10 +388,9 @@ public class TmdbMoviesTest extends AbstractTests {
|
||||
Integer rating = new Random().nextInt(10) + 1;
|
||||
|
||||
for (TestID test : FILM_IDS) {
|
||||
boolean result = instance.postMovieRating(getSessionId(), test.getTmdb(), rating);
|
||||
StatusCode result = instance.postMovieRating(test.getTmdb(), rating, getSessionId(), null);
|
||||
assertEquals("failed to post rating", 12, result.getStatusCode());
|
||||
}
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -380,11 +402,10 @@ public class TmdbMoviesTest extends AbstractTests {
|
||||
public void testGetLatestMovie() throws MovieDbException {
|
||||
LOG.info("getLatestMovie");
|
||||
|
||||
for (TestID test : FILM_IDS) {
|
||||
MovieDb result = instance.getLatestMovie();
|
||||
}
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
MovieDb result = instance.getLatestMovie();
|
||||
assertNotNull("Null movie returned", result);
|
||||
assertTrue("No ID", result.getId() > 0);
|
||||
assertTrue("No title", StringUtils.isNotBlank(result.getTitle()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -398,11 +419,8 @@ public class TmdbMoviesTest extends AbstractTests {
|
||||
Integer page = null;
|
||||
String language = LANGUAGE_DEFAULT;
|
||||
|
||||
for (TestID test : FILM_IDS) {
|
||||
TmdbResultsList<MovieDb> result = instance.getUpcoming(page, language);
|
||||
}
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
TmdbResultsList<MovieDb> result = instance.getUpcoming(page, language);
|
||||
assertFalse("No results found", result.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -416,11 +434,8 @@ public class TmdbMoviesTest extends AbstractTests {
|
||||
Integer page = null;
|
||||
String language = LANGUAGE_DEFAULT;
|
||||
|
||||
for (TestID test : FILM_IDS) {
|
||||
TmdbResultsList<MovieDb> result = instance.getNowPlayingMovies(page, language);
|
||||
}
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
TmdbResultsList<MovieDb> result = instance.getNowPlayingMovies(page, language);
|
||||
assertFalse("No results found", result.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -434,11 +449,8 @@ public class TmdbMoviesTest extends AbstractTests {
|
||||
Integer page = null;
|
||||
String language = LANGUAGE_DEFAULT;
|
||||
|
||||
for (TestID test : FILM_IDS) {
|
||||
TmdbResultsList<MovieDb> result = instance.getPopularMovieList(page, language);
|
||||
}
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
TmdbResultsList<MovieDb> result = instance.getPopularMovieList(page, language);
|
||||
assertFalse("No results found", result.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -452,11 +464,8 @@ public class TmdbMoviesTest extends AbstractTests {
|
||||
Integer page = null;
|
||||
String language = LANGUAGE_DEFAULT;
|
||||
|
||||
for (TestID test : FILM_IDS) {
|
||||
TmdbResultsList<MovieDb> result = instance.getTopRatedMovies(page, language);
|
||||
}
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
TmdbResultsList<MovieDb> result = instance.getTopRatedMovies(page, language);
|
||||
assertFalse("No results found", result.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user