コード例 #1
0
 /**
  * Verify basic behavior of search().
  *
  * @test
  * @covers ::__construct
  * @covers ::search
  *
  * @return void
  */
 public function search()
 {
     \Chadicus\FunctionRegistry::set(__NAMESPACE__, 'time', function () {
         return 1;
     });
     $adapter = new FakeAdapter();
     $client = new Client('aPrivateKey', 'aPublicKey', $adapter);
     $client->search('a Resource', ['key' => 'value']);
     $request = $adapter->getRequest();
     $hash = md5('1aPrivateKeyaPublicKey');
     $expectedUrl = Client::BASE_URL . "a+Resource?key=value&apikey=aPublicKey&ts=1&hash={$hash}";
     $this->assertSame('GET', $request->getMethod());
     $this->assertSame($expectedUrl, $request->getUrl());
 }
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
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);
//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";
}