Chimp/API.pm

filter: Statementstmt 59.3% 35 / 59 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 58.3% 7 / 12 Podpod 0.0% 0 / 3 totaltotal 43.3% 42 / 97 CC 8 SCAR 27.1
CC
8
Cov
46%
BUILD
42.0
_call
6.0
get_list
6.0
CRAP 15.1
↑ Summary Chimp/AbuseReport.pm »
1 package Mail::Chimp::API;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use XMLRPC::Lite;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '0.2.1';
9  
10  
11 1 has 'username' => (is => 'ro', isa => 'Str');
12 1 has 'password' => (is => 'ro', isa => 'Str');
13 1 has 'api' => (is => 'rw', isa => 'XMLRPC::Lite');
14 1 has 'api_version' => (is => 'ro', isa => 'Num', default => 1.2);
15 1 has 'api_url' => (is => 'rw', isa => 'Str');
16 1 has 'apikey' => (is => 'rw', isa => 'Str');
17 1 has 'use_secure' => (is => 'ro', isa => 'Bool', default => 1);
18 1 has 'datacenter' => (is => 'ro', isa => 'Str', default => 'us1');
19 1 has 'output_format' => (is => 'rw', isa => 'Str', default => 'json');
20  
21  
22 0 ▶sub BUILD {
Subroutine BUILD: not called CC=6 SCAR=37.4
Pod undocumented
23 0 my ( $self ) = @_;
24
25 0 ▶ die 'apikey or username and password is required'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->apikey or $self->username and $self->password 0 0 0
Condition0%0/6
$self->apikey or $self->username and $self->password
l!l&&r!l&&!r
000
$self->username and $self->password
!ll&&!rl&&r
000
MC/DC0%0/3
$self->apikey or $self->username and $self->password
$self->apikey $self->username $self->password
Truth table0%0/4
A or B and C
A= $self->apikeyB= $self->usernameC= $self->password
ABCresult
1XX1
0111
00X0
0100
26 unless ($self->apikey or ($self->username and $self->password));
27 0 my $url = 'http';
28 0 ▶ $url .= 's' if $self->use_secure();
Branch: 1 branch
BranchTrueFalseTotal
if $self->use_secure 0 0 0
29 0 $url .= "://" . $self->datacenter() . ".api.mailchimp.com/" . $self->api_version() . '/';
30 0 warn "# $url\n";
31 0 $self->api_url( $url );
32 0 $self->api( XMLRPC::Lite->proxy( $url ) );
33 0 ▶ unless ($self->apikey) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->apikey) 0 0 0
34 0 $self->apikey( $self->_call( 'login', $self->username(), $self->password() ) );
35 }
36 }
37  
38 0 ▶sub _call {
Subroutine _call: not called CC=2 SCAR=17.9
39 0 my $self = shift;
40  
41 0 my $call = $self->api->call( @_ );
42 return $call->result
43 0 ▶ || confess( sprintf( "MailChimp Error %d: %s", $call->fault->{faultCode}, $call->fault->{faultString} ) );
Condition0%0/2
$call->result || confess(sprintf('MailChimp Error %d: %s', $call->fault->{'faultCode'}, $call->fault->{'faultString'}))
l!l
00
MC/DC0%0/1
$call->result || confess(sprintf('MailChimp Error %d: %s', $call->fault->{'faultCode'}, $call->fault->{'faultString'}))
$call->result
Truth table0%0/2
A
A= $call->result
Aresult
11
00
44 }
45  
46 0 ▶sub all_lists {
Subroutine all_lists: not called CC=1 SCAR=6.9
Pod undocumented
47 0 my ( $self ) = @_;
48  
49 0 my $lists = $self->_call( 'lists', $self->apikey );
50 0 require Mail::Chimp::List;
51 0 return [ map { Mail::Chimp::List->new( _api => $self, %$_ ) } @$lists ];
52 }
53  
54 0 ▶sub get_list {
Subroutine get_list: not called CC=2 SCAR=17.9
Pod undocumented
55 0 my ( $self, $id ) = @_;
56 0 my $lists = $self->get_lists();
57 0 ▶ return grep { $_->id() == $id or $_->name() eq $id } @$lists;
Condition0%0/3
$_->id == $id || $_->name eq $id
l!l&&r!l&&!r
000
MC/DC0%0/2
$_->id == $id || $_->name eq $id
$_->id == $id $_->name eq $id
Truth table0%0/3
A || B
A= $_->id == $idB= $_->name eq $id
ABresult
1X1
011
000
58 }
59  
60  
61 {
62 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
63 68 ▶ sub _make_api_method {
Subroutine _make_api_method: called CC=1 SCAR=0.6
64 68 my ($class, $method) = @_;
65 0 ▶ *{"${class}::$method"} = sub { my $self = shift; $self->_call( $method, $self->apikey, @_ ) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
66 }
67 }
68  
69 1 my @api_methods = qw(
70 campaignContent
71 campaignCreate
72 campaignDelete
73 campaignEcommAddOrder
74 campaignFolders
75 campaignPause
76 campaignReplicate
77 campaignResume
78 campaignSchedule
79 campaignSegmentTest
80 campaignSendNow
81 campaignSendTest
82 campaignTemplates
83 campaignUnschedule
84 campaignUpdate
85 campaigns
86  
87 campaignAbuseReports
88 campaignAdvice
89 campaignAnalytics
90 campaignBounceMessages
91 campaignClickStats
92 campaignEcommOrders
93 campaignEepUrlStats
94 campaignEmailDomainPerformance
95 campaignGeoOpens
96 campaignGeoOpensForCountry
97 campaignHardBounces
98 campaignSoftBounces
99 campaignStats
100 campaignUnsubscribes
101  
102 campaignClickDetailAIM
103 campaignEmailStatsAIM
104 campaignEmailStatsAIMAll
105 campaignNotOpenedAIM
106 campaignOpenedAIM
107  
108 chimpChatter
109 createFolder
110 exommAddOrder
111 generateText
112 getAccountDetails
113 getAffiliateInfo
114 inlineCss
115 listsForEmail
116 ping
117  
118 listAbuseReports
119 listBatchSubscribe
120 listBatchUnsubscribe
121 listGrowthHistory
122 listInterestGroupAdd
123 listInterestGroupDel
124 listInterestGroupUpdate
125 listInterestGroups
126 listMemberInfo
127 listMembers
128 listMergeVarAdd
129 listMergeVarDel
130 listMergeVarUpdate
131 listMergeVars
132 listSubscribe
133 listUnsubscribe
134 listUpdateMember
135 listWebhookAdd
136 listWebhookDel
137 listWebhooks
138 lists
139
140 apikeyAdd
141 apikeyExpire
142 apikeys
143 );
144  
145 1 __PACKAGE__->_make_api_method( $_ ) for @api_methods;
146  
147 =head1 NAME
148  
149 Mail::Chimp::API - Perl wrapper around the Mailchimp API
150  
151 =head1 SYNOPSIS
152  
153 use strict;
154 use Mail::Chimp::API;
155  
156 my $chimp = Mail::Chimp::API->new(apikey => $apikey,
157 api_version => 1.2);
158  
159 # or if you have no apikey setup:
160 # my $chimp = Mail::Chimp::API->new(username => $username,
161 # password => $password,
162 # api_version => 1.1,
163 # );
164  
165 my $apikey = $chimp->apikey; # generated on first login if none was setup
166  
167 my $campaigns = $chimp->campaigns;
168 my $lists = $chimp->lists;
169 my $subscribers = $chimp->listMembers($lists->[0]->{id});
170  
171 print 'success' if $chimp->listSubscribe($lists->[0]->{id}, 'someone@somewhere.com', {}, 1);
172  
173 =head1 DESCRIPTION
174  
175 Mail::Chimp::API is a simple Perl wrapper around the MailChimp API.
176 The object exposes the MailChimp XML-RPC methods and confesses
177 fault codes/messages when errors occur. Further, it keeps track of
178 your API key for you so you do not need to enter it each time.
179  
180 Method parameters are passed straight through, in order, to MailChimp.
181 Thus, you do need to understand the MailChimp API as documented
182 at <http://api.mailchimp.com/> so that you will know the
183 appropriate parameters to pass to each method.
184  
185 This API has been tested with version 1.0, 1.1 and 1.2 of the API.
186  
187 =head1 NOTES
188  
189 If you find yourself getting '-32602' errors, you are probably missing
190 a required (even if empty) hash. The API documentation should be your
191 first destination to verify the validity of your parameters. For
192 example:
193  
194 # MailChimp Error -32602: server error. invalid method parameters
195 print 'fail' if $chimp->listSubscribe($lists->[0]->{id}, 'someone@somewhere.com');
196
197 # The {} is required by MailChimp to indicate that you do not want any MergeVars
198 print 'success' if $chimp->listSubscribe($lists->[0]->{id}, 'someone@somewhere.com', {}, 1);
199  
200  
201 =head1 DEPENDENCIES
202  
203 Moose
204 XMLRPC::Lite
205  
206 =head1 SEE ALSO
207  
208 XMLRPC::Lite
209 <http://www.mailchimp.com/api/1.2/>
210  
211 =head1 COPYRIGHT
212  
213 Copyright (C) 2009 Dave Pirotte. All rights reserved.
214  
215 This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
216  
217 =head1 AUTHOR
218  
219 Dave Pirotte (dpirotte@gmail.com)
220  
221 Drew Taylor (drew@drewtaylor.com)
222  
223 Ask Bjørn Hansen (ask@develooper.com)
224  
225 =cut
226  
227 1 1;
↑ Summary Chimp/AbuseReport.pm »