Skip to content

Commit

Permalink
Refactoring API namespace and expanding the Model namespace.
Browse files Browse the repository at this point in the history
- Adding $headers parameter to all API methods
- Modified client class, remove the api() method
- Adding repositories
- Cleaning up model classes
  • Loading branch information
wtfzdotnet committed Jan 11, 2014
1 parent c3926cc commit 53b2fb0
Show file tree
Hide file tree
Showing 37 changed files with 544 additions and 450 deletions.
11 changes: 9 additions & 2 deletions examples/genres/model/get.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
$token = new \Tmdb\ApiToken(TMDB_API_KEY);
$client = new \Tmdb\Client($token);

$genre = \Tmdb\Model\Genre::load($client, 28);
$repository = new \Tmdb\Repository\GenreRepository($client);
$genre = $repository->load(28);

echo $genre->getName();
var_dump($genre);

$genres = $repository->loadCollection();

foreach($genres as $genre) {
var_dump($genre);
}
21 changes: 3 additions & 18 deletions examples/movies/model/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,8 @@
$token = new \Tmdb\ApiToken(TMDB_API_KEY);
$client = new \Tmdb\Client($token);

// This is optional, but if you want lots of data this is the way.
$append = new \Tmdb\Model\Movie\QueryParameter\AppendToResponse(array(
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::ALTERNATIVE_TITLES,
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::CHANGES,
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::CREDITS,
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::IMAGES,
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::KEYWORDS,
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::LISTS,
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::RELEASES,
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::REVIEWS,
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::SIMILAR_MOVIES,
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::TRAILERS,
\Tmdb\Model\Movie\QueryParameter\AppendToResponse::TRANSLATIONS,
));

$repository = new \Tmdb\Repository\MovieRepository($client);
$movie = $repository->load(87421, array($append));
$movie = $repository->load(87421);

echo $movie->getTitle() . "<br/>";

Expand All @@ -61,11 +46,11 @@
$configRepository = new \Tmdb\Repository\ConfigurationRepository($client);
$config = $configRepository->load();

$imageHelper = new \Tmdb\Model\Helper\ImageHelper($config);
$imageHelper = new \Tmdb\Helper\ImageHelper($config);
foreach($movie->getImages() as $image) {
echo $imageHelper->getHtml($image);

printf(" - %s<br/>", $image->getFilePath());
printf(" - %s<br/>", $imageHelper->getUrl($image));
}

echo "Genres<br/>";
Expand Down
13 changes: 1 addition & 12 deletions examples/people/model/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,7 @@
$token = new \Tmdb\ApiToken(TMDB_API_KEY);
$client = new \Tmdb\Client($token);

// This is optional, but if you want lots of data this is the way.
$append = new \Tmdb\Model\Person\QueryParameter\AppendToResponse(array(
\Tmdb\Model\Person\QueryParameter\AppendToResponse::IMAGES,
\Tmdb\Model\Person\QueryParameter\AppendToResponse::CHANGES,
\Tmdb\Model\Person\QueryParameter\AppendToResponse::COMBINED_CREDITS,
\Tmdb\Model\Person\QueryParameter\AppendToResponse::LATEST,
\Tmdb\Model\Person\QueryParameter\AppendToResponse::MOVIE_CREDITS,
\Tmdb\Model\Person\QueryParameter\AppendToResponse::TV_CREDITS,
\Tmdb\Model\Person\QueryParameter\AppendToResponse::POPULAR
));

$repository = new \Tmdb\Repository\PersonRepository($client);
$person = $repository->load(33, array($append));
$person = $repository->load(33);

