Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Networks api #168

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/info/movito/themoviedbapi/TmdbApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ public TmdbMovies getMovies() {
return new TmdbMovies(this);
}

public TmdbNetworks getNetworks() {
return new TmdbNetworks(this);
}

public TmdbPeopleLists getPeopleLists() {
return new TmdbPeopleLists(this);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/info/movito/themoviedbapi/TmdbCompanies.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import info.movito.themoviedbapi.model.AlternativeName;
import info.movito.themoviedbapi.model.Company;
import info.movito.themoviedbapi.model.core.ResultsPage;
import info.movito.themoviedbapi.model.core.image.LogoImageResults;
import info.movito.themoviedbapi.model.core.image.ImageResults;
import info.movito.themoviedbapi.tools.ApiUrl;
import info.movito.themoviedbapi.tools.TmdbException;

Expand Down Expand Up @@ -55,9 +55,9 @@ public AlternativeNamesResultsPage getAlternativeNames(Integer companyId) throws
* @return The company logos
* @throws TmdbException If there was an error making the request or mapping the response.
*/
public LogoImageResults getImages(Integer companyId) throws TmdbException {
public ImageResults getImages(Integer companyId) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_COMPANY, companyId, "images");
return mapJsonResult(apiUrl, LogoImageResults.class);
return mapJsonResult(apiUrl, ImageResults.class);
}

@SuppressWarnings("checkstyle:MissingJavadocType")
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/info/movito/themoviedbapi/TmdbNetworks.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package info.movito.themoviedbapi;

import info.movito.themoviedbapi.model.core.image.ImageResults;
import info.movito.themoviedbapi.model.networks.AlternativeNamesResults;
import info.movito.themoviedbapi.model.networks.Network;
import info.movito.themoviedbapi.tools.ApiUrl;
import info.movito.themoviedbapi.tools.TmdbException;

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

/**
* Create a new TmdbNetworks instance to call the network related TMDb API methods.
*/
public TmdbNetworks(TmdbApi tmdbApi) {
super(tmdbApi);
}

/**
* <p>Get the details of a network.</p>
* <p>See the <a href="https://developer.themoviedb.org/reference/network-details">documentation</a> for more info.</p>
*
* @param networkId The network id.
* @return The network details.
* @throws TmdbException If there was an error making the request or mapping the response.
*/
public Network getDetails(int networkId) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_NETWORK, networkId);
return mapJsonResult(apiUrl, Network.class);
}

/**
* <p>Get the alternative names of a network.</p>
* <p>See the <a href="https://developer.themoviedb.org/reference/details-copy">documentation</a> for more info.</p>
*
* @param networkId The network id.
* @return The alternative names of the network.
* @throws TmdbException If there was an error making the request or mapping the response.
*/
public AlternativeNamesResults getAlternativeNames(int networkId) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_NETWORK, networkId, "alternative_names");
return mapJsonResult(apiUrl, AlternativeNamesResults.class);
}

