Skip to content

Commit 0043e43

Browse files
authored
Merge pull request #232 from SosthenG/movie-external-ids
Add movie external_ids
2 parents 0335d97 + d5af888 commit 0043e43

File tree

8 files changed

+91
-1
lines changed

8 files changed

+91
-1
lines changed

lib/Tmdb/Api/Movies.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,17 @@ public function getVideos($movie_id, array $parameters = [], array $headers = []
295295
{
296296
return $this->get('movie/' . $movie_id . '/videos', $parameters, $headers);
297297
}
298+
299+
/**
300+
* Get the external ids that we have stored for a movie.
301+
*
302+
* @param $movie_id
303+
* @param array $parameters
304+
* @param array $headers
305+
* @return mixed
306+
*/
307+
public function getExternalIds($movie_id, array $parameters = [], array $headers = [])
308+
{
309+
return $this->get('movie/' . $movie_id . '/external_ids', $parameters, $headers);
310+
}
298311
}

lib/Tmdb/Factory/MovieFactory.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Tmdb\HttpClient\HttpClient;
2323
use Tmdb\Model\AbstractModel;
2424
use Tmdb\Model\Common\Country;
25+
use Tmdb\Model\Common\ExternalIds;
2526
use Tmdb\Model\Common\GenericCollection;
2627
use Tmdb\Model\Common\SpokenLanguage;
2728
use Tmdb\Model\Common\Translation;
@@ -146,6 +147,13 @@ public function create(array $data = []): ?AbstractModel
146147
}
147148
}
148149

