Skip to content

Commit

Permalink
DEV-7942
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Pleintinger <[email protected]>
  • Loading branch information
ChripIX committed Feb 9, 2023
1 parent 25eaa7c commit a58d8db
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "internetx/php-domainrobot-sdk",
"version": "0.9.17",
"version": "0.9.18",
"description": "A php package for easy integration of the domainrobot API powered by InterNetX GmbH.",
"type": "library",
"license": "MIT",
Expand Down
48 changes: 48 additions & 0 deletions src/Service/ZoneService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Domainrobot\Model\Zone;
use Domainrobot\Model\ZoneStream;
use Domainrobot\Model\Query;
use Domainrobot\Model\ZoneBasePatchRequest;
use Domainrobot\Service\DomainrobotService;

class ZoneService extends DomainrobotService
Expand Down Expand Up @@ -164,6 +165,7 @@ public function list(Query $body = null)
$z = new Zone($d);
array_push($zones, $z);
}

return $zones;
}

Expand Down Expand Up @@ -201,6 +203,7 @@ public function listAsync(Query $body = null)
if ($body != null) {
$data = $body->toArray();
}

return new DomainrobotPromise($this->sendRequest(
$this->domainrobotConfig->getUrl() . "/zone/_search",
'POST',
Expand Down Expand Up @@ -301,15 +304,60 @@ public function updateAsync(Zone $body)
} else {
$name = $body->getOrigin();
}

if ($body->getVirtualNameServer() === null) {
throw new \InvalidArgumentException("Field Zone.virtualNameServer is missing.");
} else {
$systemNameServer = $body->getVirtualNameServer();
}

return $this->sendRequest(
$this->domainrobotConfig->getUrl() . "/zone/$name/$systemNameServer",
'PUT',
["json" => $body->toArray()]
);
}

/**
* Sends a zone patch request.
*
* @param ZoneBasePatchRequest $body
* @return Zone
*/
public function patch(ZoneBasePatchRequest $body)
{
$domainrobotPromise = $this->patchAsync($body);
$domainrobotResult = $domainrobotPromise->wait();

Domainrobot::setLastDomainrobotResult($domainrobotResult);

return new Zone(ArrayHelper::getValueFromArray($domainrobotResult->getResult(), 'data.0', []));
}

/**
* Sends a zone update request.
*
* @param ZoneBasePatchRequest $body
* @return DomainrobotPromise
*/
public function patchAsync(ZoneBasePatchRequest $body)
{
if ($body->getOrigin() === null) {
throw new \InvalidArgumentException("Field Zone.origin is missing.");
} else {
$name = $body->getOrigin();
}

if ($body->getVirtualNameServer() === null) {
throw new \InvalidArgumentException("Field Zone.virtualNameServer is missing.");
} else {
$systemNameServer = $body->getVirtualNameServer();
}

return $this->sendRequest(
$this->domainrobotConfig->getUrl() . "/zone/$name/$systemNameServer",
'PATCH',
["json" => $body->toArray()]
);
}
}

0 comments on commit a58d8db

Please sign in to comment.