Skip to content

Commit 3c68d6d

Browse files
atymicjbelien
authored andcommitted
fix: update freegeoip post-shutdown (#1002)
* fix: update freegeoip post-shutdown * chore: fixing tests * chore: docs update
1 parent 11a254c commit 3c68d6d

14 files changed

+83
-40
lines changed

src/Provider/FreeGeoIp/FreeGeoIp.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace Geocoder\Provider\FreeGeoIp;
1414

1515
use Geocoder\Collection;
16+
use Geocoder\Exception\InvalidArgument;
1617
use Geocoder\Exception\UnsupportedOperation;
1718
use Geocoder\Model\AddressBuilder;
1819
use Geocoder\Model\AddressCollection;
@@ -28,15 +29,15 @@
2829
final class FreeGeoIp extends AbstractHttpProvider implements Provider
2930
{
3031
/**
31-
* @var string
32+
* @var string|null
3233
*/
3334
private $baseUrl;
3435

3536
/**
3637
* @param HttpClient $client
3738
* @param string $baseUrl
3839
*/
39-
public function __construct(HttpClient $client, string $baseUrl = 'https://freegeoip.net/json/%s')
40+
public function __construct(HttpClient $client, string $baseUrl = null)
4041
{
4142
parent::__construct($client);
4243

@@ -48,6 +49,14 @@ public function __construct(HttpClient $client, string $baseUrl = 'https://freeg
4849
*/
4950
public function geocodeQuery(GeocodeQuery $query): Collection
5051
{
52+
if (null === $this->baseUrl) {
53+
throw new InvalidArgument(sprintf(
54+
'The FreeGeoIp.net service no longer operates. See %s and %s for more information.',
55+
'http://freegeoip.net/shutdown',
56+
'https://github.com/geocoder-php/free-geoip-provider'
57+
));
58+
}
59+
5160
$address = $query->getText();
5261
if (!filter_var($address, FILTER_VALIDATE_IP)) {
5362
throw new UnsupportedOperation('The FreeGeoIp provider does not support street addresses.');

src/Provider/FreeGeoIp/Readme.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,34 @@
1010
This is the Free GeoIp provider from the PHP Geocoder. This is a **READ ONLY** repository. See the
1111
[main repo](https://github.com/geocoder-php/Geocoder) for information and documentation.
1212

13-
### Install
13+
## Freegeoip Shutdown
14+
As per the [freegeoip.net](http://freegeoip.net/shutdown) website, the provider has been purchased by [IpStack](https://ipstack.com/).
15+
As a result, this provider no longer works with the default configuration. It will still work if you use the
16+
[self hosted variant](https://github.com/apilayer/freegeoip/) and supply a host when constructing the provider.
17+
18+
## Usage
19+
```php
20+
$httpClient = new \Http\Adapter\Guzzle6\Client();
21+
22+
// This will no longer work
23+
$provider = new Geocoder\Provider\FreeGeoIp\FreeGeoIp($httpClient);
24+
// You must provide the endpoint of your instance
25+
$provider = new Geocoder\Provider\FreeGeoIp\FreeGeoIp($httpClient, 'http://my.internal.geocoder/json/%s');
26+
```
27+
28+
## Alternatives
29+
We offer an [IpStack provider](https://github.com/geocoder-php/ipstack-provider) which you can use if you wish to continue with the new service owner.
30+
31+
### Full IP Provider List
32+
https://github.com/geocoder-php/Geocoder#ip
33+
34+
## Install
1435

1536
```bash
1637
composer require geocoder-php/free-geoip-provider
1738
```
1839

19-
### Contribute
40+
## Contribute
2041

2142
Contributions are very welcome! Send a pull request to the [main repository](https://github.com/geocoder-php/Geocoder) or
2243
report any issues you find on the [issue tracker](https://github.com/geocoder-php/Geocoder/issues).

src/Provider/FreeGeoIp/Tests/.cached_responses/freegeoip.net_500b2d9369a4fc679d5ceb9a418cf02bf10d013d

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/Provider/FreeGeoIp/Tests/.cached_responses/freegeoip.net_56adadaf03f9037e7cae3a464b6dc9617f814883

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/Provider/FreeGeoIp/Tests/.cached_responses/freegeoip.net_66299fd8d42b096fa031b8d1832fc8eb50277552

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/Provider/FreeGeoIp/Tests/.cached_responses/freegeoip.net_77986275ed32e32047ac76a39223f623f52033bc

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/Provider/FreeGeoIp/Tests/.cached_responses/freegeoip.net_8aaa58eef1ef2a53923da060d6a9de0db75bf96d

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/Provider/FreeGeoIp/Tests/.cached_responses/freegeoip.net_8c694912ce2a0ccbf93c7f24111247dbea9916ad

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/Provider/FreeGeoIp/Tests/.cached_responses/freegeoip.net_9a5acb5700a246cf22916f12ecea2dd2a58c99bb

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/Provider/FreeGeoIp/Tests/.cached_responses/freegeoip.net_bcc32e827a944478cb862d570202ef3e941ff8ef

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)