line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SMS::Send::VoIP::MS; |
2
|
2
|
|
|
2
|
|
243970
|
use strict; |
|
2
|
|
|
|
|
14
|
|
|
2
|
|
|
|
|
61
|
|
3
|
2
|
|
|
2
|
|
13
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
57
|
|
4
|
2
|
|
|
2
|
|
1165
|
use URI; |
|
2
|
|
|
|
|
9937
|
|
|
2
|
|
|
|
|
95
|
|
5
|
2
|
|
|
2
|
|
1496
|
use JSON::XS qw{decode_json}; |
|
2
|
|
|
|
|
10826
|
|
|
2
|
|
|
|
|
139
|
|
6
|
2
|
|
|
2
|
|
18
|
use base qw{SMS::Send::Driver::WebService}; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1102
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
SMS::Send::VoIP::MS - SMS::Send driver for VoIP.ms Web Services |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
Configure /etc/SMS-Send.ini |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
[VoIP::MS] |
19
|
|
|
|
|
|
|
username=myuser |
20
|
|
|
|
|
|
|
password=mypass |
21
|
|
|
|
|
|
|
did=8005551212 |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use SMS::Send; |
24
|
|
|
|
|
|
|
my $sms = SMS::Send->new('VoIP::MS'); |
25
|
|
|
|
|
|
|
my $success = $sms->send_sms(text=> 'Hello World!', to =>'+17035551212'); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use SMS::Send::VoIP::MS; |
28
|
|
|
|
|
|
|
my $sms = SMS::Send::VoIP::MS->new; |
29
|
|
|
|
|
|
|
my $success = $sms->send_sms(text=> 'Hello World!', to =>'+17035551212'); |
30
|
|
|
|
|
|
|
my $json = $sms->{__content}; |
31
|
|
|
|
|
|
|
my $href = $sms->{__data}; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 DESCRIPTION |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
SMS::Send driver for VoIP.ms Web Services. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 METHODS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 send_sms |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $success = $sms->send_sms(text=> 'Hello World!', to =>'+17035551212'); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub send_sms { |
46
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
47
|
0
|
|
|
|
|
0
|
my %argv = @_; |
48
|
0
|
0
|
|
|
|
0
|
my $to = $argv{'to'} or die('Error: to propoerty required'); |
49
|
0
|
0
|
|
|
|
0
|
my $text = defined($argv{'text'}) ? $argv{'text'} : ''; |
50
|
0
|
|
|
|
|
0
|
my $url = $self->url; #isa URI |
51
|
0
|
0
|
0
|
|
|
0
|
$url = URI->new($url) unless (ref($url) and $url->can('query_form')); |
52
|
|
|
|
|
|
|
my @form = ( |
53
|
|
|
|
|
|
|
method => 'sendSMS', |
54
|
|
|
|
|
|
|
api_username => $self->username, |
55
|
|
|
|
|
|
|
api_password => $self->password, |
56
|
|
|
|
|
|
|
did => $self->did, |
57
|
|
|
|
|
|
|
dst => $argv{'to'}, |
58
|
0
|
|
|
|
|
0
|
message => $argv{'text'}, |
59
|
|
|
|
|
|
|
); |
60
|
0
|
|
|
|
|
0
|
$url->query_form(\@form); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
#https://voip.ms/api/v1/rest.php?api_username={user}&api_password={pass}&method=sendSMS&did={from_phone}&dst={to_phone}&message=hello+world |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
my $response = $self->uat->get($url); #isa HASH from HTTP::Tiny |
65
|
0
|
0
|
|
|
|
0
|
die(sprintf('HTTP Error: %s %s', $response->{'status'}, $response->{'reason'})) unless $response->{'success'}; |
66
|
0
|
|
|
|
|
0
|
$self->{'__content'} = $response->{'content'}; |
67
|
|
|
|
|
|
|
#{"status":"success","sms":40702183} |
68
|
0
|
|
|
|
|
0
|
my $data = decode_json($response->{'content'}); |
69
|
0
|
|
|
|
|
0
|
$self->{'__data'} = $data; |
70
|
0
|
0
|
|
|
|
0
|
return $data->{'status'} eq 'success' ? 1 : 0; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 PROPERTIES |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 username |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Sets and returns the username string value which is passed to the web service as "api_username" |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$sms->username("override"); |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
#see SMS::Send::Driver::WebService->username |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 password |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Sets and returns the password string value which is passed to the web service as "api_password" |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
$sms->password("override"); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=cut |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
#see SMS::Send::Driver::WebService->password |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 did |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Sets and returns the "did" string value (Direct Inward Dialing Number aka the From Phone Number) which is passed to the web service as "did". |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub did { |
102
|
3
|
|
|
3
|
1
|
8947
|
my $self = shift; |
103
|
3
|
50
|
|
|
|
14
|
$self->{'did'} = shift if @_; |
104
|
3
|
100
|
|
|
|
15
|
$self->{'did'} = $self->cfg_property('did') unless defined $self->{'did'}; |
105
|
3
|
100
|
|
|
|
110
|
die('Error: property did required (Direct Inward Dialing Phone Number)') unless defined $self->{'did'}; |
106
|
2
|
|
|
|
|
9
|
return $self->{'did'}; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 url |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Sets and returns the url for the web service. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Default: https://voip.ms/api/v1/rest.php |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
#see SMS::Send::Driver::WebService->url |
118
|
|
|
|
|
|
|
|
119
|
2
|
|
|
2
|
|
6385
|
sub _url_default {'https://voip.ms/api/v1/rest.php'}; |
120
|
0
|
|
|
0
|
|
|
sub _protocol_default {'https'}; |
121
|
0
|
|
|
0
|
|
|
sub _host_default {'voip.ms'}; |
122
|
0
|
|
|
0
|
|
|
sub _port_default {443}; |
123
|
0
|
|
|
0
|
|
|
sub _script_name_default {'/api/v1/rest.php'}; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SEE ALSO |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
L, L, L |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 AUTHOR |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Michael R. Davis, mrdvt92 |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Copyright (C) 2020 by Michael R. Davis |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
138
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.16.3 or, |
139
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
1; |