line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::SMS::CSNetworks; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
22846
|
$Net::SMS::CSNetworks::VERSION = '0.07'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Send SMS messages via the CSNetworks HTTP API |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
9
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
29
|
|
9
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
9
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
88
|
|
12
|
1
|
|
|
1
|
|
973
|
use HTTP::Request::Common; |
|
1
|
|
|
|
|
27198
|
|
|
1
|
|
|
|
|
83
|
|
13
|
1
|
|
|
1
|
|
1200
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
32016
|
|
|
1
|
|
|
|
|
39
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use constant { |
16
|
1
|
|
|
|
|
404
|
PROVIDER => "http://api.cs-networks.net:9011/bin/send", |
17
|
|
|
|
|
|
|
TIMEOUT => 10 |
18
|
1
|
|
|
1
|
|
9
|
}; |
|
1
|
|
|
|
|
3
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
1
|
|
|
1
|
1
|
468
|
my ($class, %args) = @_; |
22
|
|
|
|
|
|
|
|
23
|
1
|
50
|
33
|
|
|
10
|
if (! exists $args{username} || ! exists $args{password}) { |
24
|
0
|
|
|
|
|
0
|
Carp::croak("${class}->new() requires username and password as parameters\n"); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
3
|
my $self = \%args; |
28
|
1
|
|
|
|
|
6
|
bless $self, $class; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub send_sms { |
32
|
0
|
|
|
0
|
1
|
|
my ($self, %args) = @_; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
35
|
0
|
|
|
|
|
|
$ua->timeout(TIMEOUT); |
36
|
0
|
|
|
|
|
|
$ua->agent("Net::SMS::CSNetworks/$Net::SMS::CSNetworks::VERSION"); |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $url = PROVIDER; |
39
|
0
|
|
|
|
|
|
my $resp = $ua->request(POST $url, [ USERNAME => $self->{username}, PASSWORD => $self->{password}, %args ]); |
40
|
0
|
|
|
|
|
|
my $as_string = $resp->as_string; |
41
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
if (! $resp->is_success) { |
43
|
0
|
|
|
|
|
|
my $status = $resp->status_line; |
44
|
0
|
|
|
|
|
|
warn "HTTP request failed: $status\n"; |
45
|
0
|
|
|
|
|
|
return 0; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $res = $resp->content; |
49
|
0
|
|
|
|
|
|
chomp($res); |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $return = 1; |
52
|
0
|
|
|
|
|
|
my @dec_response = split(/\n/, $res); |
53
|
0
|
0
|
|
|
|
|
unless ($dec_response[2] =~ /OK/) { |
54
|
0
|
|
|
|
|
|
warn "Failed:" . $dec_response[2] . "s\n"; |
55
|
0
|
|
|
|
|
|
$return = 0; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
return ($dec_response[0], $dec_response[1], $dec_response[2]); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=pod |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 NAME |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Net::SMS::CSNetworks - Send SMS messages via the CSNetworks HTTP API |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 VERSION |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
version 0.07 |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 SYNOPSIS |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Create a testing sender |
82
|
|
|
|
|
|
|
my $sms = Net::SMS::CSNetworks->new( |
83
|
|
|
|
|
|
|
username => 'testuser', password => 'testpass' |
84
|
|
|
|
|
|
|
); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# Send a message |
87
|
|
|
|
|
|
|
my ($id, $status, $response) = $sms->send_sms( |
88
|
|
|
|
|
|
|
MESSAGE => "This is the test message", |
89
|
|
|
|
|
|
|
DESTADDR => '1234567890', |
90
|
|
|
|
|
|
|
); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
$id will contain a message id given by smsc, |
94
|
|
|
|
|
|
|
$status will contain numeric status code of message from the provider. |
95
|
|
|
|
|
|
|
$response will contain textual response from the provider |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 DESCRIPTION |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Perl module to send SMS messages through the HTTP API provided by CSNetworks |
102
|
|
|
|
|
|
|
(www.cs-networks.net). |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 METHODS |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 new |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
new( username => 'testuser', password => 'testpass' ) |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
You need to supply your username and password |
111
|
|
|
|
|
|
|
in the constructor, or it will complain loudly. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head2 send_sms |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
send_sms(DESTADDR => $phone_number, MESSAGE => $message, SOURCEADDR => $sender) |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Uses the API to send a message given in C<$message> to |
118
|
|
|
|
|
|
|
the phone number given in C<$phone_number>. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Phone number should be given with only digits. No "+" or spaces, like this: |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=over 4 |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item C<1234567890> |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=back |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Returns a true / false value and a status message. The message is "success" if the server has accepted your query. It does not mean that the message has been delivered. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 SEE ALSO |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
CS Networks website, http://www.cs-networks.net/ |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 AUTHOR |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
CS Network Solutions LImited |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
This software is Copyright (c) 2012 by CS Network Solutions Limited. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
This is free software, licensed under GPL |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
__END__ |