Skip to content

Commit

Permalink
fix #211
Browse files Browse the repository at this point in the history
  • Loading branch information
c-eg committed Apr 19, 2024
1 parent 9ac0541 commit b4a1b4c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
14 changes: 4 additions & 10 deletions src/main/java/info/movito/themoviedbapi/TmdbTrending.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
public class TmdbTrending extends AbstractTmdbApi {
protected static final String TMDB_METHOD_TRENDING = "trending";

private static final String TMDB_PARAM_TIME_WINDOW = "time_window";

/**
* Create a new TmdbTrending instance to call the rending TMDb API methods.
*/
Expand All @@ -34,8 +32,7 @@ public class TmdbTrending extends AbstractTmdbApi {
* @throws TmdbException If there was an error making the request or mapping the response.
*/
public MultiResultsPage getAll(TimeWindow timeWindow, String language) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_TRENDING, "all");
apiUrl.addPathParam(TMDB_PARAM_TIME_WINDOW, timeWindow.getValue());
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_TRENDING, "all", timeWindow.getValue());
apiUrl.addLanguage(language);
return mapJsonResult(apiUrl, MultiResultsPage.class);
}
Expand All @@ -50,8 +47,7 @@ public MultiResultsPage getAll(TimeWindow timeWindow, String language) throws Tm
* @throws TmdbException If there was an error making the request or mapping the response.
*/
public MovieResultsPage getMovies(TimeWindow timeWindow, String language) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_TRENDING, "movie");
apiUrl.addPathParam(TMDB_PARAM_TIME_WINDOW, timeWindow.getValue());
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_TRENDING, "movie", timeWindow.getValue());
apiUrl.addLanguage(language);
return mapJsonResult(apiUrl, MovieResultsPage.class);
}
Expand All @@ -66,8 +62,7 @@ public MovieResultsPage getMovies(TimeWindow timeWindow, String language) throws
* @throws TmdbException If there was an error making the request or mapping the response.
*/
public PopularPersonResultsPage getPeople(TimeWindow timeWindow, String language) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_TRENDING, "person");
apiUrl.addPathParam(TMDB_PARAM_TIME_WINDOW, timeWindow.getValue());
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_TRENDING, "person", timeWindow.getValue());
apiUrl.addLanguage(language);
return mapJsonResult(apiUrl, PopularPersonResultsPage.class);
}
Expand All @@ -82,8 +77,7 @@ public PopularPersonResultsPage getPeople(TimeWindow timeWindow, String language
* @throws TmdbException If there was an error making the request or mapping the response.
*/
public TvSeriesResultsPage getTv(TimeWindow timeWindow, String language) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_TRENDING, "tv");
apiUrl.addPathParam(TMDB_PARAM_TIME_WINDOW, timeWindow.getValue());
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_TRENDING, "tv", timeWindow.getValue());
apiUrl.addLanguage(language);
return mapJsonResult(apiUrl, TvSeriesResultsPage.class);
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/info/movito/themoviedbapi/TmdbTrendingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public TmdbTrending createApiToTest() {
@Test
public void testGetAll() throws IOException, TmdbException {
String body = TestUtils.readTestFile("api_responses/trending/all.json");
URL url = new URL(TMDB_API_BASE_URL + TMDB_METHOD_TRENDING + "/all?time_window=week&language=en-US");
URL url = new URL(TMDB_API_BASE_URL + TMDB_METHOD_TRENDING + "/all/week?language=en-US");
when(getTmdbUrlReader().readUrl(url, null, RequestType.GET)).thenReturn(body);

MultiResultsPage allResults = getApiToTest().getAll(TimeWindow.WEEK, "en-US");
Expand All @@ -48,7 +48,7 @@ public void testGetAll() throws IOException, TmdbException {
@Test
public void testGetMovies() throws IOException, TmdbException {
String body = TestUtils.readTestFile("api_responses/trending/movies.json");
URL url = new URL(TMDB_API_BASE_URL + TMDB_METHOD_TRENDING + "/movie?time_window=week&language=en-US");
URL url = new URL(TMDB_API_BASE_URL + TMDB_METHOD_TRENDING + "/movie/week?language=en-US");
when(getTmdbUrlReader().readUrl(url, null, RequestType.GET)).thenReturn(body);

MovieResultsPage movieResults = getApiToTest().getMovies(TimeWindow.WEEK, "en-US");
Expand All @@ -62,7 +62,7 @@ public void testGetMovies() throws IOException, TmdbException {
@Test
public void testGetPeople() throws IOException, TmdbException {
String body = TestUtils.readTestFile("api_responses/trending/people.json");
URL url = new URL(TMDB_API_BASE_URL + TMDB_METHOD_TRENDING + "/person?time_window=week&language=en-US");
URL url = new URL(TMDB_API_BASE_URL + TMDB_METHOD_TRENDING + "/person/week?language=en-US");
when(getTmdbUrlReader().readUrl(url, null, RequestType.GET)).thenReturn(body);

PopularPersonResultsPage peopleResults = getApiToTest().getPeople(TimeWindow.WEEK, "en-US");
Expand All @@ -76,7 +76,7 @@ public void testGetPeople() throws IOException, TmdbException {
@Test
public void testGetTv() throws IOException, TmdbException {
String body = TestUtils.readTestFile("api_responses/trending/tv.json");
URL url = new URL(TMDB_API_BASE_URL + TMDB_METHOD_TRENDING + "/tv?time_window=week&language=en-US");
URL url = new URL(TMDB_API_BASE_URL + TMDB_METHOD_TRENDING + "/tv/week?language=en-US");
when(getTmdbUrlReader().readUrl(url, null, RequestType.GET)).thenReturn(body);

TvSeriesResultsPage tvResults = getApiToTest().getTv(TimeWindow.WEEK, "en-US");
Expand Down

0 comments on commit b4a1b4c

Please sign in to comment.