From d9c2ac6a61b9ff79205bdcaadd94d97e72a1fb6b Mon Sep 17 00:00:00 2001
From: Conor Egan <68134729+c-eg@users.noreply.github.com>
Date: Sat, 27 Jan 2024 02:32:13 +0000
Subject: [PATCH 1/2] update companies api
---
.../info/movito/themoviedbapi/TmdbApi.java | 4 +-
.../movito/themoviedbapi/TmdbCompanies.java | 65 +++++++++++++++++++
.../movito/themoviedbapi/TmdbCompany.java | 52 ---------------
.../themoviedbapi/model/AlternativeName.java | 16 +++++
.../movito/themoviedbapi/model/Company.java | 19 ++----
.../themoviedbapi/model/core/Results.java | 20 ++++++
.../themoviedbapi/model/core/ResultsPage.java | 21 ++----
.../model/core/image/LogoImage.java | 31 +++++++++
.../model/core/image/LogoImageResults.java | 15 +++++
src/main/java/module-info.java | 2 +
10 files changed, 161 insertions(+), 84 deletions(-)
create mode 100644 src/main/java/info/movito/themoviedbapi/TmdbCompanies.java
delete mode 100644 src/main/java/info/movito/themoviedbapi/TmdbCompany.java
create mode 100644 src/main/java/info/movito/themoviedbapi/model/AlternativeName.java
create mode 100644 src/main/java/info/movito/themoviedbapi/model/core/Results.java
create mode 100644 src/main/java/info/movito/themoviedbapi/model/core/image/LogoImage.java
create mode 100644 src/main/java/info/movito/themoviedbapi/model/core/image/LogoImageResults.java
diff --git a/src/main/java/info/movito/themoviedbapi/TmdbApi.java b/src/main/java/info/movito/themoviedbapi/TmdbApi.java
index d013012c..d71c78d6 100644
--- a/src/main/java/info/movito/themoviedbapi/TmdbApi.java
+++ b/src/main/java/info/movito/themoviedbapi/TmdbApi.java
@@ -60,8 +60,8 @@ public TmdbCollections getCollections() {
return new TmdbCollections(this);
}
- public TmdbCompany getCompany() {
- return new TmdbCompany(this);
+ public TmdbCompanies getCompanies() {
+ return new TmdbCompanies(this);
}
public TmdbConfiguration getConfiguration() {
diff --git a/src/main/java/info/movito/themoviedbapi/TmdbCompanies.java b/src/main/java/info/movito/themoviedbapi/TmdbCompanies.java
new file mode 100644
index 00000000..98f576fd
--- /dev/null
+++ b/src/main/java/info/movito/themoviedbapi/TmdbCompanies.java
@@ -0,0 +1,65 @@
+package info.movito.themoviedbapi;
+
+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.tools.ApiUrl;
+import info.movito.themoviedbapi.tools.TmdbException;
+
+/**
+ * The movie database api for companies. See the
+ * documentation for more info.
+ */
+public class TmdbCompanies extends AbstractTmdbApi {
+ protected static final String TMDB_METHOD_COMPANY = "company";
+
+ /**
+ * Create a new TmdbCompany instance to call the company related TMDb API methods.
+ */
+ TmdbCompanies(TmdbApi tmdbApi) {
+ super(tmdbApi);
+ }
+
+ /**
+ *
Get the company details by ID.
+ * See the documentation for more info.
+ *
+ * @param companyId The company ID
+ * @return The company details
+ * @throws TmdbException If there was an error making the request or mapping the response.
+ */
+ public Company getDetails(Integer companyId) throws TmdbException {
+ ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_COMPANY, companyId);
+ return mapJsonResult(apiUrl, Company.class);
+ }
+
+ /**
+ * Gets the alternative company names by ID.
+ * See the documentation for more info.
+ *
+ * @param companyId The company ID
+ * @return The alternative company names
+ * @throws TmdbException If there was an error making the request or mapping the response.
+ */
+ public AlternativeNamesResultsPage getAlternativeNames(Integer companyId) throws TmdbException {
+ ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_COMPANY, companyId, "alternative_names");
+ return mapJsonResult(apiUrl, AlternativeNamesResultsPage.class);
+ }
+
+ /**
+ * Get the company logos by ID.
+ * See the documentation for more info.
+ *
+ * @param companyId The company ID
+ * @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 {
+ ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_COMPANY, companyId, "images");
+ return mapJsonResult(apiUrl, LogoImageResults.class);
+ }
+
+ @SuppressWarnings("checkstyle:MissingJavadocType")
+ public static class AlternativeNamesResultsPage extends ResultsPage { }
+}
diff --git a/src/main/java/info/movito/themoviedbapi/TmdbCompany.java b/src/main/java/info/movito/themoviedbapi/TmdbCompany.java
deleted file mode 100644
index 74967ba7..00000000
--- a/src/main/java/info/movito/themoviedbapi/TmdbCompany.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package info.movito.themoviedbapi;
-
-import info.movito.themoviedbapi.model.Collection;
-import info.movito.themoviedbapi.model.Company;
-import info.movito.themoviedbapi.model.core.ResultsPage;
-import info.movito.themoviedbapi.tools.ApiUrl;
-import info.movito.themoviedbapi.tools.TmdbException;
-
-/**
- * The movie database api for companies. See the
- * documentation for more info.
- */
-public class TmdbCompany extends AbstractTmdbApi {
- public static final String TMDB_METHOD_COMPANY = "company";
-
- /**
- * Create a new TmdbCompany instance to call the company related TMDb API methods.
- */
- TmdbCompany(TmdbApi tmdbApi) {
- super(tmdbApi);
- }
-
- /**
- * This method is used to retrieve the basic information about a production company on TMDb.
- */
- public Company getCompanyInfo(int companyId) throws TmdbException {
- ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_COMPANY, companyId);
-
- return mapJsonResult(apiUrl, Company.class);
- }
-
- /**
- * This method is used to retrieve the movies associated with a company.
- *
- * These movies are returned in order of most recently released to oldest. The default response will return 20
- */
- public CollectionResultsPage getCompanyMovies(int companyId, String language, Integer page) throws TmdbException {
- ApiUrl apiUrl = new ApiUrl(TMDB_METHOD_COMPANY, companyId, "movies");
-
- apiUrl.addLanguage(language);
- apiUrl.addPage(page);
-
- return mapJsonResult(apiUrl, CollectionResultsPage.class);
- }
-
- /**
- * Collection Results Page.
- */
- public static class CollectionResultsPage extends ResultsPage {
-
- }
-}
diff --git a/src/main/java/info/movito/themoviedbapi/model/AlternativeName.java b/src/main/java/info/movito/themoviedbapi/model/AlternativeName.java
new file mode 100644
index 00000000..1ed5471b
--- /dev/null
+++ b/src/main/java/info/movito/themoviedbapi/model/AlternativeName.java
@@ -0,0 +1,16 @@
+package info.movito.themoviedbapi.model;
+
+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 AlternativeName extends AbstractJsonMapping {
+ @JsonProperty("name")
+ private String name;
+
+ @JsonProperty("type")
+ private String type;
+}
diff --git a/src/main/java/info/movito/themoviedbapi/model/Company.java b/src/main/java/info/movito/themoviedbapi/model/Company.java
index bbfd9d5e..5c4f2759 100644
--- a/src/main/java/info/movito/themoviedbapi/model/Company.java
+++ b/src/main/java/info/movito/themoviedbapi/model/Company.java
@@ -20,19 +20,10 @@ public class Company extends NamedIdElement {
@JsonProperty("logo_path")
private String logoPath;
- // TODO: is this field still supported? We need an example for info.movito.themoviedbapi.CompanyApiTest.testGetCompanyInfo
+ @JsonProperty("origin_country")
+ private String originCountry;
+
@JsonProperty("parent_company")
- private Company parentCompany;
-
- /**
- * Sets the parent company.
- */
- public void setParentCompany(int id, String name, String logoPath) {
- Company parent = new Company();
- parent.setId(id);
- parent.setName(name);
- parent.setLogoPath(logoPath);
-
- this.parentCompany = parent;
- }
+ private Integer parentCompanyId;
}
+
diff --git a/src/main/java/info/movito/themoviedbapi/model/core/Results.java b/src/main/java/info/movito/themoviedbapi/model/core/Results.java
new file mode 100644
index 00000000..55b57e21
--- /dev/null
+++ b/src/main/java/info/movito/themoviedbapi/model/core/Results.java
@@ -0,0 +1,20 @@
+package info.movito.themoviedbapi.model.core;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.Iterator;
+import java.util.List;
+
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class Results extends IdElement implements Iterable {
+ @JsonProperty("results")
+ private List results;
+
+ @Override
+ public Iterator iterator() {
+ return results.iterator();
+ }
+}
diff --git a/src/main/java/info/movito/themoviedbapi/model/core/ResultsPage.java b/src/main/java/info/movito/themoviedbapi/model/core/ResultsPage.java
index 90e3cfd4..fcf0fb6c 100644
--- a/src/main/java/info/movito/themoviedbapi/model/core/ResultsPage.java
+++ b/src/main/java/info/movito/themoviedbapi/model/core/ResultsPage.java
@@ -4,26 +4,15 @@
import lombok.Data;
import lombok.EqualsAndHashCode;
-import java.util.Iterator;
-import java.util.List;
-
@Data
-@EqualsAndHashCode(callSuper = false)
-public class ResultsPage extends AbstractJsonMapping implements Iterable {
- @JsonProperty("results")
- private List results;
-
+@EqualsAndHashCode(callSuper = true)
+public class ResultsPage extends Results {
@JsonProperty("page")
- private int page;
+ private Integer page;
@JsonProperty("total_pages")
- private int totalPages;
+ private Integer totalPages;
@JsonProperty("total_results")
- private int totalResults;
-
- @Override
- public Iterator iterator() {
- return results.iterator();
- }
+ private Integer totalResults;
}
diff --git a/src/main/java/info/movito/themoviedbapi/model/core/image/LogoImage.java b/src/main/java/info/movito/themoviedbapi/model/core/image/LogoImage.java
new file mode 100644
index 00000000..3123cfde
--- /dev/null
+++ b/src/main/java/info/movito/themoviedbapi/model/core/image/LogoImage.java
@@ -0,0 +1,31 @@
+package info.movito.themoviedbapi.model.core.image;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import info.movito.themoviedbapi.model.core.StringIdElement;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class LogoImage extends StringIdElement {
+ @JsonProperty("aspect_ratio")
+ private Double aspectRatio;
+
+ @JsonProperty("file_path")
+ private String filePath;
+
+ @JsonProperty("height")
+ private Integer height;
+
+ @JsonProperty("file_type")
+ private String fileType;
+
+ @JsonProperty("vote_average")
+ private Double voteAverage;
+
+ @JsonProperty("vote_count")
+ private Integer voteCount;
+
+ @JsonProperty("width")
+ private Integer width;
+}
diff --git a/src/main/java/info/movito/themoviedbapi/model/core/image/LogoImageResults.java b/src/main/java/info/movito/themoviedbapi/model/core/image/LogoImageResults.java
new file mode 100644
index 00000000..c60e6d16
--- /dev/null
+++ b/src/main/java/info/movito/themoviedbapi/model/core/image/LogoImageResults.java
@@ -0,0 +1,15 @@
+package info.movito.themoviedbapi.model.core.image;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import info.movito.themoviedbapi.model.core.IdElement;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.util.List;
+
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class LogoImageResults extends IdElement {
+ @JsonProperty("logos")
+ private List logos;
+}
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java
index 44da61af..285f6114 100644
--- a/src/main/java/module-info.java
+++ b/src/main/java/module-info.java
@@ -18,6 +18,7 @@
opens info.movito.themoviedbapi.model.config to com.fasterxml.jackson.databind; // todo: remove
opens info.movito.themoviedbapi.model.configuration to com.fasterxml.jackson.databind;
opens info.movito.themoviedbapi.model.core to com.fasterxml.jackson.databind;
+ opens info.movito.themoviedbapi.model.core.image to com.fasterxml.jackson.databind;
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;
@@ -38,6 +39,7 @@
exports info.movito.themoviedbapi.model.config;
exports info.movito.themoviedbapi.model.configuration;
exports info.movito.themoviedbapi.model.core;
+ exports info.movito.themoviedbapi.model.core.image;
exports info.movito.themoviedbapi.model.core.responses;
exports info.movito.themoviedbapi.model.keywords;
exports info.movito.themoviedbapi.model.movies.changes;
From fac92e16462be8247aae337f1081812c3e914142 Mon Sep 17 00:00:00 2001
From: Conor Egan <68134729+c-eg@users.noreply.github.com>
Date: Sat, 27 Jan 2024 02:32:19 +0000
Subject: [PATCH 2/2] test companies api
---
.../themoviedbapi/TmdbCompaniesTest.java | 83 +++++++++++++++++++
.../companies/alternative_names.json | 21 +++++
.../api_responses/companies/details.json | 10 +++
.../api_responses/companies/images.json | 25 ++++++
4 files changed, 139 insertions(+)
create mode 100644 src/test/java/info/movito/themoviedbapi/TmdbCompaniesTest.java
create mode 100644 src/test/resources/api_responses/companies/alternative_names.json
create mode 100644 src/test/resources/api_responses/companies/details.json
create mode 100644 src/test/resources/api_responses/companies/images.json
diff --git a/src/test/java/info/movito/themoviedbapi/TmdbCompaniesTest.java b/src/test/java/info/movito/themoviedbapi/TmdbCompaniesTest.java
new file mode 100644
index 00000000..0710bd47
--- /dev/null
+++ b/src/test/java/info/movito/themoviedbapi/TmdbCompaniesTest.java
@@ -0,0 +1,83 @@
+package info.movito.themoviedbapi;
+
+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.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.TmdbCompanies.TMDB_METHOD_COMPANY;
+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 TmdbCompanies}.
+ */
+public class TmdbCompaniesTest extends AbstractTmdbApiTest {
+ /**
+ * Tests {@link TmdbCompanies#getDetails(Integer)}.
+ */
+ @Test
+ public void testGetDetails() throws IOException, TmdbException {
+ int companyId = 1;
+
+ String body = TestUtils.readTestFile("api_responses/companies/details.json");
+ URL url = new URL(TMDB_API_BASE_URL + TMDB_METHOD_COMPANY + "/" + companyId);
+ when(getTmdbUrlReader().readUrl(url, null, RequestType.GET)).thenReturn(body);
+
+ TmdbCompanies tmdbCompanies = getTmdbApi().getCompanies();
+ Company company = tmdbCompanies.getDetails(companyId);
+ assertNotNull(company);
+ testForNullFieldsAndNewItems(company);
+ }
+
+ /**
+ * Tests {@link TmdbCompanies#getAlternativeNames(Integer)}.
+ */
+ @Test
+ public void testGetAlternativeNames() throws IOException, TmdbException {
+ int companyId = 1;
+
+ String body = TestUtils.readTestFile("api_responses/companies/alternative_names.json");
+ URL url = new URL(TMDB_API_BASE_URL + TMDB_METHOD_COMPANY + "/" + companyId + "/alternative_names");
+ when(getTmdbUrlReader().readUrl(url, null, RequestType.GET)).thenReturn(body);
+
+ TmdbCompanies tmdbCompanies = getTmdbApi().getCompanies();
+ TmdbCompanies.AlternativeNamesResultsPage alternativeNamesResultsPage = tmdbCompanies.getAlternativeNames(1);
+ assertNotNull(alternativeNamesResultsPage);
+ testForNullFieldsAndNewItems(alternativeNamesResultsPage);
+
+ AlternativeName alternativeName = alternativeNamesResultsPage.getResults().get(0);
+ assertNotNull(alternativeName);
+ testForNullFieldsAndNewItems(alternativeName);
+ }
+
+ /**
+ * Tests {@link TmdbCompanies#getImages(Integer)}.
+ */
+ @Test
+ public void testGetImages() throws IOException, TmdbException {
+ int companyId = 1;
+
+ String body = TestUtils.readTestFile("api_responses/companies/images.json");
+ URL url = new URL(TMDB_API_BASE_URL + TMDB_METHOD_COMPANY + "/" + companyId + "/images");
+ when(getTmdbUrlReader().readUrl(url, null, RequestType.GET)).thenReturn(body);
+
+ TmdbCompanies tmdbCompanies = getTmdbApi().getCompanies();
+ LogoImageResults logoImageResults = tmdbCompanies.getImages(1);
+ assertNotNull(logoImageResults);
+ testForNullFieldsAndNewItems(logoImageResults);
+
+ LogoImage logoImage = logoImageResults.getLogos().get(0);
+ assertNotNull(logoImage);
+ testForNullFieldsAndNewItems(logoImage);
+ }
+}
diff --git a/src/test/resources/api_responses/companies/alternative_names.json b/src/test/resources/api_responses/companies/alternative_names.json
new file mode 100644
index 00000000..e514739c
--- /dev/null
+++ b/src/test/resources/api_responses/companies/alternative_names.json
@@ -0,0 +1,21 @@
+{
+ "id": 1,
+ "results": [
+ {
+ "name": "루카스필름",
+ "type": ""
+ },
+ {
+ "name": "Lucasfilm Limited, LLC",
+ "type": ""
+ },
+ {
+ "name": "Lucasfilm Ltd. LLC",
+ "type": ""
+ },
+ {
+ "name": "Lucasfilm",
+ "type": ""
+ }
+ ]
+}
\ No newline at end of file
diff --git a/src/test/resources/api_responses/companies/details.json b/src/test/resources/api_responses/companies/details.json
new file mode 100644
index 00000000..47be5f79
--- /dev/null
+++ b/src/test/resources/api_responses/companies/details.json
@@ -0,0 +1,10 @@
+{
+ "description": "",
+ "headquarters": "San Francisco, California",
+ "homepage": "https://www.lucasfilm.com",
+ "id": 1,
+ "logo_path": "/o86DbpburjxrqAzEDhXZcyE8pDb.png",
+ "name": "Lucasfilm Ltd.",
+ "origin_country": "US",
+ "parent_company": 2
+}
\ No newline at end of file
diff --git a/src/test/resources/api_responses/companies/images.json b/src/test/resources/api_responses/companies/images.json
new file mode 100644
index 00000000..6a792a8d
--- /dev/null
+++ b/src/test/resources/api_responses/companies/images.json
@@ -0,0 +1,25 @@
+{
+ "id": 1,
+ "logos": [
+ {
+ "aspect_ratio": 2.97979797979798,
+ "file_path": "/o86DbpburjxrqAzEDhXZcyE8pDb.png",
+ "height": 99,
+ "id": "5aa080d6c3a3683fea00011e",
+ "file_type": ".svg",
+ "vote_average": 5.384,
+ "vote_count": 2,
+ "width": 295
+ },
+ {
+ "aspect_ratio": 3.03951367781155,
+ "file_path": "/tlVSws0RvvtPBwViUyOFAO0vcQS.png",
+ "height": 329,
+ "id": "63306b352b8a430096598b3d",
+ "file_type": ".svg",
+ "vote_average": 5.312,
+ "vote_count": 1,
+ "width": 1000
+ }
+ ]
+}
\ No newline at end of file