Skip to content

Commit

Permalink
Merge pull request #2 from Fnici/master
Browse files Browse the repository at this point in the history
Add missing routes
  • Loading branch information
InterNetX authored Mar 2, 2020
2 parents 7d0b0bb + b00ed1b commit 8f70984
Show file tree
Hide file tree
Showing 10 changed files with 1,853 additions and 173 deletions.
67 changes: 43 additions & 24 deletions src/service/CertificateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ public function createAsync()
{
$this->prepareCsr();

return $this->sendPostRequest(
return $this->sendRequest(
$this->domainRobotConfig->getUrl() . "/certificate",
$this->certificateModel->toArray(true)
'POST',
["json" => $this->certificateModel->toArray(true)]
);
}

Expand Down Expand Up @@ -95,9 +96,10 @@ public function realtimeAsync()
{
$this->prepareCsr();

return $this->sendPostRequest(
return $this->sendRequest(
$this->domainRobotConfig->getUrl() . "/certificate/_realtime",
$this->certificateModel->toArray(true)
'POST',
["json" => $this->certificateModel->toArray(true)]
);
}
/**
Expand Down Expand Up @@ -139,9 +141,10 @@ public function prepareOrderAsync()
$certDataModel = new CertificateData();
$certDataModel->setPlain($this->certificateModel->getCsr());

return new DomainRobotPromise($this->sendPostRequest(
return new DomainRobotPromise($this->sendRequest(
$this->domainRobotConfig->getUrl() . "/certificate/_prepareOrder",
$certDataModel->toArray(true)
'POST',
["json" => $certDataModel->toArray(true)]
));
}

Expand Down Expand Up @@ -175,14 +178,16 @@ public function listAsync(Query $query = null)
{

if ($query === null) {
return new DomainRobotPromise($this->sendPostRequest(
return new DomainRobotPromise($this->sendRequest(
$this->domainRobotConfig->getUrl() . "/certificate/_search",
null
'POST',
["json" => null]
));
} else {
return new DomainRobotPromise($this->sendPostRequest(
return new DomainRobotPromise($this->sendRequest(
$this->domainRobotConfig->getUrl() . "/certificate/_search",
$query->toArray(true)
'POST',
["json" => $query->toArray(true)]
));
}
}
Expand Down Expand Up @@ -210,8 +215,9 @@ public function info($id)
*/
public function infoAsync($id)
{
return $this->sendGetRequest(
$this->domainRobotConfig->getUrl() . "/certificate/$id"
return $this->sendRequest(
$this->domainRobotConfig->getUrl() . "/certificate/$id",
'GET'
);
}

Expand All @@ -220,14 +226,18 @@ public function infoAsync($id)
* for polling.
*
* @param [int] $id
* @return Certificate
* @return ObjectJob
*/
public function delete($id)
{
$domainRobotPromise = $this->deleteAsync($id);
$domainRobotResult = $domainRobotPromise->wait();

return new Certificate(ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0', []));
return new ObjectJob([
"job" => ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0.id', ''),
"object" => $this->certificateModel->getName()
]);
// return new Certificate(ArrayHelper::getValueFromArray($domainRobotResult->getResult(), 'data.0', []));
}


Expand All @@ -240,9 +250,9 @@ public function delete($id)
*/
public function deleteAsync($id)
{
return $this->sendDeleteRequest(
return $this->sendRequest(
$this->domainRobotConfig->getUrl() . "/certificate/$id",
// $this->certificateModel->toArray(true)
'DELETE',
);
}

Expand Down Expand Up @@ -278,9 +288,12 @@ public function reissue($id)
*/
public function reissueAsync($id)
{
return $this->sendPutRequest(
$this->prepareCsr();

return $this->sendRequest(
$this->domainRobotConfig->getUrl() . "/certificate/$id",
$this->certificateModel->toArray(true)
'PUT',
["json" => $this->certificateModel->toArray(true)]
);
}

Expand Down Expand Up @@ -316,17 +329,20 @@ public function renew($id)
*/
public function renewAsync($id)
{
return $this->sendPutRequest(
$this->prepareCsr();

return $this->sendRequest(
$this->domainRobotConfig->getUrl() . "/certificate/$id/_renew",
$this->certificateModel->toArray(true)
'PUT',
["json" => $this->certificateModel->toArray(true)]
);
}

/**
* Updates the comment for an existing certificate.
*
* @param [int] $id, [string] comment
* @return void
* @return
*/
public function commentUpdate($id, $comment)
{
Expand All @@ -340,14 +356,17 @@ public function commentUpdate($id, $comment)
* Updates the comment for an existing certificate.
*
* @param [int] $id
* @return void
* @return
*/
public function commentUpdateAsync($id, $comment)
{
$this->prepareCsr();

$cert = new Certificate(['comment' => $comment]);
$this->sendPutRequest(
$this->sendRequest(
$this->domainRobotConfig->getUrl() . "/certificate/$id/_renew",
$cert->toArray(true)
'PUT',
["json" => $cert->toArray(true)]
);
}

Expand Down
188 changes: 188 additions & 0 deletions src/service/ContactService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
<?php

namespace IXDomainRobot\Service;

use IXDomainRobot\DomainRobot;
use IXDomainRobot\Lib\ArrayHelper;
use IXDomainRobot\Lib\DomainRobotConfig;
use IXDomainRobot\Lib\DomainRobotPromise;
use IXDomainRobot\Model\Query;
use IXDomainRobot\Model\Contact;
use IXDomainRobot\Service\DomainRobotService;

class ContactService extends DomainRobotService
{
private $contactModel;

/**
*
* @param Contact $contactModel
* @param DomainRobotConfig $domainRobotConfig
*/
public function __construct(Contact $contactModel, DomainRobotConfig $domainRobotConfig)
{
parent::__construct($domainRobotConfig);
$this->contactModel = $contactModel;
}

/**
* Sends a contact create request.
*
* @return Contact
*/
public function create()
{
$domainRobotPromise = $this->createAsync();
$domainRobotResult = $domainRobotPromise->wait();

DomainRobot::setLastDomainRobotResult($domainRobotResult);

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

/**
* Sends a contact create request.
*
* @return DomainRobotPromise
*/
public function createAsync()
{
return $this->sendRequest(
$this->domainRobotConfig->getUrl() . "/contact",
'POST',
["json" => $this->contactModel->toArray(true)]
);
}

/**
* Sends a contact list request.
*
* @return Contact[]
*/
public function list(Query $query = null)
{
$domainRobotPromise = $this->listAsync($query);
$domainRobotResult = $domainRobotPromise->wait();

DomainRobot::setLastDomainRobotResult($domainRobotResult);
$data = $domainRobotResult->getResult()['data'];
$contacts = array();
foreach ($data as $d) {
$c = new Contact($d);
array_push($contacts, $c);
}
return $contacts;
}

/**
* Sends a contact list request.
*
* @return DomainRobotPromise
*/

public function listAsync(Query $query = 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)]
));
}
}

/**
* Sends a contact info request.
*
* @param [int] $id
* @return Contact
*/
public function info($id)
{
$domainRobotPromise = $this->infoAsync($id);
$domainRobotResult = $domainRobotPromise->wait();


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

/**
* Sends a contact info request.
*
* @param [int] $id
* @return GuzzleHttp\Promise\PromiseInterface $promise
*/
public function infoAsync($id)
{
return $this->sendRequest(
$this->domainRobotConfig->getUrl() . "/contact/$id",
'GET'
);
}

/**
* Sends a contact delete request.
*
* @param [int] $id
* @return
*/
public function delete($id)
{
$domainRobotPromise = $this->deleteAsync($id);
$domainRobotPromise->wait();
}


/**
* Sends a contact delete request.
*
* @param [int] $id
* @return
*/
public function deleteAsync($id)
{
$this->sendRequest(
$this->domainRobotConfig->getUrl() . "/contact/$id",
'DELETE',
);
}

/**
* Sends a contact update request.
*
* @param [int] $id
* @return Contact
*/
public function update($id)
{
$domainRobotPromise = $this->updateAsync($id);
$domainRobotResult = $domainRobotPromise->wait();

DomainRobot::setLastDomainRobotResult($domainRobotResult);

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

/**
* Sends a contact update request.
*
* @param [int] $id
* @return GuzzleHttp\Promise\PromiseInterface $promise
*/
public function updateAsync($id)
{

return $this->sendRequest(
$this->domainRobotConfig->getUrl() . "/contact/$id",
'PUT',
["json" => $this->contactModel->toArray(true)]
);
}
}
Loading

0 comments on commit 8f70984

Please sign in to comment.