diff --git a/composer.json b/composer.json index 48f31ee..39f5c81 100755 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "fromtheoutfit/ipstack", "description": "Simple custom wrapper around the ipstack api.", "type": "craft-plugin", - "version": "1.0.0", + "version": "1.0.3", "keywords": [ "craft", "cms", diff --git a/src/services/IpstackService.php b/src/services/IpstackService.php index 7868cdb..e1a19fd 100755 --- a/src/services/IpstackService.php +++ b/src/services/IpstackService.php @@ -83,6 +83,39 @@ public function getCountry() return $data; } + public function get() + { + $ip = $this->getIpAddress(); + $data = ''; + + // set IP address and API access key + + // Initialize CURL: + $ch = curl_init('http://api.ipstack.com/' . $ip . '?access_key=' . $this->access_key . ''); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + // Store the data: + $json = curl_exec($ch); + curl_close($ch); + + // make sure we got a curl response + if ($json) { + // Decode JSON response: + $api_result = json_decode($json, true); + + // The api only returns a success key if that key is set to false...which is fun. + // So we look for that key and then we look to make sure it is false + // and then we set the data to an empty string + if (array_key_exists('success', $api_result) && !$api_result['success']) { + $data = []; + } else { + $data = $api_result; + } + } + + return $data; + } + private function getIpAddress() { diff --git a/src/variables/IpstackVariable.php b/src/variables/IpstackVariable.php index 0250766..b2f71e3 100755 --- a/src/variables/IpstackVariable.php +++ b/src/variables/IpstackVariable.php @@ -49,4 +49,9 @@ public function country($optional = null) { return Ipstack::$plugin->ipstackService->getCountry(); } + + public function get($optional = null) + { + return Ipstack::$plugin->ipstackService->get(); + } }