1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the DigitalOceanV2 library. |
5
|
|
|
* |
6
|
|
|
* (c) Antoine Corcy <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace DigitalOceanV2\Api; |
13
|
|
|
|
14
|
|
|
use DigitalOceanV2\Entity\Domain as DomainEntity; |
15
|
|
|
use DigitalOceanV2\Exception\HttpException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Yassir Hannoun <[email protected]> |
19
|
|
|
* @author Graham Campbell <[email protected]> |
20
|
|
|
*/ |
21
|
|
|
class Domain extends AbstractApi |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @param int $per_page |
25
|
|
|
* @param int $page |
26
|
|
|
* |
27
|
|
|
* @return DomainEntity[] |
28
|
|
|
*/ |
29
|
|
|
public function getAll($per_page = 200, $page = 1) |
30
|
|
|
{ |
31
|
|
|
$domains = $this->adapter->get(sprintf('%s/domains?per_page=%d&page=%d', $this->endpoint, $per_page, $page)); |
32
|
|
|
|
33
|
|
|
$domains = json_decode($domains); |
34
|
|
|
|
35
|
|
|
$this->extractMeta($domains); |
36
|
|
|
|
37
|
|
|
return array_map(function ($domain) { |
38
|
|
|
return new DomainEntity($domain); |
39
|
|
|
}, $domains->domains); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param string $domainName |
44
|
|
|
* |
45
|
|
|
* @throws HttpException |
46
|
|
|
* |
47
|
|
|
* @return DomainEntity |
48
|
|
|
*/ |
49
|
|
|
public function getByName($domainName) |
50
|
|
|
{ |
51
|
|
|
$domain = $this->adapter->get(sprintf('%s/domains/%s', $this->endpoint, $domainName)); |
52
|
|
|
|
53
|
|
|
$domain = json_decode($domain); |
54
|
|
|
|
55
|
|
|
return new DomainEntity($domain->domain); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param string $name |
60
|
|
|
* @param string $ipAddress |
61
|
|
|
* |
62
|
|
|
* @throws HttpException |
63
|
|
|
* |
64
|
|
|
* @return DomainEntity |
65
|
|
|
*/ |
66
|
|
|
public function create($name, $ipAddress) |
67
|
|
|
{ |
68
|
|
|
$content = ['name' => $name, 'ip_address' => $ipAddress]; |
69
|
|
|
|
70
|
|
|
$domain = $this->adapter->post(sprintf('%s/domains', $this->endpoint), $content); |
71
|
|
|
|
72
|
|
|
$domain = json_decode($domain); |
73
|
|
|
|
74
|
|
|
return new DomainEntity($domain->domain); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @param string $domain |
79
|
|
|
* |
80
|
|
|
* @throws HttpException |
81
|
|
|
*/ |
82
|
|
|
public function delete($domain) |
83
|
|
|
{ |
84
|
|
|
$this->adapter->delete(sprintf('%s/domains/%s', $this->endpoint, $domain)); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|