line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SMS::MessageBird; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
90844
|
use 5.006; |
|
2
|
|
|
|
|
5
|
|
4
|
2
|
|
|
2
|
|
8
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
37
|
|
5
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
98
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
1159
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
64121
|
|
|
2
|
|
|
|
|
59
|
|
8
|
2
|
|
|
2
|
|
623
|
use JSON; |
|
2
|
|
|
|
|
8010
|
|
|
2
|
|
|
|
|
16
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
1109
|
use SMS::MessageBird::API::SMS; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
44
|
|
11
|
2
|
|
|
2
|
|
693
|
use SMS::MessageBird::API::Voice; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
43
|
|
12
|
2
|
|
|
2
|
|
710
|
use SMS::MessageBird::API::Verify; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
44
|
|
13
|
2
|
|
|
2
|
|
699
|
use SMS::MessageBird::API::HLR; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
41
|
|
14
|
2
|
|
|
2
|
|
672
|
use SMS::MessageBird::API::Balance; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
38
|
|
15
|
2
|
|
|
2
|
|
708
|
use SMS::MessageBird::API::Lookup; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
545
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 NAME |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
SMS::MessageBird - SMS sending module that uses the MessageBird gateway. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 VERSION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Version 0.03 |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 SYNOPSIS |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
This module is a Perl interface for interacting with the MessageBird SMS |
33
|
|
|
|
|
|
|
Gateway API. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
use SMS::MessageBird; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $messagebird = SMS::MessageBird->new( |
38
|
|
|
|
|
|
|
api_key => 'test_abcdefghijklmnopqrstuvwxyz', |
39
|
|
|
|
|
|
|
originator => 'Me!', # Specify here, or use the originator() method. |
40
|
|
|
|
|
|
|
); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Optional. This can be updated at any time, but only needs to be set once. |
43
|
|
|
|
|
|
|
$messagebird->originator('Me!'); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
my $result = $messagebird->sms->send( |
46
|
|
|
|
|
|
|
recipients => qw( 07123456789 ), |
47
|
|
|
|
|
|
|
message => 'This is my SMS text', # synonym for 'body' |
48
|
|
|
|
|
|
|
); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 DESCRIPTION |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
This module provides a simple Perl interface to the MessageBird JSON API. It |
53
|
|
|
|
|
|
|
deals with the JSON stuff allowing you to get back useful Perl data. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
To use this module you'll need an account with |
56
|
|
|
|
|
|
|
L. Once you have that, |
57
|
|
|
|
|
|
|
you can create an API key on your account and feed it to this module which will |
58
|
|
|
|
|
|
|
authenticate with their API using that key. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
The methods implmented acceept the paramteres as named in the MessageBird API |
61
|
|
|
|
|
|
|
documentation which can be found at the L. |
62
|
|
|
|
|
|
|
If you're using this distribution you should be familiar with the API |
63
|
|
|
|
|
|
|
documentation. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head2 API Modules |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
This distribution provides several modules which are used by the |
68
|
|
|
|
|
|
|
SMS::MessageBird object. Each module implements a section of the api. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Use of the functionality of a given module, is done via the accessor for that |
71
|
|
|
|
|
|
|
module, thus: |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $result = $messagebird->sms->send(...); |
74
|
|
|
|
|
|
|
my $balance = $messagebird->balance->get(); |
75
|
|
|
|
|
|
|
... |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head3 Available Modules |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=over |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item sms |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This is the accessor for the L module. Used for |
84
|
|
|
|
|
|
|
sending/receiving SMS messages. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item voice |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
This is the accessor for the L module. Used for |
89
|
|
|
|
|
|
|
sending/receiving Text-to-Voice messages. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item verify |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
This is the accessor for the L module. Used to |
94
|
|
|
|
|
|
|
implement the MessageBird number verification API. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=item hlr |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This is the accessor for the L module. Used to send |
99
|
|
|
|
|
|
|
Network Queries to mobile numbers. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item balance |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
This is the accessor for the L module. Used to |
104
|
|
|
|
|
|
|
retrieve your MessageBird account balance. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item lookup |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This is the accessor for the L module. Used to |
109
|
|
|
|
|
|
|
validate phone numbers, and provide optional formats for that number. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=back |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 METHODS |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head2 new (contructor) |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
In: %params - Various parameters for the API interface. |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Creates a new instance of SMS::MessageBird. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head3 Parameters |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Parmeters are passed to the contructor as a hash. Required / acceptable keys |
125
|
|
|
|
|
|
|
are as follows: |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=over |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item api_key |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Required. The MessageBird account API key used for authentication with |
132
|
|
|
|
|
|
|
MessageBird's API. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item originator |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
As per the MessageBird documentation, all sending functionality requires an |
137
|
|
|
|
|
|
|
originator. This can be set once on the SMS::MessageBird object and passed to |
138
|
|
|
|
|
|
|
all the module methods. This can be set later using the originator() mutator. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item api_url |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
If for some reason you need to use some form of local HTTP proxy / forwarder |
143
|
|
|
|
|
|
|
this parameter can be used to specifiy the alternate address. If it is omittied |
144
|
|
|
|
|
|
|
the default is MessageBird's URL I. |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=back |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub new { |
151
|
1
|
|
|
1
|
1
|
639
|
my ($package, %params) = @_; |
152
|
|
|
|
|
|
|
|
153
|
1
|
50
|
33
|
|
|
16
|
if (!%params || !exists $params{api_key} || !$params{api_key}) { |
|
|
|
33
|
|
|
|
|
154
|
0
|
|
|
|
|
0
|
warn 'No API key suppied to SMS::MessageBird contructor'; |
155
|
0
|
|
|
|
|
0
|
return undef; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
my $self = bless { |
159
|
|
|
|
|
|
|
module_data => { |
160
|
|
|
|
|
|
|
api_key => $params{api_key}, |
161
|
1
|
|
50
|
|
|
5
|
api_url => 'https://rest.messagebird.com', |
162
|
|
|
|
|
|
|
}, |
163
|
|
|
|
|
|
|
} => ($package || 'SMS::MessageBird'); |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
1
|
|
|
|
|
1
|
for my $param (qw( originator api_url )) { |
167
|
|
|
|
|
|
|
$self->{module_data}{$param} |
168
|
2
|
100
|
|
|
|
10
|
= $params{$param} if defined $params{$param}; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
# Make sure the api_url doesn't have a trailing slash. |
172
|
1
|
|
|
|
|
2
|
$self->{module_data}{api_url} =~ s{/$}{}; |
173
|
|
|
|
|
|
|
|
174
|
1
|
|
|
|
|
3
|
$self->_load_modules(); |
175
|
|
|
|
|
|
|
|
176
|
1
|
|
|
|
|
2
|
return $self; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head2 originator |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
In: $originator (optional) - New originator to set. |
183
|
|
|
|
|
|
|
Out: The currently set originator. |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Mutator for the originator parameter. This parameter is the displayed |
186
|
|
|
|
|
|
|
"From" in the SMS. It can be a phone number (including country code) or an |
187
|
|
|
|
|
|
|
alphanumeric string of up to 11 characters. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
This can be set for the lifetime of the object and used for all messages sent |
190
|
|
|
|
|
|
|
using the instance or passed individually to each call. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
You can pass the originator param to the constructor rather than use this |
193
|
|
|
|
|
|
|
mutator, but it's here in case you want to send 2 batches of SMS from differing |
194
|
|
|
|
|
|
|
originiators using the same object. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=cut |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub originator { |
199
|
1
|
|
|
1
|
1
|
916
|
my ($self, $originator) = @_; |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
# Set the new originator if one was supplied and reload all the modules |
202
|
|
|
|
|
|
|
# with the new data. |
203
|
1
|
50
|
|
|
|
4
|
if ($originator) { |
204
|
1
|
|
|
|
|
1
|
$self->{module_data}{originator} = $originator; |
205
|
1
|
|
|
|
|
2
|
$self->_load_modules(); |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
1
|
|
|
|
|
4
|
return $self->{module_data}{originator}; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=head2 api_url |
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
In: $api_url (optional) - New api_url to set. |
215
|
|
|
|
|
|
|
Out: The currently set api_url. |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Mutator for the api_ul parameter. Should some form of network relay be required |
218
|
|
|
|
|
|
|
this can be used to override the default I. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=cut |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
sub api_url { |
223
|
2
|
|
|
2
|
1
|
3
|
my ($self, $api_url) = @_; |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
# Set the new api_url if one was supplied and reload all the modules |
226
|
|
|
|
|
|
|
# with the new data. |
227
|
2
|
100
|
|
|
|
5
|
if ($api_url) { |
228
|
1
|
|
|
|
|
2
|
$api_url =~ s{/$}{}; |
229
|
1
|
|
|
|
|
2
|
$self->{module_data}{api_url} = $api_url; |
230
|
1
|
|
|
|
|
2
|
$self->_load_modules(); |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
|
233
|
2
|
|
|
|
|
7
|
return $self->{module_data}{api_url}; |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
# Internal method to load/reload the associated API modules. |
239
|
|
|
|
|
|
|
|
240
|
0
|
|
|
|
|
|
sub _load_modules { |
241
|
4
|
|
|
4
|
|
5
|
my ($self) = @_; |
242
|
|
|
|
|
|
|
|
243
|
4
|
|
|
|
|
5
|
$self->{loaded_modules} = undef; |
244
|
|
|
|
|
|
|
|
245
|
4
|
|
|
|
|
14
|
my %modules = ( |
246
|
|
|
|
|
|
|
sms => 'SMS::MessageBird::API::SMS', |
247
|
|
|
|
|
|
|
voice => 'SMS::MessageBird::API::Voice', |
248
|
|
|
|
|
|
|
verify => 'SMS::MessageBird::API::Verify', |
249
|
|
|
|
|
|
|
hlr => 'SMS::MessageBird::API::HLR', |
250
|
|
|
|
|
|
|
balance => 'SMS::MessageBird::API::Balance', |
251
|
|
|
|
|
|
|
lookup => 'SMS::MessageBird::API::Lookup', |
252
|
|
|
|
|
|
|
); |
253
|
|
|
|
|
|
|
|
254
|
2
|
|
|
2
|
|
8
|
no strict 'refs'; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
57
|
|
255
|
2
|
|
|
2
|
|
6
|
no warnings 'redefine'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
188
|
|
256
|
|
|
|
|
|
|
|
257
|
4
|
|
|
|
|
13
|
while (my ($module_name, $module) = each %modules) { |
258
|
24
|
|
|
|
|
62
|
*{"SMS::MessageBird::$module_name"} = sub { |
259
|
0
|
|
|
0
|
|
0
|
$module->new( %{ $self->{module_data} } ); |
|
0
|
|
|
|
|
0
|
|
260
|
24
|
|
|
|
|
42
|
}; |
261
|
24
|
|
|
|
|
14
|
push @{ $self->{loaded_modules} }, $module; |
|
24
|
|
|
|
|
89
|
|
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
|
264
|
2
|
|
|
2
|
|
7
|
use warnings 'redefine'; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
63
|
|
265
|
2
|
|
|
2
|
|
6
|
use strict 'refs'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
83
|
|
266
|
|
|
|
|
|
|
} |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=head1 AUTHOR |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
James Ronan, C<< >> |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=head1 BUGS |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, |
276
|
|
|
|
|
|
|
or through the web interface at L. |
277
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on your |
278
|
|
|
|
|
|
|
bug as I make changes. |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
Alternatively you can raise an issue on the source code which is available on |
281
|
|
|
|
|
|
|
L. |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
Copyright 2016 James Ronan. |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under |
288
|
|
|
|
|
|
|
the same terms as Perl itself. |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
=cut |
291
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
1; # End of SMS::MessageBird |