File Coverage

blib/lib/SMS/Send/AT/TMobile.pm
Criterion Covered Total %
statement 21 32 65.6
branch 1 8 12.5
condition 2 2 100.0
subroutine 7 7 100.0
pod 2 2 100.0
total 33 51 64.7


line stmt bran cond sub pod time code
1 1     1   91710 use strict;
  1         3  
  1         42  
2 1     1   5 use warnings;
  1         2  
  1         159  
3             package SMS::Send::AT::TMobile;
4             {
5             $SMS::Send::AT::TMobile::VERSION = '0.001';
6             }
7              
8             # ABSTRACT: SMS::Send driver for the T-Mobile Austria SMSC service
9              
10 1     1   7 use Carp;
  1         7  
  1         85  
11 1     1   1349 use HTTP::Tiny;
  1         83605  
  1         53  
12              
13 1     1   13 use base 'SMS::Send::Driver';
  1         2  
  1         431  
14              
15            
16             sub new {
17 4     4 1 3498 my $class = shift;
18 4         11 my $self = { @_ };
19            
20             $self->{$_}
21             or croak "$_ missing"
22 4   100     69 for qw( _login _password );
23            
24 1         5 return bless $self, $class;
25             }
26              
27             sub send_sms {
28 1     1 1 480 my ($self, %args) = @_;
29              
30 1 50       15 defined $args{_from}
31             or croak "_from missing";
32              
33 0           my $http = HTTP::Tiny->new( timeout => 3 );
34              
35             # default to numeric sender id
36 0           my $oa_ton = 1;
37 0           my $oa_npi = 1;
38             # alphanumerical sender id
39 0 0         if ( $args{_from} !~ /^\d+$/ ) {
40 0           $oa_ton = 5;
41 0           $oa_npi = 0;
42             }
43              
44 0           my $response = $http->post_form(
45             'http://213.162.67.5/cgi-bin/sendsms.fcgi',
46             [
47             id => $self->{_login},
48             passwd => $self->{_password},
49             rcpt_req => 0,
50             # sender
51             oa => $args{_from},
52             oa_ton => $oa_ton,
53             oa_npi => $oa_npi,
54             # recipient
55             da => $args{to},
56             da_ton => 1,
57             da_npi => 1,
58             text => $args{text},
59             ]
60             );
61              
62             # for example a timeout error
63 0 0         die $response->{content}
64             unless $response->{success};
65              
66             # known response messages:
67             # +OK 01 message(s) successfully sent to 4367686424320:msgid=0::
68             # -ERR 04 Currently unavailable ::
69             # -ERR 20 Unknown error ::
70 0 0         return 1
71             if $response->{content} =~ /^\+OK 01/;
72              
73 0           $@ = {
74             as_string => $response->{content},
75             };
76              
77 0           return 0;
78             }
79              
80             1;
81              
82             __END__