├── composer.json
├── src
├── IP
│ ├── Geo.php
│ └── Whois.php
├── Domain
│ ├── Whois.php
│ └── Availability.php
├── HttpAdapter.php
├── Result.php
├── Browser
│ └── Screenshot.php
└── Base.php
├── README.md
├── LICENSE
└── examples
├── example_browser_screenshot.php
├── autoload.php
├── example_ip_geo.php
├── example_domain_availability.php
├── example_ip_whois.php
└── example_domain_whois.php
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name":"jsonwhoisio/adapter",
3 | "description":"PHP Library to access the APIs provided by jsonwhois.io",
4 | "license": "MIT",
5 | "require":{
6 | "php":"^5.3.3 || ^7.0"
7 | },
8 | "autoload": {
9 | "psr-4": {
10 | "JsonWhois\\Adapter\\": "src"
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/src/IP/Geo.php:
--------------------------------------------------------------------------------
1 | payload = ['ip_address' => $ip];
17 | }
18 |
19 | /**
20 | * Build the base API request URL for this end-point
21 | *
22 | * @return String Complete API end-point URL
23 | */
24 | protected function getRequestBase() {
25 | return self::HOST . self::END_POINT;
26 | }
27 | }
--------------------------------------------------------------------------------
/src/IP/Whois.php:
--------------------------------------------------------------------------------
1 | payload = ['ip_address' => $ip];
17 | }
18 |
19 | /**
20 | * Build the base API request URL for this end-point
21 | *
22 | * @return String Complete API end-point URL
23 | */
24 | protected function getRequestBase() {
25 | return self::HOST . self::END_POINT;
26 | }
27 | }
--------------------------------------------------------------------------------
/src/Domain/Whois.php:
--------------------------------------------------------------------------------
1 | payload = ['domain' => $domain];
17 | }
18 |
19 | /**
20 | * Build the base API request URL for this end-point
21 | *
22 | * @return String Complete API end-point URL
23 | */
24 | protected function getRequestBase() {
25 | return self::HOST . self::END_POINT;
26 | }
27 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # JSON WHOIS API PHP
2 | A lightweight wrapper written in PHP for the domain and IP Whois API provided by JsonWhois (jsonwhois.io).
3 |
4 | ## Install
5 | The package is PSR-4 compliant, either use a package manager or a standards compliant autoloader (like the one included in the examples directory).
6 |
7 | Via composer:
8 | `composer require jsonwhoisio/adapter`
9 |
10 |
11 | ## Requirements
12 | + API KEY (obtain your free key from https://jsonwhois.io/register)
13 | + PHP 5.3+
14 | + CURL
15 |
16 | # Notes
17 | We have chosen to not make use of exceptions for error communication due to their impact on speed of code execution and relative difficulty for beginners.
18 |
--------------------------------------------------------------------------------
/src/Domain/Availability.php:
--------------------------------------------------------------------------------
1 | payload = ['domain' => $domain];
17 | }
18 |
19 | /**
20 | * Build the base API request URL for this end-point
21 | *
22 | * @return String Complete API end-point URL
23 | */
24 | protected function getRequestBase() {
25 | return self::HOST . self::END_POINT;
26 | }
27 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Json Whois
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/examples/example_browser_screenshot.php:
--------------------------------------------------------------------------------
1 | setPayload($domain, $width, $height);
24 |
25 | # Perform the query and store the resulting object
26 | $Result = $BrowserScreenshot->run();
27 |
28 | # check for successful execution
29 | if (!$Result->isSuccessful()) {
30 | # query failed, print the reason
31 | echo 'Lookup failed (' . $Result->getStatusCode() . '): ' . $Result->getStatusMessage();
32 | } else {
33 | # get the result of the successful query as an array (default)
34 | $dataArray = $Result->getDataArray();
35 |
36 | echo '
';
37 | }
--------------------------------------------------------------------------------
/examples/autoload.php:
--------------------------------------------------------------------------------
1 | setPayload($ip);
22 |
23 | # Perform the query and store the resulting object
24 | $Result = $IpGeo->run();
25 |
26 | # check for successful execution
27 | if (!$Result->isSuccessful()) {
28 | # query failed, print the reason
29 | echo 'Lookup failed (' . $Result->getStatusCode() . '): ' . $Result->getStatusMessage();
30 | } else {
31 | # get the result of the successful query as an array (default)
32 | $dataArray = $Result->getDataArray();
33 |
34 | echo 'ISO Country code (array): ' . $dataArray['country_code'] . '
';
35 |
36 | $dataObject = $Result->getDataObject();
37 |
38 | echo 'ISO Country code (object): ' . $dataObject->country_code . '
';
39 |
40 | echo 'ISO Country code (direct from $Result): ' . $Result->country_code . '
';
41 |
42 | echo 'Demonym (direct from $Result): ' . $Result->demonym . '
';
43 |
44 | echo 'Demonym (array): ' . $dataArray['demonym'] . '
';
45 |
46 | echo '
';
47 |
48 | print_r($dataArray);
49 | }
--------------------------------------------------------------------------------
/examples/example_domain_availability.php:
--------------------------------------------------------------------------------
1 | setPayload($domain);
22 |
23 | # Perform the query and store the resulting object
24 | $Result = $DomainAvailability->run();
25 |
26 | # check for successful execution
27 | if (!$Result->isSuccessful()) {
28 | # query failed, print the reason
29 | echo 'Lookup failed (' . $Result->getStatusCode() . '): ' . $Result->getStatusMessage();
30 | } else {
31 | # get the result of the successful query as an array (default)
32 | $dataArray = $Result->getDataArray();
33 |
34 | echo 'Is Available (array): ' . ($dataArray['is_available'] ? 'Yes' : 'No') . '
';
35 |
36 | $dataObject = $Result->getDataObject();
37 |
38 | echo 'Is Available (object): ' . ($dataObject->is_available ? 'Yes' : 'No') . '
';
39 |
40 | echo 'Is Available (direct from $Result): ' . ($Result->is_available ? 'Yes' : 'No') . '
';
41 |
42 | echo '
';
43 |
44 | var_dump($dataArray);
45 | }
--------------------------------------------------------------------------------
/examples/example_ip_whois.php:
--------------------------------------------------------------------------------
1 | setPayload($ip);
22 |
23 | # Perform the query and store the resulting object
24 | $Result = $IpWhois->run();
25 |
26 | # check for successful execution
27 | if (!$Result->isSuccessful()) {
28 | # query failed, print the reason
29 | echo 'Lookup failed (' . $Result->getStatusCode() . '): ' . $Result->getStatusMessage();
30 | } else {
31 | # get the result of the successful query as an array (default)
32 | $dataArray = $Result->getDataArray();
33 |
34 | echo 'Created date (array): ' . $dataArray['created'] . '
';
35 |
36 | $dataObject = $Result->getDataObject();
37 |
38 | echo 'Created date (object): ' . $dataObject->created . '
';
39 |
40 | echo 'Created date (direct from $Result): ' . $Result->created . '
';
41 |
42 | echo 'Owner (direct from $Result): ' . $Result->contacts->owner[0]->organization . '
';
43 |
44 | echo 'Owner (array): ' . $dataArray['contacts']['owner'][0]['organization'] . '
';
45 |
46 | echo '
';
47 |
48 | print_r($dataArray);
49 | }
--------------------------------------------------------------------------------
/examples/example_domain_whois.php:
--------------------------------------------------------------------------------
1 | setPayload($domain);
22 |
23 | # Perform the query and store the resulting object
24 | $Result = $DomainWhois->run();
25 |
26 | # check for successful execution
27 | if (!$Result->isSuccessful()) {
28 | # query failed, print the reason
29 | echo 'Lookup failed (' . $Result->getStatusCode() . '): ' . $Result->getStatusMessage();
30 | } else {
31 | # get the result of the successful query as an array (default)
32 | $dataArray = $Result->getDataArray();
33 |
34 | echo 'Expiry date (array): ' . $dataArray['expires'] . '
';
35 |
36 | $dataObject = $Result->getDataObject();
37 |
38 | echo 'Expiry date (object): ' . $dataObject->expires . '
';
39 |
40 | echo 'Expiry date (direct from $Result): ' . $Result->expires . '
';
41 |
42 | echo 'Owner Email (direct from $Result): ' . $Result->contacts->owner[0]->email . '
';
43 |
44 | echo 'Owner Email (array): ' . $dataArray['contacts']['owner'][0]['email'] . '
';
45 |
46 | echo '
';
47 |
48 | print_r($dataArray);
49 | }
--------------------------------------------------------------------------------
/src/HttpAdapter.php:
--------------------------------------------------------------------------------
1 | true,
28 | CURLOPT_URL => $url . '?' . $query,
29 | CURLOPT_USERAGENT => 'JSONWHOIS Client 1.0.0',
30 | CURLOPT_HTTPGET => true
31 | ));
32 |
33 | if (!defined('JSONWHOISIO_IGNORE_CA') || JSONWHOISIO_IGNORE_CA == true) {
34 | \curl_setopt_array($curl, array(
35 | CURLOPT_SSL_VERIFYHOST => false,
36 | CURLOPT_SSL_VERIFYPEER => false
37 | ));
38 | }
39 |
40 | // Send the request & save response to $resp
41 | $response = \curl_exec($curl);
42 |
43 | // get response code
44 | $httpcode = \curl_getinfo($curl, CURLINFO_HTTP_CODE);
45 |
46 | // Close request to clear up some resources
47 | \curl_close($curl);
48 |
49 | return ['http_code' => $httpcode, 'result' => $response];
50 | }
51 |
52 | /**
53 | * Convert an associative array of keys and thier values into
54 | * a valid query string
55 | *
56 | * @param array $params Associative array of keys and thier values
57 | * @return string Valid HTTP query string
58 | */
59 | private static function buildQuery($params) {
60 | return \http_build_query($params);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/Result.php:
--------------------------------------------------------------------------------
1 | successful = $successful;
20 | $this->rawPayload = $rawPayload;
21 | $this->responseCode = (int) $responseCode;
22 | $this->message = $message;
23 |
24 | if (!$this->successful || $this->rawPayload == null || $this->responseCode == -1) {
25 | return $this;
26 | }
27 |
28 | // make the data usable
29 | $this->process();
30 | }
31 |
32 | /**
33 | * The plain text representaiton of the HTTP response code
34 | *
35 | * @return string Text representaiton of the HTTP response code
36 | */
37 | public function getStatusMessage() {
38 | return $this->message;
39 | }
40 |
41 | /**
42 | * The status code returned by the API
43 | *
44 | * @return int HTTP status code
45 | */
46 | public function getStatusCode() {
47 | return $this->responseCode;
48 | }
49 |
50 | /**
51 | * Process the input data into a native structured way
52 | * @return void
53 | */
54 | private function process() {
55 | $this->arrayPayload = json_decode($this->rawPayload, true);
56 | if (isset($this->arrayPayload['result'])) {
57 | $this->arrayPayload = $this->arrayPayload['result'];
58 | }
59 |
60 | $this->objectPayload = json_decode($this->rawPayload, false);
61 | if (isset($this->objectPayload->result)) {
62 | $this->objectPayload = $this->objectPayload->result;
63 | }
64 |
65 | // turn this instance of Result into a result set
66 | foreach ($this->objectPayload as $key => $value) {
67 | $this->{$key} = $value;
68 | }
69 | }
70 |
71 | /**
72 | * Check if the parent API request was successful
73 | * @return boolean True on successful parent request
74 | */
75 | public function isSuccessful() {
76 | return $this->successful;
77 | }
78 |
79 | /**
80 | * Get the raw HTTP response payload of the parent request
81 | * @return string Json encoded data string
82 | */
83 | public function getRawData() {
84 | return $this->rawPayload;
85 | }
86 |
87 | /**
88 | * Get the parsed and usable form of data response from the parent request
89 | * @return Array PHP Array, result of json_decode on the raw response
90 | */
91 | public function getDataArray() {
92 | return $this->arrayPayload;
93 | }
94 |
95 | /**
96 | * Get the parsed and usable form of data response from the parent request
97 | * @return Array PHP Object, result of json_decode on the raw response
98 | */
99 | public function getDataObject() {
100 | return $this->objectPayload;
101 | }
102 | }
--------------------------------------------------------------------------------
/src/Browser/Screenshot.php:
--------------------------------------------------------------------------------
1 | payload = [
24 | 'url' => $url,
25 | 'width' => $width,
26 | 'height' => $height
27 | ];
28 | }
29 |
30 | /**
31 | * Removes the default white background of the rendering engine. Any content on the page without a background colour will be
32 | * rendered transparent (alpha 0). Set to "true" or 1 to enable, set to "false" or 0 to disable. Only available on PNG images.
33 | * Defaults to "false" server side.
34 | *
35 | * @param integer $transparent Integer from class constants such as Screenshot::SETTING_TRANSPARENT_TRUE
36 | */
37 | public function setTransparent($transparent) {
38 | $this->payload['transparent'] = $transparent;
39 | }
40 |
41 | /**
42 | * Set to "false" or 0 to capture only the above the fold content. Where above the fold is defined by the box specified in the width & height parameters.
43 | * Set to "true" or 1 to capture the entire page. Only available with PNG and jpeg export types.
44 | * Defaults to "false" server side.
45 | *
46 | * @param integer $full_page Integer from class constants such as Screenshot::SETTING_FULLPAGE_TRUE
47 | */
48 | public function setFullPage($full_page) {
49 | $this->payload['full_page'] = $full_page;
50 | }
51 |
52 | /**
53 | * Specify the quality of the screen grab on a scale between 1 and 100. The higher the number the better quality the image.
54 | * Only available on jpeg files.
55 | * Defaults to 85 server side.
56 | *
57 | * @param integer $quality A sliding scale of the quality of the screen capture, from 1 to 100
58 | */
59 | public function setQuality($quality = 85) {
60 | if ($quality > 100 || $quality < 1) {
61 | $quality = 85;
62 | }
63 |
64 | $this->payload['quality'] = $quality;
65 | }
66 |
67 | /**
68 | * The time expressed in seconds to wait before the screenshot is taken (even though resources have been loaded), defaults to 1 second.
69 | * Set to 0 to take the screenshot as soon as the network becomes idle.
70 | *
71 | * @param integer $requestTimeout Time specified in seconds to wait to take the screenshot after all resources have been loaded
72 | */
73 | public function setRequestTimeout($requestTimeout = 1) {
74 | $this->payload['request_timeout'] = $requestTimeout;
75 | }
76 |
77 | /**
78 | * Build the base API request URL for this end-point
79 | *
80 | * @return String Complete API end-point URL
81 | */
82 | protected function getRequestBase() {
83 | return self::HOST . self::END_POINT;
84 | }
85 | }
--------------------------------------------------------------------------------
/src/Base.php:
--------------------------------------------------------------------------------
1 | apiKey = $apiKey;
26 | }
27 |
28 | /**
29 | * Set the payload for the request, e.g. the domain for
30 | * which to perform a WHOIS request
31 | *
32 | * @param string $data Currently this value could be a domain name or an IP address
33 | */
34 | public function setPayload($data) {
35 | $this->payload = $data;
36 | }
37 |
38 | /**
39 | * Execute the API request
40 | *
41 | * @return Object An instance of the Result class
42 | */
43 | public function run() {
44 | $url = $this->getRequestBase();
45 |
46 | $rawResult = HttpAdapter::get($url, $this->payload + ['key' => $this->apiKey]);
47 |
48 | $success = true;
49 | if ($rawResult['http_code'] != self::RESPONSE_PROCESSED) {
50 | $success = false;
51 | }
52 |
53 | $Result = new Result($success, $this->getMessage($rawResult['http_code']), $rawResult['result'], $rawResult['http_code']);
54 |
55 | return $Result;
56 | }
57 |
58 | /**
59 | * Convert API HTTP response code into plain text explination
60 | *
61 | * @param int $code API Request HTTP response code
62 | * @return string Plain text reason for HTTP response code
63 | */
64 | private function getMessage($code) {
65 | switch($code) {
66 | case self::RESPONSE_PROCESSED:
67 | return 'The command was processed successfully.';
68 | break;
69 | case self::RESPONSE_UNPROCESSABLE:
70 | return 'Well formatted request however some technical issue is preventing the serving of the request, e.g. an unresponsive WHOIS server.';
71 | break;
72 | case self::RESPONSE_COMMAND_UNKNOWN:
73 | return 'The end-point you have sent the request to is not valid (for example, the end point should be /whois or /screenshot).';
74 | break;
75 | case self::RESPONSE_COMMAND_INVALID:
76 | return 'The HTTP request method used is not compatible with the selected end-point. This can occur when using POST rather than GET for example.';
77 | break;
78 | case self::RESPONSE_COMMAND_MALFORMED:
79 | return 'The request has been incorrectly constructed. This can occur when omitting required parameters or providing them in the wrong type.';
80 | break;
81 | case self::RESPONSE_UNAUTHORIZED:
82 | return 'The request was not authorised. This can occur when using an incorrect key, if the server IP is not on the account whitelist, or if the account is banned.';
83 | break;
84 | case self::RESPONSE_BILLING:
85 | return 'The request was refused due to a billing issue with the associated account.';
86 | break;
87 | case self::RESPONSE_INTERNAL_SERVER_ERROR:
88 | return 'The client did everything correctly, but we\'ve had an internal issue. ';
89 | break;
90 | }
91 | }
92 | }
--------------------------------------------------------------------------------