| 1 | package WWW::Hetzner::Cloud::API::Zones; | ||||||||||||
| 2 | # ABSTRACT: Hetzner Cloud DNS Zones API | ||||||||||||
| 3 | |||||||||||||
| 4 | 60 | our $VERSION = '0.102'; | |||||||||||
| 5 | |||||||||||||
| 6 | 60 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 60 | with 'WWW::Hetzner::Role::Pagination'; | |||||||||||
| 8 | 60 | ▶ | use Carp qw(croak); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 60 | ▶ | use WWW::Hetzner::Cloud::API::RRSets; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 60 | ▶ | use WWW::Hetzner::Cloud::Zone; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 60 | ▶ | use namespace::clean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | |||||||||||||
| 14 | 60 | has client => ( | |||||||||||
| 15 | is => 'ro', | ||||||||||||
| 16 | required => 1, | ||||||||||||
| 17 | weak_ref => 1, | ||||||||||||
| 18 | ); | ||||||||||||
| 19 | |||||||||||||
| 20 | 60 | with 'WWW::Hetzner::Role::HasActions'; | |||||||||||
| 21 | |||||||||||||
| 22 | 13 | ▶ | sub _wrap { | ||||||||||
|
Subroutine
_wrap: called CC=1 SCAR=0.0
| |||||||||||||
| 23 | 13 | my ($self, $data, %extra) = @_; | |||||||||||
| 24 | 13 | return WWW::Hetzner::Cloud::Zone->new( | |||||||||||
| 25 | client => $self->client, | ||||||||||||
| 26 | %$data, | ||||||||||||
| 27 | %extra, | ||||||||||||
| 28 | ); | ||||||||||||
| 29 | } | ||||||||||||
| 30 | |||||||||||||
| 31 | 5 | ▶ | sub _wrap_list { | ||||||||||
|
Subroutine
_wrap_list: called CC=1 SCAR=0.0
| |||||||||||||
| 32 | 5 | my ($self, $list) = @_; | |||||||||||
| 33 | 5 | return [ map { $self->_wrap($_) } @$list ]; | |||||||||||
| 34 | } | ||||||||||||
| 35 | |||||||||||||
| 36 | |||||||||||||
| 37 | 5 | ▶ | sub _list_page { | ||||||||||
|
Subroutine
_list_page: called CC=2 SCAR=7.1
| |||||||||||||
| 38 | 5 | my ($self, %params) = @_; | |||||||||||
| 39 | |||||||||||||
| 40 | 5 | my $result = $self->client->get('/zones', params => \%params); | |||||||||||
| 41 | 5 | ▶ | return ($self->_wrap_list($result->{zones} // []), $result->{meta}); | ||||||||||
|
Condition50%1/2
$result->{"zones"} // []
MC/DC0%0/1
$result->{"zones"} // []
$result->{"zones"}
Truth table50%1/2
A
A= $result->{"zones"}
| |||||||||||||
| 42 | } | ||||||||||||
| 43 | |||||||||||||
| 44 | 2 | ▶ | sub list { | ||||||||||
|
Subroutine
list: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 45 | 2 | my ($self, %params) = @_; | |||||||||||
| 46 | |||||||||||||
| 47 | 2 | my ($entities) = $self->_list_page(%params); | |||||||||||
| 48 | 2 | return $entities; | |||||||||||
| 49 | } | ||||||||||||
| 50 | |||||||||||||
| 51 | |||||||||||||
| 52 | |||||||||||||
| 53 | 1 | ▶ | sub list_by_label { | ||||||||||
|
Subroutine
list_by_label: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 54 | 1 | my ($self, $label_selector) = @_; | |||||||||||
| 55 | 1 | return $self->list(label_selector => $label_selector); | |||||||||||
| 56 | } | ||||||||||||
| 57 | |||||||||||||
| 58 | |||||||||||||
| 59 | 4 | ▶ | sub get { | ||||||||||
|
Subroutine
get: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 60 | 4 | my ($self, $id) = @_; | |||||||||||
| 61 | 4 | ▶ | croak "Zone ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 62 | |||||||||||||
| 63 | 3 | my $result = $self->client->get("/zones/$id"); | |||||||||||
| 64 | 3 | return $self->_wrap($result->{zone}); | |||||||||||
| 65 | } | ||||||||||||
| 66 | |||||||||||||
| 67 | |||||||||||||
| 68 | 5 | ▶ | sub create { | ||||||||||
|
Subroutine
create: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 69 | 5 | my ($self, %params) = @_; | |||||||||||
| 70 | |||||||||||||
| 71 | 5 | ▶ | croak "name required" unless $params{name}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 72 | |||||||||||||
| 73 | my $body = { | ||||||||||||
| 74 | name => $params{name}, | ||||||||||||
| 75 | 4 | }; | |||||||||||
| 76 | |||||||||||||
| 77 | 4 | ▶ | $body->{labels} = $params{labels} if $params{labels}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 78 | 4 | ▶ | $body->{ttl} = $params{ttl} if $params{ttl}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 79 | |||||||||||||
| 80 | 4 | my $result = $self->client->post('/zones', $body); | |||||||||||
| 81 | return $self->_wrap( | ||||||||||||
| 82 | $result->{zone}, | ||||||||||||
| 83 | 4 | action => $self->_wrap_action($result->{action}), | |||||||||||
| 84 | ); | ||||||||||||
| 85 | } | ||||||||||||
| 86 | |||||||||||||
| 87 | |||||||||||||
| 88 | 2 | ▶ | sub update { | ||||||||||
|
Subroutine
update: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||
| 89 | 2 | my ($self, $id, %params) = @_; | |||||||||||
| 90 | 2 | ▶ | croak "Zone ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 91 | |||||||||||||
| 92 | 1 | my $body = {}; | |||||||||||
| 93 | 1 | ▶ | $body->{name} = $params{name} if exists $params{name}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 94 | 1 | ▶ | $body->{labels} = $params{labels} if exists $params{labels}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 95 | |||||||||||||
| 96 | 1 | my $result = $self->client->put("/zones/$id", $body); | |||||||||||
| 97 | 1 | return $self->_wrap($result->{zone}); | |||||||||||
| 98 | } | ||||||||||||
| 99 | |||||||||||||
| 100 | |||||||||||||
| 101 | 5 | ▶ | sub delete { | ||||||||||
|
Subroutine
delete: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 102 | 5 | my ($self, $id) = @_; | |||||||||||
| 103 | 5 | ▶ | croak "Zone ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 104 | |||||||||||||
| 105 | 4 | my $result = $self->client->delete("/zones/$id"); | |||||||||||
| 106 | 4 | return $self->_wrap_action($result->{action}); | |||||||||||
| 107 | } | ||||||||||||
| 108 | |||||||||||||
| 109 | |||||||||||||
| 110 | 2 | ▶ | sub export { | ||||||||||
|
Subroutine
export: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 111 | 2 | my ($self, $id) = @_; | |||||||||||
| 112 | 2 | ▶ | croak "Zone ID required" unless $id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 113 | |||||||||||||
| 114 | 1 | my $result = $self->client->get("/zones/$id/export"); | |||||||||||
| 115 | 1 | return $result; | |||||||||||
| 116 | } | ||||||||||||
| 117 | |||||||||||||
| 118 | |||||||||||||
| 119 | 43 | ▶ | sub rrsets { | ||||||||||
|
Subroutine
rrsets: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 120 | 43 | my ($self, $zone_id) = @_; | |||||||||||
| 121 | 43 | ▶ | croak "Zone ID required" unless $zone_id; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 122 | |||||||||||||
| 123 | 42 | return WWW::Hetzner::Cloud::API::RRSets->new( | |||||||||||
| 124 | client => $self->client, | ||||||||||||
| 125 | zone_id => $zone_id, | ||||||||||||
| 126 | ); | ||||||||||||
| 127 | } | ||||||||||||
| 128 | |||||||||||||
| 129 | |||||||||||||
| 130 | 60 | 1; | |||||||||||
| 131 | |||||||||||||
| 132 | __END__ | ||||||||||||