diff --git a/Api/Odr.php b/Api/Odr.php index 4ee16f4..b116d46 100644 --- a/Api/Odr.php +++ b/Api/Odr.php @@ -272,6 +272,22 @@ public function transferDomain($id, array $data = array()) return $this; } + /** + * Update existing dns with new data + * + * @param string|int $id Either ID or domain name + * @param array $data Data for update + * + * @return Api_Odr + * @throws Api_Odr_Exception + */ + public function updateDNS($id, array $data = array()) + { + $this->_execute('/dns/' . trim($id) . '/', self::METHOD_PUT, $data); + + return $this; + } + /** * Return list of user's contacts * diff --git a/examples/dns.php b/examples/dns.php new file mode 100644 index 0000000..9f6f0a9 --- /dev/null +++ b/examples/dns.php @@ -0,0 +1,70 @@ + '#API_KEY#', + 'api_secret' => '#API_SECRET#', +); + +$configDomainId = 12345; + +// Create new instance of API demo class +$demo = new Api_Odr($config); + +// Login into API +$demo->login(); + +$loginResult = $demo->getResult(); + +if ($loginResult['status'] === Api_Odr::STATUS_ERROR) { + echo 'Can\'t login, reason - ' . $loginResult['response']; + + exit(1); +} + +$updateArray = [ + 'records' => [ + [ + 'name' => 'test', + 'type' => 'A', + 'content' => '123.123.123.123', + ], + [ + 'type' => 'SRV', + 'service' => '_sip', + 'domain' => '@', + 'protocol' => 'tcp', + 'priority' => '100', + 'weight' => '1', + 'port' => '5061', + 'target' => 'sipfed.online.lync.com.', + ] + ] +]; + + +// Update existing dns, by passing request data +$demo->updateDNS($configDomainId, $updateArray); + +// Get result of request +$result = $demo->getResult(); + + +if ($result['status'] !== Api_Odr::STATUS_SUCCESS) { + echo 'Following error occurred: ' . (is_array($result['response']) ? $result['response']['message'] : $result['response']); + + if (!empty($result['response']['data'])) { + foreach ($result['response']['data'] as $name => $error) { + echo "\r\n\t{$name}: {$error}"; + } + } + + exit(1); +} + +$result = $result['response']; + +// DNS successfully updated, sploosh! +echo 'DNS "' . $configDomainId . '" updated'; \ No newline at end of file