| 1 | package SMS::Send::BudgetSMS; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings FATAL => 'all'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Number::Phone::Normalize; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use base 'SMS::Send::Driver'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | my ( $class, %args ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 6 | ▶ | unless ( $args{'_login'} && $args{'_password'} && $args{'_userid'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$args{"_login"} and $args{"_password"} and $args{"_userid"}
$args{"_login"} and $args{"_password"}
MC/DC100%3/3
$args{"_login"} and $args{"_password"} and $args{"_userid"}
$args{"_login"}
$args{"_password"}
$args{"_userid"}
Truth table100%4/4
A and B and C
A= $args{"_login"}B= $args{"_password"}C= $args{"_userid"}
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | die '_login, _password and _userid are required'; | |||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | 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 | ); | |||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 3 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | sub send_sms { | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | my ( $self, %args ) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_sms: called CC=4 SCAR=20.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | ▶ | unless ( $args{'to'} && $args{'text'} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$args{"to"} and $args{"text"}
MC/DC0%0/2
$args{"to"} and $args{"text"}
$args{"to"}
$args{"text"}
Truth table66%2/3
A and B
A= $args{"to"}B= $args{"text"}
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | 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 | ▶ | return $res->decoded_content if ($res->decoded_content =~ m/^OK \d*$/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 2 | 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<https://www.budgetsms.net/> | ||||||||||||||||||||||||||||||||||||||||||
| 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<https://www.budgetsms.net/> | ||||||||||||||||||||||||||||||||||||||||||
| 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<https://www.budgetsms.net/sms-http-api/send-sms/> | ||||||||||||||||||||||||||||||||||||||||||
| 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<https://api.budgetsms.net/sendsms/> | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | For development purposes, you may also use test API | ||||||||||||||||||||||||||||||||||||||||||
| 135 | C<https://api.budgetsms.net/testsms/> | ||||||||||||||||||||||||||||||||||||||||||
| 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<new> | ||||||||||||||||||||||||||||||||||||||||||
| 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<https://github.com/Hypernova-Oy/SMS-Send-BudgetSMS/issues>. | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | =head1 AVAILABILITY | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | The project homepage is L<https://github.com/Hypernova-Oy/SMS-Send-BudgetSMS>. | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | The latest version of this module is available from the Comprehensive Perl | ||||||||||||||||||||||||||||||||||||||||||
| 171 | Archive Network (CPAN). Visit L<http://www.perl.com/CPAN/> to find a CPAN | ||||||||||||||||||||||||||||||||||||||||||
| 172 | site near you, or see L<https://metacpan.org/module/SMS::Send::BudgetSMS/>. | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | Lari Taskula <lari.taskula@hypernova.fi> | ||||||||||||||||||||||||||||||||||||||||||
| 177 | Hypernova Oy, L<https://www.hypernova.fi> | ||||||||||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||||||||||