<?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()); }