line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Sensu::API::Client::APICaller; |
2
|
|
|
|
|
|
|
$Sensu::API::Client::APICaller::VERSION = '0.02'; |
3
|
8
|
|
|
8
|
|
89094
|
use 5.010; |
|
8
|
|
|
|
|
100
|
|
|
8
|
|
|
|
|
329
|
|
4
|
8
|
|
|
8
|
|
46
|
use Moo::Role; |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
140
|
|
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
3017
|
use Carp; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
677
|
|
7
|
8
|
|
|
8
|
|
42
|
use JSON; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
74
|
|
8
|
8
|
|
|
8
|
|
11489
|
use HTTP::Tiny; |
|
8
|
|
|
|
|
531400
|
|
|
8
|
|
|
|
|
4133
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @CARP_NOT = qw/ Sensu::API::Client /; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has ua => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
default => sub { HTTP::Tiny->new }, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has headers => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
default => sub { { |
20
|
|
|
|
|
|
|
'Accept' => 'application/json', |
21
|
|
|
|
|
|
|
'Content-type' => 'application/json', |
22
|
|
|
|
|
|
|
}; }, |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub get { |
26
|
0
|
|
|
0
|
0
|
|
my ($self, $url) = @_; |
27
|
0
|
|
|
|
|
|
my $r = $self->ua->get($self->url . $url, { headers => $self->headers }); |
28
|
0
|
0
|
|
|
|
|
croak "$r->{status} $r->{reason}" unless $r->{success}; |
29
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
return $r->{content} ? decode_json($r->{content}) : 1; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub post { |
34
|
0
|
|
|
0
|
0
|
|
my ($self, $url, $body) = @_; |
35
|
0
|
|
|
|
|
|
my $post = { headers => $self->headers }; |
36
|
0
|
0
|
|
|
|
|
if (defined $body) { |
37
|
0
|
|
|
|
|
|
$post->{content} = encode_json($body); |
38
|
|
|
|
|
|
|
} else { |
39
|
0
|
|
|
|
|
|
$post->{headers}->{'Content-Length'} = '0'; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $r = $self->ua->post($self->url . $url, $post); |
43
|
0
|
0
|
|
|
|
|
croak "$r->{status} $r->{reason}" unless $r->{success}; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
return decode_json($r->{content}); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub delete { |
49
|
0
|
|
|
0
|
0
|
|
my ($self, $url) = @_; |
50
|
0
|
|
|
|
|
|
my $r = $self->ua->delete($self->url . $url, { headers => $self->headers }); |
51
|
0
|
0
|
|
|
|
|
croak "$r->{status} $r->{reason}" unless $r->{success}; |
52
|
0
|
|
|
|
|
|
return; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
1; |