Skip to content
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
21 changes: 21 additions & 0 deletions examples/movies/api/recommendations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* This file is part of the Tmdb PHP API created by Michael Roterman.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Tmdb
* @author Eugenia Schneider <[email protected]>
* @copyright (c) 2018, Eugenia Schneider
* @version 0.0.1
*/
require_once '../../../vendor/autoload.php';
require_once '../../../apikey.php';

$token = new \Tmdb\ApiToken(TMDB_API_KEY);
$client = new \Tmdb\Client($token);

$recommendedMovies = $client->getMoviesApi()->getRecommendations(87421);

var_dump($recommendedMovies);
22 changes: 22 additions & 0 deletions examples/movies/model/recommendations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* This file is part of the Tmdb PHP API created by Michael Roterman.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @package Tmdb
* @author Michael Roterman <[email protected]>
* @copyright (c) 2013, Michael Roterman
* @version 0.0.1
*/
require_once '../../../vendor/autoload.php';
require_once '../../../apikey.php';

$token = new \Tmdb\ApiToken(TMDB_API_KEY);
$client = new \Tmdb\Client($token);

$repository = new \Tmdb\Repository\MovieRepository($client);
$collection = $repository->getRecommendations(87421);

var_dump($collection);
13 changes: 13 additions & 0 deletions lib/Tmdb/Api/Movies.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,19 @@ public function getSimilar($movie_id, array $parameters = [], array $headers = [
return $this->get('movie/' . $movie_id . '/similar', $parameters, $headers);
}

/**
* Get the recommended movies for a specific movie id.
*
* @param $movie_id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to maintain coherent camelcasing of variables $movieId ( won't repeat it for all the places I come across further on )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure, you want the $movie_id variable to be written as $movieId? I'm just confused, because the file, which this code is in (as well as many others), has $movie_id as parameter everywhere, and there's no $movieId in it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll double check tonight

* @param array $parameters
* @param array $headers
* @return mixed
*/
public function getRecommendations($movie_id, array $parameters = [], array $headers = [])
{
return $this->get('movie/' . $movie_id . '/recommendations', $parameters, $headers);
}

/**
* Get the reviews for a particular movie id.
*
Expand Down
13 changes: 13 additions & 0 deletions lib/Tmdb/Api/Tv.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,19 @@ public function getSimilar($tvshow_id, array $parameters = [], array $headers =
return $this->get('tv/' . $tvshow_id . '/similar', $parameters, $headers);
}

/**
* Get the recommended TV shows for a specific tv id.
*
* @param $tvshow_id
* @param array $parameters
* @param array $headers
* @return mixed
*/
public function getRecommendations($tvshow_id, array $parameters = [], array $headers = [])
{
return $this->get('tv/' . $tvshow_id . '/recommendations', $parameters, $headers);
}

/**
* This method lets users get the status of whether or not the TV show has been rated
* or added to their favourite or watch lists.
Expand Down
4 changes: 4 additions & 0 deletions lib/Tmdb/Factory/TvFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ public function create(array $data = [])
$tvShow->setSimilar($this->createResultCollection($data['similar']));
}

if (array_key_exists('recommendations', $data) && $data['recommendations'] !== null) {
$tvShow->setRecommendations($this->createResultCollection($data['recommendations']));
}

if (array_key_exists('languages', $data) && $data['languages'] !== null) {
$collection = new GenericCollection();

Expand Down
25 changes: 25 additions & 0 deletions lib/Tmdb/Model/Movie.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ class Movie extends AbstractModel
*/
protected $similar;

/**
* @var GenericCollection
*/
protected $recommendations;

/**
* @var GenericCollection
*/
Expand Down Expand Up @@ -276,6 +281,7 @@ public function __construct()
$this->releases = new GenericCollection();
$this->release_dates = new GenericCollection();
$this->similar = new GenericCollection();
$this->recommendations = new GenericCollection();
$this->translations = new GenericCollection();
$this->videos = new Videos();
}
Expand Down Expand Up @@ -906,6 +912,17 @@ public function setSimilar($similar)
return $this;
}

