File Coverage

blib/lib/WebService/Reactio.pm
Criterion Covered Total %
statement 30 30 100.0
branch 6 6 100.0
condition 1 2 50.0
subroutine 9 9 100.0
pod 1 1 100.0
total 47 48 97.9


line stmt bran cond sub pod time code
1             package WebService::Reactio;
2 1     1   113778 use 5.008001;
  1         4  
3 1     1   7 use strict;
  1         1  
  1         23  
4 1     1   5 use warnings;
  1         8  
  1         39  
5              
6 1     1   5 use Carp;
  1         2  
  1         66  
7 1     1   5 use Furl;
  1         1  
  1         22  
8 1     1   4 use JSON;
  1         1  
  1         4  
9              
10             our $VERSION = "0.02";
11              
12 1         8 use parent qw/
13             WebService::Reactio::Incident
14 1     1   103 /;
  1         2  
15              
16             sub new {
17 8     8 1 17595 my ($class, %params) = @_;
18              
19 8         13 my $api_key = $params{api_key};
20 8         10 my $organization = $params{organization};
21 8   50     37 my $domain = $params{domain} || 'reactio.jp';
22 8 100       289 Carp::croak '[ERROR] API key is required' unless $api_key;
23 6 100       109 Carp::croak '[ERROR] Organization is required' unless $organization;
24              
25 5         38 bless {
26             api_key => $api_key,
27             host => "$organization.$domain",
28             client => Furl->new(
29             agent => "WebService::Reactio/$WebService::Reactio::VERSION",
30             timeout => 10,
31             ),
32             }, $class;
33             }
34              
35             sub _request {
36 4     4   9 my ($self, $method, $path, $content) = @_;
37              
38             my $response = $self->{client}->request(
39             method => $method,
40             scheme => 'https',
41             host => $self->{host},
42             path_query => $path,
43             headers => [
44             'X-Api-Key' => $self->{api_key},
45 4 100       107 'Content-Type' => 'application/json',
46             'Accept' => 'application/json',
47             ],
48             content => $content ? encode_json($content) : undef,
49             );
50 4         324 return decode_json($response->content);
51             }
52              
53             1;
54              
55             __END__