Skip to content

Commit

Permalink
Full Guzzle6 Support
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Oderwald committed Aug 16, 2015
1 parent 2714943 commit 9a1d232
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"require": {
"php": ">=5.4.0",
"guzzlehttp/guzzle": "~5.3|~6.0"
"guzzlehttp/guzzle": "~6.0"
},
"autoload": {
"psr-4": {
Expand Down
10 changes: 5 additions & 5 deletions src/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ public function __construct($apiKey)

public function get($uri = null, $parameters = [])
{
return $this->execute('get', $uri, $parameters)->json();
return json_decode($this->execute('get', $uri, $parameters)->getBody(), true);
}

public function post($uri = null, $parameters = [])
public function post($uri = null, $parameters = [], $body = [])
{
return $this->execute('post', $uri, $parameters)->json();
return json_decode($this->execute('post', $uri, $parameters, $body)->getBody(), true);
}

public function execute($httpMethod, $uri, array $parameters = [], array $body = [])
{
return $this->getClient()->{$httpMethod}("{$uri}", [
'query' => $parameters,
'body' => $body
'query' => $parameters,
'form_params' => $body
]);
}

Expand Down
19 changes: 7 additions & 12 deletions src/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
use GuzzleHttp\Query;
use GuzzleHttp\Event\BeforeEvent;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Message\RequestInterface;
use ComyoMedia\Shipcloud\Exception as Exception;
use Psr\Http\Message\RequestInterface;

class Client extends \GuzzleHttp\Client implements ClientInterface
{
Expand All @@ -15,19 +14,15 @@ class Client extends \GuzzleHttp\Client implements ClientInterface
public function __construct($apiKey)
{
$this->apiKey = $apiKey;
parent::__construct(['base_url' => 'https://api.shipcloud.io/v1/']);

$this->getEmitter()->on('before', function (BeforeEvent $event) {
$request = $event->getRequest();

$request->setHeader(
'Authorization', 'Basic '.base64_encode($this->apiKey)
);
});
parent::__construct([
'base_uri' => 'https://api.shipcloud.io/v1/',
'auth' => [$apiKey, null]
]);
}

public function send(RequestInterface $request)
public function send(RequestInterface $request, array $options = [])
{
return parent::send($request);
return parent::send($request, $options);
}
}
4 changes: 2 additions & 2 deletions src/Http/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace ComyoMedia\Shipcloud\Http;

use GuzzleHttp\Message\RequestInterface;
use Psr\Http\Message\RequestInterface;

interface ClientInterface
{
public function send(RequestInterface $request);
public function send(RequestInterface $request, array $options = []);
}

0 comments on commit 9a1d232

Please sign in to comment.