From f4d67c3336f05f97144695a347eed7f9476bed30 Mon Sep 17 00:00:00 2001 From: Conor Egan <68134729+c-eg@users.noreply.github.com> Date: Mon, 12 Feb 2024 01:58:27 +0000 Subject: [PATCH 1/2] update keywords api --- .../movito/themoviedbapi/TmdbKeywords.java | 25 +++++-------- .../model/keywords/KeywordMovie.java | 37 ------------------- 2 files changed, 10 insertions(+), 52 deletions(-) delete mode 100644 src/main/java/info/movito/themoviedbapi/model/keywords/KeywordMovie.java diff --git a/src/main/java/info/movito/themoviedbapi/TmdbKeywords.java b/src/main/java/info/movito/themoviedbapi/TmdbKeywords.java index 29d83cd5..7959774e 100644 --- a/src/main/java/info/movito/themoviedbapi/TmdbKeywords.java +++ b/src/main/java/info/movito/themoviedbapi/TmdbKeywords.java @@ -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 * documentation 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. @@ -21,11 +21,14 @@ public class TmdbKeywords extends AbstractTmdbApi { } /** - * Get the basic information for a specific keyword id. + *

Get the details for a specific keyword.

+ *

See the documentation for more info.

+ * + * @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); } @@ -33,21 +36,13 @@ public Keyword getKeyword(String keywordId) throws TmdbException { * 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 { - - } } diff --git a/src/main/java/info/movito/themoviedbapi/model/keywords/KeywordMovie.java b/src/main/java/info/movito/themoviedbapi/model/keywords/KeywordMovie.java deleted file mode 100644 index 38c1d49c..00000000 --- a/src/main/java/info/movito/themoviedbapi/model/keywords/KeywordMovie.java +++ /dev/null @@ -1,37 +0,0 @@ -package info.movito.themoviedbapi.model.keywords; - -import com.fasterxml.jackson.annotation.JsonProperty; -import info.movito.themoviedbapi.model.core.IdElement; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Data -@EqualsAndHashCode(callSuper = true) -public class KeywordMovie extends IdElement { - @JsonProperty("backdrop_path") - private String backdropPath; - - @JsonProperty("original_title") - private String originalTitle; - - @JsonProperty("release_date") - private String releaseDate; - - @JsonProperty("poster_path") - private String posterPath; - - @JsonProperty("title") - private String title; - - @JsonProperty("vote_average") - private float voteAverage; - - @JsonProperty("vote_count") - private double voteCount; - - @JsonProperty("adult") - private boolean adult; - - @JsonProperty("popularity") - private float popularity; -} From 57b7756193e26b440cd39a62b62e8c8d08e701f8 Mon Sep 17 00:00:00 2001 From: Conor Egan <68134729+c-eg@users.noreply.github.com> Date: Mon, 12 Feb 2024 01:58:33 +0000 Subject: [PATCH 2/2] test keywords api --- .../themoviedbapi/TmdbKeywordsTest.java | 36 +++++++++++++++++++ .../api_responses/keywords/details.json | 4 +++ 2 files changed, 40 insertions(+) create mode 100644 src/test/java/info/movito/themoviedbapi/TmdbKeywordsTest.java create mode 100644 src/test/resources/api_responses/keywords/details.json diff --git a/src/test/java/info/movito/themoviedbapi/TmdbKeywordsTest.java b/src/test/java/info/movito/themoviedbapi/TmdbKeywordsTest.java new file mode 100644 index 00000000..a8599721 --- /dev/null +++ b/src/test/java/info/movito/themoviedbapi/TmdbKeywordsTest.java @@ -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); + } +} diff --git a/src/test/resources/api_responses/keywords/details.json b/src/test/resources/api_responses/keywords/details.json new file mode 100644 index 00000000..0bab3171 --- /dev/null +++ b/src/test/resources/api_responses/keywords/details.json @@ -0,0 +1,4 @@ +{ + "id": 1701, + "name": "hero" +} \ No newline at end of file