Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed API endpoint URL's and some other minor issues
  • Loading branch information
DotRoll Ltd committed Aug 5, 2011
1 parent f27780f commit ef0174b
Show file tree
Hide file tree
Showing 11 changed files with 682 additions and 30 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.markdown
@@ -0,0 +1,15 @@
Stable release 2011-08-05
=========================

- Fixed API endpoint URL's

Preview release 2011-03-29
==========================

- Added domain registration REST API support
- Sandbox now works with all API keys (this will change once the API key interface makes it into dotroll.com)

Preview release 2011-03-17
==========================

- Initial preview release.
76 changes: 46 additions & 30 deletions DotRollApi.php
Expand Up @@ -10,12 +10,12 @@
* @author Zoltan Siegl <siegl.zoltan@dotroll.com>
*/

require('./HTTP/Client.php');
require('./HTTP/Client/ClientException.php');
require('./HTTP/Client/Request.php');
require('./HTTP/Client/Response.php');
require('./HTTP/Client/Backend/BackendInterface.php');
require('./HTTP/Client/Backend/Curl.php');
require('HTTP/Client.php');
require('HTTP/Client/ClientException.php');
require('HTTP/Client/Request.php');
require('HTTP/Client/Response.php');
require('HTTP/Client/Backend/BackendInterface.php');
require('HTTP/Client/Backend/Curl.php');

