File Coverage

blib/lib/SMS/Send/Sergel/Simple/HTTP.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package SMS::Send::Sergel::Simple::HTTP;
2              
3             # ABSTRACT: SMS::Send driver for Sergel simple http service
4              
5 1     1   15311 use HTTP::Tiny;
  1         36770  
  1         31  
6 1     1   416 use URI::Escape;
  1         878  
  1         55  
7 1     1   4 use base 'SMS::Send::Driver';
  1         2  
  1         1327  
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__