line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SMS::Send::AT::SmsAt; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
43751
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
50
|
|
4
|
2
|
|
|
2
|
|
6
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
27
|
|
5
|
2
|
|
|
2
|
|
6
|
use Carp; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
94
|
|
6
|
2
|
|
|
2
|
|
1081
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
61390
|
|
|
2
|
|
|
|
|
51
|
|
7
|
2
|
|
|
2
|
|
855
|
use XML::XPath; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use XML::Writer; |
9
|
|
|
|
|
|
|
use SMS::Send::Driver; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use version; our $VERSION = qv('0.0.5'); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use base 'SMS::Send::Driver'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
|
|
|
|
|
|
my $proto = shift; |
17
|
|
|
|
|
|
|
my $class = ref $proto || $proto; |
18
|
|
|
|
|
|
|
my $self = { @_ }; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$self->{"_$_"} or croak "no $_ specified" for qw(login password); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
return bless $self, $class; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub send_sms { |
26
|
|
|
|
|
|
|
my $self = shift; |
27
|
|
|
|
|
|
|
my %params = @_; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
croak 'no recipient specified' unless $params{to}; |
30
|
|
|
|
|
|
|
$params{to} =~ s/\A\+//; |
31
|
|
|
|
|
|
|
$params{to} =~ s/\A0/43/; # Austria as default country |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $text = unpack 'H*', $params{text} or croak 'no message specified'; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
36
|
|
|
|
|
|
|
my $message; |
37
|
|
|
|
|
|
|
my $writer = XML::Writer->new(OUTPUT => \$message, DATA_MODE => 1, DATA_INDENT => 4); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$writer->xmlDecl(); |
40
|
|
|
|
|
|
|
$writer->startTag('Request'); |
41
|
|
|
|
|
|
|
$writer->dataElement('AccountLogin', $self->{_login}, Type => 'email'); |
42
|
|
|
|
|
|
|
$writer->dataElement('AccountPass', $self->{_password}); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$writer->startTag('Message', Type => 'MTSMS'); |
45
|
|
|
|
|
|
|
$writer->startTag('Recipients'); |
46
|
|
|
|
|
|
|
$writer->dataElement('Recipient', $params{to}, Type => 'International'); |
47
|
|
|
|
|
|
|
$writer->endTag('Recipients'); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
$writer->dataElement('Text', $text, AutoSegment => 'simple'); |
50
|
|
|
|
|
|
|
$writer->endTag('Message'); |
51
|
|
|
|
|
|
|
$writer->endTag('Request'); |
52
|
|
|
|
|
|
|
$writer->end(); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $response = $ua->post('http://gateway.sms.at/xml_interface/', 'Content-type' => 'text/xml', Content => $message); |
55
|
|
|
|
|
|
|
if ($response->is_success) { |
56
|
|
|
|
|
|
|
# warn $response->content; # or whatever |
57
|
|
|
|
|
|
|
my $xp = XML::XPath->new(xml => $response->content); |
58
|
|
|
|
|
|
|
my $code = $xp->getNodeText('/Response/Code'); |
59
|
|
|
|
|
|
|
# stringify the XML::XPath::Literal object we just got for comparison |
60
|
|
|
|
|
|
|
return 1 if "$code" == 2000 or "$code" == 2001; # success |
61
|
|
|
|
|
|
|
warn $code . ': ' . $xp->getNodeText('/Response/CodeDescription'); |
62
|
|
|
|
|
|
|
return 0; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
else { |
65
|
|
|
|
|
|
|
Carp::croak($response->status_line); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
return 1; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
73
|
|
|
|
|
|
|
__END__ |