Skip to content

Commit d8cc1f7

Browse files
atymicjbelien
authored andcommitted
fix: bring back free geo ip provider (#1010)
1 parent 326a70c commit d8cc1f7

15 files changed

+67
-67
lines changed

src/Provider/FreeGeoIp/FreeGeoIp.php

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

1515
use Geocoder\Collection;
16-
use Geocoder\Exception\InvalidArgument;
1716
use Geocoder\Exception\UnsupportedOperation;
1817
use Geocoder\Model\AddressBuilder;
1918
use Geocoder\Model\AddressCollection;
@@ -37,7 +36,7 @@ final class FreeGeoIp extends AbstractHttpProvider implements Provider
3736
* @param HttpClient $client
3837
* @param string $baseUrl
3938
*/
40-
public function __construct(HttpClient $client, string $baseUrl = null)
39+
public function __construct(HttpClient $client, string $baseUrl = 'https://freegeoip.app/json/%s')
4140
{
4241
parent::__construct($client);
4342

@@ -49,15 +48,8 @@ public function __construct(HttpClient $client, string $baseUrl = null)
4948
*/
5049
public function geocodeQuery(GeocodeQuery $query): Collection
5150
{
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-
6051
$address = $query->getText();
52+
6153
if (!filter_var($address, FILTER_VALIDATE_IP)) {
6254
throw new UnsupportedOperation('The FreeGeoIp provider does not support street addresses.');
6355
}

src/Provider/FreeGeoIp/Readme.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,30 @@
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-
## 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.
13+
Provider Website: https://freegeoip.app
1714

1815
## Usage
1916
```php
2017
$httpClient = new \Http\Adapter\Guzzle6\Client();
2118

22-
// This will no longer work
19+
// Use the default provider (https://freegeoip.app)
2320
$provider = new Geocoder\Provider\FreeGeoIp\FreeGeoIp($httpClient);
24-
// You must provide the endpoint of your instance
21+
// Or provide the endpoint of your instance
2522
$provider = new Geocoder\Provider\FreeGeoIp\FreeGeoIp($httpClient, 'http://my.internal.geocoder/json/%s');
2623
```
2724

28-
## Alternatives
25+
## Freegeoip.net shutdown
26+
As per the [freegeoip.net](http://freegeoip.net/shutdown) website, the provider has been purchased by [IpStack](https://ipstack.com/).
27+
As a result, this provider no longer uses this service with the default configuration.
28+
29+
By default, it will now use `freegeoip.app` (which provides a hosted version of the same API as `freegeoip.net`).
30+
31+
You can also use the [self hosted variant](https://github.com/apilayer/freegeoip/) and supply a host when constructing the provider.
32+
33+
### Alternatives
2934
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.
3035

31-
### Full IP Provider List
36+
#### Full IP Provider List
3237
https://github.com/geocoder-php/Geocoder#ip
3338

3439
## Install
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
s:190:"{"ip":"2001:db8:0:42:0:8a2e:370:7334","country_code":"","country_name":"","region_code":"","region_name":"","city":"","zip_code":"","time_zone":"","latitude":0,"longitude":0,"metro_code":0}
2+
";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
s:230:"{"ip":"83.227.123.8","country_code":"SE","country_name":"Sweden","region_code":"K","region_name":"Blekinge","city":"Naettraby","zip_code":"370 24","time_zone":"Europe/Stockholm","latitude":56.2,"longitude":15.5167,"metro_code":0}
2+
";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
s:209:"{"ip":"87.227.124.53","country_code":"SE","country_name":"Sweden","region_code":"","region_name":"","city":"","zip_code":"","time_zone":"Europe/Stockholm","latitude":59.3247,"longitude":18.056,"metro_code":0}
2+
";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
s:235:"{"ip":"129.67.242.154","country_code":"GB","country_name":"United Kingdom","region_code":"ENG","region_name":"England","city":"Oxford","zip_code":"OX1","time_zone":"Europe/London","latitude":51.7155,"longitude":-1.2926,"metro_code":0}
2+
";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
s:274:"{"ip":"81.27.51.253","country_code":"RU","country_name":"Россия","region_code":"VLA","region_name":"Владимирская область","city":"Владимир","zip_code":"601280","time_zone":"Europe/Moscow","latitude":56.1833,"longitude":40.35,"metro_code":0}
2+
";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
s:215:"{"ip":"74.200.247.59","country_code":"US","country_name":"United States","region_code":"","region_name":"","city":"","zip_code":"","time_zone":"America/Chicago","latitude":37.751,"longitude":-97.822,"metro_code":0}
2+
";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
s:215:"{"ip":"74.200.247.59","country_code":"US","country_name":"United States","region_code":"","region_name":"","city":"","zip_code":"","time_zone":"America/Chicago","latitude":37.751,"longitude":-97.822,"metro_code":0}
2+
";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
s:239:"{"ip":"81.27.51.252","country_code":"RU","country_name":"Russie","region_code":"VLA","region_name":"Oblast de Vladimir","city":"Vladimir","zip_code":"601280","time_zone":"Europe/Moscow","latitude":56.1833,"longitude":40.35,"metro_code":0}
2+
";

0 commit comments

Comments
 (0)