File Coverage

blib/lib/SMS/Send/US/TMobile.pm
Criterion Covered Total %
statement 21 38 55.2
branch 0 10 0.0
condition 0 6 0.0
subroutine 7 9 77.7
pod 2 2 100.0
total 30 65 46.1


line stmt bran cond sub pod time code
1             package SMS::Send::US::TMobile;
2              
3 1     1   32701 use warnings;
  1         3  
  1         29  
4 1     1   6 use strict;
  1         2  
  1         33  
5 1     1   6 use Carp;
  1         5  
  1         91  
6              
7 1     1   842 use version; our $VERSION = qv('0.0.3');
  1         2729  
  1         6  
8              
9             # use LWP::UserAgent;
10 1     1   897 use URI::Escape;
  1         1713  
  1         70  
11 1     1   1572 use Net::SSLeay;
  1         21367  
  1         87  
12 1     1   10 use base 'SMS::Send::Driver';
  1         2  
  1         958  
13              
14             sub new {
15 0     0 1   return bless {}, shift;
16             }
17              
18             sub send_sms {
19 0     0 1   my ($self, %args) = @_;
20 0           my $url = 'https://web.mms.msg.t-mobile.com/smsportal/index.html'; # ?act=smsc&locale=en';
21            
22 0   0       my %params = (
      0        
      0        
23             'act' => 'smsc',
24             'locale' => 'en',
25             # 'trackResponses' => 'No',
26             # 'Send.x' => 'Yes',
27             # 'DOMAIN_NAME' => '@tmomail.com',
28             'receiver' => $args{'to'} || '', # To: maxlength 10 digits
29             'sender' => $args{'_from'} || '', # From: prepended to 'text', seperated by '/'
30             'text' => $args{'text'} || '', # message 'text'
31             'msgTermsUse' => 1,
32             'Send' => 1,
33             );
34              
35             # cleanup
36 0           $params{'receiver'} =~ s{\D}{}g; # remove non-digits
37            
38             # validate
39 0 0         croak q{'_from' must be specified} if !$params{'sender'};
40 0 0         croak q{'to' must contain ten digits} if length $params{'receiver'} != 10;
41 0 0         croak q{'_from' and 'text' combined must not be more than 159 characters}
42             if length( $params{'sender'} ) + length( $params{'text'} ) > 159;
43            
44             # send away
45 0           my $uri = join( '&', map { $_ . '=' . uri_escape( $params{ $_ } ) } keys %params );
  0            
46            
47             # my $ua = LWP::UserAgent->new;
48             # my $req = HTTP::Request->new( 'POST' => $url );
49             # $req->content_type('application/x-www-form-urlencoded');
50             # $req->content( $uri );
51             # my $res = $ua->request($req);
52              
53             # must match $url above:
54 0           my ($content, $response, %reply_headers) = Net::SSLeay::post_https(
55             'web.mms.msg.t-mobile.com',
56             443,
57             '/smsportal/index.html',
58             '',
59             Net::SSLeay::make_form(%params),
60             );
61              
62 0 0         if ( $content ) { # if( $res->is_success ) {
63 0 0         return 1 if $content =~ m{Your message has been delivered}; # if $res->as_string =~ m{Your message has been delivered};
64             # eval { die $res->as_string };
65 0           $@ = {
66             'args' => \%args,
67             # essencially useless info at this point: 'caller' => [ caller() ],
68             'url' => $url,
69             'content' => $uri,
70             'is_success' => 1,
71             'as_string' => $response, # $res->as_string,
72             };
73 0           return 0; # bah! this is not cool but required or you get 'Driver did not return a result'
74             }
75             else {
76             # eval { die $res->as_string };
77 0           $@ = {
78             'args' => \%args,
79             # essencially useless info at this point: 'caller' => [ caller() ],
80             'url' => $url,
81             'content' => $uri,
82             'is_success' => 0,
83             'as_string' => $response, # $res->as_string,
84             };
85 0           return 0; # bah! this is not cool but required or you get 'Driver did not return a result'
86             }
87             }
88              
89             1;
90              
91             __END__