Conditions | 1 |
Paths | 1 |
Total Lines | 22 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 2 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
31 | public function fetchGeo($url = "http://api.ipstack.com/") |
||
32 | { |
||
33 | $this->curl = curl_init(); |
||
34 | $apikey = require ANAX_INSTALL_PATH . "/config/apikeys.php"; |
||
35 | $accesskey = $apikey["ipstack"]; |
||
36 | //sets the url for curl to the correct one |
||
37 | curl_setopt($this->curl, CURLOPT_URL, "$url" . $this->ipinput . "?access_key=" . $accesskey); |
||
|
|||
38 | //returns a string |
||
39 | curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1); |
||
40 | //execute the started curl-session |
||
41 | $output = curl_exec($this->curl); |
||
42 | $exploded = json_decode($output, true); |
||
43 | $data = [ |
||
44 | "country" => $exploded["country_name"], |
||
45 | "city" => $exploded["city"], |
||
46 | "latitude" => $exploded["latitude"], |
||
47 | "longitude" => $exploded["longitude"], |
||
48 | ]; |
||
49 | //close curl-session to free up space |
||
50 | curl_close($this->curl); |
||
51 | |||
52 | return $data; |
||
53 | } |
||
55 |