Skip to content

Commit

Permalink
Making sure depdendencies are met for the request
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Jan 19, 2014
1 parent 811b68c commit 5c5251c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/Tmdb/Repository/DiscoverRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
namespace Tmdb\Repository;

use Tmdb\Exception\RuntimeException;
use Tmdb\Factory\MovieFactory;
use Tmdb\Factory\TvFactory;
use Tmdb\Model\Common\GenericCollection;
Expand All @@ -24,10 +25,17 @@ class DiscoverRepository extends AbstractRepository {
*
* @param DiscoverMoviesQuery $query
* @param array $headers
* @throws RuntimeException when certification_country is set but certification.lte is not given
* @return GenericCollection
*/
public function discoverMovies(DiscoverMoviesQuery $query, array $headers = array()) {
$data = $this->getApi()->discoverMovies($query->toArray(), $this->parseHeaders($headers));
$query = $query->toArray();

if (array_key_exists('certification_country', $query) && !array_key_exists('certification.lte', $query)) {
throw new RuntimeException('When the certification_country option is given the certification.lte option is required.');
}

$data = $this->getApi()->discoverMovies($query, $this->parseHeaders($headers));

return MovieFactory::createCollection($data);
}
Expand Down

0 comments on commit 5c5251c

Please sign in to comment.