/** * Move forward to next element, @see Iterator::next(). * * @return void */ public final function next() { ++$this->position; if ($this->position < $this->limit) { return; } $this->offset += $this->limit; $this->filters['offset'] = $this->offset; $this->filters['limit'] = $this->limit === 0 ? 20 : $this->limit; $indexResponse = $this->client->search($this->resource, $this->filters); $httpCode = $indexResponse->getHttpCode(); Util::ensure(200, $httpCode, "Did not receive 200 from API. Instead received {$httpCode}"); $this->limit = $indexResponse->getDataWrapper()->getData()->getLimit(); $this->total = $indexResponse->getDataWrapper()->getData()->getTotal(); $this->results = $indexResponse->getDataWrapper()->getData()->getResults(); $this->position = 0; }
<?php require_once dirname(__DIR__) . '/vendor/autoload.php'; use Chadicus\Marvel\Api\Client; $publicApiKey = getenv('PUBLIC_KEY'); $privateApiKey = getenv('PRIVATE_KEY'); $client = new Client($privateApiKey, $publicApiKey); $response = $client->get('characters', 1009351); $wrapper = $response->getDataWrapper(); $character = $wrapper->getData()->getResults()[0]; echo "{$character->getName()}\n"; echo "{$character->getDescription()}\n"; foreach ($character->getEvents()->getItems() as $event) { echo "\t{$event->getName()}\n"; }
/** * Verfiy response is return from cache. * * @test * @covers ::get * * @return void */ public function getSetsCache() { \Chadicus\FunctionRegistry::set(__NAMESPACE__, 'time', function () { return 1; }); $hash = md5('1aPrivateKeyaPublicKey'); $request = new Request(Client::BASE_URL . "a+Resource/1?apikey=aPublicKey&ts=1&hash={$hash}", 'GET'); $cache = new Cache\ArrayCache(); $adapter = new FakeAdapter(); $client = new Client('aPrivateKey', 'aPublicKey', $adapter, $cache); $response = $client->get('a Resource', 1); $cachedResponse = $cache->get($request); $this->assertSame($response->getHttpCode(), $cachedResponse->getHttpCode()); $this->assertSame($response->getHeaders(), $cachedResponse->getHeaders()); $this->assertSame($response->getBody(), $cachedResponse->getBody()); }
<?php require_once dirname(__DIR__) . '/vendor/autoload.php'; use Chadicus\Marvel\Api\Client; $publicApiKey = getenv('PUBLIC_KEY'); $privateApiKey = getenv('PRIVATE_KEY'); $client = new Client($privateApiKey, $publicApiKey); //1009165 is the character id for the Avangers $comics = $client->comics(['characters' => 1009165]); foreach ($comics as $comic) { echo "{$comic->getTitle()}\n"; }
<?php require_once dirname(__DIR__) . '/vendor/autoload.php'; use Chadicus\Marvel\Api\Client; $publicApiKey = getenv('PUBLIC_KEY'); $privateApiKey = getenv('PRIVATE_KEY'); $client = new Client($privateApiKey, $publicApiKey); //1009165 is the character id for the Avangers $response = $client->search('comics', ['characters' => 1009165]); echo "Response Headers\n"; foreach ($response->getHeaders() as $key => $value) { echo "{$key}: {$value}\n"; } $wrapper = $response->getDataWrapper(); echo "{$wrapper->getAttributionText()}\n"; echo "{$wrapper->getData()->getTotal()} total results found\n"; echo "{$wrapper->getData()->getCount()} comics in this response\n"; foreach ($wrapper->getData()->getResults() as $comic) { echo "{$comic->getTitle()}\n"; }
<?php require_once dirname(__DIR__) . '/vendor/autoload.php'; use Chadicus\Marvel\Api\Client; $publicApiKey = getenv('PUBLIC_KEY'); $privateApiKey = getenv('PRIVATE_KEY'); $client = new Client($privateApiKey, $publicApiKey); $character = $client->characters(1009351); echo "{$character->getName()}\n"; echo "{$character->getDescription()}\n"; foreach ($character->getEvents()->getItems() as $event) { echo "\t{$event->getName()}\n"; }
/** * Verify basic bahvior of __call() for entity collection. * * @test * @covers ::__call * * @return void */ public function callCollection() { $client = new Client('not under test', 'not under test', new Assets\ComicAdapter()); $comics = $client->comics(); $this->assertInstanceOf('Chadicus\\Marvel\\Api\\Collection', $comics); $this->assertSame(5, $comics->count()); foreach ($comics as $key => $comic) { $this->assertSame($key + 1, $comic->getId()); } }