Skip to content

Commit d834065

Browse files
authored
Add support for API Sandbox
1 parent d8a7e49 commit d834065

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

Diff for: src/NameSiloAPI.php

+33-8
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
class NameSiloAPI{
2121
private $apikey;
2222
private $ua;
23-
private $normalURL = 'https://www.namesilo.com/api/'; // final
24-
private $bulkURL = 'https://www.namesilo.com/apibatch/'; // final
23+
private $URLsuffix = 'api/'; // api/ OR apibatch/
24+
private $URLprefix = 'https://www'; // https://www OR https://<sandboxValue>
2525
private $currURL;
2626

2727
private $lastHTTP = NULL;
@@ -34,15 +34,24 @@ class NameSiloAPI{
3434
// An API key, User Agent MUST be provided when the class is called.
3535
// These can be changed later by calling setKey() and setUA() respectively
3636
// A third param can be set to 'bulk' to use the bulk API. Set it to any other value for the normal url
37-
function __construct($apiKey, $userAgent, $apiType='normal'){
37+
// A fourth param can be set to a value to use that sandbox subdomain.
38+
function __construct($apiKey, $userAgent, $apiType='normal', $isSandbox=null){
3839
$this->apikey = $apiKey;
3940
$this->ua = $userAgent;
4041

4142
if($apiType == 'bulk'){
42-
$this->currURL = $this->bulkURL;
43+
$this->URLsuffix = 'apibatch/';
4344
} else{
44-
$this->currURL = $this->normalURL;
45+
$this->URLsuffix = 'api/';
4546
}
47+
48+
if(empty($isSandbox)){
49+
$this->URLprefix = 'https://www';
50+
} else{
51+
$this->URLprefix = 'https://'.$isSandbox;
52+
}
53+
54+
$this->currURL = $this->URLprefix.'.namesilo.com/'.$this->URLsuffix;
4655
}
4756

4857
// Set your API key --REQUIRED
@@ -57,12 +66,22 @@ function setUA($userAgent){
5766

5867
// change the URL type
5968
// pass 'bulk' to use bulk URL. Ignore param or set it to any other value for the normal url
60-
function setAPIType($apiType='normal'){
69+
// A second param can be set to a value to use that sandbox subdomain.
70+
function setAPIType($apiType='normal', $isSandbox=null){
71+
6172
if($apiType == 'bulk'){
62-
$this->currURL = $this->bulkURL;
73+
$this->URLsuffix = 'apibatch/';
6374
} else{
64-
$this->currURL = $this->normalURL;
75+
$this->URLsuffix = 'api/';
6576
}
77+
78+
if(empty($isSandbox)){
79+
$this->URLprefix = 'https://www';
80+
} else{
81+
$this->URLprefix = 'https://'.$isSandbox;
82+
}
83+
84+
$this->currURL = $this->URLprefix.'.namesilo.com/'.$this->URLsuffix;
6685
}
6786

6887

@@ -104,6 +123,8 @@ private function returnBAD($type){
104123
return '<namesilo><request><operation>API CALL</operation><ip>0.0.0.0</ip></request><reply><code>100</code><detail>BULK API MUST BE USED FOR THIS COMMAND - SET WITH setAPIType("bulk") - API CLIENT ERROR</detail></reply></namesilo>';
105124
} elseif($type == 'nosupport'){
106125
return '<namesilo><request><operation>API CALL</operation><ip>0.0.0.0</ip></request><reply><code>100</code><detail>API ENDPOINT NOT SUPPORTED BY CLIENT - API CLIENT ERROR</detail></reply></namesilo>';
126+
} elseif($type == 'sandboxDrop'){
127+
return '<namesilo><request><operation>API CALL</operation><ip>0.0.0.0</ip></request><reply><code>100</code><detail>SANDBOX CANNOT BE USED FOR THIS METHOD</detail></reply></namesilo>';
107128
} else{
108129
return '<namesilo><request><operation>API CALL</operation><ip>0.0.0.0</ip></request><reply><code>100</code><detail>UNKNOWN API CLIENT ERROR</detail></reply></namesilo>';
109130
}
@@ -162,6 +183,10 @@ function registerDomain($domain, $years, $payment_id=null, $private=null, $auto_
162183
// domain, years required
163184
function registerDomainDrop($domain, $years, $private=null, $auto_renew=null){
164185

186+
if($this->URLprefix != 'https://www'){
187+
return $this->returnBAD('sandboxDrop');
188+
}
189+
165190
if($this->currURL != $this->bulkURL){
166191
return $this->returnBAD('reqBulk');
167192
}

0 commit comments

Comments
 (0)