Skip to content

Commit

Permalink
Adding Changes API section, added Query object to support this behavi…
Browse files Browse the repository at this point in the history
…our.
  • Loading branch information
wtfzdotnet committed Jan 18, 2014
1 parent 3a6ce54 commit dca8277
Show file tree
Hide file tree
Showing 11 changed files with 304 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,19 @@
$token = new \Tmdb\ApiToken(TMDB_API_KEY);
$client = new \Tmdb\Client($token);

$changes = new \Tmdb\Model\Changes($client);
$query = new \Tmdb\Model\Query\ChangesQuery();

$response = $changes->page(2)->execute();
$from = new \DateTime('01-01-2012');
$to = new \DateTime('08-01-2012');

$query
->page(1)
->from($from)
->to($to)
;

$repository = new \Tmdb\Repository\ChangesRepository($client);
$response = $repository->getMovieChanges($query);

var_dump($response);

34 changes: 34 additions & 0 deletions examples/changes/model/people.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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);

$query = new \Tmdb\Model\Query\ChangesQuery();

$from = new \DateTime('01-01-2012');
$to = new \DateTime('08-01-2012');

$query
->page(1)
->from($from)
->to($to)
;

$repository = new \Tmdb\Repository\ChangesRepository($client);
$response = $repository->getPeopleChanges($query);

var_dump($response);

4 changes: 4 additions & 0 deletions lib/Tmdb/Factory/MovieFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ public static function createCollection(array $data = array())
{
$collection = new GenericCollection();

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

foreach($data as $item) {
$collection->add(null, self::create($item));
}
Expand Down
4 changes: 4 additions & 0 deletions lib/Tmdb/Factory/People/PeopleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public static function createCollection(array $data = array(), Person\AbstractMe
{
$collection = new GenericCollection();

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

foreach($data as $item) {
$collection->add(null, self::create($item, $person));
}
Expand Down
73 changes: 73 additions & 0 deletions lib/Tmdb/Model/Change.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\Client;

class Change extends AbstractModel {
/**
* @var integer
*/
private $id;

/**
* @var boolean
*/
private $adult;

/**
* @var array
*/
public static $_properties = array(
'id',
'adult'
);

/**
* @param boolean $adult
* @return $this
*/
public function setAdult($adult)
{
$this->adult = $adult;
return $this;
}

/**
* @return boolean
*/
public function getAdult()
{
return $this->adult;
}

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

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


}
87 changes: 0 additions & 87 deletions lib/Tmdb/Model/Changes.php

This file was deleted.

17 changes: 17 additions & 0 deletions lib/Tmdb/Model/Collection/QueryParametersCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?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\Collection;

use Tmdb\Model\Common\GenericCollection;

class QueryParametersCollection extends GenericCollection {}
95 changes: 95 additions & 0 deletions lib/Tmdb/Model/Collection/ResultCollection.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\Collection;

use Tmdb\Model\Common\GenericCollection;

class ResultCollection extends GenericCollection {
/**
* @var int
*/
private $page = 1;

/**
* @var int
*/
private $totalPages = 1;

/**
* @var int
*/
private $totalResults = 0;

/**
* @var array
*/
public static $_properties = array(
'page',
'total_pages',
'total_results'
);

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

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

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

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

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

/**
* @return int
*/
public function getTotalResults()
{
return $this->totalResults;
}
}
Loading

0 comments on commit dca8277

Please sign in to comment.