blib/lib/SMS/Send/BR/Facilitamovel.pm

filter: Statementstmt 52.6% 20 / 38 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod 100% 2 / 2 totaltotal 45.1% 28 / 62 CC 9 SCAR 30.5
CC
9
Cov
38%
send_sms
42.0
new
20.0
BEGIN
1.0
CRAP 21.1
↑ Summary
1 package SMS::Send::BR::Facilitamovel;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 $SMS::Send::BR::Facilitamovel::VERSION = '0.03';
7  
8 # ABSTRACT: SMS::Send driver for the Facilita Movel SMS service
9  
10 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use URI::Escape qw( uri_escape );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use base 'SMS::Send::Driver';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
17 0 my ($class, %args) = @_;
18 0 my $self = \%args;
19  
20 $self->{$_}
21 or croak "$_ missing"
22 0 ▶ for qw( _login _password );
Branch: 1 branch
BranchTrueFalseTotal
$self->{$_} or croak("$_ missing") 0 0 0
23  
24 0 $self->{_http} = HTTP::Tiny->new();
25  
26 0 ▶ $self->{_verbose} = 0 unless exists $self->{_verbose};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_verbose"} 0 0 0
27  
28 0 return bless $self, $class;
29 }
30  
31 0 ▶sub send_sms {
Subroutine send_sms: not called CC=6 SCAR=37.4
Pod documented
32 0 my ($self, %args) = @_;
33  
34 # remove leading +
35 0 ( my $recipient = $args{to} ) =~ s/^\+//;
36  
37 0 my $message = $args{text};
38  
39 my $response = $self->{_http}->post_form(
40 'https://www.facilitamovel.com.br/api/simpleSend.ft',
41 {
42 user => $self->{_login},
43 password => $self->{_password},
44 0 destinatario => $recipient,
45 msg => $message,
46 },
47 );
48  
49 # Fatal error
50 croak $response->{content}
51 0 ▶ unless $response->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $response->{"success"} 0 0 0
52  
53 # If the POST succeeds we get the status of the operation in the
54 # response content as a numeric ID, a message, and optional
55 # information. All fields are separated by semicolons.
56 0 ▶ if (my ($sid, $sinfo) = split /;/, $response->{content}, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = split(/;/, $response->{"content"}, 2)) 0 0 0
57 0 ▶ if ($sid < 5) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sid < 5) { } 0 0 0
58 # All sids less than 5 signal errors
59 0 ▶ warn "send_sms failed: $sid;$sinfo" if $args{_verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"_verbose"} 0 0 0
60 0 return 0;
61 } else {
62 0 ▶ warn "send_sms succeeded: $sid;$sinfo" if $args{_verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"_verbose"} 0 0 0
63 0 return 1;
64 }
65 }
66  
67 0 croak "Can't parse response from Facilitamovel API";
68 }
69  
70 1 1;
71  
72 __END__
↑ Summary