diff --git a/config/geoip.php b/config/geoip.php index c3de525..7e43bd7 100644 --- a/config/geoip.php +++ b/config/geoip.php @@ -87,6 +87,13 @@ 'secure' => true, ], + 'ipfinder' => [ + 'class' => \Torann\GeoIP\Services\IPFinder::class, + 'key' => env('IPFINDER_API_KEY'), + 'secure' => true, + 'locales' => ['en'], + ], + ], /* diff --git a/src/Services/IPFinder.php b/src/Services/IPFinder.php new file mode 100644 index 0000000..2bc934a --- /dev/null +++ b/src/Services/IPFinder.php @@ -0,0 +1,58 @@ +client = new HttpClient([ + 'base_uri' => 'https://api.ipfinder.io/v1/', + 'headers' => [ + 'User-Agent' => 'Laravel-GeoIP-Torann', + ], + 'query' => [ + 'token' => $this->config('key'), + ], + ]); + } + + /** + * {@inheritdoc} + * @throws Exception + */ + public function locate($ip) + { + // Get data from client + $data = $this->client->get($ip); + + // Verify server response + if ($this->client->getErrors() !== null || empty($data[0])) { + throw new Exception('Request failed (' . $this->client->getErrors() . ')'); + } + + $json = json_decode($data[0], true); + + return $this->hydrate($json); + } +}