blib/lib/SMS/Send/Clickatell.pm

filter: Statementstmt 92.8% 39 / 42 Branchbran 70.0% 7 / 10 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 87.3% 55 / 63 CC 8 SCAR 13.5
CC
8
Cov
87%
send_sms
6.1
new
3.1
BEGIN
1.0
CRAP 3.9
↑ Summary
1 package SMS::Send::Clickatell;
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
6 =head1 NAME
7
8 SMS::Send::Clickatell - SMS::Send Clickatell Driver
9
10 =head1 VERSION
11
12 Version 0.02
13
14 =cut
15
16 2 our $VERSION = '0.02';
17
18 =head1 SYNOPSIS
19
20 # Create a testing sender
21 my $send = SMS::Send->new( 'Clickatell' );
22
23 # Send a message
24 $send->send_sms(
25 text => 'Hi there',
26 to => '+447700900999',
27 );
28
29 =head1 DESCRIPTION
30
31 SMS::Send::Clickatel is a very bare-bones driver for L<SMS::Send> for
32 the SMS gateway at www.clickatell.com. It currently supports only the
33 most basic of functionality required by the author so he could use
34 SMS::Send.
35
36 If you need more functionality, patches welcome.
37
38 =head1 AUTHOR
39
40 Brian McCauley, C<< <nobull at cpan.org> >>
41
42 =head1 BUGS
43
44 Please report any bugs or feature requests to
45 C<bug-sms-send-clickatell at rt.cpan.org>, or through the web
46 interface at
47 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SMS-Send-Clickatell>.
48 I will be notified, and then you'll automatically be notified of
49 progress on your bug as I make changes.
50
51 =head1 SUPPORT
52
53 You can find documentation for this module with the perldoc command.
54
55 perldoc SMS::Send::Clickatell
56
57
58 You can also look for information at:
59
60 =over 4
61
62 =item * RT: CPAN's request tracker
63
64 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=SMS-Send-Clickatell>
65
66 =item * AnnoCPAN: Annotated CPAN documentation
67
68 L<http://annocpan.org/dist/SMS-Send-Clickatell>
69
70 =item * CPAN Ratings
71
72 L<http://cpanratings.perl.org/d/SMS-Send-Clickatell>
73
74 =item * Search CPAN
75
76 L<http://search.cpan.org/dist/SMS-Send-Clickatell>
77
78 =back
79
80
81 =head1 ACKNOWLEDGEMENTS
82
83
84 =head1 COPYRIGHT & LICENSE
85
86 Copyright 2008 Brian McCauley, all rights reserved.
87
88 This program is free software; you can redistribute it and/or modify it
89 under the same terms as Perl itself.
90
91
92 =cut
93
94 2 ▶use base 'SMS::Send::Driver';
Subroutine BEGIN: called CC=1 SCAR=0.0
95 2 ▶use HTTP::Request::Common qw(POST);
Subroutine BEGIN: called CC=1 SCAR=0.0
96 #use Data::Dumper;
97
98 2 require LWP::UserAgent;
99
100 2 our $http_protocol;
101
102 #####################################################################
103 # Constructor
104
105 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.4
Pod documented
106 1 my $class = shift;
107 1 my %args = @_;
108 1 my $ua = LWP::UserAgent->new;
109
110 1 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
unless $SMS::Send::Clickatell::http_protocol 1 0 1
111 1 require Crypt::SSLeay;
112 0 $http_protocol = 'https';
113 } unless $http_protocol;
114
115
116 # Create the object
117 my $self = bless {
118 ua => $ua,
119 http_protocol => ( $http_protocol ||= 'http'),
120 verbose => $args{_verbose},
121 messages => [],
122 clickatell_account => [
123 api_id => $args{_api_id},
124 user => $args{_user},
125 password => $args{_password},
126 1 ▶ ],
Condition50%1/2
$SMS::Send::Clickatell::http_protocol ||= "http"
l!l
01
MC/DC0%0/1
$SMS::Send::Clickatell::http_protocol ||= "http"
$SMS::Send::Clickatell::http_protocol
Truth table50%1/2
A
A= $SMS::Send::Clickatell::http_protocol
Aresult
11
00
127 }, $class;
128
129 1 $self;
130 }
131
132 5 ▶sub send_sms {
Subroutine send_sms: called CC=6 SCAR=18.1
Pod documented
133 5 my $self = shift;
134 5 my $http_protocol = $self->{http_protocol};
135
136 5 my $ok;
137
138 5 my %message = @_;
139 5 my $to = $message{to};
140 5 ▶ $to =~ s/^(\+|00)// or
Branch: 1 branch
BranchTrueFalseTotal
$to =~ s/^(\+|00)// or die "SMS::Send should have ensured we had an international number" 5 0 5
141 die "SMS::Send should have ensured we had an international number";
142 5 $to =~ tr/ ()//d;
143 my $req = POST "$http_protocol://api.clickatell.com/http/sendmsg",
144 5 [ %{ {
145 5 ▶ @{ $self->{clickatell_account}},
Branch: 1 branch
BranchTrueFalseTotal
$message{'_from'} ? : 4 1 5
146 to => $to,
147 # Allow up to 3 SMS message fragments to be used
148 concat => 3,
149 text => $message{text},
150 5 $message{_from} ? (from => $message{_from}) : (),
151 } } ];
152
153 5 for ( 1,2 ) {
154 7 my $res = $self->{ua}->request($req);
155
156 7 ▶ if ( $self->{verbose} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"verbose"}) 0 7 7
157 0 print "Status: ",$res->status_line,"\n";
158 0 print $res->headers_as_string,"\n",$res->content,"\n";
159 }
160
161 7 $ok = $res->is_success;
162
163 # Retry proxy errors since the UHB proxy seems to generate a few
164 # isolated errors at random.
165 7 ▶ last unless $res->code == 502;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->code == 502 4 3 7
166 }
167 5 $ok;
168 }
169
170 2 1; # End of SMS::Send::Clickatell
↑ Summary