Skip to content

Commit 3f7ba6a

Browse files
committed
2 parents 90dfb9a + 91d08fb commit 3f7ba6a

23 files changed

+499
-407
lines changed

src/Account/InvoiceQueryClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class InvoiceQueryClient extends BaseClient
2020
*/
2121
public function getById($id)
2222
{
23-
$response = $this->request("GET", "v1/invoices/query/$id");
23+
$response = $this->request("GET", "v1/invoice-queries/$id");
2424
$body = $this->decodeJson($response->getBody()->getContents());
2525
return new InvoiceQuery($body->data);
2626
}

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct(HttpClient $client = null)
5555
* Sets the API key to be used by the client
5656
*
5757
* @param string $token
58-
* @return Client
58+
* @return $this
5959
*/
6060
public function auth($token)
6161
{

src/DDoSX/Client.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace UKFast\SDK\DDoSX;
4+
5+
use UKFast\SDK\Client as BaseClient;
6+
7+
class Client extends BaseClient
8+
{
9+
/**
10+
* Return a domainClient instance
11+
*
12+
* @return DomainClient
13+
*/
14+
public function domains()
15+
{
16+
return (new DomainClient($this->httpClient))->auth($this->token);
17+
}
18+
}

src/DDoSX/DomainClient.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
namespace UKFast\SDK\DDoSX;
4+
5+
use UKFast\SDK\Client;
6+
7+
class DomainClient extends Client
8+
{
9+
/**
10+
* @inheritDoc
11+
*/
12+
protected $basePath = 'ddosx/';
13+
14+
/**
15+
* Gets a paginated response of all DDoSX domains
16+
*
17+
* @param int $page
18+
* @param int $perPage
19+
* @param array $filters
20+
* @return \UKFast\SDK\Page
21+
* @throws \GuzzleHttp\Exception\GuzzleException
22+
* @throws \UKFast\SDK\Exception\InvalidJsonException
23+
*/
24+
public function getPage($page = 1, $perPage = 20, $filters = [])
25+
{
26+
$page = $this->paginatedRequest('v1/domains', $page, $perPage, $filters);
27+
$page->serializeWith(function ($item) {
28+
return $this->serializeDomain($item);
29+
});
30+
31+
return $page;
32+
}
33+
34+
/**
35+
* Gets an individual domain
36+
*
37+
* @param string $domainName
38+
* @return \UKFast\SDK\DDoSX\Entities\Domain
39+
* @throws \GuzzleHttp\Exception\GuzzleException
40+
* @throws \UKFast\SDK\Exception\InvalidJsonException
41+
*/
42+
public function getByName($domainName)
43+
{
44+
$response = $this->request("GET", 'v1/domains/' . $domainName);
45+
$body = $this->decodeJson($response->getBody()->getContents());
46+
47+
return $this->serializeDomain($body->data);
48+
}
49+
50+
/**
51+
* Converts a response stdClass into a Domain object
52+
*
53+
* @param \stdClass
54+
* @return Entities\Domain
55+
*/
56+
public function serializeDomain($item)
57+
{
58+
$domain = new Entities\Domain([
59+
'safednsZoneId' => $item->safedns_zone_id,
60+
'name' => $item->name,
61+
'status' => $item->status,
62+
'dnsActive' => $item->dns_active,
63+
'cdnActive' => $item->cdn_active,
64+
'wafActive' => $item->waf_active,
65+
]);
66+
67+
if (empty($item->external_dns) === false) {
68+
$domain->externalDns = new Entities\ExternalDns([
69+
'verified' => $item->external_dns->verified,
70+
'verificationString' => $item->external_dns->verification_string,
71+
'dnsAliasTarget' => $item->external_dns->dns_alias_target,
72+
]);
73+
}
74+
75+
return $domain;
76+
}
77+
}

src/DDoSX/Entities/Domain.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace UKFast\SDK\DDoSX\Entities;
4+
5+
use UKFast\SDK\Entity;
6+
7+
/**
8+
* @property int $safednsZoneId
9+
* @property string $name
10+
* @property string $status
11+
* @property bool $dnsActive
12+
* @property bool $cdnActive
13+
* @property bool $wafActive
14+
* @property externalDns|null $externalDns
15+
*/
16+
class Domain extends Entity
17+
{
18+
//
19+
}

src/DDoSX/Entities/ExternalDns.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace UKFast\SDK\DDoSX\Entities;
4+
5+
use UKFast\SDK\Entity;
6+
7+
/**
8+
* @property bool verified
9+
* @property string verificationString
10+
* @property string dnsAliasTarget
11+
*/
12+
class ExternalDns extends Entity
13+
{
14+
//
15+
}

src/Entities/Entity.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/Entity.php

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
<?php
2+
3+
namespace UKFast\SDK;
4+
5+
abstract class Entity
6+
{
7+
/**
8+
* @var array
9+
*/
10+
protected $attributes = [];
11+
12+
/**
13+
* @param array $attributes
14+
*/
15+
public function __construct($attributes = [])
16+
{
17+
if (is_object($attributes)) {
18+
$attributes = (array) $attributes;
19+
}
20+
21+
$this->attributes = $attributes;
22+
}
23+
24+
/**
25+
* Gets an attribute, if the attribute hasn't been
26+
* set yet, return $default
27+
*
28+
* @param string $attr
29+
* @param mixed $default
30+
* @return mixed
31+
*/
32+
public function get($attr, $default = null)
33+
{
34+
if ($this->has($attr)) {
35+
return $this->attributes[$attr];
36+
}
37+
38+
return $default;
39+
}
40+
41+
42+
/**
43+
* Sets an attribute
44+
*
45+
* @param string $attr
46+
* @param mixed $value
47+
* @return void
48+
*/
49+
public function set($attr, $value)
50+
{
51+
$this->attributes[$attr] = $value;
52+
}
53+
54+
/**
55+
* @return array
56+
*/
57+
public function all()
58+
{
59+
return $this->attributes;
60+
}
61+
62+
/**
63+
* Hydrates an entity
64+
*
65+
* @param array $attributes
66+
* @return void
67+
*/
68+
public function fill($attributes)
69+
{
70+
foreach ($attributes as $name => $value) {
71+
$this->attributes[$name] = $value;
72+
}
73+
}
74+
75+
/**
76+
* Returns true if the attribute is present on the
77+
* entity
78+
* @param string $attribute
79+
* @return bool
80+
*/
81+
public function has($attribute)
82+
{
83+
return isset($this->attributes[$attribute]);
84+
}
85+
86+
/**
87+
* Returns an array representation of the the entity.
88+
* Can pass a map of property names to array names
89+
* e.g. ['createdAt' => 'created_at']
90+
*
91+
* @param array $map
92+
* @return array
93+
*/
94+
public function toArray($map = [])
95+
{
96+
$arr = $this->all();
97+
98+
foreach ($arr as $name => $value) {
99+
if ($value instanceof Entity) {
100+
$arr[$name] = $arr[$name]->toArray();
101+
}
102+
}
103+
104+
foreach ($map as $entityName => $apiName) {
105+
if (isset($arr[$entityName])) {
106+
$arr[$apiName] = $arr[$entityName];
107+
unset($arr[$entityName]);
108+
}
109+
}
110+
111+
return $arr;
112+
}
113+
114+
/**
115+
* Magic getter method. Proxies property access to
116+
* internal array of attributes
117+
*
118+
* @param string $attr
119+
* @return mixed
120+
*/
121+
public function __get($attr)
122+
{
123+
return $this->get($attr);
124+
}
125+
126+
/**
127+
* Magic setter method. Proxies property access to
128+
* internal array of attributes
129+
*
130+
* @param string $attr
131+
* @param mixed $value
132+
* @return void
133+
*/
134+
public function __set($attr, $value)
135+
{
136+
$this->set($attr, $value);
137+
}
138+
139+
/**
140+
* Allows an entity to work with isset() or empty()
141+
* Checks that the attribute has been set and that
142+
* the value is not null
143+
*
144+
* @return bool
145+
*/
146+
public function __isset($key)
147+
{
148+
return !is_null($this->get($key));
149+
}
150+
}

src/PSS/Entities/Request.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ class Request
8989
*/
9090
public $unreadReplies;
9191

92+
/**
93+
* @var string
94+
*/
95+
public $contactMethod;
96+
9297
public function isCompleted()
9398
{
9499
return in_array($this->status, ['Completed', 'Replied and Completed']);

src/PSS/RequestClient.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ protected function serializeRequest($item)
155155
$request->lastRepliedAt = null;
156156
$request->systemReference = $item->system_reference;
157157
$request->unreadReplies = $item->unread_replies;
158+
$request->contactMethod = $item->contact_method;
158159
if ($item->last_replied_at) {
159160
$request->lastRepliedAt = DateTime::createFromFormat(DateTime::ISO8601, $item->last_replied_at);
160161
}
@@ -210,6 +211,10 @@ protected function requestToJson($request)
210211
$payload['cc'] = $request->cc;
211212
}
212213

214+
if (!empty($request->contactMethod)) {
215+
$payload['contact_method'] = $request->contactMethod;
216+
}
217+
213218
if ($request->customerReference) {
214219
$payload['customer_reference'] = $request->customerReference;
215220
}

0 commit comments

Comments
 (0)