diff --git a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/TheMovieDb.java b/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/TheMovieDb.java index 54c3bf0d4..ad5f8cf50 100644 --- a/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/TheMovieDb.java +++ b/themoviedbapi/src/main/java/com/moviejukebox/themoviedb/TheMovieDb.java @@ -64,13 +64,12 @@ public class TheMovieDb { private final ApiUrl tmdbPersonInfo = new ApiUrl(this, BASE_PERSON); private final ApiUrl tmdbPersonCredits = new ApiUrl(this, BASE_PERSON, "/credits"); private final ApiUrl tmdbPersonImages = new ApiUrl(this, BASE_PERSON, "/images"); - /* - * Misc Movie - Movie Add Rating - Issue 9 - */ + // Misc Movie + // Movie Add Rating - See issue 9 private final ApiUrl tmdbLatestMovie = new ApiUrl(this, "latest/movie"); private final ApiUrl tmdbNowPlaying = new ApiUrl(this, "movie/now-playing"); private final ApiUrl tmdbPopularMovieList = new ApiUrl(this, "movie/popular"); - // - Top Rated Movies + private final ApiUrl tmdbTopRatedMovies = new ApiUrl(this, "movie/top-rated"); // Company Info // - Company Info // - Company Movies @@ -630,6 +629,8 @@ public class TheMovieDb { * a curated list that will normally contain 100 movies. The default * response will return 20 movies. * + * TODO: Implement more than 20 movies + * * @param language * @return * @throws MovieDbException @@ -647,6 +648,16 @@ public class TheMovieDb { } } + /** + * This method is used to retrieve the daily movie popularity list. This + * list is updated daily. The default response will return 20 movies. + * + * TODO: Implement more than 20 movies + * + * @param language + * @return + * @throws MovieDbException + */ public List getPopularMovieList(String language) throws MovieDbException { URL url = tmdbPopularMovieList.getIdUrl("", language); String webPage = WebBrowser.request(url); @@ -659,4 +670,27 @@ public class TheMovieDb { throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webPage, ex); } } + + /** + * This method is used to retrieve the top rated movies that have over 10 + * votes on TMDb. The default response will return 20 movies. + * + * TODO: Implement more than 20 movies + * + * @param language + * @return + * @throws MovieDbException + */ + public List getTopRatedMovies(String language) throws MovieDbException { + URL url = tmdbTopRatedMovies.getIdUrl("", language); + String webPage = WebBrowser.request(url); + + try { + WrapperResultList resultList = mapper.readValue(webPage, WrapperResultList.class); + return resultList.getResults(); + } catch (IOException ex) { + LOGGER.warn("Failed to get top rated movies: " + ex.getMessage()); + throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webPage, ex); + } + } } diff --git a/themoviedbapi/src/test/java/com/moviejukebox/themoviedb/TheMovieDbTest.java b/themoviedbapi/src/test/java/com/moviejukebox/themoviedb/TheMovieDbTest.java index 20d835b3f..d18d42b35 100644 --- a/themoviedbapi/src/test/java/com/moviejukebox/themoviedb/TheMovieDbTest.java +++ b/themoviedbapi/src/test/java/com/moviejukebox/themoviedb/TheMovieDbTest.java @@ -349,4 +349,14 @@ public class TheMovieDbTest { List results = tmdb.getPopularMovieList(""); assertTrue("No popular movies found", !results.isEmpty()); } + + /** + * Test of getTopRatedMovies method, of class TheMovieDb. + */ + @Test + public void testGetTopRatedMovies() throws MovieDbException { + LOGGER.info("getTopRatedMovies"); + List results = tmdb.getTopRatedMovies(""); + assertTrue("No top rated movies found", !results.isEmpty()); + } }