Skip to content

Commit

Permalink
Merge pull request #169 from c-eg/keywords-api
Browse files Browse the repository at this point in the history
Keywords api
  • Loading branch information
c-eg authored Feb 12, 2024
2 parents ce677ba + 57b7756 commit 475ba9b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 52 deletions.
25 changes: 10 additions & 15 deletions src/main/java/info/movito/themoviedbapi/TmdbKeywords.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package info.movito.themoviedbapi;

import info.movito.themoviedbapi.model.core.MovieDbResultsPage;
import info.movito.themoviedbapi.model.core.ResultsPage;
import info.movito.themoviedbapi.model.keywords.Keyword;
import info.movito.themoviedbapi.tools.ApiUrl;
import info.movito.themoviedbapi.tools.TmdbException;
import info.movito.themoviedbapi.tools.builders.discover.DiscoverMovieParamBuilder;

/**
* The movie database api for keywords. See the
* <a href="https://developer.themoviedb.org/reference/keyword-details">documentation</a> for more info.
*/
public class TmdbKeywords extends AbstractTmdbApi {
public static final String TMDB_METHOD_KEYWORD = "keyword";
protected static final String TMDB_METHOD_KEYWORD = "keyword";

/**
* Create a new TmdbKeywords instance to call the keywords TMDb API methods.
Expand All @@ -21,33 +21,28 @@ public class TmdbKeywords extends AbstractTmdbApi {
}

/**
* Get the basic information for a specific keyword id.
* <p>Get the details for a specific keyword.</p>
* <p>See the <a href="https://developer.themoviedb.org/reference/keyword-details">documentation</a> for more info.</p>
*
* @param keywordId The keyword id.
* @return The keyword details.
*/
public Keyword getKeyword(String keywordId) throws TmdbException {
public Keyword getDetails(int keywordId) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_KEYWORD, keywordId);

return mapJsonResult(apiUrl, Keyword.class);
}

/**
* Get the list of movies for a particular keyword by id.
*
* @return List of movies with the keyword
* @deprecated use {@link TmdbDiscover#getMovie(DiscoverMovieParamBuilder)} instead.
*/
@Deprecated
public MovieDbResultsPage getKeywordMovies(String keywordId, String language, Integer page) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_KEYWORD, keywordId, "movies");

apiUrl.addLanguage(language);

apiUrl.addPage(page);

return mapJsonResult(apiUrl, MovieDbResultsPage.class);
}

/**
* Keyword Result Page.
*/
public static class KeywordResultsPage extends ResultsPage<Keyword> {

}
}

This file was deleted.

36 changes: 36 additions & 0 deletions src/test/java/info/movito/themoviedbapi/TmdbKeywordsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package info.movito.themoviedbapi;

import info.movito.themoviedbapi.model.keywords.Keyword;
import info.movito.themoviedbapi.tools.RequestType;
import info.movito.themoviedbapi.tools.TmdbException;
import info.movito.themoviedbapi.util.TestUtils;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.URL;

import static info.movito.themoviedbapi.TmdbKeywords.TMDB_METHOD_KEYWORD;
import static info.movito.themoviedbapi.tools.ApiUrl.TMDB_API_BASE_URL;
import static info.movito.themoviedbapi.util.TestUtils.testForNullFieldsAndNewItems;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.when;

/**
* Tests for {@link TmdbKeywords}.
*/
public class TmdbKeywordsTest extends AbstractTmdbApiTest {
/**
* Tests {@link TmdbKeywords#getDetails(int)} with an expected result.
*/
@Test
public void testGetDetails() throws TmdbException, IOException {
String body = TestUtils.readTestFile("api_responses/keywords/details.json");
URL url = new URL(TMDB_API_BASE_URL + TMDB_METHOD_KEYWORD + "/1");
when(getTmdbUrlReader().readUrl(url, null, RequestType.GET)).thenReturn(body);

TmdbKeywords tmdbKeywords = getTmdbApi().getKeywords();
Keyword keyword = tmdbKeywords.getDetails(1);
assertNotNull(keyword);
testForNullFieldsAndNewItems(keyword);
}
}
4 changes: 4 additions & 0 deletions src/test/resources/api_responses/keywords/details.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"id": 1701,
"name": "hero"
}

0 comments on commit 475ba9b

Please sign in to comment.