Skip to content

Commit

Permalink
Adding clear list functionality, fixes php-tmdb#22 and thus can be cl…
Browse files Browse the repository at this point in the history
…osed.
  • Loading branch information
wtfzdotnet committed Mar 26, 2014
1 parent eb106d9 commit 7cd5ea2
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
24 changes: 24 additions & 0 deletions examples/lists/api/list_clear.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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);

$clear = $client->getListsApi()->clearList(TMDB_LIST_ID, true);

var_dump($clear);
19 changes: 19 additions & 0 deletions lib/Tmdb/Api/Lists.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,23 @@ public function deleteList($id)
{
return $this->delete('list/' . $id);
}

/**
* Clear all of the items within a list.
*
* This is a irreversible action and should be treated with caution.
* A valid session id is required.
*
* @param string $id
* @param boolean $confirm
* @return mixed
*/
public function clearList($id, $confirm)
{
return $this->post(sprintf(
'list/%s/clear?confirm=%s',
$id,
(bool) $confirm === true ? 'true':'false'
));
}
}
17 changes: 17 additions & 0 deletions lib/Tmdb/Repository/ListRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@ public function deleteList($id)
);
}

/**
* Clear all of the items within a list.
*
* This is a irreversible action and should be treated with caution.
* A valid session id is required.
*
* @param string $id
* @param boolean $confirm
* @return ItemStatus
*/
public function clearList($id, $confirm)
{
return $this->getFactory()->createResult(
$this->getApi()->deleteList($id, (bool) $confirm)
);
}

/**
* Return the related API class
*
Expand Down
9 changes: 9 additions & 0 deletions test/Tmdb/Tests/Api/ListsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ public function shouldDeleteList()
$api->deleteList(self::LIST_ID);
}

/**
* @test
*/
public function shouldClearList()
{
$api = $this->getApiMock();
$api->clearList(self::LIST_ID, true);
}

protected function getApiClass()
{
return 'Tmdb\Api\Lists';
Expand Down
10 changes: 10 additions & 0 deletions test/Tmdb/Tests/Repository/ListRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ public function shouldDeleteList()
$repository->deleteList('list-id');
}

/**
* @test
*/
public function shouldClearList()
{
$repository = $this->getRepositoryWithMockedHttpClient();

$repository->clearList('list-id', true);
}

protected function getApiClass()
{
return 'Tmdb\Api\Lists';
Expand Down

0 comments on commit 7cd5ea2

Please sign in to comment.