Skip to content

Commit

Permalink
Adding missing classes for Keyword API, updated PROGRESS.md
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Feb 8, 2014
1 parent 74c2695 commit ec08a4c
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 1 deletion.
2 changes: 1 addition & 1 deletion PROGRESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The states for now defined as;
| Find | Done |
| Genres | Done |
| Jobs | Done |
| Keywords | Review |
| Keywords | Done |
| Lists | Partially Done * |
| Movies | Partially Done * |
| Networks | Review |
Expand Down
23 changes: 23 additions & 0 deletions examples/keywords/model/get.php
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);
22 changes: 22 additions & 0 deletions examples/keywords/model/movies.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\KeywordRepository($client);
$movies = $repository->getMovies(1721);

var_dump($movies);
58 changes: 58 additions & 0 deletions lib/Tmdb/Factory/KeywordFactory.php
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;
}
}
60 changes: 60 additions & 0 deletions lib/Tmdb/Model/Keyword.php
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;
}
}
66 changes: 66 additions & 0 deletions lib/Tmdb/Repository/KeywordRepository.php
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();
}
}

0 comments on commit ec08a4c

Please sign in to comment.