line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SMS::Send::BudgetSMS; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
70036
|
use strict; |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
65
|
|
4
|
2
|
|
|
2
|
|
12
|
use warnings FATAL => 'all'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
79
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
1457
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
91065
|
|
|
2
|
|
|
|
|
75
|
|
7
|
2
|
|
|
2
|
|
1032
|
use Number::Phone::Normalize; |
|
2
|
|
|
|
|
3998
|
|
|
2
|
|
|
|
|
124
|
|
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
16
|
use base 'SMS::Send::Driver'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
999
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
6
|
|
|
6
|
1
|
8496
|
my ( $class, %args ) = @_; |
15
|
|
|
|
|
|
|
|
16
|
6
|
100
|
100
|
|
|
40
|
unless ( $args{'_login'} && $args{'_password'} && $args{'_userid'} ) { |
|
|
|
100
|
|
|
|
|
17
|
3
|
|
|
|
|
27
|
die '_login, _password and _userid are required'; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
3
|
|
|
|
|
17
|
my $self = bless { |
21
|
|
|
|
|
|
|
_endpoint => 'https://api.budgetsms.net/sendsms/', |
22
|
|
|
|
|
|
|
_timeout => 20, |
23
|
|
|
|
|
|
|
%args |
24
|
|
|
|
|
|
|
}, $class; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
$self->{_ua} = LWP::UserAgent->new( |
27
|
|
|
|
|
|
|
agent => join( '/', $class, $VERSION ), |
28
|
|
|
|
|
|
|
timeout => $self->{_timeout} |
29
|
3
|
|
|
|
|
25
|
); |
30
|
|
|
|
|
|
|
|
31
|
3
|
|
|
|
|
3527
|
return $self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub send_sms { |
35
|
2
|
|
|
2
|
1
|
8
|
my ( $self, %args ) = @_; |
36
|
|
|
|
|
|
|
|
37
|
2
|
50
|
66
|
|
|
11
|
unless ( $args{'to'} && $args{'text'} ) { |
38
|
2
|
|
|
|
|
16
|
die 'to and text are required'; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $to_number = Number::Phone::Normalize->new( |
42
|
|
|
|
|
|
|
IntlPrefix => '+' |
43
|
0
|
|
|
|
|
|
)->intl( $args{'to'} ); |
44
|
0
|
|
|
|
|
|
$to_number =~ s/^\+//; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $res = $self->{_ua}->post( |
47
|
|
|
|
|
|
|
$self->{'_endpoint'}, |
48
|
|
|
|
|
|
|
Content => { |
49
|
|
|
|
|
|
|
username => $self->{'_login'}, # field 'username' in HTTP API |
50
|
|
|
|
|
|
|
userid => $self->{'_userid'}, |
51
|
|
|
|
|
|
|
handle => $self->{'_password'}, # field 'handle' in HTTP API |
52
|
|
|
|
|
|
|
msg => $args{'text'}, |
53
|
0
|
|
|
|
|
|
from => $args{'_from'}, |
54
|
|
|
|
|
|
|
to => $to_number, |
55
|
|
|
|
|
|
|
}, |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
0
|
0
|
|
|
|
|
return $res->decoded_content if ($res->decoded_content =~ m/^OK \d*$/); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
return 0; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=pod |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=for stopwords ACKNOWLEDGEMENTS CPAN Centre Unicode homepage |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 NAME |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
SMS::Send::BudgetSMS - SMS::Send driver to send messages via BudgetSMS, L |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 VERSION |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
version 0.04 |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 SYNOPSIS |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
use SMS::Send; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Create a sender |
82
|
|
|
|
|
|
|
my $sender = SMS::Send->new( |
83
|
|
|
|
|
|
|
'BudgetSMS', |
84
|
|
|
|
|
|
|
_login => 'budgetsms_username', |
85
|
|
|
|
|
|
|
_userid => 'budgetsms_userid', |
86
|
|
|
|
|
|
|
_password => 'budgetsms_handle', |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# Send a message |
90
|
|
|
|
|
|
|
my $sent = $sender->send_sms( |
91
|
|
|
|
|
|
|
text => 'This is a test message', |
92
|
|
|
|
|
|
|
to => '+61 (4) 1234 5678', |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
if ($sent) { |
96
|
|
|
|
|
|
|
print "Message sent ok\n"; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
else { |
99
|
|
|
|
|
|
|
print "Failed to send message\n"; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 DESCRIPTION |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
SMS::Send driver for BudgetSMS - L |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
This is not intended to be used directly, but instead called by SMS::Send (see |
107
|
|
|
|
|
|
|
synopsis above for a basic illustration, and see SMS::Send's documentation for |
108
|
|
|
|
|
|
|
further information). |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
The driver uses the BudgetSMS HTTP API mechanism. This is documented at |
111
|
|
|
|
|
|
|
L |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 METHODS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 new |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Constructor, takes argument pairs passed by SMS::Send, returns an |
118
|
|
|
|
|
|
|
SMS::Send::BudgetSMS object. See usage synopsis for example, and see SMS::Send |
119
|
|
|
|
|
|
|
documentation for further info on using SMS::Send drivers. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Additional arguments that may be passed include:- |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=over 3 |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item _userid |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
BudgetSMS userid |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item _endpoint |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
The HTTP API endpoint. Defaults to |
132
|
|
|
|
|
|
|
C |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
For development purposes, you may also use test API |
135
|
|
|
|
|
|
|
C |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item _timeout |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
The timeout in seconds for HTTP operations. Defaults to 20 seconds. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=back |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head2 send_sms |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Send the message - see SMS::Send for details. Additionally the following |
146
|
|
|
|
|
|
|
options can be given - these have the same meaning as they do in the C |
147
|
|
|
|
|
|
|
method:- |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=over 1 |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item _from |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Alphanumeric or Numeric senderid (shown as the sender of SMS) |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=back |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 INSTALLATION |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
See perlmodinstall for information and options on installing Perl modules. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 BUGS AND LIMITATIONS |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
You can make new bug reports, and view existing ones, through GitHub |
164
|
|
|
|
|
|
|
at L. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head1 AVAILABILITY |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
The project homepage is L. |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
The latest version of this module is available from the Comprehensive Perl |
171
|
|
|
|
|
|
|
Archive Network (CPAN). Visit L to find a CPAN |
172
|
|
|
|
|
|
|
site near you, or see L. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 AUTHOR |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Lari Taskula |
177
|
|
|
|
|
|
|
Hypernova Oy, L |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
This software is copyright (c) 2019 by Hypernova Oy. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
184
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=cut |