File Coverage

blib/lib/SMS/Send/SMSDiscount.pm
Criterion Covered Total %
statement 47 47 100.0
branch 14 14 100.0
condition n/a
subroutine 10 10 100.0
pod 2 2 100.0
total 73 73 100.0


line stmt bran cond sub pod time code
1 1     1   1151 use strict;
  1         2  
  1         35  
2 1     1   6 use warnings;
  1         2  
  1         66  
3             package SMS::Send::SMSDiscount;
4             BEGIN {
5 1     1   38 $SMS::Send::SMSDiscount::VERSION = '1.111780';
6             }
7              
8             # ABSTRACT: SMS::Send driver to send via smsdiscount.com
9              
10              
11 1     1   28 use 5.006;
  1         3  
  1         27  
12 1     1   5 use SMS::Send::Driver;
  1         2  
  1         32  
13 1     1   5 use LWP::UserAgent;
  1         1  
  1         24  
14 1     1   933 use HTTP::Request::Common qw(POST);
  1         9767  
  1         213  
15 1     1   15 use URI::Escape;
  1         2  
  1         987  
16              
17             our @ISA = qw/SMS::Send::Driver/;
18             our %EXPORT_TAGS = ( 'all' => [ qw() ] );
19             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
20             our @EXPORT = qw();
21              
22             our $URL = 'https://www.SMSDiscount.com/myaccount/sendsms.php';
23              
24              
25             sub new {
26 4     4 1 4041 my $pkg = shift;
27 4         14 my %p = @_;
28 4 100       25 exists $p{_login} or die $pkg."->new requires _login parameter\n";
29 3 100       14 exists $p{_password} or die $pkg."->new requires _password parameter\n";
30 2 100       10 exists $p{_verbose} or $p{_verbose} = 1;
31 2         4 my $self = \%p;
32 2         5 bless $self, $pkg;
33 2         57 $self->{_ua} = LWP::UserAgent->new();
34 2         5276 return $self;
35             }
36              
37             sub send_sms {
38 5     5 1 7892 my $self = shift;
39 5         19 my %p = @_;
40 5         29 $p{to} =~ s/^\+//;
41 5         16 $p{to} =~ s/[- ]//g;
42              
43             # my $u = sprintf $URL.'?username=%s&password=%s&from=%s&to=%s&text=%s',
44             # map { uri_escape $_ } $self->{_login}, $self->{_password},
45             # $self->{_login}, '+'.$p{to}, $p{text};
46              
47 5         153 my $response = $self->{_ua}->post($URL,
48             {
49             username => $self->{_login},
50             password => $self->{_password},
51             text => $p{text},
52             to => '+'.$p{to},
53             });
54 5 100       40257 unless ($response->is_success) {
55 2         26 my $s = $response->as_string;
56 2 100       235 warn "HTTP failure: $s\n" if ($self->{_verbose});
57 2         26 return 0;
58             }
59 3         312 my $s = $response->as_string;
60 3         503 $s =~ s/\r?\n$//;
61 3         42 $s =~ s/^.*?\r?\n\r?\n//s;
62 3 100       18 unless ($s =~ m!success!i) {
63 2 100       21 warn "Failed: $s\n" if ($self->{_verbose});
64 2         375 return 0;
65             }
66 1         48 return 1;
67             }
68              
69             1;
70              
71              
72             =pod
73              
74             =head1 NAME
75              
76             SMS::Send::SMSDiscount - SMS::Send driver to send via smsdiscount.com
77              
78             =head1 VERSION
79              
80             version 1.111780
81              
82             =head1 SYNOPSIS
83              
84             # Create a testing sender
85             my $send = SMS::Send->new( 'SMSDiscount',
86             _login => 'smsdiscount username',
87             _password => 'smsdiscount password' );
88              
89             # Send a message
90             $send->send_sms(
91             text => 'Hi there',
92             to => '+61 (4) 1234 5678',
93             );
94              
95             =head1 DESCRIPTION
96              
97             SMS::Send driver for sending SMS messages with the SMS Discount
98             Software (http://www.smsdiscount.com/) service.
99              
100             =head1 METHODS
101              
102             =head2 CONSTRUCTOR
103              
104             This constructor should not be called directly. See L for
105             details.
106              
107             =head1 SEE ALSO
108              
109             SMS::Send(3), SMS::Send::Driver(3)
110              
111             SMS Discount Website: http://www.smsdiscount.com/
112              
113             =head1 AUTHOR
114              
115             Mark Hindess
116              
117             =head1 COPYRIGHT AND LICENSE
118              
119             This software is copyright (c) 2010 by Mark Hindess.
120              
121             This is free software; you can redistribute it and/or modify it under
122             the same terms as the Perl 5 programming language system itself.
123              
124             =cut
125              
126              
127             __END__