blib/lib/SMS/Send/Sergel/Simple/HTTP.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Build ↑ Summary
1 package SMS::Send::Sergel::Simple::HTTP;
2  
3 # ABSTRACT: SMS::Send driver for Sergel simple http service
4  
5 1 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use base 'SMS::Send::Driver';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 use strict;
9 use warnings;
10 our $VERSION = '0.01';
11  
12 sub new {
13 my ($class, %args) = @_;
14  
15 unless (
16 $args{'_login'}
17 && $args{'_password'}
18 && $args{'_source'}
19 && $args{'_serviceid'}
20 ) {
21 die << "eof";
22 $class needs hash with non empty values:
23 _serviceid: $args{_serviceid}
24 _login: $args{_login}
25 _password: $args{_password}
26 _source: $args{_source}
27 eof
28 }
29  
30 my $self = bless {%args}, $class;
31 $self->{base_url} = $args{_url} // 'https://ws1.sp247.net/smscsimplehttp';
32 return $self;
33 }
34  
35 sub send_sms {
36 my ($self, %args) = @_;
37 my $query = $self->{base_url}
38 . '?ServiceId=' . $self->{_serviceid}
39 . '&Username=' . $self->{_login}
40 . '&Password=' . $self->{_password}
41 . '&Destination=' . uri_escape($args{'to'})
42 . '&Source=' . uri_escape($self->{_source})
43 . '&Userdata=' . uri_escape($args{'text'});
44  
45 my $response = HTTP::Tiny->new->get($query);
46  
47 if ($self->{_debug}) {
48 return $response;
49 }
50  
51 if ($response->{success}) {
52 my ($resultCode, $resultDescription, $messageId) = split /;/, $response->{content};
53 my $OK_codes = {
54 1000 => 'Sent',
55 1001 => 'Delivered',
56 1005 => 'Queued',
57 };
58  
59 if (exists($OK_codes->{$resultCode})) {
60 return 1;
61 } else {
62 return 0;
63 }
64 } else {
65 return 0;
66 }
67 }
68  
69 1;
70  
71 __END__
« Build ↑ Summary