Added new searches

This commit is contained in:
Omertron
2012-12-24 22:35:31 +00:00
parent 1009e2598e
commit 44d63fbf76
4 changed files with 281 additions and 54 deletions
@@ -24,6 +24,7 @@ import com.omertron.themoviedbapi.MovieDbException.MovieDbExceptionType;
import com.omertron.themoviedbapi.model.AlternativeTitle;
import com.omertron.themoviedbapi.model.Artwork;
import com.omertron.themoviedbapi.model.ArtworkType;
import com.omertron.themoviedbapi.model.Collection;
import com.omertron.themoviedbapi.model.CollectionInfo;
import com.omertron.themoviedbapi.model.Company;
import com.omertron.themoviedbapi.model.Genre;
@@ -48,6 +49,7 @@ import com.omertron.themoviedbapi.tools.FilteringLayout;
import com.omertron.themoviedbapi.tools.WebBrowser;
import com.omertron.themoviedbapi.wrapper.WrapperAlternativeTitles;
import com.omertron.themoviedbapi.wrapper.WrapperChanges;
import com.omertron.themoviedbapi.wrapper.WrapperCollection;
import com.omertron.themoviedbapi.wrapper.WrapperCompany;
import com.omertron.themoviedbapi.wrapper.WrapperCompanyMovies;
import com.omertron.themoviedbapi.wrapper.WrapperConfig;
@@ -1332,33 +1334,37 @@ public class TheMovieDbApi {
}
/**
* Search Companies.
* Search for collections by name.
*
* You can use this method to search for production companies that are part of TMDb. The company IDs will map to
* those returned on movie calls.
*
* http://help.themoviedb.org/kb/api/search-companies
*
* @param companyName
* @param query
* @param language
* @param page
* @return
* @throws MovieDbException
*/
public List<Company> searchCompanies(String companyName, int page) throws MovieDbException {
ApiUrl apiUrl = new ApiUrl(this, BASE_SEARCH, "company");
apiUrl.addArgument(PARAM_QUERY, companyName);
public List<Collection> searchCollection(String query, String language, int page) throws MovieDbException {
ApiUrl apiUrl = new ApiUrl(this, BASE_SEARCH, "collections");
if (StringUtils.isNotBlank(query)) {
apiUrl.addArgument(PARAM_QUERY, query);
}
if (StringUtils.isNotBlank(language)) {
apiUrl.addArgument(PARAM_LANGUAGE, language);
}
if (page > 0) {
apiUrl.addArgument(PARAM_PAGE, page);
apiUrl.addArgument(PARAM_PAGE, Integer.toString(page));
}
URL url = apiUrl.buildUrl();
String webpage = WebBrowser.request(url);
try {
WrapperCompany wrapper = mapper.readValue(webpage, WrapperCompany.class);
WrapperCollection wrapper = mapper.readValue(webpage, WrapperCollection.class);
return wrapper.getResults();
} catch (IOException ex) {
logger.warn("Failed to find company: " + ex.getMessage());
logger.warn("Failed to find collection: " + ex.getMessage());
throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex);
}
}
@@ -1395,5 +1401,78 @@ public class TheMovieDbApi {
throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex);
}
}
/**
* Search for lists by name and description.
*
* @param query
* @param language
* @param page
* @throws MovieDbException
*/
public List<MovieList> searchList(String query, String language, int page) throws MovieDbException {
ApiUrl apiUrl = new ApiUrl(this, BASE_SEARCH, "list");
if (StringUtils.isNotBlank(query)) {
apiUrl.addArgument(PARAM_QUERY, query);
}
if (StringUtils.isNotBlank(language)) {
apiUrl.addArgument(PARAM_LANGUAGE, language);
}
if (page > 0) {
apiUrl.addArgument(PARAM_PAGE, Integer.toString(page));
}
URL url = apiUrl.buildUrl();
String webpage = WebBrowser.request(url);
try {
WrapperMovieList wrapper = mapper.readValue(webpage, WrapperMovieList.class);
return wrapper.getMovieList();
} catch (IOException ex) {
logger.warn("Failed to find list: " + ex.getMessage());
throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex);
}
}
/**
* Search Companies.
*
* You can use this method to search for production companies that are part of TMDb. The company IDs will map to
* those returned on movie calls.
*
* http://help.themoviedb.org/kb/api/search-companies
*
* @param companyName
* @param page
* @return
* @throws MovieDbException
*/
public List<Company> searchCompanies(String companyName, int page) throws MovieDbException {
ApiUrl apiUrl = new ApiUrl(this, BASE_SEARCH, "company");
apiUrl.addArgument(PARAM_QUERY, companyName);
if (page > 0) {
apiUrl.addArgument(PARAM_PAGE, page);
}
URL url = apiUrl.buildUrl();
String webpage = WebBrowser.request(url);
try {
WrapperCompany wrapper = mapper.readValue(webpage, WrapperCompany.class);
return wrapper.getResults();
} catch (IOException ex) {
logger.warn("Failed to find company: " + ex.getMessage());
throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex);
}
}
public void searchKeyword() {
}
//</editor-fold>
//
// List Functions
// Keywords Functions
}
@@ -53,6 +53,8 @@ public class MovieList implements Serializable {
private String name;
@JsonProperty("poster_path")
private String posterPath;
@JsonProperty("list_type")
private String listType;
// <editor-fold defaultstate="collapsed" desc="Getter methods">
public String getDescription() {
@@ -83,6 +85,9 @@ public class MovieList implements Serializable {
return posterPath;
}
public String getListType() {
return listType;
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Setter methods">
@@ -114,6 +119,9 @@ public class MovieList implements Serializable {
this.posterPath = posterPath;
}
public void setListType(String listType) {
this.listType = listType;
}
// </editor-fold>
/**
@@ -0,0 +1,100 @@
/*
* Copyright (c) 2004-2012 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.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.omertron.themoviedbapi.model.Collection;
import com.omertron.themoviedbapi.model.MovieChanges;
import java.util.List;
import org.apache.log4j.Logger;
/**
*
* @author stuart.boston
*/
public class WrapperCollection {
/*
* Logger
*/
private static final Logger logger = Logger.getLogger(WrapperCollection.class);
/*
* Properties
*/
@JsonProperty("page")
private int page;
@JsonProperty("results")
private List<Collection> results;
@JsonProperty("total_pages")
private int totalPages;
@JsonProperty("total_results")
private int totalResults;
//<editor-fold defaultstate="collapsed" desc="Getter methods">
public int getPage() {
return page;
}
public List<Collection> getResults() {
return results;
}
public int getTotalPages() {
return totalPages;
}
public int getTotalResults() {
return totalResults;
}
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="Setter methods">
public void setPage(int page) {
this.page = page;
}
public void setResults(List<Collection> 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.trace(sb.toString());
}
}