| 1 | package Sensu::API::Client::APICaller; | ||||||||||
| 2 | 8 | $Sensu::API::Client::APICaller::VERSION = '0.02'; | |||||||||
| 3 | 8 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 8 | ▶ | use Moo::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 8 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 8 | ▶ | use JSON; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 8 | ▶ | use HTTP::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 8 | our @CARP_NOT = qw/ Sensu::API::Client /; | |||||||||
| 11 | |||||||||||
| 12 | has ua => ( | ||||||||||
| 13 | is => 'ro', | ||||||||||
| 14 | 0 | ▶ | default => sub { HTTP::Tiny->new }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 15 | 8 | ); | |||||||||
| 16 | |||||||||||
| 17 | has headers => ( | ||||||||||
| 18 | is => 'ro', | ||||||||||
| 19 | 0 | ▶ | default => sub { { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 20 | 0 | 'Accept' => 'application/json', | |||||||||
| 21 | 'Content-type' => 'application/json', | ||||||||||
| 22 | }; }, | ||||||||||
| 23 | 8 | ); | |||||||||
| 24 | |||||||||||
| 25 | 0 | ▶ | sub get { | ||||||||
|
Subroutine
get: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 26 | 0 | my ($self, $url) = @_; | |||||||||
| 27 | 0 | my $r = $self->ua->get($self->url . $url, { headers => $self->headers }); | |||||||||
| 28 | 0 | ▶ | croak "$r->{status} $r->{reason}" unless $r->{success}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | |||||||||||
| 30 | 0 | ▶ | return $r->{content} ? decode_json($r->{content}) : 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 0 | ▶ | sub post { | ||||||||
|
Subroutine
post: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 34 | 0 | my ($self, $url, $body) = @_; | |||||||||
| 35 | 0 | my $post = { headers => $self->headers }; | |||||||||
| 36 | 0 | ▶ | if (defined $body) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | croak "$r->{status} $r->{reason}" unless $r->{success}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | |||||||||||
| 45 | 0 | return decode_json($r->{content}); | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | sub delete { | ||||||||
|
Subroutine
delete: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 49 | 0 | my ($self, $url) = @_; | |||||||||
| 50 | 0 | my $r = $self->ua->delete($self->url . $url, { headers => $self->headers }); | |||||||||
| 51 | 0 | ▶ | croak "$r->{status} $r->{reason}" unless $r->{success}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 0 | return; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 8 | 1; | |||||||||