Spaces:
No application file
No application file
File size: 1,455 Bytes
d2897cd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
<?php
namespace Mautic\CoreBundle\IpLookup;
class IpstackLookup extends AbstractRemoteDataLookup
{
public string $country_code = '';
public string $region_code = '';
public string $metro_code = '';
public function getAttribution(): string
{
return '<a href="https://ipstack.com/" target="_blank">ipstack.com</a> is a free lookup service that leverages GeoLite2 data created by MaxMind.';
}
protected function getUrl(): string
{
if (empty($this->auth)) {
$this->logger->warning('FreeGeoIP has become IPStack and now requires an API key.');
}
return 'http://api.ipstack.com/'.$this->ip.'?access_key='.$this->auth.'&output=json&legacy=1';
}
protected function parseResponse($response)
{
$data = json_decode($response);
if ($data) {
foreach ($data as $key => $value) {
switch ($key) {
case 'region_name':
$key = 'region';
break;
case 'country_name':
$key = 'country';
break;
case 'zip':
$key = 'zipcode';
break;
case 'time_zone':
$key = 'timezone';
break;
}
$this->$key = $value;
}
}
}
}
|