Skip to content

Commit

Permalink
Merge branch 'enableIncludesForDomain' into 'master'
Browse files Browse the repository at this point in the history
Add includes(nameservers, contacts) to Domain

See merge request transip/restapi-php-library!178
  • Loading branch information
phorick committed Apr 21, 2022
2 parents 45e6c15 + 36dcb82 commit 63371aa
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
CHANGELOG
=========

6.19.0
-----
* Added includes to Domain

6.18.0
-----
* Added colocation access request endpoint
Expand Down
78 changes: 78 additions & 0 deletions src/Entity/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Transip\Api\Library\Entity;

use Transip\Api\Library\Entity\Domain\Nameserver;
use Transip\Api\Library\Entity\Domain\WhoisContact;

class Domain extends AbstractEntity
{
/**
Expand Down Expand Up @@ -64,6 +67,49 @@ class Domain extends AbstractEntity
*/
protected $status = '';

/**
* @var Nameserver[] $nameservers
*/
protected $nameservers = [];

/**
* @var WhoisContact[] $contacts
*/
protected $contacts = [];

public function __construct(array $valueArray = [])
{
foreach ($valueArray as $field => $value) {
if ($field === 'nameservers') {
$this->initNameservers($value);
continue;
}

if ($field === 'contacts') {
$this->initContacts($value);
continue;
}

if (property_exists($this, $field)) {
$this->$field = $value;
}
}
}

private function initNameservers(array $nameservers = [])
{
$this->nameservers = array_map(static function ($nameserver) {
return new Nameserver(($nameserver));
}, $nameservers);
}

private function initContacts(array $contacts = [])
{
$this->contacts = array_map(static function ($contact) {
return new WhoisContact($contact);
}, $contacts);
}

public function getName(): string
{
return $this->name;
Expand Down Expand Up @@ -170,4 +216,36 @@ public function setStatus(string $status): void
{
$this->status = $status;
}

/**
* @return Nameserver[]
*/
public function getNameservers()
{
return $this->nameservers;
}

/**
* @param Nameserver[] $nameservers
*/
public function setNameservers($nameservers): void
{
$this->nameservers = $nameservers;
}

/**
* @return Contact[]
*/
public function getContacts()
{
return $this->contacts;
}

/**
* @param Contact[] $contacts
*/
public function setContacts($contacts): void
{
$this->contacts = $contacts;
}
}
28 changes: 22 additions & 6 deletions src/Repository/DomainRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ class DomainRepository extends ApiRepository
/**
* @return Domain[]
*/
public function getAll(): array
public function getAll(array $includes = []): array
{
$domains = [];
$response = $this->httpClient->get($this->getResourceUrl());
$query = [];
$query = $this->addIncludesToQuery($query, $includes);

$response = $this->httpClient->get($this->getResourceUrl(), $query);
$domainsArray = $this->getParameterFromResponse($response, 'domains');

foreach ($domainsArray as $domainArray) {
Expand All @@ -32,29 +35,42 @@ public function getAll(): array
* @param int $itemsPerPage
* @return Domain[]
*/
public function getSelection(int $page, int $itemsPerPage): array
public function getSelection(int $page, int $itemsPerPage, array $includes = []): array
{
$domains = [];
$query = ['pageSize' => $itemsPerPage, 'page' => $page];
$query = $this->addIncludesToQuery($query, $includes);
$response = $this->httpClient->get($this->getResourceUrl(), $query);
$domainsArray = $this->getParameterFromResponse($response, 'domains');


foreach ($domainsArray as $domainArray) {
$domains[] = new Domain($domainArray);
}

return $domains;
}

public function getByName(string $name): Domain
public function getByName(string $name, array $includes = []): Domain
{
$response = $this->httpClient->get($this->getResourceUrl($name));
$query = $this->addIncludesToQuery([], $includes);
$response = $this->httpClient->get($this->getResourceUrl($name), $query);

$domain = $this->getParameterFromResponse($response, 'domain');

return new Domain($domain);
}

private function addIncludesToQuery(array $query = [], array $includes = [])
{
$includeString = implode(',', $includes);

if ($includeString !== '') {
$query = array_merge($query, ['include' => $includeString]);
}

return $query;
}

public function getByTagNames(array $tags): array
{
$tags = implode(',', $tags);
Expand Down
2 changes: 1 addition & 1 deletion src/TransipAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
class TransipAPI
{
public const TRANSIP_API_ENDPOINT = "https://api.transip.nl/v6";
public const TRANSIP_API_LIBRARY_VERSION = "6.18.0";
public const TRANSIP_API_LIBRARY_VERSION = "6.19.0";
public const TRANSIP_API_DEMO_TOKEN = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImN3MiFSbDU2eDNoUnkjelM4YmdOIn0.eyJpc3MiOiJhcGkudHJhbnNpcC5ubCIsImF1ZCI6ImFwaS50cmFuc2lwLm5sIiwianRpIjoiY3cyIVJsNTZ4M2hSeSN6UzhiZ04iLCJpYXQiOjE1ODIyMDE1NTAsIm5iZiI6MTU4MjIwMTU1MCwiZXhwIjoyMTE4NzQ1NTUwLCJjaWQiOiI2MDQ0OSIsInJvIjpmYWxzZSwiZ2siOmZhbHNlLCJrdiI6dHJ1ZX0.fYBWV4O5WPXxGuWG-vcrFWqmRHBm9yp0PHiYh_oAWxWxCaZX2Rf6WJfc13AxEeZ67-lY0TA2kSaOCp0PggBb_MGj73t4cH8gdwDJzANVxkiPL1Saqiw2NgZ3IHASJnisUWNnZp8HnrhLLe5ficvb1D9WOUOItmFC2ZgfGObNhlL2y-AMNLT4X7oNgrNTGm-mespo0jD_qH9dK5_evSzS3K8o03gu6p19jxfsnIh8TIVRvNdluYC2wo4qDl5EW5BEZ8OSuJ121ncOT1oRpzXB0cVZ9e5_UVAEr9X3f26_Eomg52-PjrgcRJ_jPIUYbrlo06KjjX2h0fzMr21ZE023Gw";

/**
Expand Down

0 comments on commit 63371aa

Please sign in to comment.