File Coverage

blib/lib/Mackerel/Client.pm
Criterion Covered Total %
statement 18 22 81.8
branch n/a
condition n/a
subroutine 6 7 85.7
pod 0 2 0.0
total 24 31 77.4


line stmt bran cond sub pod time code
1             package Mackerel::Client;
2 2     2   43080 use 5.008001;
  2         6  
  2         85  
3 2     2   10 use strict;
  2         3  
  2         69  
4 2     2   9 use warnings;
  2         8  
  2         66  
5 2     2   9 use JSON;
  2         1  
  2         10  
6 2     2   1341 use HTTP::Tiny;
  2         82405  
  2         363  
7              
8             our $VERSION = "0.01_1";
9              
10             sub new {
11 1     1 0 573 my ($class, %args) = @_;
12 1         8 my $self = {
13             api_key => $args{api_key},
14             service_name => $args{service_name},
15             mackerel_origin => 'https://mackerel.io' || $args{mackerel_origin},
16             agent => HTTP::Tiny->new( agent => "Mackerel::Client agent" ),
17             };
18 1         78 bless $self, $class;
19             }
20              
21             sub post_service_metrics {
22 0     0 0   my ($self,$args) = @_;
23 0           my $path = '/api/v0/services/' . $self->{service_name} . '/tsdb';
24 0           my $res = $self->{agent}->request('POST', $self->{mackerel_origin} . $path, {
25             content => encode_json $args,
26             headers => {
27             'content-type' => 'application/json',
28             'X-Api-Key' => $self->{api_key},
29             },
30             });
31 0           return $res->{content};
32             }
33              
34             1;
35             __END__