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

filter: Statementstmt 100% 18 / 18 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 100% 24 / 24 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package SMS::Send::BR::Facilitamovel;
5  
6 $SMS::Send::BR::Facilitamovel::VERSION = '0.01';
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 sub new {
17 my $class = shift;
18 my $self = { @_ };
19
20 $self->{$_}
21 or croak "$_ missing"
22 for qw( _login _password );
23
24 return bless $self, $class;
25 }
26
27 sub send_sms {
28 my ($self, %args) = @_;
29
30 my $http = HTTP::Tiny->new(
31 default_headers => {
32
33 # to ensure the response is JSON and not the XML default
34 'accept' => 'text/html; charset=ISO-8859-1',
35 'content-type' => 'text/html; charset=ISO-8859-1',
36 },
37 timeout => 3,
38 verify_ssl => 1,
39 );
40
41 # remove leading +
42 ( my $recipient = $args{to} ) =~ s/^\+//;
43
44 my $message = $args{text};
45  
46 my $response = $http->post(
47 'https://www.facilitamovel.com.br/api/simpleSend.ft'
48 . '?user='
49 . uri_escape( $self->{_login} )
50 . '&password='
51 . uri_escape( $self->{_password} )
52 . '&destinatario='
53 . uri_escape( $recipient )
54 . '&msg='
55 . uri_escape( $message )
56 );
57
58 # for example a timeout error
59 die $response->{content}
60 unless $response->{success};
61
62 my $response_message = $response->{content};
63
64 return 1
65 if $response_message->{statusCode} =~ /^6\d\d/;
66
67 $@ = $response_message;
68
69 return 0;
70 }
71
72 1;
↑ Summary