1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * This file is part of the Geocoder package. |
||
7 | * For the full copyright and license information, please view the LICENSE |
||
8 | * file that was distributed with this source code. |
||
9 | * |
||
10 | * @license MIT License |
||
11 | */ |
||
12 | |||
13 | namespace Geocoder\Provider\HostIp; |
||
14 | |||
15 | use Geocoder\Model\AddressCollection; |
||
16 | |||
17 | /** |
||
18 | * @author William Durand <[email protected]> |
||
19 | */ |
||
20 | final class HostIp extends AbstractHostIp |
||
21 | { |
||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | public const ENDPOINT_URL = 'http://api.hostip.info/get_json.php?ip=%s&position=true'; |
||
26 | |||
27 | 4 | public function getName(): string |
|
28 | { |
||
29 | 4 | return 'host_ip'; |
|
30 | } |
||
31 | |||
32 | 7 | public function getEndpointURL(): string |
|
33 | { |
||
34 | 7 | return self::ENDPOINT_URL; |
|
35 | } |
||
36 | |||
37 | 7 | protected function executeQuery(string $url): AddressCollection |
|
38 | { |
||
39 | 7 | $content = $this->getUrlContents($url); |
|
40 | 2 | $data = \json_decode($content, true); |
|
41 | |||
42 | 2 | if (!$data) { |
|
43 | return new AddressCollection([]); |
||
44 | } |
||
45 | |||
46 | 2 | return $this->prepareAddressCollection($data); |
|
47 | } |
||
48 | } |
||
49 |