Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 11 |
CRAP | |
0.00% |
0 / 31 |
Domain | |
0.00% |
0 / 1 |
|
0.00% |
0 / 11 |
182 | |
0.00% |
0 / 31 |
__construct | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
zone | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
getAll | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
|||
records | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 6 |
|||
record | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
add | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
update | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
delete | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 4 |
|||
apply | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 2 |
|||
checkZone | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 3 |
|||
zoneNameUrl | |
0.00% |
0 / 1 |
2 | |
0.00% |
0 / 1 |
1 | <?php |
2 | |
3 | namespace Qmp\Laravel\Ovh\Ovh\Actions; |
4 | |
5 | use Qmp\Laravel\Ovh\Ovh\Client; |
6 | |
7 | class Domain |
8 | { |
9 | const ZONE_LIST_URL = '/domain/zone'; |
10 | |
11 | protected $client; |
12 | |
13 | private $zoneName; |
14 | |
15 | public function __construct(Client $client) |
16 | { |
17 | $this->client = $client; |
18 | } |
19 | |
20 | public function zone($zone) |
21 | { |
22 | $this->zoneName = $zone; |
23 | } |
24 | |
25 | public function getAll() |
26 | { |
27 | return $this->client->get(self::ZONE_LIST_URL); |
28 | } |
29 | |
30 | public function records(array $options) |
31 | { |
32 | $this->checkZone(); |
33 | |
34 | $listIds = $this->client->get($this->zoneNameUrl() . '/record', $options); |
35 | |
36 | $records = []; |
37 | foreach ($listIds as $id) { |
38 | $records[$id] = $this->client->get($this->zoneNameUrl() . '/record/' . $id); |
39 | } |
40 | |
41 | return $records; |
42 | } |
43 | |
44 | public function record($id) |
45 | { |
46 | $this->checkZone(); |
47 | return $this->client->get($this->zoneNameUrl() . '/record/' . $id); |
48 | } |
49 | |
50 | public function add(array $record) |
51 | { |
52 | $this->checkZone(); |
53 | $this->client->post($this->zoneNameUrl() . '/record', $record); |
54 | $this->apply(); |
55 | } |
56 | |
57 | public function update($id, $record) |
58 | { |
59 | $this->checkZone(); |
60 | $this->client->put($this->zoneNameUrl() . '/record/' . $id, $record); |
61 | $this->apply(); |
62 | } |
63 | |
64 | public function delete($id) |
65 | { |
66 | $this->checkZone(); |
67 | $this->client->delete($this->zoneNameUrl() . '/record/' . $id); |
68 | $this->apply(); |
69 | } |
70 | |
71 | private function apply() |
72 | { |
73 | $this->client->post($this->zoneNameUrl() . '/refresh'); |
74 | } |
75 | |
76 | private function checkZone() |
77 | { |
78 | if (!$this->zoneName) { |
79 | throw new \Exception('Zone must be setted.'); |
80 | } |
81 | } |
82 | |
83 | private function zoneNameUrl() |
84 | { |
85 | return self::ZONE_LIST_URL . '/' . $this->zoneName; |
86 | } |
87 | |
88 | } |