line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SMS::Send::Clickatell;
|
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
21783
|
use warnings;
|
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
69
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict;
|
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
266
|
|
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
|
|
|
|
|
|
|
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 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<< >>
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 BUGS
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Please report any bugs or feature requests to
|
45
|
|
|
|
|
|
|
C, or through the web
|
46
|
|
|
|
|
|
|
interface at
|
47
|
|
|
|
|
|
|
L.
|
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
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
L
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item * CPAN Ratings
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
L
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item * Search CPAN
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
L
|
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
|
|
|
2
|
|
10
|
use base 'SMS::Send::Driver';
|
|
2
|
|
|
|
|
16
|
|
|
2
|
|
|
|
|
1484
|
|
95
|
2
|
|
|
2
|
|
2211
|
use HTTP::Request::Common qw(POST);
|
|
2
|
|
|
|
|
74326
|
|
|
2
|
|
|
|
|
1188
|
|
96
|
|
|
|
|
|
|
#use Data::Dumper;
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
require LWP::UserAgent;
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
our $http_protocol;
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
#####################################################################
|
103
|
|
|
|
|
|
|
# Constructor
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub new {
|
106
|
1
|
|
|
1
|
1
|
94
|
my $class = shift;
|
107
|
1
|
|
|
|
|
6
|
my %args = @_;
|
108
|
1
|
|
|
|
|
10
|
my $ua = LWP::UserAgent->new;
|
109
|
|
|
|
|
|
|
|
110
|
1
|
50
|
|
|
|
11382
|
eval {
|
111
|
1
|
|
|
|
|
573
|
require Crypt::SSLeay;
|
112
|
0
|
|
|
|
|
0
|
$http_protocol = 'https';
|
113
|
|
|
|
|
|
|
} unless $http_protocol;
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# Create the object
|
117
|
1
|
|
50
|
|
|
32
|
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
|
|
|
|
|
|
|
],
|
127
|
|
|
|
|
|
|
}, $class;
|
128
|
|
|
|
|
|
|
|
129
|
1
|
|
|
|
|
8
|
$self;
|
130
|
|
|
|
|
|
|
}
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub send_sms {
|
133
|
5
|
|
|
5
|
1
|
11026
|
my $self = shift;
|
134
|
5
|
|
|
|
|
13
|
my $http_protocol = $self->{http_protocol};
|
135
|
|
|
|
|
|
|
|
136
|
5
|
|
|
|
|
10
|
my $ok;
|
137
|
|
|
|
|
|
|
|
138
|
5
|
|
|
|
|
15
|
my %message = @_;
|
139
|
5
|
|
|
|
|
12
|
my $to = $message{to};
|
140
|
5
|
50
|
|
|
|
43
|
$to =~ s/^(\+|00)// or
|
141
|
|
|
|
|
|
|
die "SMS::Send should have ensured we had an international number";
|
142
|
5
|
|
|
|
|
26
|
$to =~ tr/ ()//d;
|
143
|
5
|
|
|
|
|
100
|
my $req = POST "$http_protocol://api.clickatell.com/http/sendmsg",
|
144
|
5
|
|
|
|
|
14
|
[ %{ {
|
145
|
5
|
100
|
|
|
|
9
|
@{ $self->{clickatell_account}},
|
146
|
|
|
|
|
|
|
to => $to,
|
147
|
|
|
|
|
|
|
# Allow up to 3 SMS message fragments to be used
|
148
|
|
|
|
|
|
|
concat => 3,
|
149
|
|
|
|
|
|
|
text => $message{text},
|
150
|
|
|
|
|
|
|
$message{_from} ? (from => $message{_from}) : (),
|
151
|
|
|
|
|
|
|
} } ];
|
152
|
|
|
|
|
|
|
|
153
|
5
|
|
|
|
|
14503
|
for ( 1,2 ) {
|
154
|
7
|
|
|
|
|
81
|
my $res = $self->{ua}->request($req);
|
155
|
|
|
|
|
|
|
|
156
|
7
|
50
|
|
|
|
481
|
if ( $self->{verbose} ) {
|
157
|
0
|
|
|
|
|
0
|
print "Status: ",$res->status_line,"\n";
|
158
|
0
|
|
|
|
|
0
|
print $res->headers_as_string,"\n",$res->content,"\n";
|
159
|
|
|
|
|
|
|
}
|
160
|
|
|
|
|
|
|
|
161
|
7
|
|
|
|
|
27
|
$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
|
100
|
|
|
|
64
|
last unless $res->code == 502;
|
166
|
|
|
|
|
|
|
}
|
167
|
5
|
|
|
|
|
83
|
$ok;
|
168
|
|
|
|
|
|
|
}
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
1; # End of SMS::Send::Clickatell
|