var_dump($person);
21 changes: 14 additions & 7 deletions lib/Tmdb/Api/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ class Account
* Get the basic information for an account. You will need to have a valid session id.
*
* @param array $options
* @param array $headers
* @throws NotImplementedException
* @return mixed
*/
public function getAccount(array $options = array())
public function getAccount(array $options = array(), array $headers = array())
{
throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.');
}
Expand All @@ -34,10 +35,11 @@ public function getAccount(array $options = array())
*
* @param $account_id
* @param $options array
* @param array $headers
* @throws NotImplementedException
* @return mixed
*/
public function getLists($account_id, array $options = array())
public function getLists($account_id, array $options = array(), array $headers = array())
{
throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.');
}
Expand All @@ -47,10 +49,11 @@ public function getLists($account_id, array $options = array())
*
* @param $account_id
* @param array $options
* @param array $headers
* @throws NotImplementedException
* @return mixed
*/
public function getFavoriteMovies($account_id, array $options = array())
public function getFavoriteMovies($account_id, array $options = array(), array $headers = array())
{
throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.');
}
Expand All @@ -60,10 +63,11 @@ public function getFavoriteMovies($account_id, array $options = array())
*
* @param $account_id
* @param array $options
* @param array $headers
* @throws NotImplementedException
* @return mixed
*/
public function favorite($account_id, array $options = array())
public function favorite($account_id, array $options = array(), array $headers = array())
{
throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.');
}
Expand All @@ -73,10 +77,11 @@ public function favorite($account_id, array $options = array())
*
* @param $account_id
* @param array $options
* @param array $headers
* @throws NotImplementedException
* @return mixed
*/
public function getRatedMovies($account_id, array $options = array())
public function getRatedMovies($account_id, array $options = array(), array $headers = array())
{
throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.');
}
Expand All @@ -86,10 +91,11 @@ public function getRatedMovies($account_id, array $options = array())
*
* @param $account_id
* @param array $options
* @param array $headers
* @throws NotImplementedException
* @return mixed
*/
public function getMovieWatchlist($account_id, array $options = array())
public function getMovieWatchlist($account_id, array $options = array(), array $headers = array())
{
throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.');
}
Expand All @@ -99,10 +105,11 @@ public function getMovieWatchlist($account_id, array $options = array())
*
* @param $account_id
* @param array $options
* @param array $headers
* @throws NotImplementedException
* @return mixed
*/
public function watchlist($account_id, array $options = array())
public function watchlist($account_id, array $options = array(), array $headers = array())
{
throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.');
}
Expand Down
9 changes: 6 additions & 3 deletions lib/Tmdb/Api/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ class Authentication
* As soon as a valid session id has been created the token will be destroyed.
*
* @param array $options
* @param array $headers
* @throws NotImplementedException
* @return mixed
*/
public function getNewToken(array $options = array())
public function getNewToken(array $options = array(), array $headers = array())
{
throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.');
}
Expand All @@ -39,10 +40,11 @@ public function getNewToken(array $options = array())
*
* @param $request_token
* @param $options array
* @param array $headers
* @throws NotImplementedException
* @return mixed
*/
public function getNewSession($request_token, array $options = array())
public function getNewSession($request_token, array $options = array(), array $headers = array())
{
throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.');
}
Expand All @@ -59,10 +61,11 @@ public function getNewSession($request_token, array $options = array())
* If a guest session is not used for the first time within 24 hours, it will be automatically discarded.
*
* @param array $options
* @param array $headers
* @throws NotImplementedException
* @return mixed
*/
public function getNewGuestSession(array $options = array())
public function getNewGuestSession(array $options = array(), array $headers = array())
{
throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.');
}
Expand Down
10 changes: 6 additions & 4 deletions lib/Tmdb/Api/Changes.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ class Changes
* on October 5, 2012 and will only show movies that have been edited since.
*
* @param array $options
* @param array $headers
* @return mixed
*/
public function getMovieChanges(array $options = array())
public function getMovieChanges(array $options = array(), array $headers = array())
{
return $this->get('movie/changes', $options);
return $this->get('movie/changes', $options, $headers);
}

