| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Net::SMS::ASPSMS; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 28723 | use warnings; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 30 |  | 
| 4 | 1 |  |  | 1 |  | 5 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 29 |  | 
| 5 | 1 |  |  | 1 |  | 4 | use Carp; | 
|  | 1 |  |  |  |  | 6 |  | 
|  | 1 |  |  |  |  | 119 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 1 |  |  | 1 |  | 1056 | use LWP::UserAgent; | 
|  | 1 |  |  |  |  | 110256 |  | 
|  | 1 |  |  |  |  | 41 |  | 
| 8 | 1 |  |  | 1 |  | 840 | use Net::SMS::ASPSMS::XML; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 30 |  | 
| 9 | 1 |  |  | 1 |  | 524 | use XML::DOM; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | use Encode qw(decode encode); | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | our $VERSION = '0.1.6'; | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | use List::Util qw(shuffle); | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | my %actions = ( | 
| 17 |  |  |  |  |  |  | send_random_logo               => 'SendRandomLogo', | 
| 18 |  |  |  |  |  |  | send_text_sms                  => 'SendTextSMS', | 
| 19 |  |  |  |  |  |  | send_picture_message           => 'SendPictureMessage', | 
| 20 |  |  |  |  |  |  | send_logo                      => 'SendLogo', | 
| 21 |  |  |  |  |  |  | send_group_logo                => 'SendGroupLogo', | 
| 22 |  |  |  |  |  |  | send_ringtone                  => 'SendRingtone', | 
| 23 |  |  |  |  |  |  | inquire_delivery_notifications => 'InquireDeliveryNotifications', | 
| 24 |  |  |  |  |  |  | show_credits                   => 'ShowCredits', | 
| 25 |  |  |  |  |  |  | send_vcard                     => 'SendVCard', | 
| 26 |  |  |  |  |  |  | send_binary_data               => 'SendBinaryData', | 
| 27 |  |  |  |  |  |  | send_wap_push_sms              => 'SendWAPPushSMS', | 
| 28 |  |  |  |  |  |  | send_originator_unlock_code    => 'SendOriginatorUnlockCode', | 
| 29 |  |  |  |  |  |  | unlock_originator              => 'UnlockOriginator', | 
| 30 |  |  |  |  |  |  | check_originator_authorization => 'CheckOriginatorAuthorization' | 
| 31 |  |  |  |  |  |  | ); | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | sub new { | 
| 34 |  |  |  |  |  |  | my $this = shift; | 
| 35 |  |  |  |  |  |  | my $class = ref($this) || $this; | 
| 36 |  |  |  |  |  |  | my $self = {}; | 
| 37 |  |  |  |  |  |  | bless $self, $class; | 
| 38 |  |  |  |  |  |  | $self->{xml} = new Net::SMS::ASPSMS::XML(@_); | 
| 39 |  |  |  |  |  |  | $self->{result} = {}; | 
| 40 |  |  |  |  |  |  | return $self; | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | sub _send { | 
| 44 |  |  |  |  |  |  | my $self = shift; | 
| 45 |  |  |  |  |  |  | my $message = $self->{xml}->as_string; | 
| 46 |  |  |  |  |  |  | my @urls = shuffle (qw(xml1.aspsms.com:5061 xml1.aspsms.com:5098 | 
| 47 |  |  |  |  |  |  | xml2.aspsms.com:5061 xml2.aspsms.com:5098)); | 
| 48 |  |  |  |  |  |  | my $ua = LWP::UserAgent->new (timeout => 10); | 
| 49 |  |  |  |  |  |  | foreach my $url (@urls) { | 
| 50 |  |  |  |  |  |  | my $req = HTTP::Request->new(POST => "http://$url/xmlsvr.asp"); | 
| 51 |  |  |  |  |  |  | $req->content(encode("iso-8859-1", $message)); | 
| 52 |  |  |  |  |  |  | my $res = $ua->request($req); | 
| 53 |  |  |  |  |  |  | if ($res->is_success) { | 
| 54 |  |  |  |  |  |  | $self->{status_line} = $res->status_line; | 
| 55 |  |  |  |  |  |  | $self->{result} = {}; | 
| 56 |  |  |  |  |  |  | my $parser = new XML::DOM::Parser; | 
| 57 |  |  |  |  |  |  | my $doc = $parser->parse($res->content); | 
| 58 |  |  |  |  |  |  | my $node; | 
| 59 |  |  |  |  |  |  | foreach (qw(ErrorCode ErrorDescription CreditsUsed Credits | 
| 60 |  |  |  |  |  |  | ParserErrorCode ParserErrorDescription ParserErrorFilePos | 
| 61 |  |  |  |  |  |  | ParserErrorLine ParserErrorLinePos ParserErrorSrcText)) { | 
| 62 |  |  |  |  |  |  | if ($node = $doc->getElementsByTagName($_)->item(0)) { | 
| 63 |  |  |  |  |  |  | $self->{result}->{$_} = | 
| 64 |  |  |  |  |  |  | $node->getFirstChild->getNodeValue; | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  | } | 
| 67 |  |  |  |  |  |  | my $dn = $doc->getElementsByTagName("DeliveryNotification") | 
| 68 |  |  |  |  |  |  | ->item(0); | 
| 69 |  |  |  |  |  |  | if ($dn) { | 
| 70 |  |  |  |  |  |  | $self->{result}->{DeliveryNotification} = {}; | 
| 71 |  |  |  |  |  |  | foreach (qw(TransRefNumber DeliveryStatus SubmissionDate | 
| 72 |  |  |  |  |  |  | NotificationDate ReasonCode)) { | 
| 73 |  |  |  |  |  |  | if ($node = $dn->getElementsByTagName($_)->item(0)) { | 
| 74 |  |  |  |  |  |  | $self->{result}->{DeliveryNotification}->{$_} = | 
| 75 |  |  |  |  |  |  | $node->getFirstChild->getNodeValue; | 
| 76 |  |  |  |  |  |  | } | 
| 77 |  |  |  |  |  |  | } | 
| 78 |  |  |  |  |  |  | } | 
| 79 |  |  |  |  |  |  | last | 
| 80 |  |  |  |  |  |  | } | 
| 81 |  |  |  |  |  |  | } | 
| 82 |  |  |  |  |  |  | } | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | sub params { | 
| 85 |  |  |  |  |  |  | my $self = shift; | 
| 86 |  |  |  |  |  |  | $self->{xml}->initialize(@_); | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | sub result { | 
| 90 |  |  |  |  |  |  | my $self = shift; | 
| 91 |  |  |  |  |  |  | return $self->{result}; | 
| 92 |  |  |  |  |  |  | } | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | sub AUTOLOAD { | 
| 95 |  |  |  |  |  |  | my $self = shift or return undef; | 
| 96 |  |  |  |  |  |  | (my $method = our $AUTOLOAD) =~ s{.*::}{}; | 
| 97 |  |  |  |  |  |  | return if $method eq 'DESTROY'; | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | if (exists $actions{$method}) { | 
| 100 |  |  |  |  |  |  | $self->{xml}->initialize(@_); | 
| 101 |  |  |  |  |  |  | $self->{xml}->action($actions{$method}); | 
| 102 |  |  |  |  |  |  | $self->_send; | 
| 103 |  |  |  |  |  |  | } | 
| 104 |  |  |  |  |  |  | } | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | 1; | 
| 107 |  |  |  |  |  |  | __END__ |