1 | <?php |
||
11 | class IPStackFinder |
||
12 | { |
||
13 | /** @var string */ |
||
14 | const BASE_URI = 'http://api.ipstack.com/'; |
||
15 | |||
16 | /** @var string */ |
||
17 | const DEFAULT_LANGUAGE = 'en'; |
||
18 | |||
19 | /** @var Client $client */ |
||
20 | public $client; |
||
21 | |||
22 | /** @var array $supportedLanguages */ |
||
23 | private $supportedLanguages = [ |
||
24 | 'en', // English/US |
||
25 | 'de', // German |
||
26 | 'es', // Spanish |
||
27 | 'fr', // French |
||
28 | 'ja', // Japanese |
||
29 | 'pt-br', // Portugues (Brazil) |
||
30 | 'ru', // Russian |
||
31 | 'zh', // Chinese |
||
32 | ]; |
||
33 | |||
34 | /** |
||
35 | * IPStackHelper constructor. |
||
36 | */ |
||
37 | public function __construct() |
||
47 | |||
48 | /** |
||
49 | * Get the API response from ipstack.com and return in php associative array format. |
||
50 | * @param $ipAddress |
||
51 | * @return array |
||
52 | * @throws \GuzzleHttp\Exception\GuzzleException |
||
53 | */ |
||
54 | public function get($ipAddress) : array |
||
65 | |||
66 | /** |
||
67 | * Defensive programming to not give ipstack.com an invalid language param. |
||
68 | * If the .env or config file provided language code is not valid, return the default. |
||
69 | * @return string |
||
70 | */ |
||
71 | private function getLanguage() : string |
||
79 | } |
||
80 |