Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 23 |
| MaxMindWebService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 2 |
6 | |
0.00% |
0 / 23 |
| boot | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
| query | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 19 |
|||
| 1 | <?php |
| 2 | |
| 3 | namespace Qmp\Laravel\Geolocation\Services\GeolocApiServices; |
| 4 | |
| 5 | use GeoIp2\WebService\Client; |
| 6 | |
| 7 | class MaxMindWebService extends AbstractService |
| 8 | { |
| 9 | protected $client; |
| 10 | |
| 11 | /** |
| 12 | * Additionnal boot method in constructor |
| 13 | */ |
| 14 | protected function boot() |
| 15 | { |
| 16 | $this->client = new Client( |
| 17 | $this->credentials->get('user_id'), |
| 18 | $this->credentials->get('license_key') |
| 19 | ); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Query to geolocation service |
| 24 | * |
| 25 | * @return array |
| 26 | */ |
| 27 | protected function query() |
| 28 | { |
| 29 | $record = $this->client->city($this->value); |
| 30 | |
| 31 | return [ |
| 32 | 'ip' => $this->value, |
| 33 | 'lat' => $record->location->latitude, |
| 34 | 'lon' => $record->location->longitude, |
| 35 | 'zipcode' => $record->postal->code, |
| 36 | 'city' => $record->city->name, |
| 37 | |
| 38 | 'continent_code' => $record->continent->code, |
| 39 | 'continent_name' => $record->continent->name, |
| 40 | |
| 41 | 'is_in_european_union' => $record->country->isInEuropeanUnion, |
| 42 | 'country_iso_code' => $record->country->isoCode, |
| 43 | 'country_name' => $record->country->name, |
| 44 | |
| 45 | 'state_code' => $record->mostSpecificSubdivision->isoCode, |
| 46 | 'state_name' => $record->mostSpecificSubdivision->name, |
| 47 | |
| 48 | 'timezone' => $record->location->timeZone, |
| 49 | |
| 50 | 'organization' => $record->traits->organization, |
| 51 | 'isp' => $record->traits->isp, |
| 52 | 'domain' => $record->traits->domain, |
| 53 | 'network' => $record->traits->network, |
| 54 | |
| 55 | 'datas' => $record->jsonSerialize(), |
| 56 | ]; |
| 57 | } |
| 58 | } |