master
Stuart Boston 11 years ago
parent 2c71a1485c
commit bc333a4cb6

@ -59,7 +59,7 @@ import com.omertron.themoviedbapi.model.MovieList;
import com.omertron.themoviedbapi.model.person.Person; import com.omertron.themoviedbapi.model.person.Person;
import com.omertron.themoviedbapi.model.person.PersonCredit; import com.omertron.themoviedbapi.model.person.PersonCredit;
import com.omertron.themoviedbapi.model.ReleaseInfo; import com.omertron.themoviedbapi.model.ReleaseInfo;
import com.omertron.themoviedbapi.model.Reviews; import com.omertron.themoviedbapi.model2.review.Review;
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.enumeration.SortBy;
@ -1220,7 +1220,7 @@ public class TheMovieDbApi {
} }
//</editor-fold> //</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Reviews"> //<editor-fold defaultstate="collapsed" desc="Review">
/** /**
* *
* @param movieId * @param movieId
@ -1230,7 +1230,7 @@ public class TheMovieDbApi {
* @return * @return
* @throws MovieDbException * @throws MovieDbException
*/ */
public TmdbResultsList<Reviews> getReviews(int movieId, String language, int page, String... appendToResponse) throws MovieDbException { public TmdbResultsList<Review> getReviews(int movieId, String language, int page, String... appendToResponse) throws MovieDbException {
return tmdbReviews.getReviews(movieId, language, page, appendToResponse); return tmdbReviews.getReviews(movieId, language, page, appendToResponse);
} }
//</editor-fold> //</editor-fold>

@ -21,15 +21,12 @@ package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.MovieDbException;
import static com.omertron.themoviedbapi.methods.AbstractMethod.MAPPER; import static com.omertron.themoviedbapi.methods.AbstractMethod.MAPPER;
import com.omertron.themoviedbapi.model.Reviews; import com.omertron.themoviedbapi.model2.review.Review;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.ApiUrl;
import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.HttpTools;
import com.omertron.themoviedbapi.tools.MethodBase; import com.omertron.themoviedbapi.tools.MethodBase;
import com.omertron.themoviedbapi.tools.MethodSub;
import com.omertron.themoviedbapi.tools.Param; import com.omertron.themoviedbapi.tools.Param;
import com.omertron.themoviedbapi.tools.TmdbParameters; import com.omertron.themoviedbapi.tools.TmdbParameters;
import com.omertron.themoviedbapi.wrapper.WrapperReviews;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import org.yamj.api.common.exception.ApiExceptionType; import org.yamj.api.common.exception.ApiExceptionType;
@ -54,30 +51,21 @@ public class TmdbReviews extends AbstractMethod {
/** /**
* Get the full details of a review by ID. * Get the full details of a review by ID.
* *
* @param id * @param reviewId
* @param language
* @param page
* @param appendToResponse
* @return * @return
* @throws MovieDbException * @throws MovieDbException
*/ */
public TmdbResultsList<Reviews> getReviews(int id, String language, int page, String... appendToResponse) throws MovieDbException { public Review getReview(String reviewId) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters(); TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.ID, id); parameters.add(Param.ID, reviewId);
parameters.add(Param.LANGUAGE, language);
parameters.add(Param.PAGE, page);
parameters.add(Param.APPEND, appendToResponse);
URL url = new ApiUrl(apiKey, MethodBase.MOVIE).setSubMethod(MethodSub.REVIEWS).buildUrl(parameters); URL url = new ApiUrl(apiKey, MethodBase.REVIEW).buildUrl(parameters);
String webpage = httpTools.getRequest(url); String webpage = httpTools.getRequest(url);
try { try {
WrapperReviews wrapper = MAPPER.readValue(webpage, WrapperReviews.class); return MAPPER.readValue(webpage, Review.class);
TmdbResultsList<Reviews> results = new TmdbResultsList<Reviews>(wrapper.getReviews());
results.copyWrapper(wrapper);
return results;
} catch (IOException ex) { } catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get reviews", url, ex); throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get review", url, ex);
} }
} }

@ -87,7 +87,7 @@ Movies
/movie/popular Get the list of popular movies on The Movie Database. This list refreshes every day. /movie/popular Get the list of popular movies on The Movie Database. This list refreshes every day.
/movie/top_rated Get the list of top rated movies. By default, this list will only include movies that have 10 or more votes. This list refreshes every day. /movie/top_rated Get the list of top rated movies. By default, this list will only include movies that have 10 or more votes. This list refreshes every day.
Networks Networks (Done)
/network/{id} This method is used to retrieve the basic information about a TV network. /network/{id} This method is used to retrieve the basic information about a TV network.
People People
@ -102,7 +102,7 @@ People
/person/popular Get the list of popular people on The Movie Database. This list refreshes every day. /person/popular Get the list of popular people on The Movie Database. This list refreshes every day.
/person/latest Get the latest person id. /person/latest Get the latest person id.
Reviews Reviews (Done)
/review/{id} Get the full details of a review by ID. /review/{id} Get the full details of a review by ID.
Search Search

