From 050dad02b6adbd9e5e150a1e4c05e2fa18b24c49 Mon Sep 17 00:00:00 2001 From: Mohamed Ben Date: Wed, 4 Sep 2019 21:03:34 +0100 Subject: [PATCH 1/2] add new Services ipfinder.io --- config/geoip.php | 7 ++++++ src/Services/IPFinder.php | 50 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/Services/IPFinder.php 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..6ad14c6 --- /dev/null +++ b/src/Services/IPFinder.php @@ -0,0 +1,50 @@ +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); + } +} \ No newline at end of file From e9f2b6e378fea39c744918baeb6e17559967a77f Mon Sep 17 00:00:00 2001 From: benemohamed Date: Wed, 4 Sep 2019 21:11:50 +0100 Subject: [PATCH 2/2] Update IPFinder.php --- src/Services/IPFinder.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Services/IPFinder.php b/src/Services/IPFinder.php index 6ad14c6..2bc934a 100644 --- a/src/Services/IPFinder.php +++ b/src/Services/IPFinder.php @@ -1,8 +1,11 @@ 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); } -} \ No newline at end of file +}