Skip to content

Commit 1603596

Browse files
authored
Allow you to configure URL for FreeGeoIp (#710)
* Allow you to configure URL for FreeGeoIp * Applied changes from StyleCI
1 parent d0e5cd3 commit 1603596

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Provider/FreeGeoIp/FreeGeoIp.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Geocoder\Http\Provider\AbstractHttpProvider;
2222
use Geocoder\Provider\IpAddressGeocoder;
2323
use Geocoder\Provider\Provider;
24+
use Http\Client\HttpClient;
2425

2526
/**
2627
* @author William Durand <[email protected]>
@@ -30,7 +31,18 @@ final class FreeGeoIp extends AbstractHttpProvider implements Provider, IpAddres
3031
/**
3132
* @var string
3233
*/
33-
const ENDPOINT_URL = 'https://freegeoip.net/json/%s';
34+
private $baseUrl;
35+
36+
/**
37+
* @param HttpClient $client
38+
* @param string $baseUrl
39+
*/
40+
public function __construct(HttpClient $client, string $baseUrl = 'https://freegeoip.net/json/%s')
41+
{
42+
parent::__construct($client);
43+
44+
$this->baseUrl = $baseUrl;
45+
}
3446

3547
/**
3648
* {@inheritdoc}
@@ -46,7 +58,7 @@ public function geocodeQuery(GeocodeQuery $query): Collection
4658
return new AddressCollection([$this->getLocationForLocalhost()]);
4759
}
4860

49-
$content = $this->getUrlContents(sprintf(self::ENDPOINT_URL, $address));
61+
$content = $this->getUrlContents(sprintf($this->baseUrl, $address));
5062
$data = json_decode($content, true);
5163
$builder = new AddressBuilder($this->getName());
5264

0 commit comments

Comments
 (0)