File Coverage

blib/lib/SMS/Send/TW/HiAir.pm
Criterion Covered Total %
statement 13 50 26.0
branch 0 10 0.0
condition n/a
subroutine 5 9 55.5
pod 2 2 100.0
total 20 71 28.1


line stmt bran cond sub pod time code
1             package SMS::Send::TW::HiAir;
2              
3 1     1   40303 use strict;
  1         2  
  1         43  
4 1     1   6 use base 'SMS::Send::Driver';
  1         3  
  1         980  
5 1     1   1604 use WWW::Mechanize;
  1         202800  
  1         44  
6              
7 1     1   13 use vars qw{$VERSION};
  1         1  
  1         60  
8             BEGIN {
9 1     1   617 $VERSION = '0.02';
10             }
11              
12             sub new {
13 0     0 1   my ($class, %params) = @_;
14              
15 0           foreach(qw/username password/) {
16 0 0         Carp::croak("No $_ specified") unless(defined $params{"_$_"});
17             }
18              
19 0           my $self = bless { %params }, $class;
20              
21 0           return $self;
22             }
23              
24             sub send_sms {
25 0     0 1   my $self = shift;
26 0           my %params = @_;
27 0           my $baseurl = 'http://hiair.hinet.net/hweb/hiairpost_new.jsp';
28 0           my $posturl = 'http://hiair.hinet.net/jweb/send_check2.jsp';
29 0           my $number = 0;
30              
31             # Get the message and destination
32 0           my $message = $self->_MESSAGE( $params{text} );
33 0           my $recipient = $self->_TO( delete $params{to} );
34            
35 0           my $ua = WWW::Mechanize->new(
36             agent => __PACKAGE__." v. $VERSION",
37             );
38              
39 0           $ua->agent_alias('Windows IE 6');
40            
41             # Should be ok now, right? Let's send it!
42             # Input SMS_Message, Recipients
43              
44 0           $ua->post($posturl,
45             [ 'add_name' => "0",
46             'message' => $message,
47             'tel' => $recipient,
48             'tran_type' => 'now',
49             'can' => "0",
50             'can1' => "0"]);
51              
52              
53             # Auth Login
54 0           $ua->form_name("loginform");
55 0           $ua->submit();
56              
57 0           $ua->form_name("AuthScreen");
58 0           $ua->field("aa-uid", $self->{"_username"});
59 0           $ua->field("aa-passwd", $self->{"_password"});
60 0           $ua->submit();
61              
62             # Send SMS
63 0           foreach (split(/\r|\n/, $ua->content()))
64             {
65 0 0         next unless (/window.location.replace\('/i);
66            
67 0           $_ =~ /window.location.replace\('(.+)'\)/i;
68 0           my $newurl = $1;
69 0           $ua->get($newurl);
70 0           last;
71             }
72            
73 0           return $ua->content();
74             }
75              
76             sub _MESSAGE {
77              
78 0 0   0     my $class = ref $_[0] ? ref shift : shift;
79 0           my $message = shift;
80 0 0         unless ( length($message) <= 160 ) {
81 0           Carp::croak("Message length limit is 160 characters");
82             }
83            
84 0           return $message;
85             }
86              
87             sub _TO {
88 0 0   0     my $class = ref $_[0] ? ref shift : shift;
89 0           my $to = shift;
90              
91             # International numbers need their + removed
92 0           $to =~ y/0123456789//cd;
93              
94 0           return $to;
95             }
96            
97              
98             1;
99             __END__