/**
* @param GenericCollection $recommendations
* @return $this
*/
public function setRecommendations($recommendations)
{
$this->recommendations = $recommendations;

return $this;
}

/**
* @return GenericCollection|Movie[]
*/
Expand All @@ -914,6 +931,14 @@ public function getSimilar()
return $this->similar;
}

/**
* @return GenericCollection|Movie[]
*/
public function getRecommendations()
{
return $this->recommendations;
}

/**
* @return GenericCollection|Movie[]
* @deprecated Use getSimilar instead
Expand Down
1 change: 1 addition & 0 deletions lib/Tmdb/Model/Movie/QueryParameter/AppendToResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ final class AppendToResponse extends BaseAppendToResponse
const RELEASE_DATES = 'release_dates';
const TRANSLATIONS = 'translations';
const SIMILAR = 'similar';
const RECOMMENDATIONS = 'recommendations';
const REVIEWS = 'reviews';
const LISTS = 'lists';
const CHANGES = 'changes';
Expand Down
25 changes: 25 additions & 0 deletions lib/Tmdb/Model/Tv.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ class Tv extends AbstractModel
*/
protected $similar;

/**
* @var GenericCollection
*/
protected $recommendations;

/**
* @var GenericCollection
*/
Expand Down Expand Up @@ -275,6 +280,7 @@ public function __construct()
$this->changes = new GenericCollection();
$this->keywords = new GenericCollection();
$this->similar = new GenericCollection();
$this->recommendations = new GenericCollection();
$this->contentRatings = new GenericCollection();
$this->alternativeTitles = new GenericCollection();
}
Expand Down Expand Up @@ -944,6 +950,17 @@ public function setSimilar($similar)
return $this;
}

/**
* @param GenericCollection $recommendations
* @return $this
*/
public function setRecommendations($recommendations)
{
$this->recommendations = $recommendations;

return $this;
}

/**
* @return GenericCollection
*/
Expand All @@ -952,6 +969,14 @@ public function getSimilar()
return $this->similar;
}

/**
* @return GenericCollection
*/
public function getRecommendations()
{
return $this->recommendations;
}

/**
* @return GenericCollection
*/
Expand Down
1 change: 1 addition & 0 deletions lib/Tmdb/Model/Tv/QueryParameter/AppendToResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AppendToResponse extends BaseAppendToResponse
const CHANGES = 'changes';
const KEYWORDS = 'keywords';
const SIMILAR = 'similar';
const RECOMMENDATIONS = 'recommendations';
const CONTENT_RATINGS = 'content_ratings';
const ALTERNATIVE_TITLES = 'alternative_titles';
}
17 changes: 17 additions & 0 deletions lib/Tmdb/Repository/MovieRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function load($id, array $parameters = [], array $headers = [])
AppendToResponse::RELEASE_DATES,
AppendToResponse::REVIEWS,
AppendToResponse::SIMILAR,
AppendToResponse::RECOMMENDATIONS,
AppendToResponse::TRANSLATIONS,
AppendToResponse::VIDEOS,
])
Expand Down Expand Up @@ -207,6 +208,22 @@ public function getSimilar($id, array $parameters = [], array $headers = [])
return $movie->getSimilar();
}

/**
* Get the recommended movies for a specific movie id.
*
* @param $id
* @param $parameters
* @param $headers
* @return null|\Tmdb\Model\AbstractModel
*/
public function getRecommendations($id, array $parameters = [], array $headers = [])
{
$data = $this->getApi()->getRecommendations($id, $this->parseQueryParameters($parameters), $headers);
$movie = $this->getFactory()->create(['recommendations' => $data]);

return $movie->getRecommendations();
}

