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