Skip to content

Commit

Permalink
Adding Certification API
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Feb 9, 2014
1 parent fa7bad2 commit 32281b9
Show file tree
Hide file tree
Showing 6 changed files with 354 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ I'm working extensively on finishing the models/repositories/factories, which sh
| Changes | Done |
| Collections | Done |
| Companies | Done |
| Credits | **TODO** _added to tmdb recently_, available in API namespace. |
| Credits | Done |
| Discover | Done |
| Find | Done |
| Genres | Done |
Expand Down
23 changes: 23 additions & 0 deletions examples/certifications/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);

$certificationRepository = new \Tmdb\Repository\CertificationRepository($client);
$certificationList = $certificationRepository->getMovieList();

var_dump($certificationList);

110 changes: 110 additions & 0 deletions lib/Tmdb/Factory/CertificationFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?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\Certification;
use Tmdb\Model\Common\GenericCollection;

class CertificationFactory extends AbstractFactory
{
/**
* @param array $data
*
* @return Certification
*/
public function create(array $data = array())
{
return $this->hydrate(new Certification\CountryCertification(), $data);
}

/**
* {@inheritdoc}
*/
public function createCollection(array $data = array())
{
if (array_key_exists('certifications', $data)) {
$data = $data['certifications'];
}

$collection = new GenericCollection();

foreach($data as $country => $certifications) {
$certification = new Certification();
$certification->setCountry($country);

foreach($certifications as $countryCertification) {
$object = $this->create($countryCertification);

$certification->getCertifications()->add(null, $object);
}

$collection->add(null, $certification);
}

return $collection;
}

/**
* @param \Tmdb\Factory\TvEpisodeFactory $tvEpisodeFactory
* @return $this
*/
public function setTvEpisodeFactory($tvEpisodeFactory)
{
$this->tvEpisodeFactory = $tvEpisodeFactory;
return $this;
}

/**
* @return \Tmdb\Factory\TvEpisodeFactory
*/
public function getTvEpisodeFactory()
{
return $this->tvEpisodeFactory;
}

/**
* @param \Tmdb\Factory\TvSeasonFactory $tvSeasonFactory
* @return $this
*/
public function setTvSeasonFactory($tvSeasonFactory)
{
$this->tvSeasonFactory = $tvSeasonFactory;
return $this;
}

/**
* @return \Tmdb\Factory\TvSeasonFactory
*/
public function getTvSeasonFactory()
{
return $this->tvSeasonFactory;
}

/**
* @param \Tmdb\Factory\PeopleFactory $peopleFactory
* @return $this
*/
public function setPeopleFactory($peopleFactory)
{
$this->peopleFactory = $peopleFactory;
return $this;
}

/**
* @return \Tmdb\Factory\PeopleFactory
*/
public function getPeopleFactory()
{
return $this->peopleFactory;
}
}
73 changes: 73 additions & 0 deletions lib/Tmdb/Model/Certification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?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;

use Tmdb\Model\Common\GenericCollection;

class Certification extends AbstractModel {

/**
* @var string
*/
private $country;

/**
* @var GenericCollection
*/
private $certifications;

public static $_properties = array(
'country',
);

public function __construct()
{
$this->certifications = new GenericCollection();
}

/**
* @param \Tmdb\Model\Common\GenericCollection $certifications
* @return $this
*/
public function setCertifications($certifications)
{
$this->certifications = $certifications;
return $this;
}

/**
* @return \Tmdb\Model\Common\GenericCollection
*/
public function getCertifications()
{
return $this->certifications;
}

/**
* @param string $country
* @return $this
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}

/**
* @return string
*/
public function getCountry()
{
return $this->country;
}
}
95 changes: 95 additions & 0 deletions lib/Tmdb/Model/Certification/CountryCertification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?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\Certification;

use Tmdb\Model\AbstractModel;

class CountryCertification extends AbstractModel {

/**
* @var string
*/
private $certification;

/**
* @var string
*/
private $meaning;

/**
* @var integer
*/
private $order;

public static $_properties = array(
'certification',
'meaning',
'order',
);

/**
* @param string $certification
* @return $this
*/
public function setCertification($certification)
{
$this->certification = $certification;
return $this;
}

/**
* @return string
*/
public function getCertification()
{
return $this->certification;
}

/**
* @param string $meaning
* @return $this
*/
public function setMeaning($meaning)
{
$this->meaning = $meaning;
return $this;
}

/**
* @return string
*/
public function getMeaning()
{
return $this->meaning;
}

/**
* @param int $order
* @return $this
*/
public function setOrder($order)
{
$this->order = $order;
return $this;
}

/**
* @return int
*/
public function getOrder()
{
return $this->order;
}


}
52 changes: 52 additions & 0 deletions lib/Tmdb/Repository/CertificationRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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\CertificationFactory;
use Tmdb\Model\Collection as ApiCollection;

class CertificationRepository extends AbstractRepository {

/**
* Get the list of supported certifications for movies.
*
* These can be used in conjunction with the certification_country and certification.lte parameters when using discover.
*
* @param $parameters
* @param $headers
* @return null|\Tmdb\Model\AbstractModel
*/
public function getMovieList(array $parameters = array(), array $headers = array())
{
$data = $this->getApi()->getMovieList($this->parseQueryParameters($parameters), $headers);
return $this->getFactory()->createCollection($data);
}

/**
* Return the Collection API Class
*
* @return \Tmdb\Api\Certifications
*/
public function getApi()
{
return $this->getClient()->getCertificationsApi();
}

/**
* @return CertificationFactory
*/
public function getFactory()
{
return new CertificationFactory();
}
}

0 comments on commit 32281b9

Please sign in to comment.