forked from php-tmdb/api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding missing classes for Keyword API, updated PROGRESS.md
- Loading branch information
1 parent
74c2695
commit ec08a4c
Showing
6 changed files
with
230 additions
and
1 deletion.
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
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,23 @@ | ||
<?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\KeywordRepository($client); | ||
$keyword = $repository->load(1721); | ||
|
||
var_dump($keyword); |
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,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\KeywordRepository($client); | ||
$movies = $repository->getMovies(1721); | ||
|
||
var_dump($movies); |
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,58 @@ | ||
<?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 | ||
*/ | ||
namespace Tmdb\Factory; | ||
|
||
use Tmdb\Model\Collection\Keywords; | ||
use Tmdb\Model\Keyword; | ||
use Tmdb\Model\Movie; | ||
|
||
class KeywordFactory extends AbstractFactory | ||
{ | ||
/** | ||
* @param array $data | ||
* | ||
* @return Keyword | ||
*/ | ||
public function create(array $data = array()) | ||
{ | ||
return $this->hydrate(new Keyword(), $data); | ||
} | ||
|
||
/** | ||
* @param array $data | ||
* | ||
* @return Movie | ||
*/ | ||
public function createMovie(array $data = array()) | ||
{ | ||
return $this->hydrate(new Movie(), $data); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createCollection(array $data = array()) | ||
{ | ||
$collection = new Keywords(); | ||
|
||
if (array_key_exists('keywords', $data)) { | ||
$data = $data['keywords']; | ||
} | ||
|
||
foreach($data as $item) { | ||
$collection->addKeyword($this->create($item)); | ||
} | ||
|
||
return $collection; | ||
} | ||
} |
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,60 @@ | ||
<?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 | ||
*/ | ||
namespace Tmdb\Model; | ||
|
||
class Keyword extends AbstractModel { | ||
|
||
private $id; | ||
private $name; | ||
|
||
public static $_properties = array( | ||
'id', | ||
'name', | ||
); | ||
|
||
/** | ||
* @param mixed $id | ||
* @return $this | ||
*/ | ||
public function setId($id) | ||
{ | ||
$this->id = (int) $id; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return integer | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @param mixed $name | ||
* @return $this | ||
*/ | ||
public function setName($name) | ||
{ | ||
$this->name = $name; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
} |
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,66 @@ | ||
<?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 | ||
*/ | ||
namespace Tmdb\Repository; | ||
|
||
use Tmdb\Factory\KeywordFactory; | ||
use Tmdb\Model\Common\GenericCollection; | ||
use Tmdb\Model\Keyword; | ||
|
||
class KeywordRepository extends AbstractRepository { | ||
/** | ||
* Get the basic information for a specific keyword id. | ||
* | ||
* @param $id | ||
* @param array $parameters | ||
* @param array $headers | ||
* @return Keyword | ||
*/ | ||
public function load($id, array $parameters = array(), array $headers = array()) { | ||
return $this->getFactory()->create( | ||
$this->getApi()->getKeyword($id, $parameters, $headers) | ||
); | ||
} | ||
|
||
/** | ||
* Get the list of movies for a particular keyword by id. By default, only movies with 10 or more votes are included. | ||
* | ||
* @param $id | ||
* @param array $parameters | ||
* @param array $headers | ||
* @return Keyword[] | ||
*/ | ||
public function getMovies($id, array $parameters = array(), array $headers = array()) { | ||
return $this->getFactory()->createResultCollection( | ||
$this->getApi()->getMovies($id, $parameters, $headers), | ||
'createMovie' | ||
); | ||
} | ||
|
||
/** | ||
* Return the related API class | ||
* | ||
* @return \Tmdb\Api\Keywords | ||
*/ | ||
public function getApi() | ||
{ | ||
return $this->getClient()->getKeywordsApi(); | ||
} | ||
|
||
/** | ||
* @return KeywordFactory | ||
*/ | ||
public function getFactory() | ||
{ | ||
return new KeywordFactory(); | ||
} | ||
} |