Permalink
Browse files

added missing samples

  • Loading branch information...
1 parent 6e0916b commit c1cf2774005d5a42234248bccc8b41199d1518b8 @odino odino committed Apr 15, 2012
Showing with 41 additions and 12 deletions.
  1. +0 −1 phpunit.xml.dist
  2. +16 −0 sample/parts.php
  3. +16 −0 sample/properties.php
  4. +8 −5 src/Robowhois/Http/Client.php
  5. +1 −6 src/Robowhois/Robowhois.php
View
@@ -31,7 +31,6 @@
<filter>
<blacklist>
<directory suffix=".php">test</directory>
- <directory suffix=".php">src</directory>
</blacklist>
</filter>
</phpunit>
View
@@ -0,0 +1,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();
+}
View
@@ -0,0 +1,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();
+}
@@ -33,13 +33,11 @@ class Client implements HttpClient
/**
* Creates a new instance of an HTTP client customized for Robowhois APIs.
*
- * @param string $apiKey The api key of Robowhois
* @param Browser $adapter The HTTP adapter used to make HTTP requests
*/
public function __construct(Browser $adapter = null)
{
- $this->adapter = $adapter ?: new Browser;
- $this->configureAdapter();
+ $this->adapter = $adapter ?: $this->getDefaultAdapter();
}
/**
@@ -73,9 +71,14 @@ public function get($uri)
/**
* Configures the adapter for authentication against the Robowhois API.
*/
- protected function configureAdapter()
+ protected function getDefaultAdapter()
{
- $this->getAdapter()->setClient(new \Buzz\Client\Curl);
+ $adapter = new Browser;
+ $client = new \Buzz\Client\Curl();
+ $client->setTimeout(5);
+ $adapter->setClient($client);
+
+ return $adapter;
}
/**
@@ -171,18 +171,13 @@ public function whoisProperties($domain)
* @param string $domain
*
* @return Robowhois\Whois\Index
- * @todo mmm nested IFs for readability, but we should do something different
*/
public function whoisRecord($domain)
{
$response = $this->decodeApiCall($domain, 'RECORD');
if (is_array($response) && isset($response['response'])) {
- $result = $response['response'];
-
- if (is_array($result) && isset($result['record']) && isset($result['daystamp'])) {
- return new Record($result);
- }
+ return new Record($response['response']);
}
throw new Exception(self::API_RESPONSE_ERROR);

0 comments on commit c1cf277

Please sign in to comment.