@ -19,6 +19,7 @@
*/ */
package com.omertron.themoviedbapi.model; package com.omertron.themoviedbapi.model;
import com.omertron.themoviedbapi.model2.review.Review;
import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.omertron.themoviedbapi.model2.AbstractJsonMapping;
import com.omertron.themoviedbapi.model2.collection.Collection; import com.omertron.themoviedbapi.model2.collection.Collection;
import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.keyword.Keyword;
@ -374,7 +375,7 @@ public class MovieDb extends AbstractJsonMapping {
return lists.getMovieList(); return lists.getMovieList();
} }
public List<Reviews> getReviews() { public List<Review> getReviews() {
return reviews.getReviews(); return reviews.getReviews();
} }
// </editor-fold> // </editor-fold>

@ -17,7 +17,7 @@
* along with TheMovieDB API. If not, see <http://www.gnu.org/licenses/>. * along with TheMovieDB API. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
package com.omertron.themoviedbapi.model; package com.omertron.themoviedbapi.model2.review;
import com.omertron.themoviedbapi.model2.AbstractJsonMapping; import com.omertron.themoviedbapi.model2.AbstractJsonMapping;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
@ -25,19 +25,24 @@ import com.fasterxml.jackson.annotation.JsonProperty;
/** /**
* @author Stuart * @author Stuart
*/ */
public class Reviews extends AbstractJsonMapping { public class Review extends AbstractJsonMapping {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
/*
* Properties
*/
@JsonProperty("id") @JsonProperty("id")
private String id; private String id;
@JsonProperty("author") @JsonProperty("author")
private String author; private String author;
@JsonProperty("content") @JsonProperty("content")
private String content; private String content;
@JsonProperty("iso_639_1")
private String langauage;
@JsonProperty("media_id")
private String mediaId;
@JsonProperty("media_title")
private String mediaTitle;
@JsonProperty("media_type")
private String mediaType;
@JsonProperty("url") @JsonProperty("url")
private String url; private String url;
@ -45,31 +50,64 @@ public class Reviews extends AbstractJsonMapping {
return id; return id;
} }
public void setId(String id) {
this.id = id;
}
public String getAuthor() { public String getAuthor() {
return author; return author;
} }
public void setAuthor(String author) {
this.author = author;
}
public String getContent() { public String getContent() {
return content; return content;
} }
public String getUrl() { public void setContent(String content) {
return url; this.content = content;
} }
public void setId(String id) { public String getLangauage() {
this.id = id; return langauage;
} }
public void setAuthor(String author) { public void setLangauage(String langauage) {
this.author = author; this.langauage = langauage;
} }
public void setContent(String content) { public String getMediaId() {
this.content = content; return mediaId;
}
public void setMediaId(String mediaId) {
this.mediaId = mediaId;
}
public String getMediaTitle() {
return mediaTitle;
}
public void setMediaTitle(String mediaTitle) {
this.mediaTitle = mediaTitle;
}
public String getMediaType() {
return mediaType;
}
public void setMediaType(String mediaType) {
this.mediaType = mediaType;
}
public String getUrl() {
return url;
} }
public void setUrl(String url) { public void setUrl(String url) {
this.url = url; this.url = url;
} }
} }

@ -41,6 +41,7 @@ public enum MethodBase {
MOVIE("movie"), MOVIE("movie"),
NETWORK("network"), NETWORK("network"),
PERSON("person"), PERSON("person"),
REVIEW("review"),
SEARCH("search"), SEARCH("search"),
TV("tv"); TV("tv");

@ -20,7 +20,7 @@
package com.omertron.themoviedbapi.wrapper; package com.omertron.themoviedbapi.wrapper;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.omertron.themoviedbapi.model.Reviews; import com.omertron.themoviedbapi.model2.review.Review;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
@ -32,13 +32,13 @@ public class WrapperReviews extends AbstractWrapperAll implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@JsonProperty("results") @JsonProperty("results")
private List<Reviews> reviews; private List<Review> reviews;
public List<Reviews> getReviews() { public List<Review> getReviews() {
return reviews; return reviews;
} }
public void setReviews(List<Reviews> reviews) { public void setReviews(List<Review> reviews) {
this.reviews = reviews; this.reviews = reviews;
} }
} }

@ -21,9 +21,13 @@ 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.model2.review.Review;
import org.apache.commons.lang3.StringUtils;
import org.junit.After; import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import static org.junit.Assert.fail; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
@ -66,7 +70,11 @@ public class TmdbReviewsTest extends AbstractTests {
@Test @Test
public void testGetReview() throws MovieDbException { public void testGetReview() throws MovieDbException {
LOG.info("getReview"); LOG.info("getReview");
fail("The test case is a prototype."); String reviewId = "53fc2f600e0a267a7b009aba";
Review result = instance.getReview(reviewId);
assertNotNull("No review", result);
assertTrue("No content", StringUtils.isNotBlank(result.getContent()));
assertEquals("Wrong media ID", "70160", result.getMediaId());
} }
} }

Loading…
Cancel
Save