Skip to content

Commit 5522331

Browse files
committed
VG-2746: Change user-key header to appKey
- The config should contain only the Base URI without context. - The header key has changed from user-key to apiKey.
1 parent a287c7a commit 5522331

File tree

14 files changed

+60
-45
lines changed

14 files changed

+60
-45
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All Notable changes to the `district09/gent-lez` package.
44

5+
## [Unreleased]
6+
7+
### Changed
8+
9+
- VG-2746: Change user-key header to appKey.
10+
511
## [3.0.0]
612

713
### Added

examples/DetailsFromLambert72.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
require_once __DIR__ . '/bootstrap.php';
1313

1414
/** @var string $apiEndpoint */
15-
/** @var string $apiUserKey */
15+
/** @var string|null $apiKey */
1616

1717
printTitle('Get the LEZ details (if any) for a given Lambert72 coordinate.');
1818

@@ -31,7 +31,7 @@
3131
}
3232

3333
printStep('Create the API client configuration.');
34-
$configuration = new Configuration($apiEndpoint, $apiUserKey);
34+
$configuration = new Configuration(endpointUri: $apiEndpoint, apiKey: $apiKey);
3535

3636
printStep('Create the Guzzle client.');
3737
$guzzleClient = new GuzzleHttp\Client(['base_uri' => $configuration->getUri()]);

examples/DetailsFromWgs84.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
require_once __DIR__ . '/bootstrap.php';
1313

1414
/** @var string $apiEndpoint */
15-
/** @var string $apiUserKey */
15+
/** @var string|null $apiKey */
1616

1717
printTitle('Get the LEZ details (if any) for a given WGS84 coordinate.');
1818

@@ -31,7 +31,7 @@
3131
}
3232

3333
printStep('Create the API client configuration.');
34-
$configuration = new Configuration($apiEndpoint, $apiUserKey);
34+
$configuration = new Configuration(endpointUri: $apiEndpoint, apiKey: $apiKey);
3535

3636
printStep('Create the Guzzle client.');
3737
$guzzleClient = new GuzzleHttp\Client(['base_uri' => $configuration->getUri()]);

examples/Lambert72InLez.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
require_once __DIR__ . '/bootstrap.php';
1313

1414
/** @var string $apiEndpoint */
15-
/** @var string $apiUserKey */
15+
/** @var string $apiKey */
1616

1717
printTitle('Check if given Lambert72 coordinate is within Gent LEZ.');
1818

@@ -31,7 +31,7 @@
3131
}
3232

3333
printStep('Create the API client configuration.');
34-
$configuration = new Configuration($apiEndpoint, $apiUserKey);
34+
$configuration = new Configuration(endpointUri: $apiEndpoint, apiKey: $apiKey);
3535

3636
printStep('Create the Guzzle client.');
3737
$guzzleClient = new GuzzleHttp\Client(['base_uri' => $configuration->getUri()]);

examples/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ and how to retrieve data from the webservice.
77

88
The examples require the `config.php` file being in place and filled in.
99

10-
Copy the `config.example.php` file to `config.php` and fill in the
11-
values. Do not alter the example scripts, all variables are defined in
12-
the `config.php` file.
10+
Copy the `config.example.php` file to `config.php` and fill in the values. Do
11+
not alter the example scripts, all variables are defined in the `config.php`
12+
file.
1313

1414
Install the libraries:
1515

examples/Wgs84InLez.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
require_once __DIR__ . '/bootstrap.php';
1313

1414
/** @var string $apiEndpoint */
15-
/** @var string $apiUserKey */
15+
/** @var string $apiKey */
1616

1717
printTitle('Check if given WGS84 coordinate is within Gent LEZ.');
1818

@@ -31,7 +31,7 @@
3131
}
3232

3333
printStep('Create the API client configuration.');
34-
$configuration = new Configuration($apiEndpoint, $apiUserKey);
34+
$configuration = new Configuration(endpointUri: $apiEndpoint, apiKey: $apiKey);
3535

3636
printStep('Create the Guzzle client.');
3737
$guzzleClient = new GuzzleHttp\Client(['base_uri' => $configuration->getUri()]);

examples/config.example.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
// The service endpoint.
88
$apiEndpoint = '';
99

10-
// Optional api endpoint user key.
11-
$apiUserKey = null;
10+
// Optional api endpoint key.
11+
$apiKey = null;

src/Client/Client.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ protected function injectHeaders(RequestInterface $request): RequestInterface
4242

4343
/** @var \District09\Gent\Lez\Configuration\ConfigurationInterface $configuration */
4444
$configuration = $this->configuration;
45-
if (!empty($configuration->userKey())) {
45+
if (!empty($configuration->apiKey())) {
4646
$request = $request->withHeader(
47-
'user-key',
48-
$configuration->userKey()
47+
'apiKey',
48+
$configuration->apiKey()
4949
);
5050
}
5151

src/Configuration/Configuration.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,31 @@
1212
final class Configuration extends BaseConfiguration implements ConfigurationInterface
1313
{
1414
/**
15-
* The API user key.
15+
* Create configuration by its parameters.
1616
*
17-
* @var string|null
17+
* @param string $endpointUri
18+
* The base endpoint URI.
19+
* @param array|null $options
20+
* The client options.
21+
* @param string|null $apiKey
22+
* The API key to use (if any).
1823
*/
19-
private $userKey;
20-
21-
/**
22-
* @inheritDoc
23-
*/
24-
public function __construct(string $endpointUri, ?string $userKey, array $options = [])
25-
{
26-
if (\substr($endpointUri, -1) !== '/') {
24+
public function __construct(
25+
string $endpointUri,
26+
?array $options = [],
27+
private ?string $apiKey = null,
28+
) {
29+
if (!str_ends_with($endpointUri, '/')) {
2730
$endpointUri .= '/';
2831
}
29-
parent::__construct($endpointUri, $options);
30-
31-
$this->userKey = $userKey;
32+
parent::__construct($endpointUri, $options ?? []);
3233
}
3334

3435
/**
3536
* @inheritDoc
3637
*/
37-
public function userKey(): ?string
38+
public function apiKey(): ?string
3839
{
39-
return $this->userKey;
40+
return $this->apiKey;
4041
}
4142
}

src/Configuration/ConfigurationInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ interface ConfigurationInterface extends BaseConfigurationInterface
1616
*
1717
* @return string|null
1818
*/
19-
public function userKey(): ?string;
19+
public function apiKey(): ?string;
2020
}

0 commit comments

Comments
 (0)