Added keyword searches
This commit is contained in:
@@ -1479,7 +1479,7 @@ public class TheMovieDbApi {
|
||||
* @return List of movies with the keyword
|
||||
* @throws MovieDbException
|
||||
*/
|
||||
public List<MovieList> getKeywordMovies(String keywordId, String language, int page) throws MovieDbException {
|
||||
public List<KeywordMovie> getKeywordMovies(String keywordId, String language, int page) throws MovieDbException {
|
||||
ApiUrl apiUrl = new ApiUrl(this, BASE_KEYWORD, "/movies");
|
||||
apiUrl.addArgument(PARAM_ID, keywordId);
|
||||
|
||||
@@ -1495,8 +1495,8 @@ public class TheMovieDbApi {
|
||||
String webpage = WebBrowser.request(url);
|
||||
|
||||
try {
|
||||
WrapperMovieList wrapper = mapper.readValue(webpage, WrapperMovieList.class);
|
||||
return wrapper.getMovieList();
|
||||
WrapperKeywordMovies wrapper = mapper.readValue(webpage, WrapperKeywordMovies.class);
|
||||
return wrapper.getResults();
|
||||
} catch (IOException ex) {
|
||||
logger.warn("Failed to get top rated movies: " + ex.getMessage());
|
||||
throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex);
|
||||
@@ -1506,5 +1506,14 @@ public class TheMovieDbApi {
|
||||
//</editor-fold>
|
||||
//
|
||||
//<editor-fold defaultstate="collapsed" desc="Changes Functions">
|
||||
|
||||
public void getMovieChangesList(int page, String startDate, String endDate) throws MovieDbException {
|
||||
throw new MovieDbException(MovieDbExceptionType.UNKNOWN_CAUSE, "Not implemented yet");
|
||||
}
|
||||
|
||||
public void getPersonChangesList(int page, String startDate, String endDate) throws MovieDbException {
|
||||
throw new MovieDbException(MovieDbExceptionType.UNKNOWN_CAUSE, "Not implemented yet");
|
||||
}
|
||||
|
||||
//</editor-fold>
|
||||
}
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (c) 2004-2013 Stuart Boston
|
||||
*
|
||||
* This file is part of TheMovieDB API.
|
||||
*
|
||||
* TheMovieDB API is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* TheMovieDB API is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with TheMovieDB API. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.omertron.themoviedbapi.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAnySetter;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.io.Serializable;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Stuart
|
||||
*/
|
||||
public class KeywordMovie implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/*
|
||||
* Logger
|
||||
*/
|
||||
private static final Logger logger = Logger.getLogger(KeywordMovie.class);
|
||||
/*
|
||||
* Properties
|
||||
*/
|
||||
@JsonProperty("id")
|
||||
private String id;
|
||||
@JsonProperty("backdrop_path")
|
||||
private String backdropPath;
|
||||
@JsonProperty("original_title")
|
||||
private String originalTitle;
|
||||
@JsonProperty("release_date")
|
||||
private String releaseDate;
|
||||
@JsonProperty("poster_path")
|
||||
private String posterPath;
|
||||
@JsonProperty("title")
|
||||
private String title;
|
||||
@JsonProperty("vote_average")
|
||||
private float voteAverage;
|
||||
@JsonProperty("vote_count")
|
||||
private double voteCount;
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Getter methods">
|
||||
public static long getSerialVersionUID() {
|
||||
return serialVersionUID;
|
||||
}
|
||||
|
||||
public String getBackdropPath() {
|
||||
return backdropPath;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getOriginalTitle() {
|
||||
return originalTitle;
|
||||
}
|
||||
|
||||
public String getReleaseDate() {
|
||||
return releaseDate;
|
||||
}
|
||||
|
||||
public String getPosterPath() {
|
||||
return posterPath;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public float getVoteAverage() {
|
||||
return voteAverage;
|
||||
}
|
||||
|
||||
public double getVoteCount() {
|
||||
return voteCount;
|
||||
}
|
||||
// </editor-fold>
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Setter methods">
|
||||
public void setBackdropPath(String backdropPath) {
|
||||
this.backdropPath = backdropPath;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setOriginalTitle(String originalTitle) {
|
||||
this.originalTitle = originalTitle;
|
||||
}
|
||||
|
||||
public void setReleaseDate(String releaseDate) {
|
||||
this.releaseDate = releaseDate;
|
||||
}
|
||||
|
||||
public void setPosterPath(String posterPath) {
|
||||
this.posterPath = posterPath;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public void setVoteAverage(float voteAverage) {
|
||||
this.voteAverage = voteAverage;
|
||||
}
|
||||
|
||||
public void setVoteCount(double voteCount) {
|
||||
this.voteCount = voteCount;
|
||||
}
|
||||
// </editor-fold>
|
||||
|
||||
/**
|
||||
* Handle unknown properties and print a message
|
||||
*
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
@JsonAnySetter
|
||||
public void handleUnknown(String key, Object value) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Unknown property: '").append(key);
|
||||
sb.append("' value: '").append(value).append("'");
|
||||
logger.trace(sb.toString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -40,19 +40,19 @@ public class MovieDb implements Serializable {
|
||||
/*
|
||||
* Properties
|
||||
*/
|
||||
@JsonProperty(("backdrop_path"))
|
||||
@JsonProperty("backdrop_path")
|
||||
private String backdropPath;
|
||||
@JsonProperty(("id"))
|
||||
@JsonProperty("id")
|
||||
private int id;
|
||||
@JsonProperty(("original_title"))
|
||||
@JsonProperty("original_title")
|
||||
private String originalTitle;
|
||||
@JsonProperty(("popularity"))
|
||||
@JsonProperty("popularity")
|
||||
private float popularity;
|
||||
@JsonProperty(("poster_path"))
|
||||
@JsonProperty("poster_path")
|
||||
private String posterPath;
|
||||
@JsonProperty(("release_date"))
|
||||
@JsonProperty("release_date")
|
||||
private String releaseDate;
|
||||
@JsonProperty(("title"))
|
||||
@JsonProperty("title")
|
||||
private String title;
|
||||
@JsonProperty("adult")
|
||||
private boolean adult;
|
||||
@@ -275,7 +275,6 @@ public class MovieDb implements Serializable {
|
||||
}
|
||||
|
||||
// </editor-fold>
|
||||
|
||||
/**
|
||||
* Handle unknown properties and print a message
|
||||
*
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2004-2013 Stuart Boston
|
||||
*
|
||||
* This file is part of TheMovieDB API.
|
||||
*
|
||||
* TheMovieDB API is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* TheMovieDB API is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with TheMovieDB API. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.omertron.themoviedbapi.wrapper;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.omertron.themoviedbapi.model.Keyword;
|
||||
import com.omertron.themoviedbapi.model.KeywordMovie;
|
||||
import java.util.List;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author stuart.boston
|
||||
*/
|
||||
public class WrapperKeywordMovies extends WrapperBase {
|
||||
/*
|
||||
* Properties
|
||||
*/
|
||||
@JsonProperty("results")
|
||||
private List<KeywordMovie> results;
|
||||
|
||||
public WrapperKeywordMovies() {
|
||||
super(Logger.getLogger(WrapperKeywordMovies.class));
|
||||
}
|
||||
|
||||
public List<KeywordMovie> getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
public void setResults(List<KeywordMovie> results) {
|
||||
this.results = results;
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ import com.omertron.themoviedbapi.model.CollectionInfo;
|
||||
import com.omertron.themoviedbapi.model.Company;
|
||||
import com.omertron.themoviedbapi.model.Genre;
|
||||
import com.omertron.themoviedbapi.model.Keyword;
|
||||
import com.omertron.themoviedbapi.model.KeywordMovie;
|
||||
import com.omertron.themoviedbapi.model.MovieChanges;
|
||||
import com.omertron.themoviedbapi.model.MovieDb;
|
||||
import com.omertron.themoviedbapi.model.MovieDbList;
|
||||
@@ -74,7 +75,6 @@ public class TheMovieDbApiTest {
|
||||
private static final String LANGUAGE_ENGLISH = "en";
|
||||
|
||||
public TheMovieDbApiTest() throws MovieDbException {
|
||||
tmdb = new TheMovieDbApi(API_KEY);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
@@ -82,6 +82,7 @@ public class TheMovieDbApiTest {
|
||||
BasicConfigurator.configure();
|
||||
// Set the logger level to TRACE
|
||||
Logger.getRootLogger().setLevel(Level.TRACE);
|
||||
tmdb = new TheMovieDbApi(API_KEY);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@@ -501,8 +502,9 @@ public class TheMovieDbApiTest {
|
||||
|
||||
/**
|
||||
* Test of getSessionToken method, of class TheMovieDbApi.
|
||||
*
|
||||
* TODO: Cannot be tested without a HTTP authorisation: http://help.themoviedb.org/kb/api/user-authentication
|
||||
*/
|
||||
// Cannot be tested without a HTTP authorisation: http://help.themoviedb.org/kb/api/user-authentication
|
||||
public void testGetSessionToken() throws Exception {
|
||||
logger.info("getSessionToken");
|
||||
TokenAuthorisation token = tmdb.getAuthorisationToken();
|
||||
@@ -536,7 +538,11 @@ public class TheMovieDbApiTest {
|
||||
assertTrue("No results found", results.size() > 0);
|
||||
}
|
||||
|
||||
// Do not test this until it is fixed
|
||||
/**
|
||||
* Test of getMovieChanges method,of class TheMovieDbApi
|
||||
*
|
||||
* TODO: Do not test this until it is fixed
|
||||
*/
|
||||
public void testGetMovieChanges() throws Exception {
|
||||
logger.info("getMovieChanges");
|
||||
|
||||
@@ -606,8 +612,9 @@ public class TheMovieDbApiTest {
|
||||
|
||||
/**
|
||||
* Test of postMovieRating method, of class TheMovieDbApi.
|
||||
*
|
||||
* TODO: Cannot be tested without a HTTP authorisation: http://help.themoviedb.org/kb/api/user-authentication
|
||||
*/
|
||||
@Test
|
||||
public void testPostMovieRating() throws Exception {
|
||||
logger.info("postMovieRating");
|
||||
String sessionId = "";
|
||||
@@ -621,16 +628,14 @@ public class TheMovieDbApiTest {
|
||||
|
||||
/**
|
||||
* Test of getPersonChanges method, of class TheMovieDbApi.
|
||||
*
|
||||
* TODO: Fix the method before testing
|
||||
*/
|
||||
@Test
|
||||
public void testGetPersonChanges() throws Exception {
|
||||
logger.info("getPersonChanges");
|
||||
int personId = 0;
|
||||
String startDate = "";
|
||||
String endDate = "";
|
||||
tmdb.getPersonChanges(personId, startDate, endDate);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
tmdb.getPersonChanges(ID_PERSON_BRUCE_WILLIS, startDate, endDate);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -661,7 +666,7 @@ public class TheMovieDbApiTest {
|
||||
public void testGetKeywordMovies() throws Exception {
|
||||
logger.info("getKeywordMovies");
|
||||
int page = 0;
|
||||
List<MovieList> result = tmdb.getKeywordMovies(ID_KEYWORD, LANGUAGE_DEFAULT, page);
|
||||
List<KeywordMovie> result = tmdb.getKeywordMovies(ID_KEYWORD, LANGUAGE_DEFAULT, page);
|
||||
assertFalse("No keyword movies found", result.isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user