Skip to content

Commit c8a33b3

Browse files
author
DomainNameApi
committed
Automatic Update Library from php-dna repo
1 parent 581d77d commit c8a33b3

File tree

1 file changed

+129
-67
lines changed
  • components/modules/domainnameapi/apis

1 file changed

+129
-67
lines changed

components/modules/domainnameapi/apis/api.php

Lines changed: 129 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* Class DomainNameAPI_PHPLibrary
1212
* @package DomainNameApi
13-
* @version 2.1.6
13+
* @version 2.1.7
1414
*/
1515

1616

@@ -25,7 +25,7 @@ class DomainNameAPI_PHPLibrary
2525
/**
2626
* Version of the library
2727
*/
28-
const VERSION = '2.1.6';
28+
const VERSION = '2.1.7';
2929

3030
const DEFAULT_NAMESERVERS = [
3131
'ns1.domainnameapi.com',
@@ -41,6 +41,84 @@ class DomainNameAPI_PHPLibrary
4141
'*Price definition not found*',
4242
];
4343

44+
const DEFAULT_ERRORS = [
45+
'INVALID_DOMAIN_DETAILS' => [
46+
'code' => 'INVALID_DOMAIN_DETAILS',
47+
'message' => 'Invalid domain details! Details format is not valid',
48+
'description' => 'The provided domain details are not in the expected format'
49+
],
50+
'INVALID_CREDENTIALS' => [
51+
'code' => 'INVALID_CREDENTIALS',
52+
'message' => 'Invalid username and password',
53+
'description' => 'The provided API credentials are invalid'
54+
],
55+
'INVALID_DOMAIN_LIST' => [
56+
'code' => 'INVALID_DOMAIN_LIST',
57+
'message' => 'Domain info is not a valid array or more than one domain info has returned!',
58+
'description' => 'The domain list response is not in the expected format'
59+
],
60+
'INVALID_TLD_LIST' => [
61+
'code' => 'INVALID_TLD_LIST',
62+
'message' => 'TLD info is not a valid array or more than one TLD info has returned!',
63+
'description' => 'The TLD list response is not in the expected format'
64+
],
65+
'INVALID_RESPONSE' => [
66+
'code' => 'INVALID_RESPONSE',
67+
'message' => 'Invalid response received from server! Response is empty.',
68+
'description' => 'The API response is empty or null'
69+
],
70+
'INVALID_RESPONSE_FORMAT' => [
71+
'code' => 'INVALID_RESPONSE_FORMAT',
72+
'message' => 'Invalid response received from server! Response format is not valid.',
73+
'description' => 'The API response format is not in the expected structure'
74+
],
75+
'INVALID_RESPONSE_COUNT' => [
76+
'code' => 'INVALID_RESPONSE_COUNT',
77+
'message' => 'Invalid parameters passed to function! Response data contains more than one result!',
78+
'description' => 'The API response contains multiple results when only one was expected'
79+
],
80+
'INVALID_RESPONSE_CODE' => [
81+
'code' => 'INVALID_RESPONSE_CODE',
82+
'message' => 'Invalid parameters passed to function! Operation result or Error code not received from server',
83+
'description' => 'The API response is missing required operation result or error code fields'
84+
],
85+
'INVALID_RESPONSE_SOAP' => [
86+
'code' => 'INVALID_RESPONSE_SOAP',
87+
'message' => 'Invalid parameters passed to function! Soap return is not a valid array!',
88+
'description' => 'The SOAP response is not in a valid array format'
89+
],
90+
'INVALID_CONTACT_INFO' => [
91+
'code' => 'INVALID_CONTACT_INFO',
92+
'message' => 'Invalid response received from server! Contact info is not a valid array or more than one contact info has returned!',
93+
'description' => 'The contact information response is not in the expected format'
94+
],
95+
'INVALID_CONTACT_SAVE' => [
96+
'code' => 'INVALID_CONTACT_SAVE',
97+
'message' => 'Invalid response received from server! Contact info could not be saved!',
98+
'description' => 'The contact information could not be saved on the server'
99+
],
100+
'INVALID_DOMAIN_TRANSFER_REQUEST' => [
101+
'code' => 'INVALID_DOMAIN_TRANSFER_REQUEST',
102+
'message' => 'Invalid response received from server! Domain transfer request could not be completed!',
103+
'description' => 'The domain transfer request failed to complete'
104+
],
105+
'INVALID_DOMAIN_RENEW' => [
106+
'code' => 'INVALID_DOMAIN_RENEW',
107+
'message' => 'Invalid response received from server! Domain renew request could not be completed!',
108+
'description' => 'The domain renewal request failed to complete'
109+
],
110+
'INVALID_DOMAIN_REGISTER' => [
111+
'code' => 'INVALID_DOMAIN_REGISTER',
112+
'message' => 'Invalid response received from server! Domain register request could not be completed!',
113+
'description' => 'The domain registration request failed to complete'
114+
],
115+
'INVALID_DOMAIN_SYNC' => [
116+
'code' => 'INVALID_DOMAIN_SYNC',
117+
'message' => 'Invalid response received from server! Domain sync request could not be completed!',
118+
'description' => 'The domain synchronization request failed to complete'
119+
]
120+
];
121+
44122
const DEFAULT_CACHE_TTL = 512;
45123
const DEFAULT_TIMEOUT = 20;
46124
const DEFAULT_REASON = 'Owner request';
@@ -179,7 +257,7 @@ private function setApplication()
179257
{
180258
$dir = __DIR__;
181259
$this->application = 'CORE';
182-
$this->errorReportingPath = '';
260+
$this->errorReportingPath = self::APPLICATIONS['CORE']['path'];
183261
$this->errorReportingDsn = self::APPLICATIONS['CORE']['dsn'];
184262

185263
foreach (self::APPLICATIONS as $app => $config) {
@@ -190,13 +268,6 @@ private function setApplication()
190268
break;
191269
}
192270
}
193-
194-
// Geçerli bir uygulama değilse CORE'a geri dön
195-
if (!array_key_exists($this->application, self::APPLICATIONS)) {
196-
$this->application = 'CORE';
197-
$this->errorReportingPath = self::APPLICATIONS['CORE']['path'];
198-
$this->errorReportingDsn = self::APPLICATIONS['CORE']['dsn'];
199-
}
200271
}
201272

