Skip to content

Commit d55393d

Browse files
committed
Update to Guzzle 6
1 parent 49d240e commit d55393d

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
}
1717
],
1818
"require": {
19-
"php": ">=5.4.0",
20-
"guzzlehttp/guzzle": "~5.0"
19+
"php": ">=5.5.0",
20+
"guzzlehttp/guzzle": "~6.0"
2121
},
2222
"autoload": {
2323
"psr-4": {

src/Picqer/Carriers/SendCloud/Connection.php

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
use GuzzleHttp\Client;
44
use GuzzleHttp\Exception\RequestException;
5-
use GuzzleHttp\Message\Response;
5+
use GuzzleHttp\Psr7\Request;
6+
use GuzzleHttp\Psr7\Response;
67

78
class Connection {
89

@@ -64,23 +65,20 @@ public function client()
6465
{
6566
if ($this->client) return $this->client;
6667

67-
6868
$this->client = new Client([
69-
'base_url' => $this->apiUrl()
70-
]);
71-
$this->client->setDefaultOption('headers/Accept', 'application/json');
72-
$this->client->setDefaultOption('headers/Content-Type', 'application/json');
73-
$this->client->setDefaultOption('auth', [
74-
$this->apiKey,
75-
$this->apiSecret
69+
'base_uri' => $this->apiUrl(),
70+
'headers' => [
71+
'Accept' => 'application/json',
72+
'Content-Type' => 'application/json'
73+
],
74+
'auth' => [$this->apiKey, $this->apiSecret]
7675
]);
7776

7877
return $this->client;
7978
}
8079

8180
public function setDebug($handle)
8281
{
83-
$this->client()->setDefaultOption('debug', $handle);
8482
}
8583

8684
/**
@@ -96,23 +94,13 @@ public function apiUrl()
9694
/**
9795
* Perform a GET request
9896
* @param string $url
99-
* @param array $params
100-
* @return string
97+
* @return array
10198
* @throws SendCloudApiException
10299
*/
103-
public function get($url, array $params = [])
100+
public function get($url)
104101
{
105-
$request = $this->client()->createRequest('GET', $url);
106-
107-
$query = $request->getQuery();
108-
109-
foreach ($params as $paramName => $paramValue)
110-
{
111-
$query->set($paramName, $paramValue);
112-
}
113-
114102
try {
115-
$result = $this->client()->send($request);
103+
$result = $this->client()->get($url);
116104
} catch (RequestException $e) {
117105
if ($e->hasResponse())
118106
$this->parseResponse($e->getResponse());
@@ -193,7 +181,7 @@ public function delete($url)
193181
public function parseResponse(Response $response)
194182
{
195183
try {
196-
$resultArray = $response->json();
184+
$resultArray = json_decode($response->getBody()->getContents(), true);
197185

198186
if (array_key_exists('error', $resultArray)
199187
&& is_array($resultArray['error'])

0 commit comments

Comments
 (0)