Skip to content

Commit

Permalink
bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MrFricker committed Feb 28, 2018
1 parent 4b73464 commit adc0e1e
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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:
Expand Down
35 changes: 35 additions & 0 deletions src/Browser/Screenshot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace WhoisAPI\Adapter\Browser;

use WhoisAPI\Adapter\Base;

class Screenshot extends Base {
const END_POINT = '/screenshot';

/**
* Set the payload for the request
*
* @param string $url the webaddress to capture
* @param integer $width width of screenshot
* @param integer $height height of screenshot
* @param integer $maxTimeout max time for the server to wait for the page to load before taking a screenshot
*/
public function setPayload($url, $width = 1200, $height = 800, $maxTimeout = 20) {
$this->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;
}
}
27 changes: 27 additions & 0 deletions src/Domain/Availability.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace WhoisAPI\Adapter\Domain;

use WhoisAPI\Adapter\Base;

class Availability extends Base {
const END_POINT = '/availability';

/**
* Set the payload for the request
*
* @param string $domain domain name such as "google.com" to check for reg availability
*/
public function setPayload($domain) {
$this->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;
}
}
7 changes: 3 additions & 4 deletions src/Domain/Whois.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
11 changes: 9 additions & 2 deletions src/HttpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
27 changes: 27 additions & 0 deletions src/IP/Geo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace WhoisAPI\Adapter\IP;

use WhoisAPI\Adapter\Base;

class Geo extends Base {
const END_POINT = '/geo';

/**
* Set the payload for the request
*
* @param string $ip IP address to lookup
*/
public function setPayload($ip) {
$this->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;
}
}
27 changes: 27 additions & 0 deletions src/IP/Whois.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace WhoisAPI\Adapter\IP;

use WhoisAPI\Adapter\Base;

class Whois extends Base {
const END_POINT = '/whois/ip';

/**
* Set the payload for the request
*
* @param string $ip IP address to lookup
*/
public function setPayload($ip) {
$this->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;
}
}
11 changes: 9 additions & 2 deletions src/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit adc0e1e

Please sign in to comment.