blib/lib/Net/CapsuleCRM.pm

filter: Statementstmt 40.9% 50 / 122 Branchbran 0.0% 0 / 56 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 61.5% 16 / 26 Podpod n/a totaltotal 31.4% 66 / 210 CC 32 SCAR 48.0
CC
32
Cov
27%
_talk
352.2
find_party_by_email
14.1
find_party
14.1
CRAP 121.2
↑ Summary
1 package Net::CapsuleCRM;
2 {
3 1 $Net::CapsuleCRM::VERSION = '1.123130';
4 }
5  
6 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Sub::Quote;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Method::Signatures;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use JSON::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use HTTP::Request::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # ABSTRACT: Connect to the Capsule API (www.capsulecrm.com)
17  
18  
19 1 has 'debug' => (is => 'rw', predicate => 'is_debug');
20 1 has 'error' => (is => 'rw', predicate => 'has_error');
21 1 has 'token' => (is => 'rw', required => 1);
22 has 'ua' => (is => 'rw',
23 0 ▶ default => sub { LWP::UserAgent->new( agent => 'Perl Net-CapsuleCRM'); } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
24 0 ▶has 'target_domain' => (is => 'rw', default => sub { 'test.capsulecrm.com' } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
25 0 ▶has 'xmls' => ( is => 'rw', default => sub { return XML::Simple->new(
Subroutine __ANON__: not called CC=1 SCAR=6.9
26 NoAttr => 1, KeyAttr => [], XMLDecl => 1, SuppressEmpty => 1, ); }
27 1 );
28  
29 1 ▶method endpoint_uri { return 'https://' . $self->target_domain . '/api/'; }
Subroutine BEGIN: called CC=1 SCAR=3.1
Subroutine endpoint_uri: not called CC=2 SCAR=12.4
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ > 0 0 0 0
30  
31 1 ▶method _talk($command,$method,$content?) {
Subroutine BEGIN: called CC=1 SCAR=5.0
Subroutine _talk: not called CC=19 SCAR=58.6
Branch: 3 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 0 0
unless scalar @_ > 1 0 0 0
if scalar @_ > 3 0 0 0
32 0 my $uri = URI->new($self->endpoint_uri);
33 0 $uri->path("api/$command");
34  
35 0 $self->ua->credentials(
36 $uri->host . ':'.$uri->port,
37 'seamApp',
38 $self->token => 'x'
39 );
40
41 0 ▶ print "$uri\n" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
42  
43 0 my $res;
44 0 ▶ my $type = ref $content eq 'HASH' ? 'json' : 'xml';
Branch: 1 branch
BranchTrueFalseTotal
ref $content eq 'HASH' ? : 0 0 0
45 0 ▶ if($method =~ /get/i){
Branch: 1 branch
BranchTrueFalseTotal
if ($method =~ /get/i) { } 0 0 0
46 0 ▶ if(ref $content eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $content eq "HASH") 0 0 0
47 0 $uri->query_form($content);
48 }
49 0 $res = $self->ua->request(
50 GET $uri, #content is ID in this instance.
51 Accept => 'application/json',
52 Content_Type => 'application/json',
53 );
54 } else {
55 #$content = $self->_template($content) if $content;
56 0 ▶ if($type eq 'json') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'json') { } 0 0 0
57 0 ▶ print "Encoding as JSON\n" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
58 0 $content = encode_json $content;
59 0 ▶ print "$content\n" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
60 0 $res = $self->ua->request(
61 POST $uri,
62 Accept => 'application/json',
63 Content_Type => 'application/json',
64 Content => $content,
65 );
66 } else {
67 #otherwise XML
68 0 $content = $self->xmls->XMLout($content, RootName => $command);
69 0 ▶ print "Encoding as XML\n" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
70 0 $res = $self->ua->request(
71 POST $uri,
72 Accept => 'text/xml',
73 Content_Type => 'text/xml',
74 Content => $content,
75 );
76 }
77  
78  
79 }
80
81 0 ▶ if ($res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 0 0 0
82 0 ▶ print "Server said: ", $res->status_line, "\n" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
83 0 ▶ if($res->status_line =~ /^201/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->status_line =~ /^201/) { } 0 0 0
84 0 return (split '/', $res->header('Location'))[-1]
85 } else {
86 0 ▶ print $res->content. "\n" if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
87 0 ▶ if($type eq 'json') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'json') { } 0 0 0
elsif ($res->content) { } 0 0 0
88 0 return decode_json $res->content;
89 } elsif($res->content) {
90 0 return XMLin $res->content;
91 } else {
92 0 return 1;
93 }
94 }
95 } else {
96 0 $self->error($res->status_line);
97 0 warn $self->error;
98 0 ▶ if ($self->debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug) 0 0 0
99 0 print $res->content;
100 }
101 }
102
103 }
104  
105  
106  
107 1 ▶method find_party_by_email($email) {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine find_party_by_email: not called CC=4 SCAR=26.4
Branch: 2 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 0 0
if scalar @_ > 1 0 0 0
108 0 my $res = $self->_talk('party', 'GET', {
109 email => $email,
110 start => 0,
111 });
112 0 ▶ return $res->{'parties'}->{'person'}->{'id'} || undef;
Condition0%0/2
$res->{'parties'}{'person'}{'id'} || undef
l!l
00
MC/DC0%0/1
$res->{'parties'}{'person'}{'id'} || undef
$res->{'parties'}{'person'}{'id'}
Truth table0%0/2
A
A= $res->{'parties'}{'person'}{'id'}
Aresult
11
00
113 }
114  
115  
116 1 ▶method find_party($id) {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine find_party: not called CC=4 SCAR=26.4
Branch: 2 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 0 0
if scalar @_ > 1 0 0 0
117 0 my $res = $self->_talk('party/'.$id, 'GET', $id);
118 0 ▶ return $res->{'parties'}->{'person'}->{'id'} || undef;
Condition0%0/2
$res->{'parties'}{'person'}{'id'} || undef
l!l
00
MC/DC0%0/1
$res->{'parties'}{'person'}{'id'} || undef
$res->{'parties'}{'person'}{'id'}
Truth table0%0/2
A
A= $res->{'parties'}{'person'}{'id'}
Aresult
11
00
119 }
120  
121  
122 1 ▶method create_person($data) {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine create_person: not called CC=3 SCAR=20.7
Branch: 2 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 0 0
if scalar @_ > 1 0 0 0
123 0 return $self->_talk('person', 'POST', { person => $data } );
124 }
125  
126  
127 1 ▶method create_organisation($data) {
Subroutine BEGIN: called CC=1 SCAR=4.1
Subroutine create_organisation: not called CC=3 SCAR=20.7
Branch: 2 branches
BranchTrueFalseTotal
unless scalar @_ > 0 0 0 0
if scalar @_ > 1 0 0 0
128 0 return $self->_talk('organisation', 'POST', { organisation => $data } );
129 }
130  
131 1 ▶method add_tag($id, @tags) {
Subroutine BEGIN: called CC=1 SCAR=3.5
Subroutine add_tag: not called CC=3 SCAR=20.3
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ > 0 0 0 0
132 # my $data = $self->xmls->XMLout(
133 # { tag => [ map { name => $_ }, @tags ] }, RootName => 'tags'
134 # );
135 0 foreach(@tags) {
136 0 $self->_talk("party/$id/tag/$_", 'POST');
137 }
138 }
139  
140  
141 1 1;
142  
143 __END__
144 =pod
145  
146 =head1 NAME
147  
148 Net::CapsuleCRM - Connect to the Capsule API (www.capsulecrm.com)
149  
150 =head1 VERSION
151  
152 version 1.123130
153  
154 =head1 SYNOPSIS
155  
156 my $foo = Net::CapsuleCRM->new(
157 token => 'xxxx',
158 target_domain => 'test.capsulecrm.com',
159 debug => 0,
160 );
161  
162 =head2 find_party_by_email
163  
164 find by email
165  
166 =head2 find_party
167  
168 find by id
169  
170 =head2 create_person
171  
172 $cap->create_person({
173 contacts => {
174 email => {
175 emailAddress => 'xxx',
176 },
177 address => {
178 type => 'xxx',
179 street => "xxx",
180 city => 'xxx',
181 zip => 'xxx',
182 country => 'xxx',
183 },
184 phone => {
185 type => 'Home',
186 phoneNumber => '123456',
187 },
188 },
189 title => 'Mr',
190 firstName => 'Simon',
191 lastName => 'Elliott',
192 });
193  
194 =head2 create_organization
195  
196 See Person
197  
198 =head2 add_tag
199  
200 $cap->add_tag($person_id,'customer','difficult');
201  
202 =head1 AUTHOR
203  
204 Simon Elliott <cpan@papercreatures.com>
205  
206 =head1 COPYRIGHT AND LICENSE
207  
208 This software is copyright (c) 2011 by Simon Elliott.
209  
210 This is free software; you can redistribute it and/or modify it under
211 the same terms as the Perl 5 programming language system itself.
212  
213 =cut
214  
↑ Summary