| 1 | package Net::SMS::RoutoMessaging; | ||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||
| 3 | 1 | $Net::SMS::RoutoMessaging::VERSION = '0.09'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Send SMS messages via the RoutoMessaging HTTP API | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use HTTP::Request::Common; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use constant { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | PROVIDER => "https://smsc5.telesignmobile.com/NewSMSsend", | |||||||||||||||||||||||||||
| 17 | TIMEOUT => 10 | ||||||||||||||||||||||||||||
| 18 | 1 | }; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=12.7
Pod
documented
| |||||||||||||||||||||||||||||
| 21 | 1 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | if (! exists $args{username} || ! exists $args{password}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $args{"username"} and exists $args{"password"}
MC/DC0%0/2
exists $args{"username"} and exists $args{"password"}
exists $args{"username"}
exists $args{"password"}
Truth table33%1/3
A and B
A= exists $args{"username"}B= exists $args{"password"}
| |||||||||||||||||||||||||||||
| 24 | 0 | Carp::croak("${class}->new() requires username and password as parameters\n"); | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 1 | my $self = \%args; | |||||||||||||||||||||||||||
| 28 | 1 | bless $self, $class; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub send_sms { | ||||||||||||||||||||||||||
|
Subroutine
send_sms: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 32 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | my $ua = LWP::UserAgent->new(); | |||||||||||||||||||||||||||
| 35 | 0 | $ua->timeout(TIMEOUT); | |||||||||||||||||||||||||||
| 36 | 0 | $ua->agent("Net::SMS::RoutoMessaging/$Net::SMS::RoutoMessaging::VERSION"); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | $args{number} =~ s{\D}{}g; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | my $url = PROVIDER; | |||||||||||||||||||||||||||
| 41 | 0 | my $resp = $ua->request(POST $url, [ user => $self->{username}, pass => $self->{password}, %args ]); | |||||||||||||||||||||||||||
| 42 | 0 | my $as_string = $resp->as_string; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if (! $resp->is_success) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | my $status = $resp->status_line; | |||||||||||||||||||||||||||
| 46 | 0 | warn "HTTP request failed: $status\n$as_string\n"; | |||||||||||||||||||||||||||
| 47 | 0 | return 0; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | my $res = $resp->content; | |||||||||||||||||||||||||||
| 51 | 0 | chomp($res); | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | my $return = 1; | |||||||||||||||||||||||||||
| 54 | 0 | ▶ | unless ($res =~ /^success/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 0 | warn "Failed: $res\n"; | |||||||||||||||||||||||||||
| 56 | 0 | $return = 0; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if ($args{long_status}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | return wantarray ? ($return, $res, status_message($res)) : $return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | else { | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | return wantarray ? ($return, $res) : $return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub status_message { | ||||||||||||||||||||||||||
|
Subroutine
status_message: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 68 | 0 | my ($status) = @_; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | my %desc = ( | |||||||||||||||||||||||||||
| 71 | success => 'sending successful', | ||||||||||||||||||||||||||||
| 72 | error => 'not all required parameters are present', | ||||||||||||||||||||||||||||
| 73 | auth_failed => 'incorrect username and/or password and/or not allowed IP address', | ||||||||||||||||||||||||||||
| 74 | wrong_number => 'the number contains non-numeric characters', | ||||||||||||||||||||||||||||
| 75 | not_allowed => 'you are not allowed to send to this number', | ||||||||||||||||||||||||||||
| 76 | too_many_numbers => 'sending to more than 10 numbers per request', | ||||||||||||||||||||||||||||
| 77 | no_message => 'the message body is empty', | ||||||||||||||||||||||||||||
| 78 | too_long => 'message is too long', | ||||||||||||||||||||||||||||
| 79 | wrong_type => 'an incorrect message type was selected', | ||||||||||||||||||||||||||||
| 80 | wrong_message => 'vCalendar or VCard contains wrong message', | ||||||||||||||||||||||||||||
| 81 | wrong_format => 'the wrong message format was selected', | ||||||||||||||||||||||||||||
| 82 | bad_operator => 'wrong operator code', | ||||||||||||||||||||||||||||
| 83 | failed => 'internal error', | ||||||||||||||||||||||||||||
| 84 | sys_error => 'the system error', | ||||||||||||||||||||||||||||
| 85 | 'No Credits Left' => 'user has no credits' | ||||||||||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | return $desc{$status} || 'unknown or empty status'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$desc{$status} || 'unknown or empty status'
MC/DC0%0/1
$desc{$status} || 'unknown or empty status'
$desc{$status}
Truth table0%0/2
A
A= $desc{$status}
| |||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 1 | 1; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | =pod | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | =head1 NAME | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | Net::SMS::RoutoMessaging - Send SMS messages via the RoutoMessaging HTTP API | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | =head1 VERSION | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | version 0.09 | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | # Create a testing sender | ||||||||||||||||||||||||||||
| 108 | my $sms = Net::SMS::RoutoMessaging->new( | ||||||||||||||||||||||||||||
| 109 | username => 'testuser', password => 'testpass' | ||||||||||||||||||||||||||||
| 110 | ); | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | # Send a message | ||||||||||||||||||||||||||||
| 113 | my ($sent, $status) = $sms->send_sms( | ||||||||||||||||||||||||||||
| 114 | message => "All your base are belong to us", | ||||||||||||||||||||||||||||
| 115 | number => '1234567890', | ||||||||||||||||||||||||||||
| 116 | ); | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | $sent will contain a true / false if the sending worked, | ||||||||||||||||||||||||||||
| 119 | $status will contain the status message from the provider. | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | # If you just want a true / false if it workes, use : | ||||||||||||||||||||||||||||
| 122 | my $sent = $sms->send_sms( | ||||||||||||||||||||||||||||
| 123 | message => "All your base are belong to us", | ||||||||||||||||||||||||||||
| 124 | number => '1234567890', | ||||||||||||||||||||||||||||
| 125 | ); | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | # If you want a better description of the status message, use the | ||||||||||||||||||||||||||||
| 128 | # long_status parameter | ||||||||||||||||||||||||||||
| 129 | my ($sent, $status, $desc) = $sms->send_sms( | ||||||||||||||||||||||||||||
| 130 | message => "All your base are belong to us", | ||||||||||||||||||||||||||||
| 131 | number => '1234567890', | ||||||||||||||||||||||||||||
| 132 | long_status => 1, | ||||||||||||||||||||||||||||
| 133 | ); | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | if ($sent) { | ||||||||||||||||||||||||||||
| 136 | # Success, message sent | ||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | else { | ||||||||||||||||||||||||||||
| 139 | # Something failed | ||||||||||||||||||||||||||||
| 140 | warn("Failed : $status"); | ||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | Perl module to send SMS messages through the HTTP API provided by RoutoMessaging | ||||||||||||||||||||||||||||
| 146 | (routomessaging.com). | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | =head1 METHODS | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | =head2 new | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | new( username => 'testuser', password => 'testpass' ) | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | Nothing fancy. You need to supply your username and password | ||||||||||||||||||||||||||||
| 155 | in the constructor, or it will complain loudly. | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | =head2 send_sms | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | send_sms(number => $phone_number, message => $message) | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | Uses the API to send a message given in C<$message> to | ||||||||||||||||||||||||||||
| 162 | the phone number given in C<$phone_number>. | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | Phone number should be given with only digits. No "+" or spaces, like this: | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | =over 4 | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | =item C<1234567890> | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | =back | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | Returns a true / false value and a status message. The message is "success" if the server has accepted your query. It does not mean that the message has been delivered. | ||||||||||||||||||||||||||||
| 173 | If the long_status argument is set, then it also returns a long description as the third value. | ||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | RoutoMessaging website, http://www.routomessaging.com/ | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | Terje Kristensen <terjek@opera.com> | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | This software is Copyright (c) 2011 by Opera Software ASA. | ||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | This is free software, licensed under: | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | The (three-clause) BSD License | ||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | =cut | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | __END__ | ||||||||||||||||||||||||||||