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

Certifications api #158

Merged
merged 3 commits into from
Jan 21, 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
23 changes: 13 additions & 10 deletions src/main/java/info/movito/themoviedbapi/TmdbApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
public class TmdbApi {
/**
* Http client to make requests to the movie database api.
* can make certain things static if necessary
*/
@Getter(AccessLevel.PROTECTED)
private final TmdbUrlReader tmdbUrlReader;
Expand All @@ -41,15 +40,18 @@ public TmdbApi(TmdbUrlReader tmdbUrlReader) {
this.tmdbUrlReader = tmdbUrlReader;
}

@SuppressWarnings("checkstyle:MissingJavadocMethod")
public List<Timezone> getTimezones() throws TmdbException {
return new TmdbTimezones(this).getTimezones();
}

public TmdbAccount getAccount() {
return new TmdbAccount(this);
}

public TmdbAuthentication getAuthentication() {
return new TmdbAuthentication(this);
}

public TmdbCertifications getCertifications() {
return new TmdbCertifications(this);
}

public TmdbConfiguration getConfiguration() {
return new TmdbConfiguration(this);
}
Expand Down Expand Up @@ -82,10 +84,6 @@ public TmdbPeople getPeople() {
return new TmdbPeople(this);
}

public TmdbAuthentication getAuthentication() {
return new TmdbAuthentication(this);
}

public TmdbChanges getChanges() {
return new TmdbChanges(this);
}
Expand Down Expand Up @@ -117,4 +115,9 @@ public TmdbTvEpisodes getTvEpisodes() {
public TmdbFind getFind() {
return new TmdbFind(this);
}

@SuppressWarnings("checkstyle:MissingJavadocMethod")
public List<Timezone> getTimezones() throws TmdbException {
return new TmdbTimezones(this).getTimezones();
}
}
45 changes: 45 additions & 0 deletions src/main/java/info/movito/themoviedbapi/TmdbCertifications.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package info.movito.themoviedbapi;

import info.movito.themoviedbapi.model.certifications.CertificationResults;
import info.movito.themoviedbapi.tools.ApiUrl;
import info.movito.themoviedbapi.tools.TmdbException;

/**
* The movie database api for certifications. See the
* <a href="https://developer.themoviedb.org/reference/certification-movie-list">documentation</a> for more info.
*/
public class TmdbCertifications extends AbstractTmdbApi {
protected static final String TMDB_METHOD_CERTIFICATIONS = "certification";

protected static final String TMDB_METHOD_MOVIE_CERTIFICATIONS = "movie/list";

protected static final String TMDB_METHOD_TV_CERTIFICATIONS = "tv/list";

TmdbCertifications(TmdbApi tmdbApi) {
super(tmdbApi);
}

/**
* <p>Get an up to date list of the officially supported movie certifications on TMDB.</p>
* <p>See the <a href="https://developer.themoviedb.org/reference/certification-movie-list">documentation</a> for more info.</p>
*
* @return The movie certifications.
* @throws TmdbException If there was an error making the request or mapping the response.
*/
public CertificationResults getMovieCertifications() throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_CERTIFICATIONS, TMDB_METHOD_MOVIE_CERTIFICATIONS);
return mapJsonResult(apiUrl, CertificationResults.class);
}

