Skip to content

Commit 9ac9f01

Browse files
committed
use consts properly, cleanup
1 parent 91c36b9 commit 9ac9f01

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ phpunit.xml
55
.phpunit.result.cache
66
.php-cs-fixer.cache
77
.puli/
8+
.idea

src/Provider/Geonames/Geonames.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,26 @@
3232
*/
3333
final class Geonames extends AbstractHttpProvider implements Provider
3434
{
35+
36+
/**
37+
* @var string
38+
*/
39+
public const PREMIUM_WEBSERVICE_BASE_URL = 'https://secure.geonames.net';
40+
3541
/**
3642
* @var string
3743
*/
38-
public const GEOCODE_ENDPOINT_URL = 'http://api.geonames.org/searchJSON?q=%s&maxRows=%d&style=full&username=%s';
44+
public const FREE_WEBSERVICE_BASE_URL = 'http://api.geonames.net';
3945

4046
/**
4147
* @var string
4248
*/
43-
public const REVERSE_ENDPOINT_URL = 'http://api.geonames.org/findNearbyPlaceNameJSON?lat=%F&lng=%F&style=full&maxRows=%d&username=%s';
49+
public const GEOCODE_ENDPOINT_PATH = '%s/searchJSON?q=%s&maxRows=%d&style=full&username=%s';
4450

4551
/**
4652
* @var string
4753
*/
48-
public const BASE_ENDPOINT_URL = 'http://api.geonames.org/%s?username=%s';
54+
public const REVERSE_ENDPOINT_PATH = '%s/findNearbyPlaceNameJSON?lat=%F&lng=%F&style=full&maxRows=%d&username=%s';
4955

5056
/**
5157
* @var string
@@ -77,11 +83,11 @@ public function __construct(ClientInterface $client, string $username, ?string $
7783
$this->username = $username;
7884
$this->token = $token;
7985

80-
// Determine base URL based on secure flag
81-
if ($secure) {
82-
$this->baseUrl = 'https://secure.geonames.net';
86+
// Determine base URL based on secure flag.
87+
if ($secure === TRUE) {
88+
$this->baseUrl = self::PREMIUM_WEBSERVICE_BASE_URL;
8389
} else {
84-
$this->baseUrl = 'http://api.geonames.org';
90+
$this->baseUrl = self::FREE_WEBSERVICE_BASE_URL;
8591
}
8692

8793
parent::__construct($client);
@@ -97,7 +103,7 @@ public function geocodeQuery(GeocodeQuery $query): Collection
97103
}
98104

99105
$url = sprintf(
100-
'%s/searchJSON?q=%s&maxRows=%d&style=full&username=%s',
106+
self::GEOCODE_ENDPOINT_PATH,
101107
$this->baseUrl,
102108
urlencode($address),
103109
$query->getLimit(),
@@ -116,7 +122,7 @@ public function reverseQuery(ReverseQuery $query): Collection
116122
$latitude = $coordinates->getLatitude();
117123

118124
$url = sprintf(
119-
'%s/findNearbyPlaceNameJSON?lat=%F&lng=%F&style=full&maxRows=%d&username=%s',
125+
self::REVERSE_ENDPOINT_PATH,
120126
$this->baseUrl,
121127
$latitude,
122128
$longitude,

0 commit comments

Comments
 (0)