Y U NO access WHOIS informations in PHP?

    This post is part of the ”WHOIS in PHP: consuming the Robowhois API” series; here is a list of all the articles contained this series:

  1. A PHP library to retrieve WHOIS informations
  2. Retrieving raw WHOIS informations in PHP
  3. Checking a domain’s availability with PHP
  4. Y U NO access WHOIS informations in PHP?

In these days we finalized the last parts of the official PHP client for the Robowhois API , and here are the changes for the 0.9.0 version.

Parts and properties API

As part of our job, we needed to implement the last 2 API endpoints provided by Robowhois, properties and parts.

Everything is documented in the README but you can also follow the examples under the sample/ directory:

Using the properties API
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php

use Robowhois\Robowhois;
use Robowhois\Exception;

require 'vendor/.composer/autoload.php';

$robowhois = new Robowhois('INSERT-YOUR-API-KEY-HERE');

try {
    $domain = $robowhois->whoisProperties('robowhois.com');

    echo $domain['properties']['created_on'] . "\n";
} catch (Exception $e) {
    echo "The following error occurred: " . $e->getMessage();
}
Using the parts API
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php

use Robowhois\Robowhois;
use Robowhois\Exception;

require 'vendor/.composer/autoload.php';

$robowhois = new Robowhois('INSERT-YOUR-API-KEY-HERE');

try {
    $domain = $robowhois->whoisParts('robowhois.com');

    echo $domain['parts'][0]['body'] . "\n";
} catch (Exception $e) {
    echo "The following error occurred: " . $e->getMessage();
}

Magic objects, behaving like arrays

We implemented the \ArrayObject interface for the objects returned by the API, which means that now you can access the results of an API call just like an array:

1
2
3
4
5
6
<?php

$account = $robowhois->account();

// $account is an instance of Robowhois\Account
echo sprintf('You have %d API calls left', $account['credits_remaining']);

but, for those like us who like the OO synthax, we implemented some magic to let you retrieve those values via getters, which are built on-the-fly thanks to PHP’s __call() method:

1
2
3
<?php

echo $account->getCreditsRemaining();

Getters are a camelized version of the array keys, and are built thanks to the Doctrine Inflector.

Mapping the existing API

We renamed the methods accessing the API in order to 100% reflect the ones exposed by the API, also used in the Ruby client: so now the Robowhois\Robowhois object has:

Simplified exceptions

We initially added tons of exceptions but we eventually decide to keep the only Robowhois\Exception class.

Now?

Wanna retrieve WHOIS informations in PHP at a decent price?

Start consuming the Robowhois APIs, with PHP.

comments powered by Disqus