3232 */
3333final 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