/**
* Get the reviews for a particular movie id.
*
Expand Down
1 change: 1 addition & 0 deletions lib/Tmdb/Repository/TvRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public function load($id, array $parameters = [], array $headers = [])
AppendToResponse::IMAGES,
AppendToResponse::TRANSLATIONS,
AppendToResponse::SIMILAR,
AppendToResponse::RECOMMENDATIONS,
AppendToResponse::KEYWORDS,
AppendToResponse::CHANGES,
AppendToResponse::CONTENT_RATINGS,
Expand Down
14 changes: 14 additions & 0 deletions test/Tmdb/Tests/Api/MoviesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,20 @@ public function shouldGetSimilarMovies()
$api->getSimilar(self::MOVIE_ID);
}

/**
* @test
*/
public function shouldGetRecommendedMovies()
{
$api = $this->getApiWithMockedHttpAdapter();

$this->getAdapter()->expects($this->once())
->method('get')
->with($this->getRequest('https://api.themoviedb.org/3/movie/' . self::MOVIE_ID . '/recommendations'));

$api->getRecommendations(self::MOVIE_ID);
}

/**
* @test
*/
Expand Down
15 changes: 15 additions & 0 deletions test/Tmdb/Tests/Api/TvTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,21 @@ public function shouldGetSimilar()
$api->getSimilar(self::TV_ID);
}

/**
* @test
*/
public function shouldGetRecommended()
{
$api = $this->getApiWithMockedHttpAdapter();

$this->getAdapter()->expects($this->once())
->method('get')
->with($this->getRequest('https://api.themoviedb.org/3/tv/' . self::TV_ID . '/recommendations'))
;

$api->getRecommendations(self::TV_ID);
}

/**
* @test
*/
Expand Down
1 change: 1 addition & 0 deletions test/Tmdb/Tests/Factory/MovieFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public function shouldBeFunctional()
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getReleases());
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getReleaseDates());
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getSimilar());
$this->assertInstanceOf('Tmdb\Model\Common\GenericCollection', $this->movie->getRecommendations());
$this->assertInstanceOf('Tmdb\Model\Collection\Videos', $this->movie->getVideos());

/** @var Release[] $releases */
Expand Down
1 change: 1 addition & 0 deletions test/Tmdb/Tests/Model/MovieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function shouldConstructMovie()
'getReleases' => 'Tmdb\Model\Common\GenericCollection',
'getReleaseDates' => 'Tmdb\Model\Common\GenericCollection',
'getSimilar' => 'Tmdb\Model\Common\GenericCollection',
'getRecommendations' => 'Tmdb\Model\Common\GenericCollection',
'getTranslations' => 'Tmdb\Model\Common\GenericCollection',
'getVideos' => 'Tmdb\Model\Collection\Videos',
]
Expand Down
17 changes: 16 additions & 1 deletion test/Tmdb/Tests/Repository/MovieRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function shouldLoadMovie()
->method('get')
->with($this->getRequest(
'https://api.themoviedb.org/3/movie/' . self::MOVIE_ID,
['append_to_response' => 'alternative_titles,changes,credits,images,keywords,lists,release_dates,reviews,similar,translations,videos']
['append_to_response' => 'alternative_titles,changes,credits,images,keywords,lists,release_dates,reviews,similar,recommendations,translations,videos']
))
;

Expand Down Expand Up @@ -140,6 +140,21 @@ public function shouldGetSimilar()
$repository->getSimilar(self::MOVIE_ID);
}

/**
* @test
*/
public function shouldGetRecommended()
{
$repository = $this->getRepositoryWithMockedHttpAdapter();

$this->getAdapter()->expects($this->once())
->method('get')
->with($this->getRequest('https://api.themoviedb.org/3/movie/' . self::MOVIE_ID . '/recommendations'))
;

$repository->getRecommendations(self::MOVIE_ID);
}

/**
* @test
*/
Expand Down
2 changes: 1 addition & 1 deletion test/Tmdb/Tests/Repository/TvRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function shouldLoadTv()
->method('get')
->with($this->getRequest(
'https://api.themoviedb.org/3/tv/' . self::TV_ID,
['append_to_response' => 'credits,external_ids,images,translations,similar,keywords,changes,content_ratings,alternative_titles,videos']
['append_to_response' => 'credits,external_ids,images,translations,similar,recommendations,keywords,changes,content_ratings,alternative_titles,videos']
))
;

Expand Down