| 1 | package SMS::Send::VoIP::MS; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use JSON::XS qw{decode_json}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use base qw{SMS::Send::Driver::WebService}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||
| 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=8005550123 | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | use SMS::Send; | ||||||||||||||||||||||||||||
| 24 | my $sms = SMS::Send->new('VoIP::MS'); | ||||||||||||||||||||||||||||
| 25 | my $success = $sms->send_sms(text=> 'Hello World!', to =>'+17035550123'); | ||||||||||||||||||||||||||||
| 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 =>'+17035550123'); | ||||||||||||||||||||||||||||
| 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 =>'+17035550123'); | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | =cut | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub send_sms { | ||||||||||||||||||||||||||
|
Subroutine
send_sms: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 47 | 0 | my %argv = @_; | |||||||||||||||||||||||||||
| 48 | 0 | ▶ | my $to = $argv{'to'} or die('Error: to propoerty required'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | my $text = defined($argv{'text'}) ? $argv{'text'} : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | my $url = $self->url; #isa URI | |||||||||||||||||||||||||||
| 51 | 0 | ▶ | $url = URI->new($url) unless (ref($url) and $url->can('query_form')); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $url and $url->can("query_form")
MC/DC0%0/2
ref $url and $url->can("query_form")
ref $url
$url->can("query_form")
Truth table0%0/3
A and B
A= ref $urlB= $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 | message => $argv{'text'}, | |||||||||||||||||||||||||||
| 59 | ); | ||||||||||||||||||||||||||||
| 60 | 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 | my $response = $self->uat->get($url); #isa HASH from HTTP::Tiny | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | die(sprintf('HTTP Error: %s %s', $response->{'status'}, $response->{'reason'})) unless $response->{'success'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 0 | $self->{'__content'} = $response->{'content'}; | |||||||||||||||||||||||||||
| 67 | #{"status":"success","sms":40702183} | ||||||||||||||||||||||||||||
| 68 | 0 | my $data = decode_json($response->{'content'}); | |||||||||||||||||||||||||||
| 69 | 0 | $self->{'__data'} = $data; | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | return $data->{'status'} eq 'success' ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 3 | ▶ | sub did { | ||||||||||||||||||||||||||
|
Subroutine
did: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 102 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 103 | 3 | ▶ | $self->{'did'} = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 3 | ▶ | $self->{'did'} = $self->cfg_property('did') unless defined $self->{'did'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | 3 | ▶ | die('Error: property did required (Direct Inward Dialing Phone Number)') unless defined $self->{'did'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 2 | 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 | ▶ | sub _url_default {'https://voip.ms/api/v1/rest.php'}; | ||||||||||||||||||||||||||
|
Subroutine
_url_default: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | sub _protocol_default {'https'}; | ||||||||||||||||||||||||||
|
Subroutine
_protocol_default: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | sub _host_default {'voip.ms'}; | ||||||||||||||||||||||||||
|
Subroutine
_host_default: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 122 | 0 | ▶ | sub _port_default {443}; | ||||||||||||||||||||||||||
|
Subroutine
_port_default: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub _script_name_default {'/api/v1/rest.php'}; | ||||||||||||||||||||||||||
|
Subroutine
_script_name_default: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | L<VoIPms>, L<https://www.voip.ms/m/apidocs.php>, L<https://voip.ms/m/api.php> | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | Michael R. Davis, mrdvt92 | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | Copyright (C) 2024 by Michael R. Davis | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | MIT | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | =cut | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 2 | 1; | |||||||||||||||||||||||||||