Skip to content

Commit

Permalink
updating to use the Guzzle 6.x client
Browse files Browse the repository at this point in the history
  • Loading branch information
caseysoftware committed Jan 3, 2016
1 parent 9bcf96f commit 1e72c28
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/Marvel/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Marvel;

use Guzzle\Http;
use GuzzleHttp\Client as GuzzleClient;
use Marvel\Exceptions\InvalidResource;

/**
Expand Down Expand Up @@ -31,8 +31,9 @@ public function __construct($publicKey, $privateKey, $httpClient = null)
{
$this->publicKey = $publicKey;
$this->privateKey = $privateKey;
$this->client = (is_null($httpClient)) ? new Http\Client($this->baseURI) : $httpClient;
$this->client->setUserAgent($this::USER_AGENT . '/' . PHP_VERSION);
$this->httpClient = (is_null($httpClient)) ? new GuzzleClient(
['base_uri' => $this->baseURI, 'headers' => ['User-Agent' => $this::USER_AGENT . '/' . PHP_VERSION ]]
) : $httpClient;
}

public function get($uri, $params = array())
Expand All @@ -42,15 +43,12 @@ public function get($uri, $params = array())
$params['apikey'] = $this->publicKey;
$params['hash'] = md5($timestamp . $this->privateKey . $this->publicKey);

$request = $this->client->get($uri, array(), array('exceptions' => false));
foreach($params as $key => $value) {
$request->getQuery()->set($key, $value);
}
$this->response = $this->httpClient->get($uri, ['exceptions' => false, 'query' => $params] );

$this->response = $request->send();
$this->statusCode = $this->response->getStatusCode();
$raw_body = $this->response->getBody();

return $this->response->json();
return json_decode($raw_body, true);
}

/**
Expand All @@ -67,7 +65,7 @@ public function __get($name)
return new $fullclass($this);
}

throw new \Marvel\Exceptions\InvalidResource('Resource not found');
throw new InvalidResource('Resource not found');
}

public function getUri()
Expand Down

0 comments on commit 1e72c28

Please sign in to comment.