File tree Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Expand file tree Collapse file tree 2 files changed +57
-0
lines changed Original file line number Diff line number Diff line change 8787 'secure ' => true ,
8888 ],
8989
90+ 'ipfinder ' => [
91+ 'class ' => \Torann \GeoIP \Services \IPFinder::class,
92+ 'key ' => env ('IPFINDER_API_KEY ' ),
93+ 'secure ' => true ,
94+ 'locales ' => ['en ' ],
95+ ],
96+
9097 ],
9198
9299 /*
Original file line number Diff line number Diff line change 1+ <?php
2+ namespace Torann \GeoIP \Services ;
3+ use Exception ;
4+ use Illuminate \Support \Arr ;
5+ use Torann \GeoIP \Support \HttpClient ;
6+ /**
7+ * Class GeoIP
8+ * @package Torann\GeoIP\Services
9+ */
10+ class IPFinder extends AbstractService
11+ {
12+ /**
13+ * Http client instance.
14+ *
15+ * @var HttpClient
16+ */
17+ protected $ client ;
18+ /**
19+ * The "booting" method of the service.
20+ *
21+ * @return void
22+ */
23+ public function boot ()
24+ {
25+ $ this ->client = new HttpClient ([
26+ 'base_uri ' => 'https://api.ipfinder.io/v1/ ' ,
27+ 'headers ' => [
28+ 'User-Agent ' => 'Laravel-GeoIP-Torann ' ,
29+ ],
30+ 'query ' => [
31+ 'token ' => $ this ->config ('key ' ),
32+ ],
33+ ]);
34+ }
35+ /**
36+ * {@inheritdoc}
37+ * @throws Exception
38+ */
39+ public function locate ($ ip )
40+ {
41+ // Get data from client
42+ $ data = $ this ->client ->get ($ ip );
43+ // Verify server response
44+ if ($ this ->client ->getErrors () !== null || empty ($ data [0 ])) {
45+ throw new Exception ('Request failed ( ' . $ this ->client ->getErrors () . ') ' );
46+ }
47+ $ json = json_decode ($ data [0 ], true );
48+ return $ this ->hydrate ($ json );
49+ }
50+ }
You can’t perform that action at this time.
0 commit comments