/**
* DotRoll API class
Expand Down Expand Up @@ -47,7 +47,8 @@ public function __construct($userName, $password, $apiKey, $useSandBox = true) {
$this->password = $password;
$this->apiKey = $apiKey;
$this->useSandBox = $useSandBox;
$this->apiVersion = $useSandBox?'sandbox':self::API_VERSION;
$this->apiVersion = $useSandBox === true?'sandbox':self::API_VERSION;
$this->apiUrl = isset($_ENV['API_URL'])?$_ENV['API_URL']:self::API_URL;
}

/**
Expand All @@ -58,13 +59,14 @@ public function __construct($userName, $password, $apiKey, $useSandBox = true) {
public function get($uri) {
$uri = rtrim($uri, '/');
$request = new HTTP_Client_Request(
self::API_URL.'/'.$this->apiVersion.'/'.$uri,
$this->apiUrl.'/'.$this->apiVersion.'/'.$uri,
HTTP_Client_Request::METHOD_GET
);
$request->setAuth($this->userName, $this->password);
$request->addParam('api_key', $this->apiKey);
$result = $this->httpClient->sendRequest($request);
return json_decode($result->getResponseText());
$resultObject = json_decode($result->getResponseText());
return $resultObject;
}

/**
Expand All @@ -75,7 +77,7 @@ public function get($uri) {
public function delete($uri) {
$uri = rtrim($uri, '/');
$request = new HTTP_Client_Request(
self::API_URL.'/'.$this->apiVersion.'/'.$uri,
$this->apiUrl.'/'.$this->apiVersion.'/'.$uri,
HTTP_Client_Request::METHOD_DELETE
);
$request->setAuth($this->userName, $this->password);
Expand All @@ -88,17 +90,25 @@ public function delete($uri) {
*
* @param string $uri
*/
public function post($uri, $data) {
public function post($uri, $data, $expectedErrorCode = false) {
$uri = rtrim($uri, '/');
$request = new HTTP_Client_Request(
self::API_URL.'/'.$this->apiVersion.'/'.$uri,
HTTP_Client_Request::METHOD_POST
);
if($expectedErrorCode && $this->useSandBox) {
$request = new HTTP_Client_Request(
$this->apiUrl.'/'.$this->apiVersion.'/'.$uri . '?error=' . $expectedErrorCode,
HTTP_Client_Request::METHOD_POST
);
} else {
$request = new HTTP_Client_Request(
$this->apiUrl.'/'.$this->apiVersion.'/'.$uri,
HTTP_Client_Request::METHOD_POST
);
}
$request->setAuth($this->userName, $this->password);
$request->addParams($data);
$request->addParam('api_key', $this->apiKey);
$result = $this->httpClient->sendRequest($request);
return json_decode($result->getResponseText());
$resultObject = json_decode($result->getResponseText());
return $resultObject;
}

/**
Expand All @@ -109,11 +119,12 @@ public function post($uri, $data) {
public function put($uri, $data) {
$uri = rtrim($uri, '/');
$request = new HTTP_Client_Request(
self::API_URL.'/'.$this->apiVersion.'/'.$uri,
HTTP_Client_Request::METHOD_POST
$this->apiUrl.'/'.$this->apiVersion.'/'.$uri,
HTTP_Client_Request::METHOD_PUT
);
$request->setAuth($this->userName, $this->password);
$request->addParams($data);
$request->addParam('api_key', $this->apiKey);
$result = $this->httpClient->sendRequest($request);
return json_decode($result->getResponseText());
}
Expand Down Expand Up @@ -201,7 +212,7 @@ public function createDomainContact(
$orgLongName,
$domainPartnerType,
$addressName,
$addressCountry,
$addressCountry,
$addressState,
$addressLocality,
$addressPostalCode,
Expand All @@ -211,6 +222,7 @@ public function createDomainContact(
$phone,
$fax
) {

$data = array(
'firstName' => $firstName,
'lastName' => $lastName,
Expand Down Expand Up @@ -248,7 +260,7 @@ public function createDomainContact(
* @param integer $years The term in years to register domain for
* @param string $nameserver1 Nameserver 1 (if empty, default dotrol ns will be used)
* @param string $nameserver2 Nameserver 2 (if empty, default dotrol ns will be used)
* @param boolean $priority Priority registration (for .hu domains only)
* @param boolean $expectedErrorCode In SandBox mode, you can set an expected error code.
*
* @return integer | boolean The id of the domain that was registered on
* success, false on failure
Expand All @@ -261,20 +273,24 @@ public function registerDomain(
$years,
$nameserver1 = null,
$nameserver2 = null,
$priority = false
$expectedErrorCode = false
) {
$data = array(
'ownerContactId' => $ownerContactId,
'adminContactId' => $adminContactId,
'techContactId' => $techContactId,
'years' => $years,
'ns1' => $nameserver1 = null,
'ns2' => $nameserver2 = null,
'priority' => $priority = false
'ns1' => $nameserver1 = 'ns1.dotroll.com',
'ns2' => $nameserver2 = 'ns2.dotroll.com'
);
return $this->post('domain/'.$domainName, $data);
if ($this->useSandBox === true && $expectedErrorCode !== false) {
$data['expectedErrorCode'] = $expectedErrorCode;
}
$response = $this->post('domain/'.$domainName, $data);
return $response;
}


/**
* Test if every needed PHP extension is installed
*/
Expand All @@ -298,7 +314,7 @@ protected function selfTest() {
* DotRoll REST API base URL
* @var string API_URL
*/
const API_URL = 'http://webservices.dotroll.com/rest';
const API_URL = 'https://webservices.dotroll.com/rest';

/**
* Domain-partner kapcsolat típus: HUREG tulaj
Expand All @@ -309,7 +325,7 @@ protected function selfTest() {
*/
const DOMAIN_PARTNER_TYPE_HUREG_CONTACT=2;
/**
* Domain-partner kapcsolat típus: COMREG kontakt
* Domain-partner kapcsolat típus: COMREG kontakt .info,.biz
*/
const DOMAIN_PARTNER_TYPE_COMREG_CONTACT=3;
/**
Expand All @@ -321,11 +337,11 @@ protected function selfTest() {
*/
const DOMAIN_PARTNER_TYPE_EUREG_CONTACT=5;
/**
* Domain-partner kapcsolat típus: HUREG tulaj
* Domain-partner kapcsolat típus: HUREG tulaj .info, .biz
*/
const DOMAIN_PARTNER_TYPE_COMREG_OWNER=6;
/**
* COMNET kontakt
* COMNET kontakt .com, .net
*/
const DOMAIN_PARTNER_TYPE_VERISIGN_CONTACT=7;
/**
Expand Down
2 changes: 2 additions & 0 deletions HTTP/Client/Request.php
Expand Up @@ -150,6 +150,8 @@ public function addParams($paramArray) {
//if (is_array($value)) $value = urldecode(http_build_query(array($key => $value)));
if (is_array($value)) {
$this->params[(string)$key] = $value;
} elseif (is_object($value)) {
$this->params[(string)$key] = get_object_vars($value);
} else {
$this->params[(string)$key] = (string)$value;
}
Expand Down
File renamed without changes.

0 comments on commit ef0174b

Please sign in to comment.