forked from dotroll/DotRoll-API-PHP-SDK
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDotRollApi.php
More file actions
390 lines (364 loc) · 10.7 KB
/
DotRollApi.php
File metadata and controls
390 lines (364 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
<?php
/**
* This SDK is aimed to provide understandably easy access to the DotRoll REST API
*
* Usage:
* $dotRoll = new DotRollApi('myUserName', 'myPassword12', true);
* $prices = $dotRoll->get('domain/prices/HUF');
*
* @copyright Copyright (c) 2010 DotRoll Kft. (http://www.dotroll.com)
* @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');
/**
* DotRoll API class
*
* This is the main class to be used in the SDK. This implements all the functions
* needed to access services of the DotRoll REST API
*
* @copyright Copyright (c) 2010 DotRoll Kft. (http://www.dotroll.com)
* @author Siegl Zoltan <siegl.zoltan@dotroll.com>
*/
class DotRollApi {
/**
* Constructor
*
* This boots up DotRoll API
*
* @param string $userName A username that is registered at DotRoll and
* is eligable to access DotRoll API
* @param string $password The password for the user above
* @param string $apiKey The API key provided by DotRoll support staff
* @param boolean $useSandBox Use the API in sandbox mode? If true, test mode
* is in use, changes will not effect production
* database.
*/
public function __construct($userName, $password, $apiKey, $useSandBox = true) {
$this->selfTest();
$this->httpClient = new HTTP_Client();
$this->userName = $userName;
$this->password = $password;
$this->apiKey = $apiKey;
$this->useSandBox = $useSandBox;
$this->apiVersion = $useSandBox === true?'sandbox':self::API_VERSION;
$this->apiUrl = isset($_ENV['API_URL'])?$_ENV['API_URL']:self::API_URL;
}
/**
* Send a get request for the DotRoll rest API
*
* @param string $uri
*/
public function get($uri) {
$uri = rtrim($uri, '/');
$request = new HTTP_Client_Request(
$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);
$resultObject = json_decode($result->getResponseText());
return $resultObject;
}
/**
* Send a delete request for the DotRoll rest API
*
* @param string $uri
*/
public function delete($uri) {
$uri = rtrim($uri, '/');
$request = new HTTP_Client_Request(
$this->apiUrl.'/'.$this->apiVersion.'/'.$uri,
HTTP_Client_Request::METHOD_DELETE
);
$request->setAuth($this->userName, $this->password);
$result = $this->httpClient->sendRequest($request);
return json_decode($result->getResponseText());
}
/**
* Send a post request for the DotRoll rest API
*
* @param string $uri
*/
public function post($uri, $data, $expectedErrorCode = false) {
$uri = rtrim($uri, '/');
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);
$resultObject = json_decode($result->getResponseText());
return $resultObject;
}
/**
* Send a put request for the DotRoll rest API
*
* @param string $uri
*/
public function put($uri, $data) {
$uri = rtrim($uri, '/');
$request = new HTTP_Client_Request(
$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());
}
/**
* Get domain prices in the given currency
* 'HUF', 'EUR', and 'USD' is currently accepted
* @param string $currency
*/
public function getDomainPrices($currency) {
return $this->get('domain/prices/'.$currency);
}
/**
* Get hosting prices in the given currency
* 'HUF', 'EUR', and 'USD' is currently accepted
* @param string $domainName The domain name to check
*/
public function getHostingPrices($currency) {
return $this->get('hosting/prices/'.$currency);
}
/**
* Get virtual personal server prices in the given currency
* 'HUF', 'EUR', and 'USD' is currently accepted
* @param string $domainName The domain name to check
*/
public function getVPSPrices($currency) {
return $this->get('vps/prices/'.$currency);
}
/**
* Get availablity of a domain name
*
* @param string $currency
*/
public function getDomainAvailablity($domainName) {
return $this->get('domain/search/'.$domainName);
}
/**
* Get list of all the domains owned by the user
*/
public function getDomainList() {
return $this->get('domain/list/');
}
/**
* Create a new domain contact
*
* @param string $firstName
* @param string $lastName
* @param bolean $isOrganisation
* @param string $identity
* @param string $vatNumber
* @param string $euVatNumber
* @param string $passport
* @param string $registryNumber
* @param string $orgLongName
* @param string $domainPartnerType
* @param string $addressName
* @param string $addressCountry
* @param string $addressState
* @param string $addressLocality
* @param string $addressPostalCode
* @param string $addressStreet
* @param string $addressStreetNumber
* @param string $email
* @param string $phone
* @param string $fax
*
* @return int|boolean The id of the created domain contact if success
* or false if failed
*/
public function createDomainContact(
$firstName,
$lastName,
$isOrganisation,
$identity,
$vatNumber,
$euVatNumber,
$passport,
$registryNumber,
$orgName,
$orgLongName,
$domainPartnerType,
$addressName,
$addressCountry,
$addressState,
$addressLocality,
$addressPostalCode,
$addressStreet,
$addressStreetNumber,
$email,
$phone,
$fax
) {
$data = array(
'firstName' => $firstName,
'lastName' => $lastName,
'isOrganisation' => $isOrganisation,
'identity' => $identity,
'vatNumber' => $vatNumber,
'euVatNumber' => $euVatNumber,
'passport' => $passport,
'registryNumber' => $registryNumber,
'orgLongName' => $orgLongName,
'domainPartnerType' => $domainPartnerType,
'country' => $addressCountry,
'state' => $addressState,
'locality' => $addressLocality,
'postalCode' => $addressPostalCode,
'street' => $addressStreet,
'name' => $addressName,
'streetNumber' => $addressStreetNumber,
'email' => $email,
'phone' => $phone,
'fax' => $fax
);
return $this->post('domain/contact', $data);
}
/**
* Register a new domain
* @param string $domainName The domain name to be registered
* @param integer $ownerContactId The id received when creating contact with
* createDomainContact()
* @param integer $adminContactId The id received when creating contact with
* createDomainContact()
* @param integer $techContactId The id received when creating contact with
* 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 $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
*/
public function registerDomain(
$domainName,
$ownerContactId,
$adminContactId,
$techContactId,
$years,
$nameserver1 = 'ns1.dotroll.com',
$nameserver2 = 'ns2.dotroll.com',
$expectedErrorCode = false
) {
$data = array(
'ownerContactId' => $ownerContactId,
'adminContactId' => $adminContactId,
'techContactId' => $techContactId,
'years' => $years,
'ns1' => $nameserver1,
'ns2' => $nameserver2
);
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
*/
protected function selfTest() {
if (!function_exists('curl_init')) {
throw new Exception('DotRoll PHP SDK needs the CURL PHP extension.');
}
if (!function_exists('json_decode')) {
throw new Exception('DotRoll PHP SDK needs the JSON PHP extension.');
}
}
/**
* API Version to use
* @var string API_VERSION
*/
const API_VERSION = '1.0';
/**
* DotRoll REST API base URL
* @var string API_URL
*/
const API_URL = 'https://webservices.dotroll.com/rest';
/**
* Domain-partner kapcsolat típus: HUREG tulaj
*/
const DOMAIN_PARTNER_TYPE_HUREG_OWNER=1;
/**
* Domain-partner kapcsolat típus: HUREG kontakt
*/
const DOMAIN_PARTNER_TYPE_HUREG_CONTACT=2;
/**
* Domain-partner kapcsolat típus: COMREG kontakt .info,.biz
*/
const DOMAIN_PARTNER_TYPE_COMREG_CONTACT=3;
/**
* Domain-partner kapcsolat típus: EUREG tulaj
*/
const DOMAIN_PARTNER_TYPE_EUREG_OWNER=4;
/**
* Domain-partner kapcsolat típus: EUREG kontakt
*/
const DOMAIN_PARTNER_TYPE_EUREG_CONTACT=5;
/**
* Domain-partner kapcsolat típus: HUREG tulaj .info, .biz
*/
const DOMAIN_PARTNER_TYPE_COMREG_OWNER=6;
/**
* COMNET kontakt .com, .net
*/
const DOMAIN_PARTNER_TYPE_VERISIGN_CONTACT=7;
/**
* ORG kontakt
*/
const DOMAIN_PARTNER_TYPE_ORG_CONTACT=8;
/**
* HTTP_Client instance
* @var HTTP_Client $httpClient
*/
protected $httpClient;
/**
* DotRoll API user name
* @var string $userName
*/
protected $userName;
/**
* DotRoll API password
* @var string $password
*/
protected $password;
/**
* The API key, provided by DotRoll support staff
* @var string $apiKey
*/
protected $apiKey;
/**
* Use API in sandbox or production mode
* (true = sandbox mode, false = production mode)
*
* @var boolean $useSandBox
*/
protected $useSandBox;
/**
* The API version to use ("sandbox" in sandbox mode)
*
* @var string $apiVersion
*/
protected $apiVersion;
}