Skip to content

Commit

Permalink
Adding Lists API
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Feb 9, 2014
1 parent 632c8bf commit 37cb54f
Show file tree
Hide file tree
Showing 10 changed files with 933 additions and 5 deletions.
22 changes: 22 additions & 0 deletions examples/lists/model/get.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 <michael@wtfz.net>
* @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\ListRepository($client);
$list = $repository->load('509ec17b19c2950a0600050d');

var_dump($list);
22 changes: 22 additions & 0 deletions examples/lists/model/item_status.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 <michael@wtfz.net>
* @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\ListRepository($client);
$list = $repository->getItemStatus('509ec17b19c2950a0600050d');

var_dump($list);
8 changes: 5 additions & 3 deletions lib/Tmdb/Api/Lists.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ public function createList()
/**
* Check to see if a movie ID is already added to a list.
*
* @throws NotImplementedException
* @param $list_id
* @param array $parameters
* @param array $headers
* @return mixed
*/
public function getItemStatus()
public function getItemStatus($list_id, array $parameters = array(), array $headers = array())
{
throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.');
return $this->get('list/' . $list_id . '/item_status', $parameters, $headers);
}

/**
Expand Down
128 changes: 128 additions & 0 deletions lib/Tmdb/Factory/ListFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?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 <michael@wtfz.net>
* @copyright (c) 2013, Michael Roterman
* @version 0.0.1
*/
namespace Tmdb\Factory;

use Tmdb\Factory\Lists\ListItemFactory;
use Tmdb\Model\Collection\Genres;
use Tmdb\Model\Genre;
use Tmdb\Model\Lists;
use Tmdb\Model\Movie;

class ListFactory extends AbstractFactory
{
/**
* @var ImageFactory
*/
private $imageFactory;

/**
* @var ListItemFactory
*/
private $listItemFactory;

public function __construct()
{
$this->imageFactory = new ImageFactory();
$this->listItemFactory = new ListItemFactory();
}

/**
* @param array $data
*
* @return Genre
*/
public function create(array $data = array())
{
$lists = new Lists();

if (array_key_exists('items', $data)) {
$lists->setItems(
$this->getListItemFactory()->createCollection($data['items'])
);
}

/** Images */
if (array_key_exists('backdrop_path', $data)) {
$lists->setBackdropImage($this->getImageFactory()->createFromPath($data['backdrop_path'], 'backdrop_path'));
}

if (array_key_exists('poster_path', $data)) {
$lists->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path'));
}
return $this->hydrate($lists, $data);
}

/**
* @param array $data
*
* @return Movie
*/
public function createItemStatus(array $data = array())
{
return $this->hydrate(new Lists\ItemStatus(), $data);
}

/**
* {@inheritdoc}
*/
public function createCollection(array $data = array())
{
$collection = new Genres();

if (array_key_exists('genres', $data)) {
$data = $data['genres'];
}

foreach($data as $item) {
$collection->addGenre($this->create($item));
}

return $collection;
}

/**
* @param \Tmdb\Factory\ImageFactory $imageFactory
* @return $this
*/
public function setImageFactory($imageFactory)
{
$this->imageFactory = $imageFactory;
return $this;
}

/**
* @return \Tmdb\Factory\ImageFactory
*/
public function getImageFactory()
{
return $this->imageFactory;
}

/**
* @param \Tmdb\Factory\Lists\ListItemFactory $listItemFactory
* @return $this
*/
public function setListItemFactory($listItemFactory)
{
$this->listItemFactory = $listItemFactory;
return $this;
}

/**
* @return \Tmdb\Factory\Lists\ListItemFactory
*/
public function getListItemFactory()
{
return $this->listItemFactory;
}
}
88 changes: 88 additions & 0 deletions lib/Tmdb/Factory/Lists/ListItemFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?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 <michael@wtfz.net>
* @copyright (c) 2013, Michael Roterman
* @version 0.0.1
*/
namespace Tmdb\Factory\Lists;

use Tmdb\Factory\AbstractFactory;
use Tmdb\Factory\ImageFactory;
use Tmdb\Model\Common\GenericCollection;
use Tmdb\Model\Lists\ListItem;

class ListItemFactory extends AbstractFactory
{
/**
* @var ImageFactory
*/
private $imageFactory;

public function __construct()
{
$this->imageFactory = new ImageFactory();
}

/**
* @param array $data
*
* @return ListItem
*/
public function create(array $data = array())
{
$listItem = new ListItem();

/** Images */
if (array_key_exists('backdrop_path', $data)) {
$listItem->setBackdropImage($this->getImageFactory()->createFromPath($data['backdrop_path'], 'backdrop_path'));
}

if (array_key_exists('poster_path', $data)) {
$listItem->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path'));
}

return $this->hydrate($listItem, $data);
}

/**
* {@inheritdoc}
*/
public function createCollection(array $data = array())
{
$collection = new GenericCollection();

if (array_key_exists('items', $data)) {
$data = $data['items'];
}

foreach($data as $item) {
$collection->add(null, $this->create($item));
}

return $collection;
}

/**
* @param \Tmdb\Factory\ImageFactory $imageFactory
* @return $this
*/
public function setImageFactory($imageFactory)
{
$this->imageFactory = $imageFactory;
return $this;
}

/**
* @return \Tmdb\Factory\ImageFactory
*/
public function getImageFactory()
{
return $this->imageFactory;
}
}
Loading

0 comments on commit 37cb54f

Please sign in to comment.