/* * Copyright (c) 2004-2016 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.methods; import com.omertron.themoviedbapi.MovieDbException; import com.omertron.themoviedbapi.model.keyword.Keyword; import com.omertron.themoviedbapi.model.movie.MovieBasic; import com.omertron.themoviedbapi.results.ResultList; import com.omertron.themoviedbapi.tools.ApiUrl; import com.omertron.themoviedbapi.tools.HttpTools; import com.omertron.themoviedbapi.tools.MethodBase; import com.omertron.themoviedbapi.tools.MethodSub; import com.omertron.themoviedbapi.tools.Param; import com.omertron.themoviedbapi.tools.TmdbParameters; import com.omertron.themoviedbapi.results.WrapperGenericList; import java.io.IOException; import java.net.URL; import org.yamj.api.common.exception.ApiExceptionType; /** * Class to hold the Keyword Methods * * @author stuart.boston */ public class TmdbKeywords extends AbstractMethod { /** * Constructor * * @param apiKey * @param httpTools */ public TmdbKeywords(String apiKey, HttpTools httpTools) { super(apiKey, httpTools); } /** * Get the basic information for a specific keyword id. * * @param keywordId * @return * @throws MovieDbException */ public Keyword getKeyword(String keywordId) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.ID, keywordId); URL url = new ApiUrl(apiKey, MethodBase.KEYWORD).buildUrl(parameters); String webpage = httpTools.getRequest(url); try { return MAPPER.readValue(webpage, Keyword.class); } catch (IOException ex) { throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get keyword " + keywordId, url, ex); } } /** * Get the list of movies for a particular keyword by id. * * @param keywordId * @param language * @param page * @return List of movies with the keyword * @throws MovieDbException */ public ResultList<MovieBasic> getKeywordMovies(String keywordId, String language, Integer page) throws MovieDbException { TmdbParameters parameters = new TmdbParameters(); parameters.add(Param.ID, keywordId); parameters.add(Param.LANGUAGE, language); parameters.add(Param.PAGE, page); URL url = new ApiUrl(apiKey, MethodBase.KEYWORD).subMethod(MethodSub.MOVIES).buildUrl(parameters); WrapperGenericList<MovieBasic> wrapper = processWrapper(getTypeReference(MovieBasic.class), url, "keyword movies"); return wrapper.getResultsList(); } }