ConstantContact/Campaign.pm

filter: Statementstmt 24.8% 36 / 145 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 66.6% 10 / 15 Podpod 0.0% 0 / 5 totaltotal 21.6% 46 / 213 CC 25 SCAR 41.1
CC
25
Cov
19%
events
156.0
new
42.0
create
30.0
CRAP 60.9
« ConstantContact.pm ↑ Summary ConstantContact/Contact.pm »
1 package Email::ConstantContact::Campaign;
2
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use HTTP::Request::Common qw(POST GET);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use XML::Writer;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use POSIX qw( strftime );
Subroutine BEGIN: called CC=1 SCAR=0.0
11
12 2 ▶use Email::ConstantContact::CampaignEvent;
Subroutine BEGIN: called CC=1 SCAR=0.0
13
14 =head1 NAME
15
16 Email::ConstantContact::Campaign - Internal class to interact with ConstantContact Campaign Objects.
17
18 =head1 VERSION
19
20 Version 0.05
21
22 =cut
23
24 2 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
25
26 2 require Exporter;
27
28 2 @ISA = qw(Exporter);
29 2 @EXPORT = qw( );
30
31 2 $VERSION = '0.05';
32
33 =head1 SYNOPSIS
34
35 This module is not typically used directly, but internally by the main
36 Email::ConstantContact object for processing requests.
37
38 =cut
39
40
41 2 my @fields = qw (
42 id ArchiveStatus ArchiveURL Bounces CampaignType Clicks ContactLists Date
43 EmailContent EmailContentFormat EmailTextContent ForwardEmailLinkText Forwards
44 FromEmail FromName GreetingName GreetingSalutation GreetingString
45 IncludeForwardEmail IncludeSubscribeLink LastEditDate LastRunDate Name
46 NextRunDate Opens OptOuts OrganizationAddress1 OrganizationAddress2
47 OrganizationAddress3 OrganizationCity OrganizationCountry
48 OrganizationInternationalState OrganizationName OrganizationPostalCode
49 OrganizationState PermissionReminder ReplyToEmail Sent Status StyleSheet Subject
50 SubscribeLinkText URLS ViewAsWebageText ViewAsWebpage ViewAsWebpageLinkText
51 );
52
53 0 ▶sub new {
Subroutine new: not called CC=6 SCAR=37.4
Pod undocumented
54 0 my $class = shift;
55 0 my $ccobj = shift;
56 0 my $data = shift;
57 0 my $self = {'_cc' => $ccobj};
58
59 0 foreach my $field (@fields) {
60 0 $self->{$field} = $data->{'content'}->{'Campaign'}->{$field};
61 }
62
63 0 ▶ if (exists($data->{'link'}) && ref($data->{'link'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $data->{"link"} and ref $data->{"link"}) 0 0 0
Condition0%0/3
exists $data->{"link"} and ref $data->{"link"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $data->{"link"} and ref $data->{"link"}
exists $data->{"link"} ref $data->{"link"}
Truth table0%0/3
A and B
A= exists $data->{"link"}B= ref $data->{"link"}
ABresult
0X0
100
111
64 0 foreach my $link (@{$data->{'link'}}) {
65 0 ▶ if ($link->{'rel'} eq 'edit') {
Branch: 1 branch
BranchTrueFalseTotal
if ($link->{"rel"} eq "edit") 0 0 0
66 0 $self->{'link'} = $link->{'href'};
67 }
68 }
69 }
70
71 0 bless ($self, $class);
72 0 return $self;
73 }
74
75 0 ▶sub remove {
Subroutine remove: not called CC=2 SCAR=17.9
Pod undocumented
76 0 my $self = shift;
77
78 0 my $ua = new LWP::UserAgent;
79 0 my $url = lc($self->id);
80 0 $url =~ s/^http:/https:/;
81
82 0 my $req = new HTTP::Request('DELETE', $url);
83 0 $req->authorization_basic($self->{'_cc'}->{apikey} . '%' . $self->{'_cc'}->{username}, $self->{'_cc'}->{password});
84 0 $req->content_type('application/atom+xml');
85
86 0 my $res = $ua->request($req);
87
88 0 ▶ if ($res->code == 204) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->code == 204) { } 0 0 0
89 # Delete is successful
90 0 return 1;
91 }
92 else {
93 0 carp "Campaign removal request returned code " . $res->status_line;
94 }
95 }
96
97 0 ▶sub save {
Subroutine save: not called CC=4 SCAR=30.0
Pod undocumented
98 0 my $self = shift;
99
100 0 my $xmlcontent;
101 0 my $writer = new XML::Writer(OUTPUT => \$xmlcontent, DATA_MODE => 1, DATA_INDENT => 1);
102
103 0 $writer->startTag('entry', 'xmlns' => 'http://www.w3.org/2005/Atom');
104 0 $writer->dataElement('id', $self->{'id'});
105 0 $writer->dataElement('title', $self->{'title'}, type => 'text');
106 0 $writer->dataElement('author', '');
107 0 $writer->dataElement('updated', strftime('%Y-%m-%dT%H:%M:%SZ', gmtime()));
108 0 $writer->dataElement('summary', 'Campaign', type => 'text');
109 0 $writer->startTag('content', 'type' => 'application/vnd.ctct+xml');
110 $writer->startTag('Campaign', 'xmlns' => 'http://ws.constantcontact.com/ns/1.0/',
111 0 'id' => $self->{'id'});
112
113 0 foreach my $field (@fields) {
114 $writer->dataElement($field, $self->{$field})
115 0 ▶ if ($self->{$field});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{$field} 0 0 0
116 }
117
118 0 $writer->endTag('Campaign');
119 0 $writer->endTag('content');
120 0 $writer->endTag('entry');
121 0 $writer->end();
122
123 0 my $ua = new LWP::UserAgent;
124 0 my $url = lc($self->{'id'});
125 0 $url =~ s/^http:/https:/;
126
127 0 my $req = new HTTP::Request('PUT', $url);
128 0 $req->authorization_basic($self->{'_cc'}->{apikey} . '%' . $self->{'_cc'}->{username}, $self->{'_cc'}->{password});
129 0 $req->content_type('application/atom+xml');
130 0 $req->content($xmlcontent);
131
132 0 my $res = $ua->request($req);
133
134 0 ▶ if ($res->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success) { } 0 0 0
135 0 return 1;
136 }
137 else {
138 0 carp "Campaign update request returned code " . $res->status_line;
139 }
140
141 }
142
143 0 ▶sub create {
Subroutine create: not called CC=5 SCAR=34.0
Pod undocumented
144 0 my $self = shift;
145
146 0 my $xmlcontent;
147 0 my $writer = new XML::Writer(OUTPUT => \$xmlcontent, DATA_MODE => 1, DATA_INDENT => 1);
148
149 0 $writer->startTag('entry', 'xmlns' => 'http://www.w3.org/2005/Atom');
150 0 $writer->dataElement('id', 'data:,none');
151 0 $writer->dataElement('title', '', type => 'text');
152 0 $writer->dataElement('author', '');
153 0 $writer->dataElement('updated', strftime('%Y-%m-%dT%H:%M:%SZ', gmtime()));
154 0 $writer->dataElement('summary', 'Campaign', type => 'text');
155 0 $writer->startTag('content', 'type' => 'application/vnd.ctct+xml');
156 0 $writer->startTag('Campaign', 'xmlns' => 'http://ws.constantcontact.com/ns/1.0/');
157
158 0 foreach my $field (@fields) {
159 $writer->dataElement($field, $self->{$field})
160 0 ▶ if ($self->{$field});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{$field} 0 0 0
161 }
162
163 0 $writer->endTag('Campaign');
164 0 $writer->endTag('content');
165 0 $writer->endTag('entry');
166 0 $writer->end();
167
168 0 my $ua = new LWP::UserAgent;
169 0 my $url = lc($self->{'_cc'}->{rooturl} . '/campaigns');
170 0 my $req = new HTTP::Request('POST', $url);
171 0 $req->authorization_basic($self->{'_cc'}->{apikey} . '%' . $self->{'_cc'}->{username}, $self->{'_cc'}->{password});
172 0 $req->content_type('application/atom+xml');
173 0 $req->content($xmlcontent);
174
175 0 my $res = $ua->request($req);
176
177 0 ▶ if ($res->code == 201) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->code == 201) { } 0 0 0
178 # Create is successful
179 0 my $xs = XML::Simple->new(KeyAttr => [], ForceArray => ['link','entry']);
180 0 my $xmlobj = $xs->XMLin($res->content);
181 0 my $newcamp = new Email::ConstantContact::Campaign($self->{'_cc'}, $xmlobj);
182
183 0 $self = $newcamp;
184 0 return $newcamp;
185 }
186 else {
187 0 carp "Campaign creation request returned code " . $res->status_line;
188 0 ▶ return wantarray? (): undef;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
189 }
190 }
191
192 0 ▶sub events {
Subroutine events: not called CC=12 SCAR=50.5
Pod undocumented
193 0 my $self = shift;
194 0 my $cc = $self->{'_cc'};
195 0 my $type = shift;
196
197 0 my $ua = new LWP::UserAgent;
198 0 my @URLS = (lc($cc->{cchome} . $self->{'link'} . '/events/' . $type));
199 0 my @contacts;
200
201 0 ▶ while (my $url = shift(@URLS)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $url = shift @URLS) 0 0 0
202 0 my $req = GET($url);
203 0 $req->authorization_basic($cc->{apikey} . '%' . $cc->{username}, $cc->{password});
204 0 my $res = $ua->request($req);
205
206 0 ▶ if ($res->code == 200) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->code == 200) { } 0 0 0
207 0 my $xs = XML::Simple->new(SuppressEmpty => 'undef', KeyAttr => [], ForceArray => ['link','entry']);
208 0 my $xmlobj = $xs->XMLin($res->content);
209
210 0 ▶ if (defined($xmlobj->{'entry'}) && ref($xmlobj->{'entry'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $xmlobj->{"entry"} and ref $xmlobj->{"entry"}) 0 0 0
Condition0%0/3
defined $xmlobj->{"entry"} and ref $xmlobj->{"entry"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $xmlobj->{"entry"} and ref $xmlobj->{"entry"}
defined $xmlobj->{"entry"} ref $xmlobj->{"entry"}
Truth table0%0/3
A and B
A= defined $xmlobj->{"entry"}B= ref $xmlobj->{"entry"}
ABresult
0X0
100
111
211 0 foreach my $subobj (@{$xmlobj->{'entry'}}) {
212 0 push (@contacts, new Email::ConstantContact::CampaignEvent($cc, $subobj));
213 }
214 0 ▶ if (defined($xmlobj->{'link'}) && ref($xmlobj->{'link'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $xmlobj->{"link"} and ref $xmlobj->{"link"}) 0 0 0
Condition0%0/3
defined $xmlobj->{"link"} and ref $xmlobj->{"link"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $xmlobj->{"link"} and ref $xmlobj->{"link"}
defined $xmlobj->{"link"} ref $xmlobj->{"link"}
Truth table0%0/3
A and B
A= defined $xmlobj->{"link"}B= ref $xmlobj->{"link"}
ABresult
0X0
100
111
215 0 foreach my $subobj (@{$xmlobj->{'link'}}) {
216 0 ▶ if ($subobj->{'rel'} && ($subobj->{'rel'} eq "next")) {
Branch: 1 branch
BranchTrueFalseTotal
if ($subobj->{"rel"} and $subobj->{"rel"} eq "next") 0 0 0
Condition0%0/3
$subobj->{"rel"} and $subobj->{"rel"} eq "next"
!ll&&!rl&&r
000
MC/DC0%0/2
$subobj->{"rel"} and $subobj->{"rel"} eq "next"
$subobj->{"rel"} $subobj->{"rel"} eq "next"
Truth table0%0/3
A and B
A= $subobj->{"rel"}B= $subobj->{"rel"} eq "next"
ABresult
0X0
100
111
217 0 push (@URLS, $cc->{cchome} . $subobj->{'href'});
218 }
219 }
220 }
221 }
222 }
223 else {
224 0 carp "Campaign Events request returned code " . $res->status_line;
225 0 ▶ return wantarray? (): undef;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
226 }
227 }
228 0 return @contacts;
229 }
230
231
232 =head1 AUTHOR
233
234 Adam Rich, C<< <arich at cpan.org> >>
235
236 =head1 BUGS
237
238 Please report any bugs or feature requests to C<bug-email-constantcontact at rt.cpan.org>, or through
239 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Email-ConstantContact>. I will be notified, and then you'll
240 automatically be notified of progress on your bug as I make changes.
241
242
243
244
245 =head1 SUPPORT
246
247 You can find documentation for this module with the perldoc command.
248
249 perldoc Email::ConstantContact::Campaign
250
251
252 You can also look for information at:
253
254 =over 4
255
256 =item * RT: CPAN's request tracker
257
258 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Email-ConstantContact>
259
260 =item * AnnoCPAN: Annotated CPAN documentation
261
262 L<http://annocpan.org/dist/Email-ConstantContact>
263
264 =item * CPAN Ratings
265
266 L<http://cpanratings.perl.org/d/Email-ConstantContact>
267
268 =item * Search CPAN
269
270 L<http://search.cpan.org/dist/Email-ConstantContact/>
271
272 =back
273
274
275 =head1 ACKNOWLEDGEMENTS
276
277
278 =head1 COPYRIGHT & LICENSE
279
280 Copyright 2009-2011 Adam Rich, all rights reserved.
281
282 This program is free software; you can redistribute it and/or modify it
283 under the same terms as Perl itself.
284
285
286 =cut
287
288 2 1; # End of Email::ConstantContact::Campaign
« ConstantContact.pm ↑ Summary ConstantContact/Contact.pm »