Spaces:
No application file
No application file
File size: 1,497 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 IpinfodbLookup extends AbstractRemoteDataLookup
{
public string $statusCode = '';
public string $statusMessage = '';
public string $ipAddress = '';
public string $countryCode = '';
public function getAttribution(): string
{
return '<a href="http://www.ipinfodb.com/" target="_blank">iPInfoDB</a> offers a free service (2 lookups per second) that leverages data from IP2Location. API key required.';
}
protected function getUrl(): string
{
return "http://api.ipinfodb.com/v3/ip-city/?key={$this->auth}&format=json&ip={$this->ip}";
}
protected function parseResponse($response)
{
$data = json_decode($response);
if ($data) {
foreach ($data as $key => $value) {
switch ($key) {
case 'cityName':
$key = 'city';
break;
case 'regionName':
$key = 'region';
break;
case 'countryName':
$key = 'country';
break;
case 'zipCode':
$key = 'zipcode';
break;
case 'timeZone':
$key = 'timezone';
break;
}
$this->$key = ucfirst($value);
}
}
}
}
|