|
6 | 6 | use GuzzleHttp\Client as HTTPClient; |
7 | 7 | use GuzzleHttp\ClientInterface; |
8 | 8 | 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; |
11 | 11 |
|
12 | 12 | /** |
13 | 13 | * Client library for postcodeapi.nu 2.0 web service. |
|
16 | 16 | */ |
17 | 17 | class Client |
18 | 18 | { |
19 | | - /** @var string */ |
20 | 19 | const BASE_URI = 'https://postcode-api.apiwise.nl'; |
21 | 20 |
|
22 | 21 | /** |
23 | 22 | * @var HTTPClient |
24 | 23 | */ |
25 | 24 | private $httpClient; |
26 | 25 |
|
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) |
43 | 27 | { |
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; |
51 | 29 | } |
52 | 30 |
|
53 | 31 | /** |
@@ -107,23 +85,23 @@ private function parseResponse(ResponseInterface $response) |
107 | 85 | $out = json_decode((string) $response->getBody()); |
108 | 86 |
|
109 | 87 | 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); |
111 | 89 | } |
112 | 90 |
|
113 | 91 | return $out; |
114 | 92 | } |
115 | 93 |
|
116 | 94 | /** |
117 | 95 | * @param string $method |
118 | | - * @param string $path |
| 96 | + * @param string $url |
119 | 97 | * @param array $queryParams |
120 | 98 | * |
121 | 99 | * @return Request |
122 | 100 | */ |
123 | | - private function createHttpRequest($method, $path, array $queryParams = array()) |
| 101 | + private function createHttpRequest($method, $url, array $queryParams = array()) |
124 | 102 | { |
125 | | - $path = $path . (count($queryParams) > 0 ? '?' . http_build_query($queryParams) : ''); |
| 103 | + $url = $url . (count($queryParams) > 0 ? '?' . http_build_query($queryParams) : ''); |
126 | 104 |
|
127 | | - return $this->httpClient->createRequest($method, $path); |
| 105 | + return new Request($method, $url); |
128 | 106 | } |
129 | 107 | } |
0 commit comments