diff --git a/src/Base.php b/src/Base.php index 99f2572..7b10b88 100644 --- a/src/Base.php +++ b/src/Base.php @@ -21,7 +21,7 @@ class Base { const RESPONSE_BILLING = 402; const RESPONSE_INTERNAL_SERVER_ERROR = 500; - public __construct($apiKey) { + public function __construct($apiKey) { $this->apiKey = $apiKey; } @@ -43,10 +43,10 @@ public function setPayload($data) { public function run() { $url = $this->getRequestBase(); - $rawResult = HttpAdapter::get($url, $this->payload); + $rawResult = HttpAdapter::get($url, $this->payload + ['key' => $this->apiKey]); $success = true; - if ($rawResult['http_code'] != 200) { + if ($rawResult['http_code'] != self::RESPONSE_PROCESSED) { $success = false; } @@ -63,7 +63,7 @@ public function run() { */ private function getMessage($code) { switch($code) { - case self::PROCESSED: + case self::RESPONSE_PROCESSED: return 'The command was processed successfully.'; break; case self::RESPONSE_UNPROCESSABLE: diff --git a/src/Browser/Screenshot.php b/src/Browser/Screenshot.php new file mode 100644 index 0000000..93e7e13 --- /dev/null +++ b/src/Browser/Screenshot.php @@ -0,0 +1,35 @@ +payload = [ + 'url' => $url, + 'width' => $width, + 'height' => $height, + 'maxTimeout' => $maxTimeout + ]; + } + + /** + * Build the base API request URL for this end-point + * + * @return String Complete API end-point URL + */ + protected function getRequestBase() { + return self::HOST . self::END_POINT; + } +} \ No newline at end of file diff --git a/src/Domain/Availability.php b/src/Domain/Availability.php new file mode 100644 index 0000000..9295243 --- /dev/null +++ b/src/Domain/Availability.php @@ -0,0 +1,27 @@ +payload = ['domain' => $domain]; + } + + /** + * Build the base API request URL for this end-point + * + * @return String Complete API end-point URL + */ + protected function getRequestBase() { + return self::HOST . self::END_POINT; + } +} \ No newline at end of file diff --git a/src/Domain/Whois.php b/src/Domain/Whois.php index 9b3f623..64fa8c1 100644 --- a/src/Domain/Whois.php +++ b/src/Domain/Whois.php @@ -4,14 +4,13 @@ use WhoisAPI\Adapter\Base; -class Whois { +class Whois extends Base { const END_POINT = '/whois/domain'; /** - * Set the payload for the request, e.g. the domain for - * which to perform a WHOIS request + * Set the payload for the request * - * @param string $data Currently this value could be a domain name or an IP address + * @param string $domain domain name to lookup */ public function setPayload($domain) { $this->payload = ['domain' => $domain]; diff --git a/src/HttpAdapter.php b/src/HttpAdapter.php index 6a45933..7863ee9 100644 --- a/src/HttpAdapter.php +++ b/src/HttpAdapter.php @@ -22,14 +22,21 @@ public static function get($url, $params) { // build query string $query = self::buildQuery($params); - // Set some options - we are passing in a useragent too here + // Set some options \curl_setopt_array($curl, array( - CURLOPT_RETURNTRANSFER => 1, + CURLOPT_RETURNTRANSFER => true, CURLOPT_URL => $url . '?' . $query, CURLOPT_USERAGENT => 'WHOISAPIEU Client 1.0.0', CURLOPT_HTTPGET => true )); + if (!defined('WHOISAPIEU_IGNORE_CA') || WHOISAPIEU_IGNORE_CA == true) { + \curl_setopt_array($curl, array( + CURLOPT_SSL_VERIFYHOST => false, + CURLOPT_SSL_VERIFYPEER => false + )); + } + // Send the request & save response to $resp $response = \curl_exec($curl); diff --git a/src/IP/Geo.php b/src/IP/Geo.php new file mode 100644 index 0000000..27ad7d5 --- /dev/null +++ b/src/IP/Geo.php @@ -0,0 +1,27 @@ +payload = ['ip_address' => $ip]; + } + + /** + * Build the base API request URL for this end-point + * + * @return String Complete API end-point URL + */ + protected function getRequestBase() { + return self::HOST . self::END_POINT; + } +} \ No newline at end of file diff --git a/src/IP/Whois.php b/src/IP/Whois.php new file mode 100644 index 0000000..592e14a --- /dev/null +++ b/src/IP/Whois.php @@ -0,0 +1,27 @@ +payload = ['ip_address' => $ip]; + } + + /** + * Build the base API request URL for this end-point + * + * @return String Complete API end-point URL + */ + protected function getRequestBase() { + return self::HOST . self::END_POINT; + } +} \ No newline at end of file diff --git a/src/Result.php b/src/Result.php index 3871944..b0b1ebb 100644 --- a/src/Result.php +++ b/src/Result.php @@ -15,7 +15,7 @@ class Result { private $responseCode; private $message; - public __construct($successful = false, $message = 'Error', $rawPayload = null, $responseCode = -1) { + public function __construct($successful = false, $message = 'Error', $rawPayload = null, $responseCode = -1) { $this->successful = $successful; $this->rawPayload = $rawPayload; $this->responseCode = (int) $responseCode; @@ -53,10 +53,17 @@ public function getStatusCode() { */ private function process() { $this->arrayPayload = json_decode($this->rawPayload, true); + if (isset($this->arrayPayload['result'])) { + $this->arrayPayload = $this->arrayPayload['result']; + } + $this->objectPayload = json_decode($this->rawPayload, false); + if (isset($this->objectPayload->result)) { + $this->objectPayload = $this->objectPayload->result; + } // turn this instance of Result into a result set - foreach ($this->arrayPayload as $key => $value) { + foreach ($this->objectPayload as $key => $value) { $this->{$key} = $value; } }