-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from chadicus/develop
Add __call() to Client
- Loading branch information
Showing
8 changed files
with
212 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?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"; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?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"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
namespace Chadicus\Marvel\Api\Assets; | ||
|
||
use Chadicus\Marvel\Api\Adapter\AdapterInterface; | ||
use Chadicus\Marvel\Api\RequestInterface; | ||
use Chadicus\Marvel\Api\Response; | ||
|
||
/** | ||
* Adapter implementation that only returns empty responses. | ||
*/ | ||
final class ErrorAdapter implements AdapterInterface | ||
{ | ||
/** | ||
* The last request given to this adapter. | ||
* | ||
* @var Request | ||
*/ | ||
private $request = null; | ||
|
||
/** | ||
* Returns an empty Response. | ||
* | ||
* @param RequestInterface $request The request to send. | ||
* | ||
* @return ResponseInterface | ||
*/ | ||
public function send(RequestInterface $request) | ||
{ | ||
$this->request = $request; | ||
|
||
return new Response( | ||
404, | ||
[ | ||
'code' => 'ResourceNotFound', | ||
'message' => "{$request->getUrl()} was not found", | ||
], | ||
[ | ||
'Response Code' => 404, | ||
'Response Status' => 'Not Found', | ||
'Content-Type' => 'application/json', | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Return the last request given to this Adapter. | ||
* | ||
* @return RequestInterface | ||
*/ | ||
public function getRequest() | ||
{ | ||
return $this->request; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters