Skip to content

Commit 29f46ee

Browse files
committed
0.6.0
1 parent bc96a2c commit 29f46ee

16 files changed

+334
-4
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
## [0.6.0] - 2020-06-23
4+
5+
* added possibility to gain direct access to response and request through callback methods
6+
* added User info and list tasks
7+
* added examples for some basic tasks
8+
** more examples (hopefully for all tasks) will be added in future versions
9+
* fixed some tasks that did not give correct access to the DomainrobotResult
10+
* improved documentation and readme
11+
312
## [0.5.2] - 2020-06-16
413

514
* Fixed printing null or empty values (#8)

README.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ A php package for easy integration of the **Domainrobot API** powered by [InterN
88
2. [Install and Use](#install-and-use)
99
* [Installation](#installation)
1010
* [Basic Use](#basic-use)
11-
3. [Usage](#usage)
11+
3. [Example Implementations](#example-implementations)
12+
4. [Usage](#usage)
13+
* [Logging Requests and Responses](#logging-requests-and-responses)
1214
* [Asynchronous vs Synchronous Requests](#asynchronous-vs-synchronous-requests)
1315
* [Models](#models)
1416
* [Supported API calls](#supported-api-calls)
1517
* [Exception handling](#exception-handling)
1618
* [(Custom) Headers](#custom-headers)
17-
4. [Changelog](#changelog)
18-
5. [Copyright and license](#copyright-and-license)
19+
5. [Changelog](#changelog)
20+
6. [Copyright and license](#copyright-and-license)
1921

2022
## Preamble
2123

@@ -37,6 +39,11 @@ composer require internetx/php-domainrobot-sdk
3739
use Domainrobot\Domainrobot;
3840
```
3941

42+
## Example Implementations
43+
44+
You can find some example implemnation in the *example* Folder in the source code.
45+
We will add examples for all or at least most tasks in the next versions of this SDK.
46+
4047
## Usage
4148

4249
Before you can interact with the API you need to specify your authentication credentials, the baseurl and the context.
@@ -46,6 +53,7 @@ Before you can interact with the API you need to specify your authentication cre
4653

4754
```php
4855
use Domainrobot\Domainrobot;
56+
use Domainrobot\Lib\DomainrobotAuth;
4957

5058
$domainrobot = new Domainrobot([
5159
"url" => "https://api.autodns.com/v1",
@@ -57,6 +65,22 @@ $domainrobot = new Domainrobot([
5765
]);
5866
```
5967

68+
### Logging Requests and Responses
69+
70+
There may be certain circumstances where you may want to log your requests and responses.
71+
For this cases we provide you with two integrated callback methods you can use for this purpose.
72+
Find an example on how to use them below.
73+
74+
```php
75+
$domainrobot->domain->logRequest(function($method, $url, $options) use ($user){
76+
// execute your code here
77+
print_r($method);
78+
})->logResponse(function($url, $response, $statusCode, $exectime) use ($user){
79+
// execute your code here
80+
print_r($user);
81+
})->info("example.com");
82+
```
83+
6084
### Asynchronous vs Synchronous Requests
6185

6286
This library is mainly meant to be used with synchronous request but also provides the possibility to be used with asynchronous requests.
@@ -265,6 +289,13 @@ function answer($domain, $answer);
265289
function list(Query $body = null);
266290
```
267291

292+
#### User tasks
293+
294+
```php
295+
function info($user, $context);
296+
function list(Query $body = null);
297+
```
298+
268299
### Exception handling
269300

270301
If there is any error response from the API, the services will throw a DomainrobotException, which contains information about the error.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "internetx/php-domainrobot-sdk",
3-
"version": "0.5.2",
3+
"version": "0.6.0",
44
"description": "A php package for easy integration of the domainrobot API powered by InterNetX GmbH.",
55
"type": "library",
66
"license": "MIT",

example/DomainUpdateForSubuser.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Example;
4+
5+
use Domainrobot\Domainrobot;
6+
use Domainrobot\Lib\DomainrobotAuth;
7+
use Domainrobot\Lib\DomainrobotException;
8+
use Domainrobot\Lib\DomainrobotHeaders;
9+
use Domainrobot\Model\Contact;
10+
11+
/**
12+
* This example is focused on a domain update the general principle holds true
13+
* for ALL tasks you want to execute for a subuser of your auth user
14+
*/
15+
class SDKController
16+
{
17+
/**
18+
* Inquire and update a domain for a subuser
19+
* returns an ObjectJob since the task itself is asynchronous
20+
*
21+
* @return ObjectJob
22+
*/
23+
public function updateDomain()
24+
{
25+
$domainrobot = new Domainrobot([
26+
"url" => "https://api.autodns.com/v1",
27+
"auth" => new DomainrobotAuth([
28+
"user" => "username",
29+
"password" => "password",
30+
"context" => 4
31+
])
32+
]);
33+
34+
try {
35+
$domain = $domainrobot->domain->info("example.com");
36+
37+
// update the domain model with the new data
38+
// for example set a new admin contact
39+
$domain->setAdminc(new Contact(["id" => 21365838]));
40+
41+
// to update the domain for the subuser set the following headers
42+
$job = $domainrobot->domain->addHeaders([
43+
DomainrobotHeaders::DOMAINROBOT_HEADER_OWNER => "ownername",
44+
DomainrobotHeaders::DOMAINROBOT_HEADER_OWNER_CONTEXT => 797095 //owner context
45+
46+
])->update($domain);
47+
48+
} catch (DomainrobotException $exception) {
49+
return$exception;
50+
}
51+
52+
return $job;
53+
}
54+
}

example/UserInfo.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Example;
4+
5+
use Domainrobot\Domainrobot;
6+
use Domainrobot\Lib\DomainrobotAuth;
7+
use Domainrobot\Lib\DomainrobotException;
8+
use Domainrobot\Model\User;
9+
10+
class SDKController
11+
{
12+
/**
13+
* Inquire user by context and return found user as model
14+
*
15+
* @return User
16+
*/
17+
public function userInfo()
18+
{
19+
$domainrobot = new Domainrobot([
20+
"url" => "https://api.autodns.com/v1",
21+
"auth" => new DomainrobotAuth([
22+
"user" => "username",
23+
"password" => "password",
24+
"context" => 4
25+
])
26+
]);
27+
28+
try {
29+
// pass username and context to info command
30+
// returns Domainrobot\Model\User
31+
$user = $domainrobot->user->info("username", 4);
32+
} catch (DomainrobotException $exception) {
33+
return $exception;
34+
}
35+
36+
return $user;
37+
}
38+
}

example/UserList.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Example;
4+
5+
use Domainrobot\Domainrobot;
6+
use Domainrobot\Lib\DomainrobotAuth;
7+
use Domainrobot\Lib\DomainrobotException;
8+
use Domainrobot\Model\Query;
9+
use Domainrobot\Model\QueryFilter;
10+
use Domainrobot\Model\QueryView;
11+
use Domainrobot\Model\User;
12+
13+
class SDKController
14+
{
15+
/**
16+
* Inquire a list of users
17+
* returns an array of Domainrobot\Model\User
18+
*
19+
* @return [ User ]
20+
*/
21+
public function userList()
22+
{
23+
$domainrobot = new Domainrobot([
24+
"url" => "https://api.autodns.com/v1",
25+
"auth" => new DomainrobotAuth([
26+
"user" => "username",
27+
"password" => "password",
28+
"context" => 4
29+
])
30+
]);
31+
32+
try {
33+
$query = new Query([
34+
'filters' => [ new QueryFilter([
35+
'key' => 'user',
36+
'value' => 'username',
37+
'operator' => 'EQUAL'
38+
])],
39+
'view' => new QueryView([
40+
'children' => 1,
41+
'limit' => 10
42+
])
43+
]);
44+
$userList = $domainrobot->user->list($query);
45+
46+
} catch (DomainrobotException $exception) {
47+
return $exception;
48+
}
49+
50+
return $userList;
51+
}
52+
}

src/Domainrobot.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Domainrobot\Service\TrustedApplicationService;
1414
use Domainrobot\Service\ZoneService;
1515
use Domainrobot\Service\PollMessageService;
16+
use Domainrobot\Service\UserService;
1617

1718
class Domainrobot
1819
{
@@ -98,6 +99,13 @@ class Domainrobot
9899
*/
99100
public $zone;
100101

102+
/**
103+
* Interface for all zone related requests
104+
*
105+
* @var UserService
106+
*/
107+
public $user;
108+
101109
/**
102110
* [
103111
* "url" => string, //optional
@@ -119,6 +127,7 @@ public function __construct($domainrobotConfig = [])
119127
$this->transferOut = new TransferOutService($this->domainrobotConfig);
120128
$this->trustedApp = new TrustedApplicationService($this->domainrobotConfig);
121129
$this->zone = new ZoneService($this->domainrobotConfig);
130+
$this->user = new UserService($this->domainrobotConfig);
122131
}
123132

124133
public function setDomainrobotConfig(DomainrobotConfig $domainrobotConfig)

src/Service/CertificateService.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public function info($id)
234234
$domainrobotPromise = $this->infoAsync($id);
235235
$domainrobotResult = $domainrobotPromise->wait();
236236

237+
Domainrobot::setLastDomainrobotResult($domainrobotResult);
237238

238239
return new Certificate(ArrayHelper::getValueFromArray($domainrobotResult->getResult(), 'data.0', []));
239240
}
@@ -264,6 +265,8 @@ public function delete($id)
264265
$domainrobotPromise = $this->deleteAsync($id);
265266
$domainrobotResult = $domainrobotPromise->wait();
266267

268+
Domainrobot::setLastDomainrobotResult($domainrobotResult);
269+
267270
return new ObjectJob([
268271
"job" => ArrayHelper::getValueFromArray($domainrobotResult->getResult(), 'data.0.id', '')
269272
]);

src/Service/ContactService.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,15 @@ public function list(Query $body = null)
9090
$domainrobotResult = $domainrobotPromise->wait();
9191

9292
Domainrobot::setLastDomainrobotResult($domainrobotResult);
93+
9394
$data = $domainrobotResult->getResult()['data'];
9495
$contacts = array();
96+
9597
foreach ($data as $d) {
9698
$c = new Contact($d);
9799
array_push($contacts, $c);
98100
}
101+
99102
return $contacts;
100103
}
101104

@@ -136,6 +139,7 @@ public function listAsync(Query $body = null)
136139
if ($body != null) {
137140
$data = $body->toArray();
138141
}
142+
139143
return new DomainrobotPromise($this->sendRequest(
140144
$this->domainrobotConfig->getUrl() . "/contact/_search",
141145
'POST',
@@ -154,6 +158,7 @@ public function info($id)
154158
$domainrobotPromise = $this->infoAsync($id);
155159
$domainrobotResult = $domainrobotPromise->wait();
156160

161+
Domainrobot::setLastDomainrobotResult($domainrobotResult);
157162

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

src/Service/DomainCancelationService.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public function info($domain)
131131
$domainrobotPromise = $this->infoAsync($domain);
132132
$domainrobotResult = $domainrobotPromise->wait();
133133

134+
Domainrobot::setLastDomainrobotResult($domainrobotResult);
134135

135136
return new DomainCancelation(ArrayHelper::getValueFromArray($domainrobotResult->getResult(), 'data.0', []));
136137
}
@@ -176,8 +177,10 @@ public function list(Query $body = null)
176177
$domainrobotResult = $domainrobotPromise->wait();
177178

178179
Domainrobot::setLastDomainrobotResult($domainrobotResult);
180+
179181
$data = $domainrobotResult->getResult()['data'];
180182
$domainCancelations = array();
183+
181184
foreach ($data as $d) {
182185
$dc = new DomainCancelation($d);
183186
array_push($domainCancelations, $dc);
@@ -213,6 +216,7 @@ public function listAsync(Query $body = null)
213216
if ($body != null) {
214217
$data = $body->toArray();
215218
}
219+
216220
return new DomainrobotPromise($this->sendRequest(
217221
$this->domainrobotConfig->getUrl() . "/domain/cancelation/_search",
218222
'POST',

0 commit comments

Comments
 (0)