File size: 1,786 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
52
53
54
55
56
57
58
59
60
61
62
<?php

namespace Mautic\CoreBundle\IpLookup;

class ExtremeIpLookup extends AbstractRemoteDataLookup
{
    public string $businessWebsite = '';
    public string $continent       = '';
    public string $countryCode     = '';
    public string $ipName          = '';
    public string $ipType          = '';
    public string $lat             = '';
    public string $lon             = '';
    public string $org             = '';
    public string $query           = '';
    public string $status          = '';

    /**
     * Return attribution HTML displayed in the configuration UI.
     */
    public function getAttribution(): string
    {
        return '<a href="https://extreme-ip-lookup.com/" target="_blank">extreme-ip-lookup.com</a> is a free lookup service that does not require an api key.';
    }

    /**
     * Get the URL to fetch data from.
     */
    protected function getUrl(): string
    {
        $auth = !empty($this->auth) ? '?key='.$this->auth : '';

        return 'https://extreme-ip-lookup.com/json/'.$this->ip.$auth;
    }

    protected function parseResponse($response)
    {
        $data = json_decode($response, true);

        if ($data) {
            foreach ($data as $key => $value) {
                switch ($key) {
                    case 'region':
                        $key = 'region';
                        break;
                    case 'country':
                        $key = 'country';
                        break;
                    case 'city':
                        $key = 'city';
                        break;
                    case 'businessName':
                        $key = 'organization';
                        break;
                }

                $this->$key = $value;
            }
        }
    }
}