Conditions | 1 |
Paths | 1 |
Total Lines | 28 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 2 |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
12 | public function findGeoLocation($ipAdress) |
||
13 | { |
||
14 | global $di; |
||
15 | |||
16 | // get the secret api key |
||
17 | $config = $di->get("configuration")->load("api_keys.php") ?? null; |
||
18 | $apiKey = $config["config"]["ipStack"]["apiKey"] ?? null; |
||
19 | |||
20 | // make curl api call with ip address and api key |
||
21 | $ch1 = curl_init('http://api.ipstack.com/'.$ipAdress.'?access_key='.$apiKey.''); |
||
22 | curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true); |
||
|
|||
23 | $json = curl_exec($ch1); |
||
24 | curl_close($ch1); |
||
25 | |||
26 | /** |
||
27 | * decode the json result |
||
28 | * for usage in both view and rest-api controller |
||
29 | */ |
||
30 | $result = json_decode($json, true); |
||
31 | |||
32 | $data = [ |
||
33 | "city" => $result['city'] ?? "-", |
||
34 | "country_name" => $result['country_name'] ?? "-", |
||
35 | "longitude" => $result['longitude'] ?? "-", |
||
36 | "latitude" => $result['latitude'] ?? "-" |
||
37 | ]; |
||
38 | |||
39 | return $data; |
||
40 | } |
||
42 |