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