fixes issue 16

fixes issue 17
master
Omertron 14 years ago
parent 485d6d9630
commit 62832a8368

@ -44,6 +44,7 @@ public class TheMovieDb {
*/
private static final String BASE_MOVIE = "movie/";
private static final String BASE_PERSON = "person/";
private static final String BASE_COMPANY = "company/";
// Configuration URL
private final ApiUrl tmdbConfigUrl = new ApiUrl(this, "configuration");
// Search URLS
@ -71,8 +72,8 @@ public class TheMovieDb {
private final ApiUrl tmdbPopularMovieList = new ApiUrl(this, "movie/popular");
private final ApiUrl tmdbTopRatedMovies = new ApiUrl(this, "movie/top-rated");
// Company Info
// - Company Info
// - Company Movies
private final ApiUrl tmdbCompanyInfo = new ApiUrl(this, BASE_COMPANY);
private final ApiUrl tmdbCompanyMovies = new ApiUrl(this, BASE_COMPANY, "/movies");
/*
* Jackson JSON configuration
*/
@ -632,10 +633,11 @@ public class TheMovieDb {
* TODO: Implement more than 20 movies
*
* @param language
* @param allResults
* @return
* @throws MovieDbException
*/
public List<MovieDb> getNowPlayingMovies(String language) throws MovieDbException {
public List<MovieDb> getNowPlayingMovies(String language, boolean allResults) throws MovieDbException {
URL url = tmdbNowPlaying.getIdUrl("", language);
String webPage = WebBrowser.request(url);
@ -655,10 +657,11 @@ public class TheMovieDb {
* TODO: Implement more than 20 movies
*
* @param language
* @param allResults
* @return
* @throws MovieDbException
*/
public List<MovieDb> getPopularMovieList(String language) throws MovieDbException {
public List<MovieDb> getPopularMovieList(String language, boolean allResults) throws MovieDbException {
URL url = tmdbPopularMovieList.getIdUrl("", language);
String webPage = WebBrowser.request(url);
@ -678,10 +681,11 @@ public class TheMovieDb {
* TODO: Implement more than 20 movies
*
* @param language
* @param allResults
* @return
* @throws MovieDbException
*/
public List<MovieDb> getTopRatedMovies(String language) throws MovieDbException {
public List<MovieDb> getTopRatedMovies(String language, boolean allResults) throws MovieDbException {
URL url = tmdbTopRatedMovies.getIdUrl("", language);
String webPage = WebBrowser.request(url);
@ -693,4 +697,50 @@ public class TheMovieDb {
throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webPage, ex);
}
}
/**
* This method is used to retrieve the basic information about a production
* company on TMDb.
*
* @param companyId
* @return
* @throws MovieDbException
*/
public Company getCompanyInfo(int companyId) throws MovieDbException {
URL url = tmdbCompanyInfo.getIdUrl(companyId);
String webPage = WebBrowser.request(url);
try {
return mapper.readValue(webPage, Company.class);
} catch (IOException ex) {
LOGGER.warn("Failed to get company information: " + ex.getMessage());
throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webPage, ex);
}
}
/**
* 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.
*
* TODO: Implement more than 20 movies
*
* @param companyId
* @param language
* @param allResults
* @return
* @throws MovieDbException
*/
public List<MovieDb> getCompanyMovies(int companyId, String language, boolean allResults) throws MovieDbException {
URL url = tmdbCompanyMovies.getIdUrl(companyId, language);
String webPage = WebBrowser.request(url);
try {
WrapperCompanyMovies resultList = mapper.readValue(webPage, WrapperCompanyMovies.class);
return resultList.getResults();
} catch (IOException ex) {
LOGGER.warn("Failed to get company movies: " + ex.getMessage());
throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webPage, ex);
}
}
}

@ -0,0 +1,115 @@
/*
* Copyright (c) 2004-2012 YAMJ Members
* http://code.google.com/p/moviejukebox/people/list
*
* Web: http://code.google.com/p/moviejukebox/
*
* This software is licensed under a Creative Commons License
* See this page: http://code.google.com/p/moviejukebox/wiki/License
*
* For any reuse or distribution, you must make clear to others the
* license terms of this work.
*/
package com.moviejukebox.themoviedb.model;
import org.apache.log4j.Logger;
import org.codehaus.jackson.annotate.JsonAnySetter;
import org.codehaus.jackson.annotate.JsonProperty;
/**
*
* @author Stuart
*/
public class Company {
// Logger
private static final Logger LOGGER = Logger.getLogger(Company.class);
// Properties
@JsonProperty("id")
private int companyId;
@JsonProperty("name")
private String name;
@JsonProperty("description")
private String description;
@JsonProperty("headquarters")
private String headquarters;
@JsonProperty("homepage")
private String homepage;
@JsonProperty("logo_path")
private String logoPath;
@JsonProperty("parent_company")
private String parentCompany;
//<editor-fold defaultstate="collapsed" desc="Getter Methods">
public int getCompanyId() {
return companyId;
}
public String getDescription() {
return description;
}
public String getHeadquarters() {
return headquarters;
}
public String getHomepage() {
return homepage;
}
public String getLogoPath() {
return logoPath;
}
public String getName() {
return name;
}
public String getParentCompany() {
return parentCompany;
}
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Setter Methods">
public void setCompanyId(int companyId) {
this.companyId = companyId;
}
public void setDescription(String description) {
this.description = description;
}
public void setHeadquarters(String headquarters) {
this.headquarters = headquarters;
}
public void setHomepage(String homepage) {
this.homepage = homepage;
}
public void setLogoPath(String logoPath) {
this.logoPath = logoPath;
}
public void setName(String name) {
this.name = name;
}
public void setParentCompany(String parentCompany) {
this.parentCompany = parentCompany;
}
//</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.warn(sb.toString());
}
}

@ -0,0 +1,110 @@
/*
* Copyright (c) 2004-2012 YAMJ Members
* http://code.google.com/p/moviejukebox/people/list
*
* Web: http://code.google.com/p/moviejukebox/
*
* This software is licensed under a Creative Commons License
* See this page: http://code.google.com/p/moviejukebox/wiki/License
*
* For any reuse or distribution, you must make clear to others the
* license terms of this work.
*/
package com.moviejukebox.themoviedb.wrapper;
import com.moviejukebox.themoviedb.model.MovieDb;
import java.util.List;
import org.apache.log4j.Logger;
import org.codehaus.jackson.annotate.JsonAnySetter;
import org.codehaus.jackson.annotate.JsonProperty;
/**
*
* @author stuart.boston
*/
public class WrapperCompanyMovies {
// Loggers
private static final Logger LOGGER = Logger.getLogger(WrapperCompanyMovies.class);
/*
* Properties
*/
@JsonProperty("id")
private int companyId;
@JsonProperty("page")
private int page;
@JsonProperty("results")
private List<MovieDb> results;
@JsonProperty("total_pages")
private int totalPages;
@JsonProperty("total_results")
private int totalResults;
//<editor-fold defaultstate="collapsed" desc="Getter methods">
public int getCompanyId() {
return companyId;
}
public int getPage() {
return page;
}
public List<MovieDb> getResults() {
return results;
}
public int getTotalPages() {
return totalPages;
}
public int getTotalResults() {
return totalResults;
}
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Setter methods">
public void setCompanyId(int companyId) {
this.companyId = companyId;
}
public void setPage(int page) {
this.page = page;
}
public void setResults(List<MovieDb> results) {
this.results = results;
}
public void setTotalPages(int totalPages) {
this.totalPages = totalPages;
}
public void setTotalResults(int totalResults) {
this.totalResults = totalResults;
}
//</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.warn(sb.toString());
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder("[ResultList=[");
sb.append("[companyId=").append(companyId);
sb.append("],[page=").append(page);
sb.append("],[pageResults=").append(results.size());
sb.append("],[totalPages=").append(totalPages);
sb.append("],[totalResults=").append(totalResults);
sb.append("]]");
return sb.toString();
}
}

@ -27,15 +27,16 @@ import org.junit.*;
*/
public class TheMovieDbTest {
// Logger
private static final Logger LOGGER = Logger.getLogger(TheMovieDbTest.class);
// API Key
private static final String API_KEY = "5a1a77e2eba8984804586122754f969f";
private static TheMovieDb tmdb;
/*
* Test data
*/
private static final int ID_BLADE_RUNNER = 78;
private static final int ID_STAR_WARS_COLLECTION = 10;
private static final int ID_BRUCE_WILLIS = 62;
// Test data
private static final int ID_MOVIE_BLADE_RUNNER = 78;
private static final int ID_MOVIE_STAR_WARS_COLLECTION = 10;
private static final int ID_PERSON_BRUCE_WILLIS = 62;
private static final int ID_COMPANY_LUCASFILM = 1;
public TheMovieDbTest() throws MovieDbException {
tmdb = new TheMovieDb(API_KEY);
@ -100,7 +101,7 @@ public class TheMovieDbTest {
public void testGetMovieInfo() throws MovieDbException {
LOGGER.info("getMovieInfo");
String language = "en";
MovieDb result = tmdb.getMovieInfo(ID_BLADE_RUNNER, language);
MovieDb result = tmdb.getMovieInfo(ID_MOVIE_BLADE_RUNNER, language);
assertEquals("Incorrect movie information", "Blade Runner", result.getOriginalTitle());
}
@ -111,11 +112,11 @@ public class TheMovieDbTest {
public void testGetMovieAlternativeTitles() throws MovieDbException {
LOGGER.info("getMovieAlternativeTitles");
String country = "";
List<AlternativeTitle> results = tmdb.getMovieAlternativeTitles(ID_BLADE_RUNNER, country);
List<AlternativeTitle> results = tmdb.getMovieAlternativeTitles(ID_MOVIE_BLADE_RUNNER, country);
assertTrue("No alternative titles found", results.size() > 0);
country = "US";
results = tmdb.getMovieAlternativeTitles(ID_BLADE_RUNNER, country);
results = tmdb.getMovieAlternativeTitles(ID_MOVIE_BLADE_RUNNER, country);
assertTrue("No alternative titles found", results.size() > 0);
}
@ -126,7 +127,7 @@ public class TheMovieDbTest {
@Test
public void testGetMovieCasts() throws MovieDbException {
LOGGER.info("getMovieCasts");
List<Person> people = tmdb.getMovieCasts(ID_BLADE_RUNNER);
List<Person> people = tmdb.getMovieCasts(ID_MOVIE_BLADE_RUNNER);
assertTrue("No cast information", people.size() > 0);
String name1 = "Harrison Ford";
@ -154,7 +155,7 @@ public class TheMovieDbTest {
public void testGetMovieImages() throws MovieDbException {
LOGGER.info("getMovieImages");
String language = "";
List<Artwork> result = tmdb.getMovieImages(ID_BLADE_RUNNER, language);
List<Artwork> result = tmdb.getMovieImages(ID_MOVIE_BLADE_RUNNER, language);
assertFalse("No artwork found", result.isEmpty());
}
@ -164,7 +165,7 @@ public class TheMovieDbTest {
@Test
public void testGetMovieKeywords() throws MovieDbException {
LOGGER.info("getMovieKeywords");
List<Keyword> result = tmdb.getMovieKeywords(ID_BLADE_RUNNER);
List<Keyword> result = tmdb.getMovieKeywords(ID_MOVIE_BLADE_RUNNER);
assertFalse("No keywords found", result.isEmpty());
}
@ -174,7 +175,7 @@ public class TheMovieDbTest {
@Test
public void testGetMovieReleaseInfo() throws MovieDbException {
LOGGER.info("getMovieReleaseInfo");
List<ReleaseInfo> result = tmdb.getMovieReleaseInfo(ID_BLADE_RUNNER, "");
List<ReleaseInfo> result = tmdb.getMovieReleaseInfo(ID_MOVIE_BLADE_RUNNER, "");
assertFalse("Release information missing", result.isEmpty());
}
@ -184,7 +185,7 @@ public class TheMovieDbTest {
@Test
public void testGetMovieTrailers() throws MovieDbException {
LOGGER.info("getMovieTrailers");
List<Trailer> result = tmdb.getMovieTrailers(ID_BLADE_RUNNER, "");
List<Trailer> result = tmdb.getMovieTrailers(ID_MOVIE_BLADE_RUNNER, "");
assertFalse("Movie trailers missing", result.isEmpty());
}
@ -194,7 +195,7 @@ public class TheMovieDbTest {
@Test
public void testGetMovieTranslations() throws MovieDbException {
LOGGER.info("getMovieTranslations");
List<Translation> result = tmdb.getMovieTranslations(ID_BLADE_RUNNER);
List<Translation> result = tmdb.getMovieTranslations(ID_MOVIE_BLADE_RUNNER);
assertFalse("No translations found", result.isEmpty());
}
@ -205,14 +206,14 @@ public class TheMovieDbTest {
public void testGetCollectionInfo() throws MovieDbException {
LOGGER.info("getCollectionInfo");
String language = "";
CollectionInfo result = tmdb.getCollectionInfo(ID_STAR_WARS_COLLECTION, language);
CollectionInfo result = tmdb.getCollectionInfo(ID_MOVIE_STAR_WARS_COLLECTION, language);
assertFalse("No collection information", result.getParts().isEmpty());
}
@Test
public void testCreateImageUrl() throws MovieDbException {
LOGGER.info("createImageUrl");
MovieDb movie = tmdb.getMovieInfo(ID_BLADE_RUNNER, "");
MovieDb movie = tmdb.getMovieInfo(ID_MOVIE_BLADE_RUNNER, "");
String result = tmdb.createImageUrl(movie.getPosterPath(), "original").toString();
assertTrue("Error compiling image URL", !result.isEmpty());
}
@ -269,8 +270,8 @@ public class TheMovieDbTest {
@Test
public void testGetPersonInfo() throws MovieDbException {
LOGGER.info("getPersonInfo");
Person result = tmdb.getPersonInfo(ID_BRUCE_WILLIS);
assertTrue("Wrong actor returned", result.getId() == ID_BRUCE_WILLIS);
Person result = tmdb.getPersonInfo(ID_PERSON_BRUCE_WILLIS);
assertTrue("Wrong actor returned", result.getId() == ID_PERSON_BRUCE_WILLIS);
}
/**
@ -280,7 +281,7 @@ public class TheMovieDbTest {
public void testGetPersonCredits() throws MovieDbException {
LOGGER.info("getPersonCredits");
List<PersonCredit> people = tmdb.getPersonCredits(ID_BRUCE_WILLIS);
List<PersonCredit> people = tmdb.getPersonCredits(ID_PERSON_BRUCE_WILLIS);
assertTrue("No cast information", people.size() > 0);
}
@ -291,7 +292,7 @@ public class TheMovieDbTest {
public void testGetPersonImages() throws MovieDbException {
LOGGER.info("getPersonImages");
List<Artwork> artwork = tmdb.getPersonImages(ID_BRUCE_WILLIS);
List<Artwork> artwork = tmdb.getPersonImages(ID_PERSON_BRUCE_WILLIS);
assertTrue("No cast information", artwork.size() > 0);
}
@ -336,7 +337,7 @@ public class TheMovieDbTest {
@Test
public void testGetNowPlayingMovies() throws MovieDbException {
LOGGER.info("getNowPlayingMovies");
List<MovieDb> results = tmdb.getNowPlayingMovies("");
List<MovieDb> results = tmdb.getNowPlayingMovies("", true);
assertTrue("No now playing movies found", !results.isEmpty());
}
@ -346,7 +347,7 @@ public class TheMovieDbTest {
@Test
public void testGetPopularMovieList() throws MovieDbException {
LOGGER.info("getPopularMovieList");
List<MovieDb> results = tmdb.getPopularMovieList("");
List<MovieDb> results = tmdb.getPopularMovieList("", true);
assertTrue("No popular movies found", !results.isEmpty());
}
@ -356,7 +357,27 @@ public class TheMovieDbTest {
@Test
public void testGetTopRatedMovies() throws MovieDbException {
LOGGER.info("getTopRatedMovies");
List<MovieDb> results = tmdb.getTopRatedMovies("");
List<MovieDb> results = tmdb.getTopRatedMovies("", true);
assertTrue("No top rated movies found", !results.isEmpty());
}
/**
* Test of getCompanyInfo method, of class TheMovieDb.
*/
@Test
public void testGetCompanyInfo() throws Exception {
LOGGER.info("getCompanyInfo");
Company company = tmdb.getCompanyInfo(ID_COMPANY_LUCASFILM);
assertTrue("No company information found", company.getCompanyId() > 0);
}
/**
* Test of getCompanyMovies method, of class TheMovieDb.
*/
@Test
public void testGetCompanyMovies() throws Exception {
LOGGER.info("getCompanyMovies");
List<MovieDb> results = tmdb.getCompanyMovies(ID_COMPANY_LUCASFILM, "", true);
assertTrue("No company movies found", !results.isEmpty());
}
}

Loading…
Cancel
Save