150+
/** External ids */
151+
if (array_key_exists('external_ids', $data)) {
152+
$movie->setExternalIds(
153+
$this->hydrate(new ExternalIds(), $data['external_ids'])
154+
);
155+
}
156+
149157
/** Genres */
150158
if (array_key_exists('genres', $data)) {
151159
$movie->setGenres($this->getGenreFactory()->createCollection($data['genres']));

lib/Tmdb/Model/Movie.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Tmdb\Model\Collection\ResultCollection;
2222
use Tmdb\Model\Collection\Videos;
2323
use Tmdb\Model\Common\Country;
24+
use Tmdb\Model\Common\ExternalIds;
2425
use Tmdb\Model\Common\GenericCollection;
2526
use Tmdb\Model\Common\SpokenLanguage;
2627
use Tmdb\Model\Movie\AlternativeTitle;
@@ -76,6 +77,12 @@ class Movie extends AbstractModel
7677
* @var CreditsCollection
7778
*/
7879
protected $credits;
80+
/**
81+
* External Ids
82+
*
83+
* @var ExternalIds
84+
*/
85+
private $externalIds;
7986
/**
8087
* Images
8188
*
@@ -238,6 +245,7 @@ public function __construct()
238245
$this->alternativeTitles = new GenericCollection();
239246
$this->changes = new GenericCollection();
240247
$this->credits = new CreditsCollection();
248+
$this->externalIds = new ExternalIds();
241249
$this->images = new Images();
242250
$this->keywords = new GenericCollection();
243251
$this->lists = new GenericCollection();
@@ -785,6 +793,26 @@ public function setCredits(CreditsCollection $credits)
785793
return $this;
786794
}
787795

796+
/**
797+
* @return ExternalIds
798+
*/
799+
public function getExternalIds()
800+
{
801+
return $this->externalIds;
802+
}
803+
804+
/**
805+
* @param ExternalIds $externalIds
806+
* @return $this
807+
*/
808+
public function setExternalIds($externalIds)
809+
{
810+
$this->externalIds = $externalIds;
811+
812+
return $this;
813+
}
814+
815+
788816
/**
789817
* @return GenericCollection|Keyword[]
790818
*/

lib/Tmdb/Model/Movie/QueryParameter/AppendToResponse.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
final class AppendToResponse extends BaseAppendToResponse
2424
{
2525
public const ALTERNATIVE_TITLES = 'alternative_titles';
26+
public const EXTERNAL_IDS = 'external_ids';
2627
public const CREDITS = 'credits';
2728
public const IMAGES = 'images';
2829
public const KEYWORDS = 'keywords';

lib/Tmdb/Repository/MovieRepository.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public function load($id, array $parameters = [], array $headers = [])
7070
$parameters = array_merge($parameters, [
7171
new AppendToResponse([
7272
AppendToResponse::ALTERNATIVE_TITLES,
73+
AppendToResponse::EXTERNAL_IDS,
7374
AppendToResponse::CHANGES,
7475
AppendToResponse::CREDITS,
7576
AppendToResponse::IMAGES,
@@ -453,6 +454,22 @@ public function getVideos($id, array $parameters = [], array $headers = [])
453454
return $movie->getVideos();
454455
}
455456

457+
/**
458+
* Get the external ids that we have stored for a movie.
459+
*
460+
* @param $id
461+
* @param $parameters
462+
* @param $headers
463+
* @return null|AbstractModel
464+
*/
465+
public function getExternalIds($id, array $parameters = [], array $headers = [])
466+
{
467+
$data = $this->getApi()->getExternalIds($id, $this->parseQueryParameters($parameters), $headers);
468+
$movie = $this->getFactory()->create(['external_ids' => $data]);
469+
470+
return $movie->getExternalIds();
471+
}
472+
456473
/**
457474
* @return AlternativeTitleFactory
458475
*/

test/Tmdb/Tests/Api/MoviesTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ public function shouldGetAlternativeTitles()
4040
$this->assertLastRequestIsWithPathAndMethod('/3/movie/' . self::MOVIE_ID . '/alternative_titles');
4141
}
4242

43+
/**
44+
* @test
45+
*/
46+
public function shouldGetExternalIds()
47+
{
48+
$api = $this->getApiWithMockedHttpAdapter();
49+
50+
$api->getExternalIds(self::MOVIE_ID);
51+
$this->assertLastRequestIsWithPathAndMethod('/3/movie/' . self::MOVIE_ID . '/external_ids');
52+
}
53+
4354
/**
4455
* @test
4556
*/

test/Tmdb/Tests/Model/MovieTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function shouldConstructMovie()
3737
'getSpokenLanguages' => 'Tmdb\Model\Common\GenericCollection',
3838
'getAlternativeTitles' => 'Tmdb\Model\Common\GenericCollection',
3939
'getChanges' => 'Tmdb\Model\Common\GenericCollection',
40+
'getExternalIds' => 'Tmdb\Model\Common\ExternalIds',
4041
'getCredits' => 'Tmdb\Model\Collection\CreditsCollection',
4142
'getImages' => 'Tmdb\Model\Collection\Images',
4243
'getKeywords' => 'Tmdb\Model\Common\GenericCollection',

test/Tmdb/Tests/Repository/MovieRepositoryTest.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function shouldLoadMovie()
3030
$repository->load(self::MOVIE_ID);
3131
$this->assertLastRequestIsWithPathAndMethod('/3/movie/' . self::MOVIE_ID);
3232
$this->assertRequestHasQueryParameters([
33-
'append_to_response' => 'alternative_titles,changes,credits,images,keywords,lists,release_dates,reviews,similar,recommendations,translations,videos'
33+
'append_to_response' => 'alternative_titles,external_ids,changes,credits,images,keywords,lists,release_dates,reviews,similar,recommendations,translations,videos'
3434
]);
3535
}
3636

@@ -45,6 +45,17 @@ public function shouldGetAlternativeTitles()
4545
$this->assertLastRequestIsWithPathAndMethod('/3/movie/' . self::MOVIE_ID . '/alternative_titles');
4646
}
4747

48+
/**
49+
* @test
50+
*/
51+
public function shouldGetExternalIds()
52+
{
53+
$repository = $this->getRepositoryWithMockedHttpAdapter();
54+
55+
$repository->getExternalIds(self::MOVIE_ID);
56+
$this->assertLastRequestIsWithPathAndMethod('/3/movie/' . self::MOVIE_ID . '/external_ids');
57+
}
58+
4859
/**
4960
* @test
5061
*/

0 commit comments

Comments
 (0)