/**
* <p>Get an up to date list of the officially supported tv certifications on TMDB.</p>
* <p>See the <a href="https://developer.themoviedb.org/reference/certifications-tv-list">documentation</a> for more info.</p>
*
* @return The tv certifications.
* @throws TmdbException If there was an error making the request or mapping the response.
*/
public CertificationResults getTvCertifications() throws TmdbException {
ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_CERTIFICATIONS, TMDB_METHOD_TV_CERTIFICATIONS);
return mapJsonResult(apiUrl, CertificationResults.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package info.movito.themoviedbapi.model.certifications;

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

@Data
@EqualsAndHashCode(callSuper = false)
public class Certification extends AbstractJsonMapping {
@JsonProperty("certification")
private String certification;

@JsonProperty("meaning")
private String meaning;

@JsonProperty("order")
private Integer order;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package info.movito.themoviedbapi.model.certifications;

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

import java.util.List;
import java.util.Map;

@Data
@EqualsAndHashCode(callSuper = false)
public class CertificationResults extends AbstractJsonMapping {
@JsonProperty("certifications")
private Map<String, List<Certification>> certifications;
}
2 changes: 2 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
opens info.movito.themoviedbapi.model to com.fasterxml.jackson.databind;
opens info.movito.themoviedbapi.model.account to com.fasterxml.jackson.databind;
opens info.movito.themoviedbapi.model.authentication to com.fasterxml.jackson.databind;
opens info.movito.themoviedbapi.model.certifications to com.fasterxml.jackson.databind;
opens info.movito.themoviedbapi.model.changes to com.fasterxml.jackson.databind;
opens info.movito.themoviedbapi.model.config to com.fasterxml.jackson.databind; // todo: remove
opens info.movito.themoviedbapi.model.configuration to com.fasterxml.jackson.databind;
Expand All @@ -31,6 +32,7 @@
exports info.movito.themoviedbapi.model;
exports info.movito.themoviedbapi.model.account;
exports info.movito.themoviedbapi.model.authentication;
exports info.movito.themoviedbapi.model.certifications;
exports info.movito.themoviedbapi.model.changes;
exports info.movito.themoviedbapi.model.config;
exports info.movito.themoviedbapi.model.configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package info.movito.themoviedbapi;

import info.movito.themoviedbapi.model.certifications.Certification;
import info.movito.themoviedbapi.model.certifications.CertificationResults;
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 java.util.Map;

import static info.movito.themoviedbapi.TmdbCertifications.TMDB_METHOD_CERTIFICATIONS;
import static info.movito.themoviedbapi.TmdbCertifications.TMDB_METHOD_MOVIE_CERTIFICATIONS;
import static info.movito.themoviedbapi.TmdbCertifications.TMDB_METHOD_TV_CERTIFICATIONS;
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 TmdbCertifications}.
*/
public class TmdbCertificationsTest extends AbstractTmdbApiTest {
/**
* Test {@link TmdbCertifications#getMovieCertifications()} with an expected result.
*/
@Test
public void testGetMovieCertifications() throws IOException, TmdbException {
String body = TestUtils.readTestFile("api_responses/certifications/movie.json");
URL url = new URL(TMDB_API_BASE_URL + TMDB_METHOD_CERTIFICATIONS + "/" + TMDB_METHOD_MOVIE_CERTIFICATIONS);
when(getTmdbUrlReader().readUrl(url, null, RequestType.GET)).thenReturn(body);

TmdbCertifications tmdbCertifications = getTmdbApi().getCertifications();
CertificationResults movieCertifications = tmdbCertifications.getMovieCertifications();
assertNotNull(movieCertifications);
testForNullFieldsAndNewItems(movieCertifications);

Map<String, List<Certification>> certifications = movieCertifications.getCertifications();
assertFalse(certifications.isEmpty());

List<Certification> auCertifications = certifications.get("AU");
assertFalse(auCertifications.isEmpty());

Certification auCertification = auCertifications.get(0);
assertNotNull(auCertification);
testForNullFieldsAndNewItems(auCertification);
}

/**
* Test {@link TmdbCertifications#getTvCertifications()} with an expected result.
*/
@Test
public void testGetTvCertifications() throws IOException, TmdbException {
String body = TestUtils.readTestFile("api_responses/certifications/tv.json");
URL url = new URL(TMDB_API_BASE_URL + TMDB_METHOD_CERTIFICATIONS + "/" + TMDB_METHOD_TV_CERTIFICATIONS);
when(getTmdbUrlReader().readUrl(url, null, RequestType.GET)).thenReturn(body);

TmdbCertifications tmdbCertifications = getTmdbApi().getCertifications();
CertificationResults tvCertifications = tmdbCertifications.getTvCertifications();
assertNotNull(tvCertifications);
testForNullFieldsAndNewItems(tvCertifications);

Map<String, List<Certification>> certifications = tvCertifications.getCertifications();
assertFalse(certifications.isEmpty());

List<Certification> auCertifications = certifications.get("AU");
assertFalse(auCertifications.isEmpty());

Certification auCertification = auCertifications.get(0);
assertNotNull(auCertification);
testForNullFieldsAndNewItems(auCertification);
}
}
Loading