-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from c-eg/companies-api
Companies api
- Loading branch information
Showing
14 changed files
with
300 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/main/java/info/movito/themoviedbapi/TmdbCompanies.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
* <a href="https://developer.themoviedb.org/reference/company-details">documentation</a> 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); | ||
} | ||
|
||
/** | ||
* <p>Get the company details by ID.</p> | ||
* <p>See the <a href="https://developer.themoviedb.org/reference/company-details">documentation</a> for more info.</p> | ||
* | ||
* @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); | ||
} | ||
|
||
/** | ||
* <p>Gets the alternative company names by ID.</p> | ||
* <p>See the <a href="https://developer.themoviedb.org/reference/company-alternative-names">documentation</a> for more info.</p> | ||
* | ||
* @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); | ||
} | ||
|
||
/** | ||
* <p>Get the company logos by ID.</p> | ||
* <p>See the <a href="https://developer.themoviedb.org/reference/company-images">documentation</a> for more info.</p> | ||
* | ||
* @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<AlternativeName> { } | ||
} |
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
src/main/java/info/movito/themoviedbapi/model/AlternativeName.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/info/movito/themoviedbapi/model/core/Results.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<T> extends IdElement implements Iterable<T> { | ||
@JsonProperty("results") | ||
private List<T> results; | ||
|
||
@Override | ||
public Iterator<T> iterator() { | ||
return results.iterator(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/info/movito/themoviedbapi/model/core/image/LogoImage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/info/movito/themoviedbapi/model/core/image/LogoImageResults.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<LogoImage> logos; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/test/java/info/movito/themoviedbapi/TmdbCompaniesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/resources/api_responses/companies/alternative_names.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"id": 1, | ||
"results": [ | ||
{ | ||
"name": "루카스필름", | ||
"type": "" | ||
}, | ||
{ | ||
"name": "Lucasfilm Limited, LLC", | ||
"type": "" | ||
}, | ||
{ | ||
"name": "Lucasfilm Ltd. LLC", | ||
"type": "" | ||
}, | ||
{ | ||
"name": "Lucasfilm", | ||
"type": "" | ||
} | ||
] | ||
} |
Oops, something went wrong.