File Coverage

blib/lib/WWW/SMS/GsmboxUK.pm
Criterion Covered Total %
statement 12 33 36.3
branch 0 8 0.0
condition n/a
subroutine 4 6 66.6
pod 0 1 0.0
total 16 48 33.3


line stmt bran cond sub pod time code
1             #Copyright (c) 2001 Giulio Motta. All rights reserved.
2             #http://www-sms.sourceforge.net/
3             #This program is free software; you can redistribute it and/or
4             #modify it under the same terms as Perl itself.
5              
6             package WWW::SMS::GsmboxUK;
7 1     1   664 use Telephone::Number;
  1         3  
  1         221  
8             require Exporter;
9             @ISA = qw(Exporter);
10             @EXPORT = qw();
11             @EXPORT_OK = qw(@PREFIXES _send MAXLENGTH);
12              
13             @PREFIXES = (Telephone::Number->new('44', [
14             qw(370 374 378 385 401 402 403 410 411 421 441 467 468 498 585 589 772
15             780 798 802 831 836 850 860 966 973 976 4481 4624 7000 7002 7074 7624
16             7730 7765 7771 7781 7787 7866 7939 7941 7956 7957 7958 7961 7967 7970
17             7977 7979 8700 9797)
18             ], undef)
19             );
20              
21             $VERSION = '1.00';
22              
23             sub MAXLENGTH () {120} # maximum message length
24              
25             sub hnd_error {
26 0     0 0   $_ = shift;
27 0           $WWW::SMS::Error = "Failed at step $_ of module GsmboxUK.pm";
28 0           return 0;
29             }
30              
31             sub _send {
32 0     0     my $self = shift;
33              
34 1     1   6 use HTTP::Request::Common qw(GET POST);
  1         2  
  1         70  
35 1     1   5 use HTTP::Cookies;
  1         2  
  1         29  
36 1     1   5 use LWP::UserAgent;
  1         2  
  1         389  
37            
38 0 0         $self->{smstext} = substr($self->{smstext}, 0, MAXLENGTH - 1) if (length($self->{smstext})>MAXLENGTH);
39              
40 0           my $ua = LWP::UserAgent->new;
41 0           $ua->agent('Mozilla/5.0');
42 0 0         $ua->proxy('http', $self->{proxy}) if ($self->{proxy});
43 0           $ua->cookie_jar(HTTP::Cookies->new(
44             file => $self->{cookie_jar},
45             autosave => 1
46             )
47             );
48              
49             #STEP 1
50 0           my $step = 1;
51 0           my $req = POST 'http://uk.gsmbox.com/freesms/preview.gsmbox',
52             [
53             messaggio => $self->{smstext},
54             prefisso => $self->{prefix},
55             telefono => $self->{telnum},
56             pluto => 'pippo',
57             SUBMIT => 'Send'
58             ];
59              
60 0           my $file = $ua->request($req)->as_string;
61 0 0         return &hnd_error($step) unless $file =~ //i;
62 0           my $image_button = $1;
63 0           my $width_button = $2;
64 0           my $height_button = $3;
65             #STEP 1
66              
67             #STEP 2
68 0           $step++;
69 0           $req = POST 'http://uk.gsmbox.com/freesms/conf_invio.gsmbox',
70             [
71             messaggio => $self->{smstext},
72             telefono => $self->{telnum},
73             prefisso => $self->{prefix},
74             $image_button.'.x' => int(rand($width_button)),
75             $image_button.'.y' => int(rand($height_button)),
76             pluto => 'pippo',
77             ];
78              
79 0           $file = $ua->simple_request($req)->as_string;
80 0 0         return &hnd_error($step) unless $file =~ /successfully/i;
81             #STEP 2
82              
83 0           1;
84             }
85              
86             1;