/**
* <p>Get the images of a network.</p>
* <p>See the <a href="https://developer.themoviedb.org/reference/alternative-names-copy">documentation</a> for more info.</p>
*
* @param networkId The network id.
* @return The images of the network.
* @throws TmdbException If there was an error making the request or mapping the response.
*/
public ImageResults getImages(int networkId) throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_NETWORK, networkId, "images");
return mapJsonResult(apiUrl, ImageResults.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@Data
@EqualsAndHashCode(callSuper = true)
public class LogoImage extends StringIdElement {
public class Image extends StringIdElement {
@JsonProperty("aspect_ratio")
private Double aspectRatio;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@Data
@EqualsAndHashCode(callSuper = true)
public class LogoImageResults extends IdElement {
public class ImageResults extends IdElement {
@JsonProperty("logos")
private List<LogoImage> logos;
private List<Image> logos;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package info.movito.themoviedbapi.model.networks;

import info.movito.themoviedbapi.model.AlternativeName;
import info.movito.themoviedbapi.model.core.Results;

public class AlternativeNamesResults extends Results<AlternativeName> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package info.movito.themoviedbapi.model.networks;

import com.fasterxml.jackson.annotation.JsonProperty;
import info.movito.themoviedbapi.model.core.NamedIdElement;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
public class Network extends NamedIdElement {
@JsonProperty("headquarters")
private String headquarters;

@JsonProperty("homepage")
private String homepage;

@JsonProperty("logo_path")
private String logoPath;

@JsonProperty("origin_country")
private String originCountry;
}
2 changes: 2 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
opens info.movito.themoviedbapi.model.core.responses to com.fasterxml.jackson.databind;
opens info.movito.themoviedbapi.model.keywords to com.fasterxml.jackson.databind;
opens info.movito.themoviedbapi.model.movies.changes to com.fasterxml.jackson.databind;
opens info.movito.themoviedbapi.model.networks to com.fasterxml.jackson.databind;
opens info.movito.themoviedbapi.model.people to com.fasterxml.jackson.databind;
opens info.movito.themoviedbapi.model.peoplelists to com.fasterxml.jackson.databind;
opens info.movito.themoviedbapi.model.providers to com.fasterxml.jackson.databind;
Expand All @@ -46,6 +47,7 @@
exports info.movito.themoviedbapi.model.core.responses;
exports info.movito.themoviedbapi.model.keywords;
exports info.movito.themoviedbapi.model.movies.changes;
exports info.movito.themoviedbapi.model.networks;
exports info.movito.themoviedbapi.model.people;
exports info.movito.themoviedbapi.model.peoplelists;
exports info.movito.themoviedbapi.model.providers;
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/info/movito/themoviedbapi/TmdbCompaniesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import info.movito.themoviedbapi.model.AlternativeName;
import info.movito.themoviedbapi.model.Company;
import info.movito.themoviedbapi.model.core.image.LogoImage;
import info.movito.themoviedbapi.model.core.image.LogoImageResults;
import info.movito.themoviedbapi.model.core.image.Image;
import info.movito.themoviedbapi.model.core.image.ImageResults;
import info.movito.themoviedbapi.tools.RequestType;
import info.movito.themoviedbapi.tools.TmdbException;
import info.movito.themoviedbapi.util.TestUtils;
Expand Down Expand Up @@ -72,12 +72,12 @@ public void testGetImages() throws IOException, TmdbException {
when(getTmdbUrlReader().readUrl(url, null, RequestType.GET)).thenReturn(body);

TmdbCompanies tmdbCompanies = getTmdbApi().getCompanies();
LogoImageResults logoImageResults = tmdbCompanies.getImages(1);
ImageResults logoImageResults = tmdbCompanies.getImages(1);
assertNotNull(logoImageResults);
testForNullFieldsAndNewItems(logoImageResults);

LogoImage logoImage = logoImageResults.getLogos().get(0);
assertNotNull(logoImage);
testForNullFieldsAndNewItems(logoImage);
Image image = logoImageResults.getLogos().get(0);
assertNotNull(image);
testForNullFieldsAndNewItems(image);
}
}
88 changes: 88 additions & 0 deletions src/test/java/info/movito/themoviedbapi/TmdbNetworksTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package info.movito.themoviedbapi;

import info.movito.themoviedbapi.model.AlternativeName;
import info.movito.themoviedbapi.model.core.image.Image;
import info.movito.themoviedbapi.model.core.image.ImageResults;
import info.movito.themoviedbapi.model.networks.AlternativeNamesResults;
import info.movito.themoviedbapi.model.networks.Network;
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 java.util.List;

import static info.movito.themoviedbapi.TmdbNetworks.TMDB_METHOD_NETWORK;
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.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.when;

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

TmdbNetworks tmdbNetworks = getTmdbApi().getNetworks();
Network network = tmdbNetworks.getDetails(1);
assertNotNull(network);
testForNullFieldsAndNewItems(network);
}

/**
* Tests the {@link TmdbNetworks#getAlternativeNames(int)} with an expected result.
*/
@Test
public void testGetAlternativeNames() throws TmdbException, IOException {
String body = TestUtils.readTestFile("api_responses/networks/alternative_names.json");
URL url = new URL(TMDB_API_BASE_URL + TMDB_METHOD_NETWORK + "/1/alternative_names");
when(getTmdbUrlReader().readUrl(url, null, RequestType.GET)).thenReturn(body);

TmdbNetworks tmdbNetworks = getTmdbApi().getNetworks();
AlternativeNamesResults alternativeNamesResults = tmdbNetworks.getAlternativeNames(1);
assertNotNull(alternativeNamesResults);
testForNullFieldsAndNewItems(alternativeNamesResults);

List<AlternativeName> alternativeNames = alternativeNamesResults.getResults();
assertNotNull(alternativeNames);
assertFalse(alternativeNames.isEmpty());

AlternativeName alternativeName = alternativeNames.get(0);
assertNotNull(alternativeName);
testForNullFieldsAndNewItems(alternativeName);
}

/**
* Tests the {@link TmdbNetworks#getImages(int)} with an expected result.
*/
@Test
public void testGetImages() throws TmdbException, IOException {
String body = TestUtils.readTestFile("api_responses/networks/images.json");
URL url = new URL(TMDB_API_BASE_URL + TMDB_METHOD_NETWORK + "/1/images");
when(getTmdbUrlReader().readUrl(url, null, RequestType.GET)).thenReturn(body);

TmdbNetworks tmdbNetworks = getTmdbApi().getNetworks();
ImageResults imageResults = tmdbNetworks.getImages(1);
assertNotNull(imageResults);
testForNullFieldsAndNewItems(imageResults);

List<Image> images = imageResults.getLogos();
assertNotNull(images);
assertFalse(images.isEmpty());

Image image = images.get(0);
assertNotNull(image);
testForNullFieldsAndNewItems(image);
}
}
13 changes: 13 additions & 0 deletions src/test/resources/api_responses/networks/alternative_names.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"id": 49,
"results": [
{
"name": "Home Box Office",
"type": "programming block"
},
{
"name": "HBO HD",
"type": "programming block"
}
]
}
8 changes: 8 additions & 0 deletions src/test/resources/api_responses/networks/details.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"headquarters": "New York City, New York",
"homepage": "https://www.hbo.com",
"id": 49,
"logo_path": "/tuomPhY2UtuPTqqFnKMVHvSb724.png",
"name": "HBO",
"origin_country": "US"
}
25 changes: 25 additions & 0 deletions src/test/resources/api_responses/networks/images.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"id": 49,
"logos": [
{
"aspect_ratio": 2.425287356321839,
"file_path": "/tuomPhY2UtuPTqqFnKMVHvSb724.png",
"height": 174,
"id": "5a7a67a40e0a26020a000091",
"file_type": ".svg",
"vote_average": 5.318,
"vote_count": 3,
"width": 422
},
{
"aspect_ratio": 2.424242424242424,
"file_path": "/hizvY65SpyF3BPY2qsBZMgUOxjs.png",
"height": 495,
"id": "63e7979663aad200858726da",
"file_type": ".png",
"vote_average": 5.312,
"vote_count": 1,
"width": 1200
}
]
}
Loading