API.pm

filter: Statementstmt 51.1% 23 / 45 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 58.3% 7 / 12 Podpod 100% 2 / 2 totaltotal 43.8% 32 / 73 CC 7 SCAR 22.6
CC
7
Cov
40%
new
20.0
call
20.0
__ANON__
2.0
CRAP 9.6
↑ Summary API/Response.pm »
1 package WWW::Bizowie::API;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use WWW::Bizowie::API::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use HTTP::Request::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 our $VERSION = '0.02';
13  
14 =head1 NAME
15  
16 WWW::Bizowie::API - Perl interface to the Bizowie.com API
17  
18 =head1 SYNOPSIS
19  
20 my $bz = WWW::Bizowie::API->new(
21 api_key => '02cc7058-cd22-4c8e-ad7c-a8f3f2a64bd0',
22 secret_key => '58c57abc-1e16-3571-bb35-73876bcef746',
23 site => 'mysite.bizowie.com',
24 );
25  
26 $bz->call(
27 '/tickets/add_comment/0824', {
28 comment => "I added this comment via the API!",
29 },
30 );
31  
32 =head1 METHODS
33  
34 =head2 new
35  
36 Returns a new instance of WWW::Bizowie::API
37  
38 Requires three parameters: api_key (your Bizowie API key), secret_key, and site (the hostname of your Bizowie instance).
39  
40 =cut
41  
42 sub new
43 {
44 0 ▶ my ($class, %params) = @_;
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
45  
46 0 my $bzua = LWP::UserAgent->new;
47 0 $bzua->ssl_opts( verify_hostname => 0 );
48 0 $bzua->agent('Bizowie::API');
49  
50 0 ▶ die 'site not specified' unless $params{site};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"site"} 0 0 0
51 0 ▶ die 'api_key not specified' unless $params{api_key};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"api_key"} 0 0 0
52 0 ▶ die 'secret_key not specified' unless $params{secret_key};
Branch: 1 branch
BranchTrueFalseTotal
unless $params{"secret_key"} 0 0 0
53  
54 my $self = {
55 ua => $bzua,
56 api_key => $params{api_key},
57 secret_key => $params{secret_key},
58 site => $params{site},
59 0 };
60  
61 0 bless($self);
62  
63 0 return $self;
64 }
65  
66 =head2 call
67  
68 Makes a Bizowie API call.
69  
70 Takes two a parameters: a string indicating the path to the API method you wish to call, and a has reference of the parameters to be passed.
71  
72 =cut
73  
74 sub call
75 {
76 0 ▶ my ($self, $method, $params) = @_;
Subroutine call: not called CC=4 SCAR=30.0
Pod documented
77  
78 0 my $site = $self->{site};
79  
80 0 ▶ die "[Bizowie::API] fatal error: no method given" unless $method;
Branch: 1 branch
BranchTrueFalseTotal
unless $method 0 0 0
81  
82 0 ▶ my $request = encode_json($params || { });
Condition0%0/2
$params || {}
l!l
00
MC/DC0%0/1
$params || {}
$params
Truth table0%0/2
A
A= $params
Aresult
11
00
83  
84 my $q = $self->{ua}->request(POST("https://${site}/bz/api/$method",
85 Content_Type => 'form-data',
86 Content => [
87 api_key => $self->{api_key},
88 secret_key => $self->{secret_key},
89 0 site => $site,
90 request => $request,
91 ])
92 );
93  
94 0 my $o;
95 {
96 0 ▶ local $SIG{__DIE__} = sub { };
Subroutine __ANON__: not called CC=1 SCAR=6.9
97 try {
98 0 ▶ $o = decode_json($q->decoded_content);
Subroutine __ANON__: not called CC=1 SCAR=6.9
99 } catch {
100 0 ▶ $o = { unprocessed => 1 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
101 0 };
102 }
103  
104 return WWW::Bizowie::API::Response->new(
105 data => $o,
106 0 ▶ success => delete $o->{success} || 0,
Condition0%0/2
delete $o->{'success'} || 0
l!l
00
MC/DC0%0/1
delete $o->{'success'} || 0
delete $o->{'success'}
Truth table0%0/2
A
A= delete $o->{'success'}
Aresult
11
00
107 );
108 }
109  
110 =head1 DEPENDENCIES
111  
112 HTTP::Request::Common, LWP::UserAgent, Try::Tiny, JSON, Mo
113  
114 =head1 AUTHORS
115  
116 Bizowie <http://bizowie.com>
117  
118 =head1 COPYRIGHT AND LICENSE
119  
120 Copyright (C) 2013 Bizowie
121  
122 This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
123  
124 =cut
125  
126 1 1;
127  
↑ Summary API/Response.pm »