Skip to content

Commit

Permalink
Implementing Lists API into the modelled sections
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Feb 25, 2014
1 parent 382b694 commit d958f28
Show file tree
Hide file tree
Showing 15 changed files with 427 additions and 14 deletions.
25 changes: 25 additions & 0 deletions examples/lists/model/add.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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);

$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
$client->setSessionToken($sessionToken);

$repository = new \Tmdb\Repository\ListRepository($client);
$result = $repository->add(TMDB_LIST_ID, 150);

var_dump($result);
25 changes: 25 additions & 0 deletions examples/lists/model/create_list.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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);

$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
$client->setSessionToken($sessionToken);

$repository = new \Tmdb\Repository\ListRepository($client);
$result = $repository->createList('php-tmdb-api', 'just a test');

var_dump($result);
25 changes: 25 additions & 0 deletions examples/lists/model/remove.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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);

$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
$client->setSessionToken($sessionToken);

$repository = new \Tmdb\Repository\ListRepository($client);
$result = $repository->remove(TMDB_LIST_ID, 150);

var_dump($result);
6 changes: 3 additions & 3 deletions lib/Tmdb/Api/Lists.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function getItemStatus($id, $movieId, array $parameters = array(), array
}

/**
* Get the cast information for a specific list id.
* This method lets users add new movies to a list that they created. A valid session id is required.
*
* @param string $id
* @param string $mediaId
Expand All @@ -73,7 +73,7 @@ public function addMediaToList($id, $mediaId)
}

/**
* Get the images (posters and backdrops) for a specific list id.
* This method lets users delete movies from a list that they created. A valid session id is required.
*
* @param string $id
* @param string $mediaId
Expand All @@ -85,7 +85,7 @@ public function removeMediaFromList($id, $mediaId)
}

/**
* Get the plot keywords for a specific list id.
* This method lets users delete a list that they created. A valid session id is required.
*
* @param string $id
* @return mixed
Expand Down
22 changes: 21 additions & 1 deletion lib/Tmdb/Factory/ListFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,33 @@ public function create(array $data = array())
/**
* @param array $data
*
* @return Movie
* @return Lists\ItemStatus
*/
public function createItemStatus(array $data = array())
{
return $this->hydrate(new Lists\ItemStatus(), $data);
}

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

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

/**
* {@inheritdoc}
*/
Expand Down
71 changes: 71 additions & 0 deletions lib/Tmdb/Model/Lists/Result.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?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\Lists;

use Tmdb\Model\AbstractModel;

class Result extends AbstractModel {
/**
* @var int
*/
private $statusCode;

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

/**
* @var array
*/
public static $_properties = array(
'status_code',
'status_message'
);

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

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

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

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

class ResultWithListId extends Result {
/**
* @var string
*/
private $listId;

/**
* @var array
*/
public static $_properties = array(
'status_code',
'status_message',
'list_id'
);

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

/**
* @return string
*/
public function getListId()
{
return $this->listId;
}
}
72 changes: 65 additions & 7 deletions lib/Tmdb/Repository/ListRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
namespace Tmdb\Repository;

use Tmdb\Factory\ListFactory;
use Tmdb\Model\Collection\Jobs;
use Tmdb\Model\Job;
use Tmdb\Model\Lists\ItemStatus;
use Tmdb\Model\Lists;

class ListRepository extends AbstractRepository {
/**
Expand All @@ -23,7 +23,7 @@ class ListRepository extends AbstractRepository {
* @param string $id
* @param array $parameters
* @param array $headers
* @return Job
* @return Lists
*/
public function load($id, array $parameters = array(), array $headers = array()) {
return $this->getFactory()->create(
Expand All @@ -34,15 +34,73 @@ public function load($id, array $parameters = array(), array $headers = array())
/**
* Check to see if a movie ID is already added to a list.
*
* @param int $id
* @param string $id
* @param int $mediaId
* @param array $parameters
* @param array $headers
* @return Jobs|Job[]
* @return ItemStatus
*/
public function getItemStatus($id, array $parameters = array(), array $headers = array())
public function getItemStatus($id, $mediaId, array $parameters = array(), array $headers = array())
{
return $this->getFactory()->createItemStatus(
$this->getApi()->getItemStatus($id, $parameters, $headers)
$this->getApi()->getItemStatus($id, $mediaId, $parameters, $headers)
);
}

/**
* This method lets users create a new list. A valid session id is required.
*
* @param string $name
* @param string $description
* @param array $parameters
* @param array $headers
* @return string The list id
*/
public function createList($name, $description = null, array $parameters = array(), array $headers = array())
{
return $this->getFactory()->createResultWithListId(
$this->getApi()->createList($name, $description, $parameters, $headers)
);
}

/**
* This method lets users add new movies to a list that they created. A valid session id is required.
*
* @param string $id
* @param int $mediaId
* @return ItemStatus
*/
public function add($id, $mediaId)
{
return $this->getFactory()->createResult(
$this->getApi()->addMediaToList($id, $mediaId)
);
}

/**
* This method lets users delete movies from a list that they created. A valid session id is required.
*
* @param string $id
* @param int $mediaId
* @return ItemStatus
*/
public function remove($id, $mediaId)
{
return $this->getFactory()->createResult(
$this->getApi()->removeMediaFromList($id, $mediaId)
);
}

/**
* This method lets users delete a list that they created. A valid session id is required.
*
* @param string $id
* @return ItemStatus
*/
public function deleteList($id)
{
return $this->getFactory()->createResult(
$this->getApi()->deleteList($id)
);
}

Expand Down
Loading

0 comments on commit d958f28

Please sign in to comment.