From 9ed18ebd9f25d71f3f4763282a7e4be65ef8f6e8 Mon Sep 17 00:00:00 2001 From: Daniel Linsenmeier Date: Mon, 2 Mar 2020 14:09:19 +0100 Subject: [PATCH] Prepare release 0.3.0# --- CHANGELOG.md | 14 +- README.md | 367 +++++++++-------------- composer.json | 4 +- src/service/CertificateService.php | 201 +++++++------ src/service/ContactService.php | 69 ++--- src/service/DomainCancelationService.php | 103 +++---- src/service/DomainRobotService.php | 12 +- src/service/DomainService.php | 219 +++++++------- src/service/DomainStudioService.php | 67 +++-- src/service/PollMessageService.php | 24 +- src/service/SslContactService.php | 70 +++-- src/service/TransferOutService.php | 52 ++-- src/service/TrustedAppService.php | 66 ++-- src/service/ZoneService.php | 166 ++++++---- 14 files changed, 722 insertions(+), 712 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09bb395c..e8bf404c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,17 @@ # Changelog +## [0.3.0] - 2020-03-02 + +* Added all important routes from the domainrobot open api documentation +* Updated README.md +* Fix return value of the DomainStudio->search() method + ## [0.2.0] - 2020-02-11 -* added DomainStudio calls -* added possiblity to use asynchronous as well as synchronous tasks -* improved documentation +* Added DomainStudio calls +* Added possiblity to use asynchronous as well as synchronous tasks +* Improved documentation ## [0.1.0] - 2020-02-10 -* initial release +* Initial release diff --git a/README.md b/README.md index 2914102b..32a0f13c 100644 --- a/README.md +++ b/README.md @@ -4,32 +4,22 @@ A php package for easy integration of the **Domainrobot API** powered by [InterN ## Table of Contents -- [PHP Domainrobot API](#php-domainrobot-api) - - [Table of Contents](#table-of-contents) - - [Install and Use](#install-and-use) - - [Installation](#installation) - - [Basic Use](#basic-use) - - [Usage](#usage) - - [Asynchronous vs Synchronous Requests](#asynchronous-vs-synchronous-requests) - - [Example for a synchronous Request](#example-for-a-synchronous-request) - - [Example for an asynchronous Request](#example-for-an-asynchronous-request) - - [Models](#models) - - [Instantiating](#instantiating) - - [How to set properties](#how-to-set-properties) - - [DomainRobotException](#domainrobotexception) - - [DomainRobotResult (only available for async methods/requests)](#domainrobotresult-only-available-for-async-methodsrequests) - - [Supported API calls](#supported-api-calls) - - [Certificate tasks](#certificate-tasks) - - [Prepare Order](#prepare-order) - - [Create Realtime](#create-realtime) - - [DomainStudio tasks](#domainstudio-tasks) - - [Search](#search) - - [(Custom) Headers](#custom-headers) - - [Use](#use) - - [Available Headers](#available-headers) - - [Setting Headers](#setting-headers) - - [Changelog](#changelog) - - [Copyright and license](#copyright-and-license) +1. [Preamble](#preamble) +2. [Install and Use](#install-and-use) + * [Installation](#installation) + * [Basic Use](#basic-use) +3. [Usage](#usage) + * [Asynchronous vs Synchronous Requests](#asynchronous-vs-synchronous-requests) + * [Models](#models) + * [Supported API calls](#supported-api-calls) + * [Exception handling](#exception-handling) + * [(Custom) Headers](#custom-headers) +4. [Changelog](#changelog) +5. [Copyright and license](#copyright-and-license) + +## Preamble + +This Maven package is not available via known repositories. It must be manually installed into a local Maven repository. ## Install and Use @@ -47,7 +37,10 @@ use IXDomainRobot\DomainRobot; ## Usage -Before you can interact with the API you need to specify your authentication credentials and if you have a "Personal AutoDNS" account your url and context. +Before you can interact with the API you need to specify your authentication credentials, the baseurl and the context. + +* Productive System: +* Demo System: ```php use IXDomainRobot\DomainRobot; @@ -62,14 +55,7 @@ $domainRobot = new DomainRobot([ ]); ``` -- url - ** can be left blank! (mandatory for "Personal AutoDNS" accounts) -- auth (mandatory) - ** user (mandatory) - ** password (mandatory) - ** context (mandatory for "Personal AutoDNS" accounts) - -## Asynchronous vs Synchronous Requests +### Asynchronous vs Synchronous Requests This library is mainly meant to be used with synchronous request but also provides the possibility to be used with asynchronous requests. @@ -83,40 +69,41 @@ Be aware that synchronous request will give you access to the return status code Please refer to the examples below for more details. -### Example for a synchronous Request +#### Example for a synchronous Request ```php +// Sends a synchronous request try { - // this return an instance of new CertificateData() see [Models](#models) for more info - $certData = $domainRobot->certificate($certificateModel)->prepareOrder(); + $certData = $domainRobot->certificate()->prepareOrder($body); }catch(DomainRobotException $exception){ return response()->json($exception->getError(), $exception->getStatusCode()); } -// access response values through the provided CertificateData Object +// Access response values through the provided CertificateData object $certData->getName(); -// access plain result and statuscode through DomainRobot::getLastDomainRobotResult +// Access plain result and statuscode through DomainRobot::getLastDomainRobotResult return response()->json( DomainRobot::getLastDomainRobotResult()->getResult(), DomainRobot::getLastDomainRobotResult()->getStatusCode() ); ``` -### Example for an asynchronous Request +#### Example for an asynchronous Request ```php +// Sends an asynchronous request try { - // returns a DomainRobotPromise Object - $promise = $domainRobot->certificate($certificateModel)->prepareOrderAsync(); - // the promise returns a DomainRobotResult Object + $promise = $domainRobot->certificate()->prepareOrderAsync($body); + // Wait for the promise. This will return a DomainRobotResult object $result = $promise->wait(); }catch(DomainRobotException $exception){ return response()->json($exception->getError(), $exception->getStatusCode()); } -// directly access plain result and statuscode through the DomainRobotResult Object -return response()->json($result->getResult(), $result->getStatusCode()); +// Access response values through the provided DomainRobotResult object +$statusCode = $result->getStatusCode(); +$data = $result->getData() ``` ### Models @@ -171,16 +158,120 @@ $certificateModel->setLifetime($timePeriod); $certificateModel->setProduct("BASIC_SSL") ``` -### DomainRobotException +### Supported API calls + +#### Domain tasks + +```php +function create(Domain $body); +function update(Domain $body); +function info($name); +function list(Query $body = null) +function updateStatus(Domain $body); +function renew(Domain $body); +function transfer(Domain $body); +function createAuthinfo1($name); +function deleteAuthinfo1($name); +function createAuthinfo2($name); +function restoreList(Query $body = null); +function restore(DomainRestore $body); +``` + +#### Domain cancelation tasks + +```php +function create(DomainCancelation $body); +function update(DomainCancelation $body); +function delete($domain); +function info($domain); +function list(Query $body = null); +``` + +#### Contact tasks + +```php +function create(Contact $body); +function update(Contact $body); +function delete($id); +function info($id); +function list(Query $body = null); +``` + +#### Zone tasks + +```php +function create(Zone $body); +function update(Zone $body); +function delete($name, $systemNameServer); +function info($name, $systemNameServer); +function list(Query $body = null); +function stream($origin, ZoneStream $body); +function importZone(Zone $body); +``` + +#### Certificate tasks + +```php +function create(Certificate $body); +function realtime(Certificate $body); +function prepareOrder(CertificateData $body); +function list(Query $body = null); +function info($id); +function delete($id); +function reissue(Certificate $body); +function renew(Certificate $body); +function commentUpdate($id, $comment); +``` + +#### SslContact tasks + +```php +function create(SslContact $body); +function update(SslContact $body); +function delete($id); +function info($id); +function list(Query $body = null); +``` + +#### TrustedApplication tasks + +```php +function create(TrustedApplication $body); +function update(TrustedApplication $body); +function delete($id); +function info($id); +function list(Query $body = null); +``` + +#### Domainstudio tasks + +```php +function search(DomainEnvelopeSearchRequest $body); +``` + +#### Poll tasks -Errors produced in available services will throw a DomainRobotException. +```php +function info(); +function confirm($id); +``` + +#### Transferout tasks + +```php +function answer($domain, $answer); +function list(Query $body = null); +``` + +### Exception handling + +If there is any error response from the API, the services will throw a DomainRobotException, which contains information about the error. Example: ```php try { - $promise = $domainRobot->certificate($certificateModel)->createRealtime(); - $domainRobotResult = $promise->wait(); + $promise = $domainRobot->certificate()->createRealtime($certificate); }catch(DomainRobotException $exception){ return response()->json($exception->getError(), $exception->getStatusCode()); } @@ -217,173 +308,6 @@ Array ) ``` -### DomainRobotResult (only available for async methods/requests) - -Successful asnychronous requests will return a DomainRobotResult object which contains the result as an array and the http status code of the request. - -Example: - -```php -try { - $promise = $domainRobot->certificate($certificateModel)->createRealtime(); - // this returns a DomainRobotResult Object - $domainRobotResult = $promise->wait(); -}catch(DomainRobotException $exception){ - return response()->json($exception->getError(), $exception->getStatusCode()); -} - -// retrieve result and statuscode from the DomainRobotResult Object -return response()->json($domainRobotResult->getResult(), $domainRobotResult->getStatusCode()); -``` - -The specific result message is stored in $domainRobotResult->result and can be accessed with $domainRobotResult->getResult(). -The specific http status code can be accessed with $domainRobotResult->getStatusCode(). -See an example of an error below. - -```php -( - [stid] => 20200210-app3-dev-5063 - [status] => Array - ( - [code] => S400110 - [text] => CSR key was checked successfully. - [type] => SUCCESS - ) - [data] => Array - ( - [0] => Array - ( - [plain] => -----BEGIN CERTIFICATE REQUEST----- -... ------END CERTIFICATE REQUEST----- - [name] => example.com - [keySize] => 2048 - [countryCode] => AU - [state] => Some-State - [organization] => Example Ltd - [algorithm] => RSA - [signatureHashAlgorithm] => SHA256 - ) - ) -) -``` - -### Supported API calls - -All API calls are asynchronous. Asynchronous calls should always be wrapped in a try-catch block to catch -possible exceptions. - -All API calls return a [DomainRobotException](#domainrobotexception) if an error occurs. - -All asnychronous API calls return a [DomainRobotResult](#domainrobotresult) if the task was successful. - -All synchronouse API calls return a call specific Object as defined in our [Technical Documentation](https://help.internetx.com/display/APIJSONEN/Technical+Documentation) (Please also refer to the examples of available tasks below for more details.) - -#### Certificate tasks - -##### Prepare Order - -```php -use IXDomainRobot\DomainRobot; -use IXDomainRobot\Lib\DomainRobotAuth; -use IXDomainRobot\Lib\DomainRobotException; -use IXDomainRobot\Model\Certificate; - -$domainRobot = new DomainRobot([ - "auth" => new DomainRobotAuth([ - "user" => "user", - "password" => "password" - ]) -]); - -$certificateModel = new Certificate(); -$certificateModel->setCsr( - "-----BEGIN CERTIFICATE REQUEST-----" . - ... - "-----END CERTIFICATE REQUEST-----" -); - -// sync version -try { - // this return an instance of new IXDomainRobot\Model\CertificateData() see [Models](#models) for more info - $certData = $domainRobot->certificate($certificateModel)->prepareOrder(); -}catch(DomainRobotException $exception){ - return response()->json($exception->getError(), $exception->getStatusCode()); -} - -return response()->json( - DomainRobot::getLastDomainRobotResult()->getResult(), - DomainRobot::getLastDomainRobotResult()->getStatusCode() -); - -// async version -try { - $promise = $domainRobot->certificate($certificateModel)->prepareOrderAsync(); - $result = $promise->wait(); -}catch(DomainRobotException $exception){ - return response()->json($exception->getError(), $exception->getStatusCode()); -} - -return response()->json($result->getResult(), $result->getStatusCode()); -``` - -##### Create Realtime - -```php -use IXDomainRobot\Lib\DomainRobotException; -use IXDomainRobot\Model\Certificate; -use IXDomainRobot\Model\TimePeriod; -use IXDomainRobot\Model\CertAuthentication; - -$certificateModel = new Certificate(); -$certificateModel->setCsr( - "-----BEGIN CERTIFICATE REQUEST-----" . - ... - "-----END CERTIFICATE REQUEST-----" -); -$certificateModel->setName("example.com"); - -$timePeriod = new TimePeriod([ - "unit" => "MONTH", - "period" => 12 -]); -$certificateModel->setLifetime($timePeriod); -$certificateModel->setProduct("BASIC_SSL"); -$certAuthentication = new CertAuthentication([ - "method" => "FILE" -]); -$certificateModel->setAuthentication($certAuthentication); - -// sync [returns a new IXDomainRobot\Model\Certificate() Object] -$certificate = $domainRobot->certificate($certificateModel)->createRealtime(); - -// async [returns a IXDomainRobot\Lib\DomainRobotPromise] -$promise = $domainRobot->certificate($certificateModel)->createRealtimeAsync(); -``` - -### DomainStudio tasks - -#### Search - -```php -use IXDomainRobot\Model\DomainEnvelopeSearchRequest; -use IXDomainRobot\Model\DomainStudioSources; -use IXDomainRobot\Model\DomainStudioSourceSuggestion; - -$domainEnvelopeSearchRequest = new DomainEnvelopeSearchRequest(); -$sources = new DomainStudioSources(); -$sources->setSuggestion(new DomainStudioSourceSuggestion(["max" => 5])); -$domainEnvelopeSearchRequest->setSources($sources); -$domainEnvelopeSearchRequest->setSearchToken("google"); -$domainEnvelopeSearchRequest->setCurrency("USD"); - -// sync [returns a new IXDomainRobot\Model\DomainEnvelope() Object] -$domainEnvelope = $domainRobot->domainStudio($domainEnvelopeSearchRequest)->search(); - -// async [returns a IXDomainRobot\Lib\DomainRobotPromise] -$promise = $domainRobot->certificate($certificateModel)->searchAsync(); -``` - ## (Custom) Headers ### Use @@ -422,14 +346,13 @@ Custom Headers (see available headers in [Available Headers](#available-headers) **addHeaders** expects an array. Default headers can also be overwritten like this. See example below. -```javascript +```php use IXDomainRobot\Lib\DomainRobotHeaders; -$promise = $domainRobot->certificate($certificateModel) +$certificateData = $domainRobot->certificate() ->addHeaders( [DomainRobotHeaders::DOMAINROBOT_HEADER_2FA_TOKEN => "token"] - )->prepareOrder(); -$domainRobotResult = $promise->wait(); + )->prepareOrder($body); ``` ## Changelog @@ -440,7 +363,7 @@ For a detailed changelog, see the [CHANGELOG.md](CHANGELOG.md) file. MIT License -Copyright (c) 2019 InterNetX GmbH +Copyright (c) 2020 InterNetX GmbH Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/composer.json b/composer.json index cf26b657..2c230229 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "internetx/php-domainrobot-sdk", - "version": "0.2.2", + "version": "0.3.0", "description": "A php package for easy integration of the domainrobot API powered by InterNetX GmbH.", "type": "library", "license": "MIT", @@ -13,4 +13,4 @@ "require": { "guzzlehttp/guzzle": "~6.0" } -} +} \ No newline at end of file diff --git a/src/service/CertificateService.php b/src/service/CertificateService.php index d822838f..705ca539 100644 --- a/src/service/CertificateService.php +++ b/src/service/CertificateService.php @@ -14,17 +14,14 @@ class CertificateService extends DomainRobotService { - private $certificateModel; /** * - * @param Certificate $certificateModel * @param DomainRobotConfig $domainRobotConfig */ - public function __construct(Certificate $certificateModel, DomainRobotConfig $domainRobotConfig) + public function __construct(DomainRobotConfig $domainRobotConfig) { parent::__construct($domainRobotConfig); - $this->certificateModel = $certificateModel; } /** @@ -32,18 +29,18 @@ public function __construct(Certificate $certificateModel, DomainRobotConfig $do * generate the necessary DCV data. Returns a Job with an id that can be used * for polling. * + * @param Certificate $body * @return Objectjob */ - public function create() + public function create(Certificate $body) { - $domainRobotPromise = $this->createAsync(); + $domainRobotPromise = $this->createAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); return new ObjectJob([ - "job" => ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0.id', ''), - "object" => $this->certificateModel->getName() + "job" => ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0.id', '') ]); } /** @@ -51,31 +48,33 @@ public function create() * generate the necessary DCV data. Returns a Job with an id that can be used * for polling. * + * @param Certificate $body * @return DomainRobotPromise */ - public function createAsync() + public function createAsync(Certificate $body) { - $this->prepareCsr(); + $this->prepareCsr($body); return $this->sendRequest( $this->domainRobotConfig->getUrl() . "/certificate", 'POST', - ["json" => $this->certificateModel->toArray(true)] + ["json" => $body->toArray(true)] ); } /** * Orders a certificate in realtime. The prepareOrder tasks should be called * before to generate the necessary DCV data. - * + * * **Note:** This works only for certain DV certificate products and dcv * methods. - * + * + * @param Certificate $body * @return Certificate */ - public function realtime() + public function realtime(Certificate $body) { - $domainRobotPromise = $this->realtimeAsync(); + $domainRobotPromise = $this->realtimeAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); @@ -86,34 +85,36 @@ public function realtime() /** * Orders a certificate in realtime. The prepareOrder tasks should be called * before to generate the necessary DCV data. - * + * * **Note:** This works only for certain DV certificate products and dcv * methods. - * + * + * @param Certificate $body * @return DomainRobotPromise */ - public function realtimeAsync() + public function realtimeAsync(Certificate $body) { - $this->prepareCsr(); + $this->prepareCsr($body); return $this->sendRequest( $this->domainRobotConfig->getUrl() . "/certificate/_realtime", 'POST', - ["json" => $this->certificateModel->toArray(true)] + ["json" => $body->toArray(true)] ); } /** * Check the csr and generate DCV data for an order, renew and reissue. This * should be called everytime before the following tasks : - * + * * * realtime * * create * * reissue * * renew - * + * + * @param CertificateData $body * @return CertificateData */ - public function prepareOrder() + public function prepareOrder(CertificateData $body) { $domainRobotPromise = $this->prepareOrderAsync(); $domainRobotResult = $domainRobotPromise->wait(); @@ -126,36 +127,52 @@ public function prepareOrder() /** * Check the csr and generate DCV data for an order, renew and reissue. This * should be called everytime before the following tasks : - * + * * * realtime * * create * * reissue * * renew * + * @param CertificateData $body * @return DomainRobotPromise */ - public function prepareOrderAsync() + public function prepareOrderAsync(CertificateData $body) { - $this->prepareCsr(); - - $certDataModel = new CertificateData(); - $certDataModel->setPlain($this->certificateModel->getCsr()); + //$this->prepareCsr(); return new DomainRobotPromise($this->sendRequest( $this->domainRobotConfig->getUrl() . "/certificate/_prepareOrder", 'POST', - ["json" => $certDataModel->toArray(true)] + ["json" => $body->toArray(true)] )); } /** * Sends a certificate list request. * + * The following keys can be used for filtering, ordering or fetching additional + * data via query parameter: + * + * * product + * * technical + * * orderId + * * created + * * admin + * * type + * * expire + * * domain + * * name + * * comment + * * id + * * updated + * * authentication + * + * @param Query $body * @return Certificate[] */ - public function list(Query $query = null) + public function list(Query $body = null) { - $domainRobotPromise = $this->listAsync($query); + $domainRobotPromise = $this->listAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); @@ -171,32 +188,45 @@ public function list(Query $query = null) /** * Sends a certificate list request. * + * The following keys can be used for filtering, ordering or fetching additional + * data via query parameter: + * + * * product + * * technical + * * orderId + * * created + * * admin + * * type + * * expire + * * domain + * * name + * * comment + * * id + * * updated + * * authentication + * + * @param Query $body * @return DomainRobotPromise */ - public function listAsync(Query $query = null) + public function listAsync(Query $body = null) { - - if ($query === null) { - return new DomainRobotPromise($this->sendRequest( - $this->domainRobotConfig->getUrl() . "/certificate/_search", - 'POST', - ["json" => null] - )); - } else { - return new DomainRobotPromise($this->sendRequest( - $this->domainRobotConfig->getUrl() . "/certificate/_search", - 'POST', - ["json" => $query->toArray(true)] - )); + $data = null; + if ($query != null) { + $data = $body->toArray(true); } + return new DomainRobotPromise($this->sendRequest( + $this->domainRobotConfig->getUrl() . "/certificate/_search", + 'POST', + ["json" => $data] + )); } /** * Fetches the information for an existing certificate. * * @param [int] $id - * @return CertificateData + * @return Certificate */ public function info($id) { @@ -204,14 +234,14 @@ public function info($id) $domainRobotResult = $domainRobotPromise->wait(); - return new CertificateData(ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0', [])); + return new Certificate(ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0', [])); } /** * Fetches the information for an existing certificate. * * @param [int] $id - * @return GuzzleHttp\Promise\PromiseInterface $promise + * @return DomainRobotPromise */ public function infoAsync($id) { @@ -234,10 +264,8 @@ public function delete($id) $domainRobotResult = $domainRobotPromise->wait(); return new ObjectJob([ - "job" => ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0.id', ''), - "object" => $this->certificateModel->getName() + "job" => ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0.id', '') ]); - // return new Certificate(ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0', [])); } @@ -246,13 +274,13 @@ public function delete($id) * for polling. * * @param [int] $id - * @return GuzzleHttp\Promise\PromiseInterface $promise + * @return DomainRobotPromise */ public function deleteAsync($id) { return $this->sendRequest( $this->domainRobotConfig->getUrl() . "/certificate/$id", - 'DELETE', + 'DELETE' ); } @@ -262,19 +290,18 @@ public function deleteAsync($id) * generate the necessary DCV data. Returns a Job with an id that can be used * for polling. * - * @param [int] $id + * @param Certificate $body * @return ObjectJob */ - public function reissue($id) + public function reissue(Certificate $body) { - $domainRobotPromise = $this->reissueAsync($id); + $domainRobotPromise = $this->reissueAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); return new ObjectJob([ - "job" => ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0.id', ''), - "object" => $this->certificateModel->getName() + "job" => ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0.id', '') ]); } @@ -283,17 +310,20 @@ public function reissue($id) * generate the necessary DCV data. Returns a Job with an id that can be used * for polling. * - * @param [int] $id - * @return GuzzleHttp\Promise\PromiseInterface $promise + * @param Certificate $body + * @return DomainRobotPromise */ - public function reissueAsync($id) + public function reissueAsync(Certificate $body) { - $this->prepareCsr(); + if ($body->getId() === null) { + throw InvalidArgumentException("Field Certificate.id is missing."); + } + $this->prepareCsr($body); return $this->sendRequest( - $this->domainRobotConfig->getUrl() . "/certificate/$id", + $this->domainRobotConfig->getUrl() . "/certificate/".$body->getId(), 'PUT', - ["json" => $this->certificateModel->toArray(true)] + ["json" => $body->toArray(true)] ); } @@ -303,19 +333,18 @@ public function reissueAsync($id) * generate the necessary DCV data. Returns a Job with an id that can be used * for polling. * - * @param [int] $id + * @param Certificate $body * @return ObjectJob */ - public function renew($id) + public function renew(Certificate $body) { - $domainRobotPromise = $this->renewAsync($id); + $domainRobotPromise = $this->renewAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); return new ObjectJob([ - "job" => ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0.id', ''), - "object" => $this->certificateModel->getName() + "job" => ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0.id', '') ]); } @@ -324,17 +353,20 @@ public function renew($id) * generate the necessary DCV data. Returns a Job with an id that can be used * for polling. * - * @param [int] $id - * @return GuzzleHttp\Promise\PromiseInterface $promise + * @param Certificate $body + * @return DomainRobotPromise */ - public function renewAsync($id) + public function renewAsync(Certificate $body) { - $this->prepareCsr(); + if ($body->getId() === null) { + throw InvalidArgumentException("Field Certificate.id is missing."); + } + $this->prepareCsr($body); return $this->sendRequest( - $this->domainRobotConfig->getUrl() . "/certificate/$id/_renew", + $this->domainRobotConfig->getUrl() . "/certificate/".$body->getId()."/_renew", 'PUT', - ["json" => $this->certificateModel->toArray(true)] + ["json" => $body->toArray(true)] ); } @@ -342,7 +374,7 @@ public function renewAsync($id) * Updates the comment for an existing certificate. * * @param [int] $id, [string] comment - * @return + * @return */ public function commentUpdate($id, $comment) { @@ -355,13 +387,11 @@ public function commentUpdate($id, $comment) /** * Updates the comment for an existing certificate. * - * @param [int] $id - * @return + * @param [int] $id, [string] comment + * @return */ public function commentUpdateAsync($id, $comment) { - $this->prepareCsr(); - $cert = new Certificate(['comment' => $comment]); $this->sendRequest( $this->domainRobotConfig->getUrl() . "/certificate/$id/_renew", @@ -372,16 +402,19 @@ public function commentUpdateAsync($id, $comment) /** * make sure the csr has the right format + * + * @param Certificate $body + * @return */ - private function prepareCsr() + private function prepareCsr(Certificate $body) { preg_match( "/^(-----BEGIN CERTIFICATE REQUEST-----)(.*)(-----END CERTIFICATE REQUEST-----)$/", - trim($this->certificateModel->getCsr()), + trim($body->getCsr()), $matches ); if (!empty($matches)) { - $this->certificateModel->setCsr(implode("\n", [ + $body->setCsr(implode("\n", [ $matches[1], $matches[2], $matches[3] diff --git a/src/service/ContactService.php b/src/service/ContactService.php index a351bb58..26d3f485 100644 --- a/src/service/ContactService.php +++ b/src/service/ContactService.php @@ -12,27 +12,25 @@ class ContactService extends DomainRobotService { - private $contactModel; /** * - * @param Contact $contactModel * @param DomainRobotConfig $domainRobotConfig */ - public function __construct(Contact $contactModel, DomainRobotConfig $domainRobotConfig) + public function __construct(DomainRobotConfig $domainRobotConfig) { parent::__construct($domainRobotConfig); - $this->contactModel = $contactModel; } /** * Sends a contact create request. * + * @param Contact $body * @return Contact */ - public function create() + public function create(Contact $body) { - $domainRobotPromise = $this->createAsync(); + $domainRobotPromise = $this->createAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); @@ -43,25 +41,27 @@ public function create() /** * Sends a contact create request. * + * @param Contact $body * @return DomainRobotPromise */ - public function createAsync() + public function createAsync(Contact $body) { return $this->sendRequest( $this->domainRobotConfig->getUrl() . "/contact", 'POST', - ["json" => $this->contactModel->toArray(true)] + ["json" => $body->toArray(true)] ); } /** * Sends a contact list request. * + * @param Query $body * @return Contact[] */ - public function list(Query $query = null) + public function list(Query $body = null) { - $domainRobotPromise = $this->listAsync($query); + $domainRobotPromise = $this->listAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); @@ -77,25 +77,20 @@ public function list(Query $query = null) /** * Sends a contact list request. * + * @param Query $body * @return DomainRobotPromise */ - - public function listAsync(Query $query = null) + public function listAsync(Query $body = null) { - - if ($query === null) { - return new DomainRobotPromise($this->sendRequest( - $this->domainRobotConfig->getUrl() . "/contact/_search", - 'POST', - ["json" => null] - )); - } else { - return new DomainRobotPromise($this->sendRequest( - $this->domainRobotConfig->getUrl() . "/contact/_search", - 'POST', - ["json" => $query->toArray(true)] - )); + $data = null; + if ($body != null) { + $data = $body->toArray(true); } + return new DomainRobotPromise($this->sendRequest( + $this->domainRobotConfig->getUrl() . "/contact/_search", + 'POST', + ["json" => $data] + )); } /** @@ -117,7 +112,7 @@ public function info($id) * Sends a contact info request. * * @param [int] $id - * @return GuzzleHttp\Promise\PromiseInterface $promise + * @return DomainRobotPromise */ public function infoAsync($id) { @@ -150,19 +145,19 @@ public function deleteAsync($id) { $this->sendRequest( $this->domainRobotConfig->getUrl() . "/contact/$id", - 'DELETE', + 'DELETE' ); } /** * Sends a contact update request. * - * @param [int] $id + * @param Contact $body * @return Contact */ - public function update($id) + public function update(Contact $body) { - $domainRobotPromise = $this->updateAsync($id); + $domainRobotPromise = $this->updateAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); @@ -173,16 +168,18 @@ public function update($id) /** * Sends a contact update request. * - * @param [int] $id - * @return GuzzleHttp\Promise\PromiseInterface $promise + * @param Contact $body + * @return DomainRobotPromise */ - public function updateAsync($id) + public function updateAsync(Contact $body) { - + if ($body->getId() === null) { + throw InvalidArgumentException("Field Contact.id is missing."); + } return $this->sendRequest( - $this->domainRobotConfig->getUrl() . "/contact/$id", + $this->domainRobotConfig->getUrl() . "/contact/".$body->getId(), 'PUT', - ["json" => $this->contactModel->toArray(true)] + ["json" => $body->toArray(true)] ); } } diff --git a/src/service/DomainCancelationService.php b/src/service/DomainCancelationService.php index b6044d9f..a7d73515 100644 --- a/src/service/DomainCancelationService.php +++ b/src/service/DomainCancelationService.php @@ -12,28 +12,25 @@ class DomainCancelationService extends DomainRobotService { - private $domainCancelationModel; /** * - * @param DomainCancelation $domainCancelationModel * @param DomainRobotConfig $domainRobotConfig */ - public function __construct(DomainCancelation $domainCancelationModel, DomainRobotConfig $domainRobotConfig) + public function __construct(DomainRobotConfig $domainRobotConfig) { parent::__construct($domainRobotConfig); - $this->domainCancelationModel = $domainCancelationModel; } /** * Sends a DomainCancelation create request. * - * @param [string] $name + * @param DomainCancelation $body * @return DomainCancelation */ - public function create($name) + public function create(DomainCancelation $body) { - $domainRobotPromise = $this->createAsync($name); + $domainRobotPromise = $this->createAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); @@ -44,24 +41,28 @@ public function create($name) /** * Sends a DomainCancelation create request. * + * @param DomainCancelation $body * @return DomainRobotPromise */ - public function createAsync($name) + public function createAsync(DomainCancelation $body) { + if ($body->getDomain() === null) { + throw InvalidArgumentException("Field DomainCancelation.domain is missing."); + } return $this->sendRequest( - $this->domainRobotConfig->getUrl() . "/domain/$name/cancelation", + $this->domainRobotConfig->getUrl() . "/domain/".$body->getDomain()."/cancelation", 'POST', - ["json" => $this->domainCancelationModel->toArray(true)] + ["json" => $body->toArray(true)] ); } /** * Sends a DomainCancelation update request. * - * @param [string] $name + * @param DomainCancelation $body * @return DomainCancelation */ - public function update($name) + public function update(DomainCancelation $body) { $domainRobotPromise = $this->updateAsync($name); $domainRobotResult = $domainRobotPromise->wait(); @@ -74,28 +75,30 @@ public function update($name) /** * Sends a DomainCancelation update request. * - * @param [string] $name + * @param DomainCancelation $body * @return DomainRobotPromise */ - public function updateAsync($name) + public function updateAsync(DomainCancelation $body) { - + if ($body->getDomain() === null) { + throw InvalidArgumentException("Field DomainCancelation.domain is missing."); + } return $this->sendRequest( - $this->domainRobotConfig->getUrl() . "/domain/$name/cancelation", + $this->domainRobotConfig->getUrl() . "/domain/".$body->getDomain()."/cancelation", 'PUT', - ["json" => $this->domainCancelationModel->toArray(true)] + ["json" => $body->toArray(true)] ); } /** * Deletes an existing cancelation for the given domain. * - * @param [string] $name - * @return + * @param [string] $domain + * @return */ - public function delete($name) + public function delete($domain) { - $domainRobotPromise = $this->deleteAsync($name); + $domainRobotPromise = $this->deleteAsync($domain); $domainRobotPromise->wait(); } @@ -103,14 +106,14 @@ public function delete($name) /** * Deletes an existing cancelation for the given domain. * - * @param [string] $name + * @param [string] $domain * @return */ - public function deleteAsync($name) + public function deleteAsync($domain) { $this->sendRequest( - $this->domainRobotConfig->getUrl() . "/domain/$name/cancelation", - 'DELETE', + $this->domainRobotConfig->getUrl() . "/domain/$domain/cancelation", + 'DELETE' ); } @@ -118,12 +121,12 @@ public function deleteAsync($name) /** * Fetches the cancelation for the given domain. * - * @param [string] $name + * @param [string] $domain * @return DomainCancelation */ - public function info($name) + public function info($domain) { - $domainRobotPromise = $this->infoAsync($name); + $domainRobotPromise = $this->infoAsync($domain); $domainRobotResult = $domainRobotPromise->wait(); @@ -133,23 +136,23 @@ public function info($name) /** * Fetches the cancelation for the given domain. * - * @param [string] $name + * @param [string] $domain * @return DomainRobotPromise */ - public function infoAsync($name) + public function infoAsync($domain) { return $this->sendRequest( - $this->domainRobotConfig->getUrl() . "/domain/$name/cancelation", + $this->domainRobotConfig->getUrl() . "/domain/$domain/cancelation", 'GET' ); } /** * Sends a DomainCancelation list request. - * + * * The following keys can be used for filtering, ordering or fetching additional * data via query parameter: - * + * * * disconnect * * execdate * * ctid @@ -162,11 +165,12 @@ public function infoAsync($name) * * gainingRegistrar * * updated * + * @param Query $body * @return DomainCancelation[] */ - public function list(Query $query = null) + public function list(Query $body = null) { - $domainRobotPromise = $this->listAsync($query); + $domainRobotPromise = $this->listAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); @@ -181,10 +185,10 @@ public function list(Query $query = null) /** * Sends a DomainCancelation list request. - * + * * The following keys can be used for filtering, ordering or fetching additional * data via query parameter: - * + * * * disconnect * * execdate * * ctid @@ -196,24 +200,21 @@ public function list(Query $query = null) * * subtld * * gainingRegistrar * * updated - * + * + * @param Query $body * @return DomainRobotPromise */ - public function listAsync(Query $query = null) + public function listAsync(Query $body = null) { - if ($query === null) { - return new DomainRobotPromise($this->sendRequest( - $this->domainRobotConfig->getUrl() . "/domain/cancelation/_search", - 'POST', - ["json" => null] - )); - } else { - return new DomainRobotPromise($this->sendRequest( - $this->domainRobotConfig->getUrl() . "/domain/cancelation/_search", - 'POST', - ["json" => $query->toArray(true)] - )); + $data = null; + if ($body != null) { + $data = $body->toArray(true); } + return new DomainRobotPromise($this->sendRequest( + $this->domainRobotConfig->getUrl() . "/domain/cancelation/_search", + 'POST', + ["json" => $data] + )); } } diff --git a/src/service/DomainRobotService.php b/src/service/DomainRobotService.php index 8ee83cf5..70cff092 100644 --- a/src/service/DomainRobotService.php +++ b/src/service/DomainRobotService.php @@ -10,10 +10,10 @@ use IXDomainRobot\Lib\DomainRobotHeaders; use IXDomainRobot\Lib\DomainRobotException; use IXDomainRobot\Lib\DomainRobotResult; +use IXDomainRobot\Lib\DomainRobotPromise; use IXDomainRobot\Model\Certificate; use Psr\Http\Message\ResponseInterface; - class DomainRobotService { /** @@ -53,12 +53,12 @@ public function addHeaders($headers = []) /** * General guzzle interface - * + * * @param string $url * @param string $method * @param array $options * - * @return GuzzleHttp\Promise\PromiseInterface $promise + * @return DomainRobotPromise */ public function sendRequest($url, $method, $options = []) @@ -71,7 +71,7 @@ public function sendRequest($url, $method, $options = []) $options )->then( /** - * + * * @return DomainRobotException */ function (ResponseInterface $response) { @@ -96,8 +96,6 @@ function (\Exception $exception) { throw new DomainRobotException($msg, $exception->getCode(), "DomainRobot Error"); } ); - - - return $promise; + return new DomainRobotPromise($promise); } } diff --git a/src/service/DomainService.php b/src/service/DomainService.php index 1f363bb7..de3597e8 100644 --- a/src/service/DomainService.php +++ b/src/service/DomainService.php @@ -14,56 +14,54 @@ class DomainService extends DomainRobotService { - private $domainModel; /** * - * @param Domain $domainModel * @param DomainRobotConfig $domainRobotConfig */ - public function __construct(Domain $domainModel, DomainRobotConfig $domainRobotConfig) + public function __construct(DomainRobotConfig $domainRobotConfig) { parent::__construct($domainRobotConfig); - $this->domainModel = $domainModel; } /** * Sends a Domain create request. * + * @param Domain $body * @return ObjectJob */ - public function create() + public function create(Domain $body) { - $domainRobotPromise = $this->createAsync(); + $domainRobotPromise = $this->createAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); return new ObjectJob([ - "job" => ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0.id', ''), - "object" => $this->domainModel->getName() + "job" => ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0.id', '') ]); } /** * Sends a Domain create request. * + * @param Domain $body * @return DomainRobotPromise */ - public function createAsync() + public function createAsync(Domain $body) { return $this->sendRequest( $this->domainRobotConfig->getUrl() . "/domain", 'POST', - ["json" => $this->domainModel->toArray(true)] + ["json" => $body->toArray(true)] ); } /** * Sends a authinfo1 create request. - * + * * @param [string] $name - * @return Domain + * @return */ public function createAuthinfo1($name) { @@ -77,7 +75,7 @@ public function createAuthinfo1($name) /** * Sends a authinfo1 create request. - * + * * @param [string] $name * @return DomainRobotPromise */ @@ -85,16 +83,15 @@ public function createAuthinfo1Async($name) { return $this->sendRequest( $this->domainRobotConfig->getUrl() . "/domain/$name/_authinfo1", - 'POST', - ["json" => $this->domainModel->toArray(true)] + 'POST' ); } /** * Sends a authinfo2 create request. - * + * * @param [string] $name - * @return Domain + * @return */ public function createAuthinfo2($name) { @@ -104,82 +101,84 @@ public function createAuthinfo2($name) /** * Sends a authinfo2 create request. - * + * * @param [string] $name - * @return + * @return */ public function createAuthinfo2Async($name) { $this->sendRequest( $this->domainRobotConfig->getUrl() . "/domain/$name/_authinfo2", - 'POST', - ["json" => $this->domainModel->toArray(true)] + 'POST' ); } /** * Sends a Domain renew request. * - * @param [string] $name + * @param Domain $body * @return ObjectJob */ - public function renew($name) + public function renew(Domain $body) { - $domainRobotPromise = $this->renewAsync($name); + $domainRobotPromise = $this->renewAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); return new ObjectJob([ - "job" => ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0.id', ''), - "object" => $this->domainModel->getName() + "job" => ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0.id', '') ]); } /** * Sends a Domain renew request. * - * @param [string] $name - * @return GuzzleHttp\Promise\PromiseInterface $promise + * @param Domain $body + * @return DomainRobotPromise */ - public function renewAsync($name) + public function renewAsync(Domain $body) { + if ($body->getName() === null) { + throw InvalidArgumentException("Field Domain.name is missing."); + } return $this->sendRequest( - $this->domainRobotConfig->getUrl() . "/domain/$name/_renew", + $this->domainRobotConfig->getUrl() . "/domain/".$body->getName()."/_renew", 'PUT', - ["json" => $this->domainModel->toArray(true)] + ["json" => $body->toArray(true)] ); } /** * Sends a Domain transfer request. * + * @param Domain $body * @return ObjectJob */ - public function transfer() + public function transfer(Domain $body) { - $domainRobotPromise = $this->transferAsync(); + $domainRobotPromise = $this->transferAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); return new ObjectJob([ - "job" => ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0.id', ''), - "object" => $this->domainModel->getName() + "job" => ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0.id', '') ]); } /** * Sends a Domain transfer request. * + * @param Domain $body * @return DomainRobotPromise */ - public function transferAsync() + public function transferAsync(Domain $body) { return $this->sendRequest( $this->domainRobotConfig->getUrl() . "/domain/_transfer", 'POST', - ["json" => $this->domainModel->toArray(true)] + ["json" => $body->toArray(true)] ); } @@ -187,10 +186,10 @@ public function transferAsync() /** * Update the registry status for an existing domain. * - * @param [string] $name + * @param Domain $body * @return */ - public function updateStatus($name) + public function updateStatus(Domain $body) { $domainRobotPromise = $this->updateStatusAsync($name); $domainRobotPromise->wait(); @@ -199,25 +198,28 @@ public function updateStatus($name) /** * Update the registry status for an existing domain. * - * @param [string] $name - * @return + * @param Domain $body + * @return */ - public function updateStatusAsync($name) + public function updateStatusAsync(Domain $body) { + if ($body->getName() === null) { + throw InvalidArgumentException("Field Domain.name is missing."); + } $this->sendRequest( - $this->domainRobotConfig->getUrl() . "/domain/$name/_statusUpdate", + $this->domainRobotConfig->getUrl() . "/domain/".$body->getName()."/_statusUpdate", 'PUT', - ["json" => $this->domainModel->toArray(true)] + ["json" => $body->toArray(true)] ); } /** * Sends a Domain list request. - * - * + * + * * The following keys can be used for filtering, ordering or fetching additional * data via query parameter: - * + * * * sld * * subtld * * tld @@ -235,11 +237,12 @@ public function updateStatusAsync($name) * * created * * autorenew * + * @param Query $body * @return Domain[] */ - public function list(Query $query = null) + public function list(Query $body = null) { - $domainRobotPromise = $this->listAsync($query); + $domainRobotPromise = $this->listAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); @@ -254,11 +257,11 @@ public function list(Query $query = null) /** * Sends a Domain list request. - * - * + * + * * The following keys can be used for filtering, ordering or fetching additional * data via query parameter: - * + * * * sld * * subtld * * tld @@ -276,32 +279,29 @@ public function list(Query $query = null) * * created * * autorenew * + * @param Query $body * @return DomainRobotPromise */ - public function listAsync(Query $query = null) + public function listAsync(Query $body = null) { - if ($query === null) { - return new DomainRobotPromise($this->sendRequest( - $this->domainRobotConfig->getUrl() . "/domain/_search", - 'POST', - ["json" => null] - )); - } else { - return new DomainRobotPromise($this->sendRequest( - $this->domainRobotConfig->getUrl() . "/domain/_search", - 'POST', - ["json" => $query->toArray(true)] - )); + $data = null; + if ($body != null) { + $data = $body->toArray(true); } + return new DomainRobotPromise($this->sendRequest( + $this->domainRobotConfig->getUrl() . "/domain/_search", + 'POST', + ["json" => $data] + )); } /** * Sends a Domain restore list request. - * - * + * + * * The following keys can be used for filtering, ordering or fetching additional * data via query parameter:
- * + * * * parking * * certificate * * adminc @@ -328,11 +328,12 @@ public function listAsync(Query $query = null) * * authinfo * * status * + * @param Query $body * @return DomainRestore[] */ - public function restoreList(Query $query = null) + public function restoreList(Query $body = null) { - $domainRobotPromise = $this->restoreListAsync($query); + $domainRobotPromise = $this->restoreListAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); @@ -348,11 +349,11 @@ public function restoreList(Query $query = null) /** * Sends a Domain restore list request. - * - * + * + * * The following keys can be used for filtering, ordering or fetching additional * data via query parameter:
- * + * * * parking * * certificate * * adminc @@ -379,23 +380,20 @@ public function restoreList(Query $query = null) * * authinfo * * status * + * @param Query $body * @return DomainRobotPromise */ - public function restoreListAsync(Query $query = null) + public function restoreListAsync(Query $body = null) { - if ($query === null) { - return new DomainRobotPromise($this->sendRequest( - $this->domainRobotConfig->getUrl() . "/domain/_search", - 'POST', - ["json" => null] - )); - } else { - return new DomainRobotPromise($this->sendRequest( - $this->domainRobotConfig->getUrl() . "/domain/_search", - 'POST', - ["json" => $query->toArray(true)] - )); + $data = null; + if ($body != null) { + $data = $body->toArray(true); } + return new DomainRobotPromise($this->sendRequest( + $this->domainRobotConfig->getUrl() . "/domain/restore/_search", + 'POST', + ["json" => $data] + )); } /** @@ -430,7 +428,7 @@ public function infoAsync($name) * Sends a authinfo1 delete request. * * @param [string] $name - * @return + * @return */ public function deleteAuthinfo1($name) { @@ -442,82 +440,85 @@ public function deleteAuthinfo1($name) * Sends a authinfo1 delete request. * * @param [string] $name - * @param [string] $systemNameServer - * @return + * @return */ public function deleteAuthinfo1Async($name) { $this->sendRequest( $this->domainRobotConfig->getUrl() . "/domain/$name/_authinfo1", - 'DELETE', + 'DELETE' ); } /** * Sends a Domain update request. * - * @param [string] $name + * @param Domain $body * @return ObjektJob */ - public function update($name) + public function update(Domain $body) { - $domainRobotPromise = $this->updateAsync($name); + $domainRobotPromise = $this->updateAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); return new ObjectJob([ - "job" => ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0.id', ''), - "object" => $this->domainModel->getName() + "job" => ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0.id', '') ]); } /** * Sends a Domain update request. * - * @param [string] $name + * @param Domain $body * @return DomainRobotPromise */ - public function updateAsync($name) + public function updateAsync(Domain $body) { + if ($body->getName() === null) { + throw InvalidArgumentException("Field Domain.name is missing."); + } return $this->sendRequest( - $this->domainRobotConfig->getUrl() . "/domain/$name", + $this->domainRobotConfig->getUrl() . "/domain/".$body->getName(), 'PUT', - ["json" => $this->domainModel->toArray(true)] + ["json" => $body->toArray(true)] ); } /** * Sends a Domain restore request. * - * @param [string] $name + * @param DomainRestore $body * @return ObjectJob */ - public function restore(DomainRestore $domainRestore, $name) + public function restore(DomainRestore $body) { - $domainRobotPromise = $this->restoreAsync($domainRestore, $name); + $domainRobotPromise = $this->restoreAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); return new ObjectJob([ - "job" => ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0.id', ''), - "object" => $domainRestore->getName() + "job" => ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0.id', '') ]); } /** * Sends a Domain restore request. * - * @param [string] $name - * @return GuzzleHttp\Promise\PromiseInterface $promise + * @param DomainRestore $body + * @return DomainRobotPromise */ - public function restoreAsync(DomainRestore $domainRestore, $name) + public function restoreAsync(DomainRestore $body) { + if ($body->getName() === null) { + throw InvalidArgumentException("Field DomainRestore.name is missing."); + } return $this->sendRequest( - $this->domainRobotConfig->getUrl() . "/domain/$name/_restore", + $this->domainRobotConfig->getUrl() . "/domain/".$body->getName()."/_restore", 'PUT', - ["json" => $domainRestore->toArray(true)] + ["json" => $body->toArray(true)] ); } } diff --git a/src/service/DomainStudioService.php b/src/service/DomainStudioService.php index 6394731f..cbaf313c 100644 --- a/src/service/DomainStudioService.php +++ b/src/service/DomainStudioService.php @@ -11,47 +11,76 @@ use IXDomainRobot\Model\DomainEnvelopeSearchRequest; use IXDomainRobot\Service\DomainRobotService; +/** + * Implementation of the domainstudio specific API functions. + * + * @author Benjamin Krammel + */ class DomainStudioService extends DomainRobotService { - private $domainEnvelopeSearchRequest; - /** - * - * @param DomainEnvelopeSearchRequest $domainEnvelopeSearchRequest - * @param DomainRobotConfig $domainRobotConfig - */ - public function __construct(DomainEnvelopeSearchRequest $domainEnvelopeSearchRequest, DomainRobotConfig $domainRobotConfig) + * + * @param DomainRobotConfig $domainRobotConfig + */ + public function __construct(DomainRobotConfig $domainRobotConfig) { parent::__construct($domainRobotConfig); - $this->domainEnvelopeSearchRequest = $domainEnvelopeSearchRequest; } /** - * Powerful search api for free domains, premium domains and alternate domain names. + * Sends a domainstudio search request. + * + * **Note:** By default, search results are provided synchronously. The + * search response contains all the additional data for each domain name created. + * + * With the following header the asynchronous (websocket) mode can be activated: + * + * * X-Domainrobot-WS : ASYNC * - * @return DomainEnvelope + * The additional domain data will then be delivered via websocket. + * See the official at https://help.internetx.com/display/APIADDITIONALEN/DomainStudio+Guide for more information. + * + * @param DomainEnvelopeSearchRequest $body + * @return DomainEnvelope[] */ - public function search() + public function search(DomainEnvelopeSearchRequest $body) { - $domainRobotPromise = $this->searchAsync(); + $domainRobotPromise = $this->searchAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); - return new DomainEnvelope(ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0', [])); + $data = $domainRobotResult->getResult()['data']; + $envelopes = array(); + foreach ($data as $d) { + $c = new DomainEnvelope($d); + array_push($envelopes, $c); + } + return $envelopes; } /** - * Async version of search() - * Powerful search api for free domains, premium domains and alternate domain names. + * Sends a domainstudio search request. + * + * **Note:** By default, search results are provided synchronously. The + * search response contains all the additional data for each domain name created. + * + * With the following header the asynchronous (websocket) mode can be activated: + * + * * X-Domainrobot-WS : ASYNC + * + * The additional domain data will then be delivered via websocket. + * See the official at https://help.internetx.com/display/APIADDITIONALEN/DomainStudio+Guide for more information. * - * @return DomainRobotPromise $promise + * @param DomainEnvelopeSearchRequest $body + * @return DomainRobotPromise */ - public function searchAsync() + public function searchAsync(DomainEnvelopeSearchRequest $body) { - return $this->sendPostRequest( + return $this->sendRequest( $this->domainRobotConfig->getUrl()."/domainstudio", - $this->domainEnvelopeSearchRequest->toArray(true) + "POST", + $body->toArray(true) ); } } diff --git a/src/service/PollMessageService.php b/src/service/PollMessageService.php index 3e800b51..9ffa4e1c 100644 --- a/src/service/PollMessageService.php +++ b/src/service/PollMessageService.php @@ -6,49 +6,45 @@ use IXDomainRobot\Lib\ArrayHelper; use IXDomainRobot\Lib\DomainRobotConfig; use IXDomainRobot\Model\PollMessage; +use IXDomainRobot\Model\DomainRobotPromise; use IXDomainRobot\Service\DomainRobotService; class PollMessageService extends DomainRobotService { - private $pollMessageModel; - /** * - * @param PollMessage $pollMessageModel * @param DomainRobotConfig $domainRobotConfig */ - public function __construct(PollMessage $pollMessageModel, DomainRobotConfig $domainRobotConfig) + public function __construct(DomainRobotConfig $domainRobotConfig) { parent::__construct($domainRobotConfig); - $this->pollMessageModel = $pollMessageModel; } /** * Fetches the latest poll message. To receive the next message, the current * message needs to be confirmed via the confirm function. - * + * * The poll system works according to the "First In First Out (FIFO)" principle. + * More information at https://help.internetx.com/display/APIPROCESSEN/Asynchronous+Notifications#AsynchronousNotifications-Polling * - * * @return PollMessage */ - public function info($id) + public function info() { $domainRobotPromise = $this->infoAsync(); $domainRobotResult = $domainRobotPromise->wait(); - return new PollMessage(ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0', [])); } /** * Fetches the latest poll message. To receive the next message, the current * message needs to be confirmed via the confirm function. - * + * * The poll system works according to the "First In First Out (FIFO)" principle. + * More information at https://help.internetx.com/display/APIPROCESSEN/Asynchronous+Notifications#AsynchronousNotifications-Polling * - * @param [int] $id * @return GuzzleHttp\Promise\PromiseInterface $promise */ public function infoAsync() @@ -78,15 +74,13 @@ public function confirm($id) * Confirms the PollMessage with the given id. * * @param [int] $id - * @return GuzzleHttp\Promise\PromiseInterface $promise + * @return DomainRobotPromise */ public function confirmAsync($id) { - $this->sendRequest( $this->domainRobotConfig->getUrl() . "/poll/$id", - 'PUT', - ["json" => $this->pollMessageModel->toArray(true)] + 'PUT' ); } } diff --git a/src/service/SslContactService.php b/src/service/SslContactService.php index 2833b637..1b11c732 100644 --- a/src/service/SslContactService.php +++ b/src/service/SslContactService.php @@ -12,27 +12,25 @@ class SSlContactService extends DomainRobotService { - private $sslContactModel; /** * - * @param SslContact $sslContactModel * @param DomainRobotConfig $domainRobotConfig */ - public function __construct(SslContact $sslContacteModel, DomainRobotConfig $domainRobotConfig) + public function __construct(DomainRobotConfig $domainRobotConfig) { parent::__construct($domainRobotConfig); - $this->sslContactModel = $sslContacteModel; } /** * Sends a sslcontact create request. * + * @param SslContact $body * @return SslContact */ - public function create() + public function create(SslContact $body) { - $domainRobotPromise = $this->createAsync(); + $domainRobotPromise = $this->createAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); @@ -43,25 +41,27 @@ public function create() /** * Sends a sslcontact create request. * + * @param SslContact $body * @return DomainRobotPromise */ - public function createAsync() + public function createAsync(SslContact $body) { return $this->sendRequest( $this->domainRobotConfig->getUrl() . "/sslcontacct", 'POST', - ["json" => $this->sslContactModel->toArray(true)] + ["json" => $body->toArray(true)] ); } /** * Sends a sslcontact list request. * + * @param Query $body * @return SslContact[] */ - public function list(Query $query = null) + public function list(Query $body = null) { - $domainRobotPromise = $this->listAsync($query); + $domainRobotPromise = $this->listAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); @@ -77,25 +77,20 @@ public function list(Query $query = null) /** * Sends a sslcontact list request. * + * @param Query $body * @return DomainRobotPromise */ - - public function listAsync(Query $query = null) + public function listAsync(Query $body = null) { - - if ($query === null) { - return new DomainRobotPromise($this->sendRequest( - $this->domainRobotConfig->getUrl() . "/sslcontact/_search", - 'POST', - ["json" => null] - )); - } else { - return new DomainRobotPromise($this->sendRequest( - $this->domainRobotConfig->getUrl() . "/sslcontact/_search", - 'POST', - ["json" => $query->toArray(true)] - )); + $data = null; + if ($body != null) { + $data = $body->toArray(true); } + return new DomainRobotPromise($this->sendRequest( + $this->domainRobotConfig->getUrl() . "/sslcontact/_search", + 'POST', + ["json" => $data] + )); } /** @@ -117,7 +112,7 @@ public function info($id) * Sends a sslcontact info request. * * @param [int] $id - * @return GuzzleHttp\Promise\PromiseInterface $promise + * @return DomainRobotPromise */ public function infoAsync($id) { @@ -143,25 +138,25 @@ public function delete($id) * Sends a sslcontact delete request. * * @param [int] $id - * @return GuzzleHttp\Promise\PromiseInterface $promise + * @return DomainRobotPromise */ public function deleteAsync($id) { $this->sendRequest( $this->domainRobotConfig->getUrl() . "/sslcontact/$id", - 'DELETE', + 'DELETE' ); } /** * Sends a sslcontact update request. * - * @param [int] $id + * @param SslContact $body * @return SslContact */ - public function update($id) + public function update(SslContact $body) { - $domainRobotPromise = $this->updateAsync($id); + $domainRobotPromise = $this->updateAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); @@ -172,15 +167,18 @@ public function update($id) /** * Sends a sslcontact update request. * - * @param [int] $id - * @return GuzzleHttp\Promise\PromiseInterface $promise + * @param SslContact $body + * @return DomainRobotPromise */ - public function updateAsync($id) + public function updateAsync(SslContact $body) { + if ($body->getId() === null) { + throw InvalidArgumentException("Field SslContact.id is missing."); + } return $this->sendRequest( - $this->domainRobotConfig->getUrl() . "/sslcontact/$id", + $this->domainRobotConfig->getUrl()."/sslcontact/".$body->getId(), 'PUT', - ["json" => $this->sslContactModel->toArray(true)] + ["json" => $body->toArray(true)] ); } } diff --git a/src/service/TransferOutService.php b/src/service/TransferOutService.php index e32113ce..085e44ef 100644 --- a/src/service/TransferOutService.php +++ b/src/service/TransferOutService.php @@ -14,17 +14,14 @@ class TransferOutService extends DomainRobotService { - private $transferOutModel; /** * - * @param TransferOut $transferOutModel * @param DomainRobotConfig $domainRobotConfig */ - public function __construct(TransferOut $transferOutModel, DomainRobotConfig $domainRobotConfig) + public function __construct(DomainRobotConfig $domainRobotConfig) { parent::__construct($domainRobotConfig); - $this->transferOutModel = $transferOutModel; } /** @@ -34,7 +31,7 @@ public function __construct(TransferOut $transferOutModel, DomainRobotConfig $do * @param [string] $type * @return TransferOut */ - public function answer($domain, TransferAnswer $answer) + public function answer($domain, $answer) { $domainRobotPromise = $this->answerAsync($domain, $answer); $domainRobotResult = $domainRobotPromise->wait(); @@ -47,13 +44,12 @@ public function answer($domain, TransferAnswer $answer) /** * Answer a transfer for the given domain with the given answer. * - * @param [string] $domain - * @param [string] $type + * @param [string] $domain, + * @param [string] $answer * @return DomainRobotPromise */ public function answerAsync($domain, $answer) { - $transformedAnswer = ""; if ($answer === TransferAnswer::ACK) { $transformedAnswer = "ack"; @@ -63,17 +59,16 @@ public function answerAsync($domain, $answer) return $this->sendRequest( $this->domainRobotConfig->getUrl() . "/transferout/$domain/$transformedAnswer", - 'PUT', - ["json" => $this->transferOutModel->toArray(true)] + 'PUT' ); } /** * Sends a TransferOut list request. - * + * * The following keys can be used for filtering, ordering or fetching additional * data via query parameter: - * + * * * reminder * * created * * loosingRegistrar @@ -89,11 +84,12 @@ public function answerAsync($domain, $answer) * * transaction * * status * + * @param Query $body * @return TransferOut[] */ - public function list(Query $query = null) + public function list(Query $body = null) { - $domainRobotPromise = $this->listAsync($query); + $domainRobotPromise = $this->listAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); @@ -108,10 +104,10 @@ public function list(Query $query = null) /** * Sends a TransferOut list request. - * + * * The following keys can be used for filtering, ordering or fetching additional * data via query parameter: - * + * * * reminder * * created * * loosingRegistrar @@ -127,23 +123,19 @@ public function list(Query $query = null) * * transaction * * status * + * @param Query $body * @return DomainRobotPromise */ - - public function listAsync(Query $query = null) + public function listAsync(Query $body = null) { - if ($query === null) { - return new DomainRobotPromise($this->sendRequest( - $this->domainRobotConfig->getUrl() . "/transferout/_search", - 'POST', - ["json" => null] - )); - } else { - return new DomainRobotPromise($this->sendRequest( - $this->domainRobotConfig->getUrl() . "/transferout/_search", - 'POST', - ["json" => $query->toArray(true)] - )); + $data = null; + if ($body != null) { + $data = $body->toArray(true); } + return new DomainRobotPromise($this->sendRequest( + $this->domainRobotConfig->getUrl() . "/transferout/_search", + 'POST', + ["json" => $data] + )); } } diff --git a/src/service/TrustedAppService.php b/src/service/TrustedAppService.php index 87ecac8d..f6d7c9e9 100644 --- a/src/service/TrustedAppService.php +++ b/src/service/TrustedAppService.php @@ -12,27 +12,26 @@ class TrustedApplicationService extends DomainRobotService { - private $trustedApplicationModel; + /** * - * @param TrustedApplicationModel $trustedApplicationModel * @param DomainRobotConfig $domainRobotConfig */ - public function __construct(TrustedApplication $trustedApplicationModel, DomainRobotConfig $domainRobotConfig) + public function __construct(DomainRobotConfig $domainRobotConfig) { parent::__construct($domainRobotConfig); - $this->trustedApplicationModel = $trustedApplicationModel; } /** * Sends a TrustedApplication create request. * + * @param TrustedApplication $body * @return TrustedApplication */ - public function create() + public function create(TrustedApplication $body) { - $domainRobotPromise = $this->createAsync(); + $domainRobotPromise = $this->createAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); @@ -43,14 +42,15 @@ public function create() /** * Sends a TrustedApplication create request. * + * @param TrustedApplication $body * @return DomainRobotPromise */ - public function createAsync() + public function createAsync(TrustedApplication $body) { return $this->sendRequest( $this->domainRobotConfig->getUrl() . "/trustedapp", 'POST', - ["json" => $this->trustedApplicationModel->toArray(true)] + ["json" => $body->toArray(true)] ); } @@ -79,23 +79,17 @@ public function list(Query $query = null) * * @return DomainRobotPromise */ - public function listAsync(Query $query = null) { - - if ($query === null) { - return new DomainRobotPromise($this->sendRequest( - $this->domainRobotConfig->getUrl() . "/trustedapp/_search", - 'POST', - ["json" => null] - )); - } else { - return new DomainRobotPromise($this->sendRequest( - $this->domainRobotConfig->getUrl() . "/trustedapp/_search", - 'POST', - ["json" => $query->toArray(true)] - )); + $body = null; + if ($query != null) { + $body = $query->toArray(true); } + return new DomainRobotPromise($this->sendRequest( + $this->domainRobotConfig->getUrl() . "/trustedapp/_search", + 'POST', + ["json" => $body] + )); } /** @@ -117,7 +111,7 @@ public function info($id) * Sends a TrustedApplication info request. * * @param [int] $id - * @return GuzzleHttp\Promise\PromiseInterface $promise + * @return DomainRobotPromise */ public function infoAsync($id) { @@ -144,43 +138,43 @@ public function delete($id) * Sends a TrustedApplication delete request. * * @param [int] $id - * @return + * @return DomainRobotPromise */ public function deleteAsync($id) { $this->sendRequest( $this->domainRobotConfig->getUrl() . "/trustedapp/$id", - 'DELETE', + 'DELETE' ); } /** * Sends a TrustedApplication update request. * - * @param [int] $id - * @return + * @param TrustedApplication $body + * @return TrustedApplication */ - public function update($id) + public function update(TrustedApplication $body) { - $domainRobotPromise = $this->updateAsync($id); + $domainRobotPromise = $this->updateAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); - - // return new TrustedApplication(ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0', [])); } /** * Sends a TrustedApplication update request. * - * @param [int] $id - * @return GuzzleHttp\Promise\PromiseInterface $promise + * @param TrustedApplication $body + * @return DomainRobotPromise */ - public function updateAsync($id) + public function updateAsync(TrustedApplication $body) { - + if ($body->getId() === null) { + throw InvalidArgumentException("Field TrustedApplication.id is missing."); + } $this->sendRequest( - $this->domainRobotConfig->getUrl() . "/trustedapp/$id", + $this->domainRobotConfig->getUrl() . "/trustedapp/".$body->getId(), 'PUT', ["json" => $this->trustedApplicationModel->toArray(true)] ); diff --git a/src/service/ZoneService.php b/src/service/ZoneService.php index 3311ad62..d7d70173 100644 --- a/src/service/ZoneService.php +++ b/src/service/ZoneService.php @@ -7,32 +7,31 @@ use IXDomainRobot\Lib\DomainRobotConfig; use IXDomainRobot\Lib\DomainRobotPromise; use IXDomainRobot\Model\Zone; +use IXDomainRobot\Model\ZoneStream; use IXDomainRobot\Model\Query; use IXDomainRobot\Service\DomainRobotService; class ZoneService extends DomainRobotService { - private $zoneModel; /** * - * @param Zone $zoneModel * @param DomainRobotConfig $domainRobotConfig */ - public function __construct(Zone $zoneModel, DomainRobotConfig $domainRobotConfig) + public function __construct(DomainRobotConfig $domainRobotConfig) { parent::__construct($domainRobotConfig); - $this->zoneModel = $zoneModel; } /** * Sends a zone create request. * + * @param Zone $body * @return Zone */ - public function create() + public function create(Zone $body) { - $domainRobotPromise = $this->createAsync(); + $domainRobotPromise = $this->createAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); @@ -43,27 +42,28 @@ public function create() /** * Sends a zone create request. * + * @param Zone $body * @return DomainRobotPromise */ - public function createAsync() + public function createAsync(Zone $body) { return $this->sendRequest( $this->domainRobotConfig->getUrl() . "/zone", 'POST', - ["json" => $this->zoneModel->toArray(true)] + ["json" => $body->toArray(true)] ); } /** * Sends a zone stream request to add and/or remove records for every zone with * the given origin. - * - * @param [string] $name - * @return Zone + * + * @param [string] $origin + * @param ZoneStream $body */ - public function stream($name) + public function stream($origin, ZoneStream $body) { - $domainRobotPromise = $this->streamAsync($name); + $domainRobotPromise = $this->streamAsync($origin, $body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); @@ -74,29 +74,29 @@ public function stream($name) /** * Sends a zone stream request to add and/or remove records for every zone with * the given origin. - * - * @param [string] $name + * + * @param [string] $origin + * @param ZoneStream $body * @return DomainRobotPromise */ - public function streamAsync($name) + public function streamAsync($origin, ZoneStream $body) { return $this->sendRequest( - $this->domainRobotConfig->getUrl() . "/zone/$name/_stream", + $this->domainRobotConfig->getUrl() . "/zone/$origin/_stream", 'POST', - ["json" => $this->zoneModel->toArray(true)] + ["json" => $body->toArray(true)] ); } /** * Imports an existing zone. - * - * @param [string] $name - * @param [string] $systemNameServer + * + * @param Zone $body * @return Zone */ - public function importZone() + public function importZone(Zone $body) { - $domainRobotPromise = $this->importZoneAsync(); + $domainRobotPromise = $this->importZoneAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); @@ -106,31 +106,53 @@ public function importZone() /** * Imports an existing zone. - * - * @param [string] $name - * @param [string] $systemNameServer + * + * @param Zone $body * @return DomainRobotPromise */ - public function importZoneAsync() + public function importZoneAsync(Zone $body) { - $name = $this->zoneModel->getOrigin(); - $systemNameServer = $this->zoneModel->getVirtualNameServer(); + $name = $body->getOrigin(); + $systemNameServer = $body->getVirtualNameServer(); return new DomainRobotPromise($this->sendRequest( $this->domainRobotConfig->getUrl() . "/zone/$name/$systemNameServer/_import", 'POST', - ["json" => $this->zoneModel->toArray(true)] + ["json" => $body->toArray(true)] )); } /** * Sends a zone list request. * + * The following keys can be used for filtering, ordering or fetching additional + * data via query parameter: + * + * * dnssec + * * created + * * mainip + * * secondary1 + * * secondary2 + * * secondary3 + * * secondary4 + * * secondary5 + * * secondary6 + * * secondary7 + * * virtualNameServer + * * domainsafe + * * name + * * comment + * * updated + * * action + * * primary + * * changed + * + * @param Query $body * @return Zone[] */ - public function list(Query $query = null) + public function list(Query $body = null) { - $domainRobotPromise = $this->listAsync($query); + $domainRobotPromise = $this->listAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); @@ -146,28 +168,46 @@ public function list(Query $query = null) /** * Sends a zone list request. * + * The following keys can be used for filtering, ordering or fetching additional + * data via query parameter: + * + * * dnssec + * * created + * * mainip + * * secondary1 + * * secondary2 + * * secondary3 + * * secondary4 + * * secondary5 + * * secondary6 + * * secondary7 + * * virtualNameServer + * * domainsafe + * * name + * * comment + * * updated + * * action + * * primary + * * changed + * + * @param Query $body * @return DomainRobotPromise */ - public function listAsync(Query $query = null) + public function listAsync(Query $body = null) { - - if ($query === null) { - return new DomainRobotPromise($this->sendRequest( - $this->domainRobotConfig->getUrl() . "/zone/_search", - 'POST', - ["json" => null] - )); - } else { - return new DomainRobotPromise($this->sendRequest( - $this->domainRobotConfig->getUrl() . "/zone/_search", - 'POST', - ["json" => $query->toArray(true)] - )); + $data = null; + if ($body != null) { + $data = $body->toArray(true); } + return new DomainRobotPromise($this->sendRequest( + $this->domainRobotConfig->getUrl() . "/zone/_search", + 'POST', + ["json" => $data] + )); } /** - * Sends a Contact info request. + * Sends a zone info request. * * @param [string] $name * @param [string] $systemNameServer @@ -182,7 +222,7 @@ public function info($name, $systemNameServer) } /** - * Sends a Contact info request. + * Sends a zone info request. * * @param [string] $name * @param [string] $systemNameServer @@ -197,11 +237,11 @@ public function infoAsync($name, $systemNameServer) } /** - * Sends a Zone delete request. + * Sends a zone delete request. * * @param [string] $name * @param [string] $systemNameServer - * @return + * @return */ public function delete($name, $systemNameServer) { @@ -210,30 +250,29 @@ public function delete($name, $systemNameServer) } /** - * Sends a Zone delete request. + * Sends a zone delete request. * * @param [string] $name * @param [string] $systemNameServer - * @return + * @return */ public function deleteAsync($name, $systemNameServer) { $this->sendRequest( $this->domainRobotConfig->getUrl() . "/zone/$name/$systemNameServer", - 'DELETE', + 'DELETE' ); } /** * Sends a zone update request. * - * @param [string] $name - * @param [string] $systemNameServer + * @param Zone $body * @return Zone */ - public function update($name, $systemNameServer) + public function update(Zone $body) { - $domainRobotPromise = $this->updateAsync($name, $systemNameServer); + $domainRobotPromise = $this->updateAsync($body); $domainRobotResult = $domainRobotPromise->wait(); DomainRobot::setLastDomainRobotResult($domainRobotResult); @@ -244,16 +283,21 @@ public function update($name, $systemNameServer) /** * Sends a zone update request. * - * @param [string] $name - * @param [string] $systemNameServer + * @param Zone $body * @return GuzzleHttp\Promise\PromiseInterface $promise */ - public function updateAsync($name, $systemNameServer) + public function updateAsync(Zone $body) { + if ($body->getOrigin() === null) { + throw InvalidArgumentException("Field Zone.origin is missing."); + } + if ($body->getVirtualNameServer() === null) { + throw InvalidArgumentException("Field Zone.virtualNameServer is missing."); + } return $this->sendRequest( $this->domainRobotConfig->getUrl() . "/zone/$name/$systemNameServer", 'PUT', - ["json" => $this->zoneModel->toArray(true)] + ["json" => $body->toArray(true)] ); } }