202273
/**
@@ -401,8 +472,7 @@ public function GetResellerDetails()
401472
$resp['balances'] = $balances;
402473
} else {
403474
$resp['result'] = 'ERROR';
404-
$resp['error'] = $this->setError("INVALID_CREDINENTIALS", "Invalid response received from server!",
405-
"invalid username and password");
475+
$resp['error'] = $this->setError("INVALID_CREDINENTIALS");
406476
}
407477

408478

@@ -555,10 +625,9 @@ public function GetList($extra_parameters = [])
555625
} else {
556626
// Set error
557627
$result["result"] = "ERROR";
558-
$result["error"] = $this->setError("INVALID_DOMAIN_LIST", "Invalid response received from server!",
559-
"Domain info is not a valid array or more than one domain info has returned!");
628+
$result["error"] = $this->setError("INVALID_DOMAIN_LIST");
560629

561-
$this->sendErrorToSentryAsync(new Exception("INVALID_DOMAIN_LIST: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned!"));
630+
$this->sendErrorToSentryAsync(new Exception("[INVALID_DOMAIN_LIST] ". self::DEFAULT_ERRORS['INVALID_DOMAIN_LIST']['description']));
562631
}
563632
return $result;
564633
});
@@ -624,10 +693,9 @@ public function GetTldList($count = 20)
624693
// Set error
625694
$result = [
626695
'result' => 'ERROR',
627-
'error' => $this->setError("INVALID_TLD_LIST", "Invalid response received from server!",
628-
"Domain info is not a valid array or more than one domain info has returned!")
696+
'error' => $this->setError("INVALID_TLD_LIST")
629697
];
630-
$this->sendErrorToSentryAsync(new Exception("INVALID_TLD_LIST: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned!"));
698+
$this->sendErrorToSentryAsync(new Exception("[INVALID_TLD_LIST] ". self::DEFAULT_ERRORS['INVALID_TLD_LIST']['description']));
631699
}
632700

633701
return $result;
@@ -655,22 +723,18 @@ public function GetDetails($domainName)
655723

656724
$response = self::parseCall(__FUNCTION__, $parameters, function ($response) {
657725
$data = $response[key($response)];
658-
659-
$this->sendErrorToSentryAsync(new Exception("INVALID_DOMAIN_LIST: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned!"));
660-
661-
662726
// If DomainInfo a valid array
663727
if (isset($data["DomainInfo"]) && is_array($data["DomainInfo"])) {
664728
// Parse domain info
729+
665730
$result["data"] = $this->parseDomainInfo($data["DomainInfo"]);
666731
$result["result"] = "OK";
667732
} else {
668733
// Set error
669734
$result["result"] = "ERROR";
670-
$result["error"] = $this->setError("INVALID_DOMAIN_LIST", "Invalid response received from server!",
671-
"Domain info is not a valid array or more than one domain info has returned!");
735+
$result["error"] = $this->setError("INVALID_DOMAIN_DETAILS");
672736

673-
$this->sendErrorToSentryAsync(new Exception("INVALID_DOMAIN_LIST: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned!"));
737+
$this->sendErrorToSentryAsync(new Exception("[INVALID_DOMAIN_DETAILS] ". self::DEFAULT_ERRORS['INVALID_DOMAIN_DETAILS']['description']));
674738
}
675739
return $result;
676740
});
@@ -911,11 +975,10 @@ public function GetContacts($domainName)
911975
} else {
912976
// Set error
913977
$result = [
914-
'error' => $this->setError("INVALID_CONTACT_INTO", "Invalid response received from server!",
915-
"Contact info is not a valid array or more than one contact info has returned!"),
978+
'error' => $this->setError("INVALID_CONTACT_INFO"),
916979
'result' => 'ERROR'
917980
];
918-
$this->sendErrorToSentryAsync(new Exception("INVALID_CONTACT_INTO: Invalid response received from server! Contact info is not a valid array or more than one contact info has returned!"));
981+
$this->sendErrorToSentryAsync(new Exception("[INVALID_CONTACT_INFO] ". self::DEFAULT_ERRORS['INVALID_CONTACT_INFO']['description']));
919982
}
920983
return $result;
921984
});
@@ -958,11 +1021,10 @@ public function SaveContacts($domainName, $contacts)
9581021
// Set error
9591022
$result = [
9601023
'result' => 'ERROR',
961-
'error' => $this->setError("INVALID_CONTACT_SAVE", "Invalid response received from server!",
962-
"Contact info is not a valid array or more than one contact info has returned!")
1024+
'error' => $this->setError("INVALID_CONTACT_SAVE")
9631025
];
9641026

965-
$this->sendErrorToSentryAsync(new Exception("INVALID_CONTACT_SAVE: Invalid response received from server! Contact info is not a valid array or more than one contact info has returned!"));
1027+
$this->sendErrorToSentryAsync(new Exception("[INVALID_CONTACT_SAVE] ". self::DEFAULT_ERRORS['INVALID_CONTACT_SAVE']['description']));
9661028
}
9671029
return $result;
9681030
});
@@ -1012,11 +1074,9 @@ public function Transfer($domainName, $eppCode, $period)
10121074
// Set error
10131075
$result = [
10141076
'result' => 'ERROR',
1015-
'data' => $this->setError("INVALID_DOMAIN_TRANSFER_REQUEST",
1016-
"Invalid response received from server!",
1017-
"Domain info is not a valid array or more than one domain info has returned!")
1077+
'data' => $this->setError("INVALID_DOMAIN_TRANSFER_REQUEST")
10181078
];
1019-
$this->sendErrorToSentryAsync(new Exception("INVALID_DOMAIN_TRANSFER_REQUEST: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned!"));
1079+
$this->sendErrorToSentryAsync(new Exception("[INVALID_DOMAIN_TRANSFER_REQUEST] ". self::DEFAULT_ERRORS['INVALID_DOMAIN_TRANSFER_REQUEST']['description']));
10201080
}
10211081
return $result;
10221082
});
@@ -1148,10 +1208,9 @@ public function Renew($domainName, $period)
11481208
} else {
11491209
return [
11501210
'result' => 'ERROR',
1151-
'error' => $this->setError("INVALID_DOMAIN_RENEW", "Invalid response received from server!",
1152-
"Domain info is not a valid array or more than one domain info has returned!")
1211+
'error' => $this->setError("INVALID_DOMAIN_RENEW")
11531212
];
1154-
$this->sendErrorToSentryAsync(new Exception("INVALID_DOMAIN_RENEW: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned!"));
1213+
$this->sendErrorToSentryAsync(new Exception("[INVALID_DOMAIN_RENEW] ". self::DEFAULT_ERRORS['INVALID_DOMAIN_RENEW']['description']));
11551214
}
11561215
});
11571216

@@ -1232,10 +1291,9 @@ public function RegisterWithContactInfo(
12321291
// Set error
12331292
$result = [
12341293
'result' => 'ERROR',
1235-
'error' => $this->setError("INVALID_DOMAIN_REGISTER", "Invalid response received from server!",
1236-
"Domain info is not a valid array or more than one domain info has returned!")
1294+
'error' => $this->setError("INVALID_DOMAIN_REGISTER")
12371295
];
1238-
$this->sendErrorToSentryAsync(new Exception("INVALID_DOMAIN_REGISTER: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned!"));
1296+
$this->sendErrorToSentryAsync(new Exception("[INVALID_DOMAIN_REGISTER] ". self::DEFAULT_ERRORS['INVALID_DOMAIN_REGISTER']['description']));
12391297
}
12401298
return $result;
12411299
});
@@ -1303,11 +1361,10 @@ public function SyncFromRegistry($domainName)
13031361
} else {
13041362
// Set error
13051363
$result = [
1306-
'error' => $this->setError("INVALID_DOMAIN_SYNC", "Invalid response received from server!",
1307-
"Domain info is not a valid array or more than one domain info has returned!"),
1364+
'error' => $this->setError("INVALID_DOMAIN_SYNC"),
13081365
'result' => 'ERROR'
13091366
];
1310-
$this->sendErrorToSentryAsync(new Exception("INVALID_DOMAIN_SYNC: Invalid response received from server! Domain info is not a valid array or more than one domain info has returned!"));
1367+
$this->sendErrorToSentryAsync(new Exception("[INVALID_DOMAIN_SYNC] ". self::DEFAULT_ERRORS['INVALID_DOMAIN_SYNC']['description']));
13111368
}
13121369

13131370
return $result;
@@ -1346,17 +1403,16 @@ private function parseError($response, $trace = true)
13461403
// Set error data
13471404
$result = [];
13481405
$result["Code"] = "INVALID_RESPONSE";
1349-
$result["Message"] = "Invalid response or no response received from server!";
1350-
$result["Details"] = "SOAP Connection returned null value!";
1406+
$result["Message"] = self::DEFAULT_ERRORS['INVALID_RESPONSE']['message'];
1407+
$result["Details"] = self::DEFAULT_ERRORS['INVALID_RESPONSE']['description'];
13511408
} elseif (!is_array($response)) {
13521409
// Set error data
13531410
$result = [];
1354-
$result["Code"] = "INVALID_RESPONSE";
1355-
$result["Message"] = "Invalid response or no response received from server!";
1356-
$result["Details"] = "SOAP Connection returned non-array value!";
1411+
$result["Code"] = "INVALID_RESPONSE_FORMAT";
1412+
$result["Message"] = self::DEFAULT_ERRORS['INVALID_RESPONSE_FORMAT']['message'];
1413+
$result["Details"] = self::DEFAULT_ERRORS['INVALID_RESPONSE_FORMAT']['description'];
13571414
} elseif (strtolower(key($response)) == "faultstring") {
13581415
// Handle soap fault
1359-
13601416
$result = [];
13611417
$result["Code"] = "";
13621418
$result["Message"] = "";
@@ -1383,22 +1439,21 @@ private function parseError($response, $trace = true)
13831439
} elseif (count($response) != 1) {
13841440
// Set error data
13851441
$result = [];
1386-
$result["Code"] = "INVALID_RESPONSE";
1387-
$result["Message"] = "Invalid response or no response received from server!";
1388-
$result["Details"] = "Response data contains more than one result! Only one result accepted!";
1442+
$result["Code"] = "INVALID_RESPONSE_COUNT";
1443+
$result["Message"] = self::DEFAULT_ERRORS['INVALID_RESPONSE_COUNT']['message'];
1444+
$result["Details"] = self::DEFAULT_ERRORS['INVALID_RESPONSE_COUNT']['description'];
13891445
} elseif (!isset($response[key($response)]["OperationResult"]) || !isset($response[key($response)]["ErrorCode"])) {
13901446
// Set error data
13911447
$result = [];
1392-
$result["Code"] = "INVALID_RESPONSE";
1393-
$result["Message"] = "Invalid response or no response received from server!";
1394-
$result["Details"] = "Operation result or Error code not received from server!";
1448+
$result["Code"] = "INVALID_RESPONSE_CODE";
1449+
$result["Message"] = self::DEFAULT_ERRORS['INVALID_RESPONSE_CODE']['message'];
1450+
$result["Details"] = self::DEFAULT_ERRORS['INVALID_RESPONSE_CODE']['description'];
13951451
} elseif (strtoupper($response[key($response)]["OperationResult"]) != "SUCCESS") {
13961452
// Set error data
13971453
$result = [
13981454
"Code" => '',
13991455
"Message" => 'Failed',
14001456
"Details" => '',
1401-
14021457
];
14031458

14041459
if (isset($response[key($response)]["OperationMessage"])) {
@@ -1416,7 +1471,7 @@ private function parseError($response, $trace = true)
14161471
}
14171472

14181473
if (isset($result["Code"]) && $trace === true) {
1419-
$this->sendErrorToSentryAsync(new Exception("API_ERROR: " . $result["Code"] . " - " . $result["Message"] . " - " . $result["Details"]));
1474+
$this->sendErrorToSentryAsync(new Exception("[API_ERROR]: " . $result["Code"] . " - " . $result["Message"] . " - " . $result["Details"]));
14201475
}
14211476

14221477
return $result;
@@ -1436,17 +1491,24 @@ private function hasError($response)
14361491
/**
14371492
* Set error message
14381493
*
1439-
* @param string $Code Error code
1440-
* @param string $Message Error message
1441-
* @param string $Details Error details
1494+
* @param string $code Error code
1495+
* @param string $message Error message
1496+
* @param string $details Error details
14421497
* @return array Error information
14431498
*/
1444-
private function setError($Code, $Message, $Details)
1499+
private function setError($code, $message = '', $details = '')
14451500
{
1446-
$result = [];
1447-
$result["Code"] = $Code;
1448-
$result["Message"] = $Message;
1449-
$result["Details"] = $Details;
1501+
$result = [];
1502+
if (isset(self::DEFAULT_ERRORS[$code])) {
1503+
$error = self::DEFAULT_ERRORS[$code];
1504+
$result["Code"] = $error['code'];
1505+
$result["Message"] = $error['message'];
1506+
$result["Details"] = $error['description'];
1507+
} else {
1508+
$result["Code"] = $code;
1509+
$result["Message"] = $message;
1510+
$result["Details"] = $details;
1511+
}
14501512
return $result;
14511513
}
14521514

@@ -1746,7 +1808,7 @@ private function parseCall($fn, $parameters, $_callback): array
17461808
}
17471809
} catch (SoapFault $ex) {
17481810
$result["result"] = "ERROR";
1749-
$result["error"] = $this->setError('INVALID_RESPONSE', 'Invalid response occurred', $ex->getMessage());
1811+
$result["error"] = $this->setError('INVALID_RESPONSE_SOAP', self::DEFAULT_ERRORS['INVALID_RESPONSE_SOAP']['description'], $ex->getMessage());
17501812
$this->sendErrorToSentryAsync($ex);
17511813
} catch (Exception $ex) {
17521814
$result["result"] = "ERROR";

0 commit comments

Comments
 (0)