line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DNS::Hetzner::APIBase; |
2
|
|
|
|
|
|
|
$DNS::Hetzner::APIBase::VERSION = '0.05'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Base class for all entity classes |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
1257
|
use v5.24; |
|
2
|
|
|
|
|
8
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
10
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
143
|
|
8
|
2
|
|
|
2
|
|
12
|
use Moo; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
13
|
|
9
|
2
|
|
|
2
|
|
721
|
use Mojo::UserAgent; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
18
|
|
10
|
2
|
|
|
2
|
|
96
|
use Mojo::Util qw(url_escape); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
112
|
|
11
|
2
|
|
|
2
|
|
12
|
use Types::Mojo qw(:all); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
17
|
|
12
|
2
|
|
|
2
|
|
7819
|
use Types::Standard qw(Str); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
11
|
|
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
1420
|
use DNS::Hetzner::Schema; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
59
|
|
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
10
|
use Mojo::Base -strict, -signatures; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
13
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has token => ( is => 'ro', isa => Str, required => 1 ); |
19
|
|
|
|
|
|
|
has host => ( is => 'ro', isa => MojoURL["https?"], default => sub { 'https://dns.hetzner.com' }, coerce => 1 ); |
20
|
|
|
|
|
|
|
has base_uri => ( is => 'ro', isa => Str, default => sub { 'api/v1' } ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has client => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
lazy => 1, |
25
|
|
|
|
|
|
|
isa => MojoUserAgent, |
26
|
|
|
|
|
|
|
default => sub { |
27
|
|
|
|
|
|
|
Mojo::UserAgent->new, |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
0
|
|
0
|
sub _do ( $self, $op, $params, $path, $opts ) { |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
32
|
0
|
|
|
|
|
0
|
my ($req_params, @errors) = DNS::Hetzner::Schema->validate( $op, $params ); |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
0
|
croak 'invalid parameters' if @errors; |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
0
|
$self->request( $path, $req_params, $opts ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
0
|
1
|
0
|
sub request ( $self, $partial_uri, $params = {}, $opts = {} ) { |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
40
|
|
|
|
|
|
|
|
41
|
0
|
|
0
|
|
|
0
|
my $method = delete $opts->{type} // 'get'; |
42
|
0
|
|
|
|
|
0
|
my $sub = $self->client->can(lc $method); |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
0
|
croak sprintf 'Invalid request method %s', $method if !$sub; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
0
|
|
|
0
|
$params->{path} //= {}; |
47
|
0
|
|
|
|
|
0
|
my %path_params = $params->{path}->%*; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
0
|
$partial_uri =~ s{ |
50
|
|
|
|
|
|
|
:(?\w+)\b |
51
|
|
|
|
|
|
|
}{ |
52
|
1
|
|
|
1
|
|
1027
|
$path_params{$+{mandatory}} |
|
1
|
|
|
|
|
486
|
|
|
1
|
|
|
|
|
409
|
|
53
|
0
|
|
|
|
|
0
|
}xmsge; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
0
|
my %request_opts; |
56
|
0
|
|
0
|
|
|
0
|
$params->{body} //= {}; |
57
|
0
|
0
|
|
|
|
0
|
if ( $params->{body}->%* ) { |
58
|
0
|
|
|
|
|
0
|
%request_opts = ( json => $params->{body} ); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
0
|
|
|
0
|
$params->{query} //= {}; |
62
|
0
|
|
|
|
|
0
|
my $query = ''; |
63
|
0
|
0
|
|
|
|
0
|
if ( $params->{query}->%* ) { |
64
|
0
|
|
|
|
|
0
|
my $query_params = delete $params->{query}; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$query = join '&', map{ |
67
|
0
|
|
|
|
|
0
|
$_ . '=' . url_escape($query_params->{$_}) |
|
0
|
|
|
|
|
0
|
|
68
|
|
|
|
|
|
|
}sort keys $query_params->%*; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
0
|
my $uri = join '/', |
72
|
|
|
|
|
|
|
$self->host, |
73
|
|
|
|
|
|
|
$self->base_uri, |
74
|
|
|
|
|
|
|
$self->endpoint, |
75
|
|
|
|
|
|
|
$partial_uri; |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
0
|
$uri =~ s{/\z}{}; |
78
|
|
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
0
|
$uri .= '?' . $query if $query; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
0
|
my $tx = $self->client->$method( |
82
|
|
|
|
|
|
|
$uri, |
83
|
|
|
|
|
|
|
{ |
84
|
|
|
|
|
|
|
'Auth-API-Token' => $self->token, |
85
|
|
|
|
|
|
|
}, |
86
|
|
|
|
|
|
|
%request_opts, |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
0
|
my $response = $tx->res; |
90
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
0
|
if ( $tx->error ) { |
92
|
0
|
|
|
|
|
0
|
carp $tx->error->{message}; |
93
|
0
|
|
|
|
|
0
|
return; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
0
|
return $response->json; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
__END__ |