blib/lib/SMS/Send/BudgetSMS.pm

filter: Statementstmt 78.7% 26 / 33 Branchbran 37.5% 3 / 8 Conditioncond 53.3% 8 / 15 MC/DCmcdc 33.3% 3 / 9 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 66.2% 49 / 74 CC 10 SCAR 26.2
CC
10
Cov
66%
send_sms
28.5
new
4.0
BEGIN
1.0
CRAP 13.8
↑ Summary
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.05';
12  
13 6 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
14 6 my ( $class, %args ) = @_;
15  
16 6 ▶ unless ( $args{'_login'} && $args{'_password'} && $args{'_userid'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"_login"} and $args{"_password"} and $args{"_userid"}) 3 3 6
Condition100%6/6
$args{"_login"} and $args{"_password"} and $args{"_userid"}
!ll&&!rl&&r
213
$args{"_login"} and $args{"_password"}
!ll&&!rl&&r
114
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"}
ABCresult
0XX0
10X0
1100
1111
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 2 ▶sub send_sms {
Subroutine send_sms: called CC=7 SCAR=33.5
Pod documented
35 2 my ( $self, %args ) = @_;
36  
37 2 ▶ unless ( $args{'to'} && $args{'text'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"to"} and $args{"text"}) 2 0 2
Condition66%2/3
$args{"to"} and $args{"text"}
!ll&&!rl&&r
110
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"}
ABresult
0X0
100
111
38 2 die 'to and text are required';
39 }
40  
41 0 ▶ if ( !$args{'_from'} && !$self->{'_from'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"_from"} or $self->{"_from"}) 0 0 0
Condition0%0/3
$args{"_from"} or $self->{"_from"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"_from"} or $self->{"_from"}
$args{"_from"} $self->{"_from"}
Truth table0%0/3
A or B
A= $args{"_from"}B= $self->{"_from"}
ABresult
1X1
011
000
42 0 die 'SMS::Send::BudgetSMS->new() or send_sms() requires parameter _from';
43 }
44  
45 my $to_number = Number::Phone::Normalize->new(
46 IntlPrefix => '+'
47 0 )->intl( $args{'to'} );
48 0 $to_number =~ s/^\+//;
49  
50 my $res = $self->{_ua}->post(
51 $self->{'_endpoint'},
52 Content => {
53 username => $self->{'_login'}, # field 'username' in HTTP API
54 userid => $self->{'_userid'},
55 handle => $self->{'_password'}, # field 'handle' in HTTP API
56 msg => $args{'text'},
57 0 ▶ from => $args{'_from'} || $self->{'_from'},
Condition0%0/3
$args{'_from'} || $self->{'_from'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{'_from'} || $self->{'_from'}
$args{'_from'} $self->{'_from'}
Truth table0%0/3
A || B
A= $args{'_from'}B= $self->{'_from'}
ABresult
1X1
011
000
58 to => $to_number,
59 },
60 );
61  
62 0 ▶ return $res->decoded_content if ($res->decoded_content =~ m/^OK \d*$/);
Branch: 1 branch
BranchTrueFalseTotal
if $res->decoded_content =~ /^OK \d*$/ 0 0 0
63  
64 0 return 0;
65 }
66  
67 2 1;
68  
69 =pod
70  
71 =for stopwords ACKNOWLEDGEMENTS CPAN Centre Unicode homepage
72  
73 =head1 NAME
74  
75 SMS::Send::BudgetSMS - SMS::Send driver to send messages via BudgetSMS, L<https://www.budgetsms.net/>
76  
77 =head1 VERSION
78  
79 version 0.04
80  
81 =head1 SYNOPSIS
82  
83 use SMS::Send;
84  
85 # Create a sender
86 my $sender = SMS::Send->new(
87 'BudgetSMS',
88 _login => 'budgetsms_username',
89 _userid => 'budgetsms_userid',
90 _password => 'budgetsms_handle',
91 );
92  
93 # Send a message
94 my $sent = $sender->send_sms(
95 text => 'This is a test message',
96 to => '+61 (4) 1234 5678',
97 );
98  
99 if ($sent) {
100 print "Message sent ok\n";
101 }
102 else {
103 print "Failed to send message\n";
104 }
105  
106 =head1 DESCRIPTION
107  
108 SMS::Send driver for BudgetSMS - L<https://www.budgetsms.net/>
109  
110 This is not intended to be used directly, but instead called by SMS::Send (see
111 synopsis above for a basic illustration, and see SMS::Send's documentation for
112 further information).
113  
114 The driver uses the BudgetSMS HTTP API mechanism. This is documented at
115 L<https://www.budgetsms.net/sms-http-api/send-sms/>
116  
117 =head1 METHODS
118  
119 =head2 new
120  
121 Constructor, takes argument pairs passed by SMS::Send, returns an
122 SMS::Send::BudgetSMS object. See usage synopsis for example, and see SMS::Send
123 documentation for further info on using SMS::Send drivers.
124  
125 Additional arguments that may be passed include:-
126  
127 =over 3
128  
129 =item _userid
130  
131 BudgetSMS userid
132  
133 =item _endpoint
134  
135 The HTTP API endpoint. Defaults to
136 C<https://api.budgetsms.net/sendsms/>
137  
138 For development purposes, you may also use test API
139 C<https://api.budgetsms.net/testsms/>
140  
141 =item _timeout
142  
143 The timeout in seconds for HTTP operations. Defaults to 20 seconds.
144  
145 =back
146  
147 =head2 send_sms
148  
149 Send the message - see SMS::Send for details. Additionally the following
150 options can be given - these have the same meaning as they do in the C<new>
151 method:-
152  
153 =over 1
154  
155 =item _from
156  
157 Alphanumeric or Numeric senderid (shown as the sender of SMS)
158  
159 =back
160  
161 =head1 INSTALLATION
162  
163 See perlmodinstall for information and options on installing Perl modules.
164  
165 =head1 BUGS AND LIMITATIONS
166  
167 You can make new bug reports, and view existing ones, through GitHub
168 at L<https://github.com/Hypernova-Oy/SMS-Send-BudgetSMS/issues>.
169  
170 =head1 AVAILABILITY
171  
172 The project homepage is L<https://github.com/Hypernova-Oy/SMS-Send-BudgetSMS>.
173  
174 The latest version of this module is available from the Comprehensive Perl
175 Archive Network (CPAN). Visit L<http://www.perl.com/CPAN/> to find a CPAN
176 site near you, or see L<https://metacpan.org/module/SMS::Send::BudgetSMS/>.
177  
178 =head1 AUTHOR
179  
180 Lari Taskula <lari.taskula@hypernova.fi>
181 Hypernova Oy, L<https://www.hypernova.fi>
182  
183 =head1 COPYRIGHT AND LICENSE
184  
185 This software is copyright (c) 2019 by Hypernova Oy.
186  
187 This is free software; you can redistribute it and/or modify it under
188 the same terms as the Perl 5 programming language system itself.
189  
190 =cut
↑ Summary