/**
Expand All @@ -46,10 +47,11 @@ public function getMovieChanges(array $options = array())
* on October 5, 2012 and will only show movies that have been edited since.
*
* @param array $options
* @param array $headers
* @return mixed
*/
public function getPeopleChanges(array $options = array())
public function getPeopleChanges(array $options = array(), array $headers = array())
{
return $this->get('person/changes', $options);
return $this->get('person/changes', $options, $headers);
}
}
10 changes: 6 additions & 4 deletions lib/Tmdb/Api/Collections.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,24 @@ class Collections
*
* @param $collection_id
* @param array $options
* @param array $headers
* @return mixed
*/
public function getCollection($collection_id, array $options = array())
public function getCollection($collection_id, array $options = array(), array $headers = array())
{
return $this->get('collection/' . $collection_id, $options);
return $this->get('collection/' . $collection_id, $options, $headers);
}

/**
* Get all of the images for a particular collection by collection id.
*
* @param $collection_id
* @param array $options
* @param array $headers
* @return mixed
*/
public function getImages($collection_id, array $options = array())
public function getImages($collection_id, array $options = array(), array $headers = array())
{
return $this->get('collection/' . $collection_id . '/images', $options);
return $this->get('collection/' . $collection_id . '/images', $options, $headers);
}
}
10 changes: 6 additions & 4 deletions lib/Tmdb/Api/Companies.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,24 @@ class Companies
*
* @param $company_id
* @param array $options
* @param array $headers
* @return mixed
*/
public function getCompany($company_id, array $options = array())
public function getCompany($company_id, array $options = array(), array $headers = array())
{
return $this->get('company/' . $company_id, $options);
return $this->get('company/' . $company_id, $options, $headers);
}

/**
* Get the list of movies associated with a particular company.
*
* @param $company_id
* @param array $options
* @param array $headers
* @return mixed
*/
public function getMovies($company_id, array $options = array())
public function getMovies($company_id, array $options = array(), array $headers = array())
{
return $this->get('company/' . $company_id . '/movies', $options);
return $this->get('company/' . $company_id . '/movies', $options, $headers);
}
}
5 changes: 3 additions & 2 deletions lib/Tmdb/Api/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ class Configuration
*
* http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w500/8uO0gUM8aNqYLs1OsTBQiXu0fEv.jpg
*
* @param array $headers
* @return mixed
*/
public function getConfiguration()
public function getConfiguration(array $headers = array())
{
return $this->get('configuration');
return $this->get('configuration', array(), $headers);
}
}
4 changes: 2 additions & 2 deletions lib/Tmdb/Api/Discover.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class Discover
* @param array $options
* @return mixed
*/
public function discoverMovies(array $options = array())
public function discoverMovies(array $options = array(), array $headers = array())
{
return $this->get('discover/movie', $options);
return $this->get('discover/movie', $options, $headers);
}
}
13 changes: 8 additions & 5 deletions lib/Tmdb/Api/Genres.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class Genres
*
* @param integer $id
* @param array $options
* @param array $headers
* @return mixed
*/
public function getGenre($id, array $options = array())
public function getGenre($id, array $options = array(), array $headers = array())
{
$response = $this->getGenres();

Expand All @@ -39,22 +40,24 @@ public function getGenre($id, array $options = array())
* Get the list of genres.
*
* @param array $options
* @param array $headers
* @return mixed
*/
public function getGenres(array $options = array())
public function getGenres(array $options = array(), array $headers = array())
{
return $this->get('genre/list', $options);
return $this->get('genre/list', $options, $headers);
}

/**
* Get the list of movies for a particular genre by id. By default, only movies with 10 or more votes are included.
*
* @param $genre_id
* @param array $options
* @param array $headers
* @return mixed
*/
public function getMovies($genre_id, array $options = array())
public function getMovies($genre_id, array $options = array(), array $headers = array())
{
return $this->get('genre/' . $genre_id . '/movies', $options);
return $this->get('genre/' . $genre_id . '/movies', $options, $headers);
}
}
5 changes: 3 additions & 2 deletions lib/Tmdb/Api/Jobs.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ class Jobs
* Get a list of valid jobs.
*
* @param array $options
* @param array $headers
* @return mixed
*/
public function getMovieChanges(array $options = array())
public function getMovieChanges(array $options = array(), array $headers = array())
{
return $this->get('job/list', $options);
return $this->get('job/list', $options, $headers);
}
}
Loading

0 comments on commit 53b2fb0

Please sign in to comment.