Skip to content
This repository was archived by the owner on Apr 24, 2026. It is now read-only.

Commit 51062a6

Browse files
bart-van-amelsvoortEvert Harmeling
authored andcommitted
guzzle 6
1 parent 53517be commit 51062a6

3 files changed

Lines changed: 12 additions & 34 deletions

File tree

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
],
1818
"require": {
1919
"php": ">=5.4.0",
20-
"guzzlehttp/guzzle": "^5.2|^6.0"
20+
"guzzlehttp/guzzle": "^6.0"
2121
},
2222
"autoload": {
2323
"psr-0": { "FH\\PostcodeAPI": "lib/" }
2424
},
2525
"extra": {
2626
"branch-alias": {
27-
"dev-master": "2.0.x-dev"
27+
"dev-master": "3.0.x-dev"
2828
}
2929
}
3030
}

lib/FH/PostcodeAPI/Client.php

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
use GuzzleHttp\Client as HTTPClient;
77
use GuzzleHttp\ClientInterface;
88
use GuzzleHttp\Exception\RequestException;
9-
use GuzzleHttp\Message\Request;
10-
use GuzzleHttp\Message\ResponseInterface;
9+
use GuzzleHttp\Psr7\Request;
10+
use Psr\Http\Message\ResponseInterface;
1111

1212
/**
1313
* Client library for postcodeapi.nu 2.0 web service.
@@ -16,38 +16,16 @@
1616
*/
1717
class Client
1818
{
19-
/** @var string */
2019
const BASE_URI = 'https://postcode-api.apiwise.nl';
2120

2221
/**
2322
* @var HTTPClient
2423
*/
2524
private $httpClient;
2625

27-
/**
28-
* @param ClientInterface $httpClient
29-
* @param string $apiKey Required API key for authenticating client
30-
*/
31-
public function __construct(ClientInterface $httpClient, $apiKey)
32-
{
33-
$this->httpClient = $this->prepareClient($httpClient, $apiKey);
34-
}
35-
36-
/**
37-
* @param ClientInterface $client
38-
* @param string $apiKey
39-
*
40-
* @return HTTPClient
41-
*/
42-
private function prepareClient(ClientInterface $client, $apiKey)
26+
public function __construct(ClientInterface $httpClient)
4327
{
44-
if ($client->getDefaultOption('timeout') === null) {
45-
$client->setDefaultOption('timeout', 5.0);
46-
}
47-
48-
$client->setDefaultOption('headers/X-Api-Key', $apiKey);
49-
50-
return $client;
28+
$this->httpClient = $httpClient;
5129
}
5230

5331
/**
@@ -107,23 +85,23 @@ private function parseResponse(ResponseInterface $response)
10785
$out = json_decode((string) $response->getBody());
10886

10987
if (json_last_error() !== JSON_ERROR_NONE) {
110-
throw new CouldNotParseResponseException('Could not parse resonse', $response);
88+
throw new CouldNotParseResponseException('Could not parse repsonse', $response);
11189
}
11290

11391
return $out;
11492
}
11593

11694
/**
11795
* @param string $method
118-
* @param string $path
96+
* @param string $url
11997
* @param array $queryParams
12098
*
12199
* @return Request
122100
*/
123-
private function createHttpRequest($method, $path, array $queryParams = array())
101+
private function createHttpRequest($method, $url, array $queryParams = array())
124102
{
125-
$path = $path . (count($queryParams) > 0 ? '?' . http_build_query($queryParams) : '');
103+
$url = $url . (count($queryParams) > 0 ? '?' . http_build_query($queryParams) : '');
126104

127-
return $this->httpClient->createRequest($method, $path);
105+
return new Request($method, $url);
128106
}
129107
}

lib/FH/PostcodeAPI/Exception/CouldNotParseResponseException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace FH\PostcodeAPI\Exception;
44

5-
use GuzzleHttp\Message\ResponseInterface;
5+
use Psr\Http\Message\ResponseInterface;
66

77
/**
88
* @author Gijs Nieuwenhuis <gijs.nieuwenhuis@freshheads.com>

0 commit comments

Comments
 (0)