| 1 | package SMS::Send::Smstrade; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | $SMS::Send::Smstrade::VERSION = '0.03'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | # ABSTRACT: A SMS::Send driver for smstrade.de | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use parent qw(SMS::Send::Driver); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =head1 NAME | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | SMS::Send::Smstrade - A SMS::Send driver for the smstrade.de service | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | =head1 VERSION | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | version 0.03 | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # create the sender object | ||||||||||||||||||||||||||||
| 26 | my $sender = SMS::Send::->new('Smstrade', | ||||||||||||||||||||||||||||
| 27 | _apikey => '123', | ||||||||||||||||||||||||||||
| 28 | _route => 'basic', | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | # send a message | ||||||||||||||||||||||||||||
| 31 | my $sent = $sender->send_sms( | ||||||||||||||||||||||||||||
| 32 | text => 'You message may use up to 160 chars', | ||||||||||||||||||||||||||||
| 33 | to' => '+49 555 4444', # always use the intl. calling prefix | ||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | if ( $sent ) { | ||||||||||||||||||||||||||||
| 37 | print "Sent message\n"; | ||||||||||||||||||||||||||||
| 38 | } else { | ||||||||||||||||||||||||||||
| 39 | print "Failed to send test message\n"; | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | L<SMS::Send::Smstrade> is an international L<SMS::Send> driver for | ||||||||||||||||||||||||||||
| 45 | the smstrade service. It is a paid service which offers very competitive | ||||||||||||||||||||||||||||
| 46 | prices. | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =head2 Preparing to use this driver | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | You need to sign-up on L<http://www.smstrade.eu> and get an API key. | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | This API key is used instead of a username and password to authenticate yourself. | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | =head2 Disclaimer | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | The authors of this driver take no responibility for any cost accured on your bill | ||||||||||||||||||||||||||||
| 57 | by using this module. | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | Using this driver will cost you money. B<YOU HAVE BEEN WARNED> | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =head1 METHODS | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =head2 new | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | # Create new sender using this driver. | ||||||||||||||||||||||||||||
| 66 | my $sender = SMS::Send::->new( | ||||||||||||||||||||||||||||
| 67 | 'Smstrade', | ||||||||||||||||||||||||||||
| 68 | _apikey => '123', | ||||||||||||||||||||||||||||
| 69 | _route => 'basic', | ||||||||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | The C<new> constructor requires at least one parameter, which should be passed | ||||||||||||||||||||||||||||
| 73 | throuh from the L<SMS::Send> constructor. | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =over | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | =item _apikey | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | The C<_apikey> param is the api key you get after signing up with smstrade. | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | =item _route | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | The C<_route> param determines how much the messages sent will cost you. | ||||||||||||||||||||||||||||
| 84 | The more expensive routes offer you more options. See L<http://www.smstrade.eu> | ||||||||||||||||||||||||||||
| 85 | for more details. Not all features of the different routes are supported right now. | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | Returns a new C<SMS::Send::Smstrade> object, or dies on error. | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | =back | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | =cut | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 95 | 0 | my %params = @_; | |||||||||||||||||||||||||||
| 96 | exists $params{_apikey} | ||||||||||||||||||||||||||||
| 97 | 0 | ▶ | or die $class."->new requires _apikey parameter\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if(exists $params{_route}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if($params{_route} !~ m/^(?:basic|gold|direct)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | die $class."->new's _route parameter takes only one of: basic, gold or direct\n"; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | } else { | ||||||||||||||||||||||||||||
| 103 | 0 | $params{_route} = 'basic'; | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | exists $params{_from} | ||||||||||||||||||||||||||||
| 106 | 0 | ▶ | or $params{_from} = 'SMS::Send::Smstrade'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | exists $params{_verbose} | ||||||||||||||||||||||||||||
| 108 | 0 | ▶ | or $params{_verbose} = 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 0 | my $self = \%params; | |||||||||||||||||||||||||||
| 110 | 0 | bless $self, $class; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | $self->{_url} = 'https://gateway.smstrade.de/'; | |||||||||||||||||||||||||||
| 113 | 0 | $self->{_ua} = LWP::UserAgent::->new(); | |||||||||||||||||||||||||||
| 114 | 0 | $self->{_ua}->agent('SMS::Send::Smstrade/0.1'); | |||||||||||||||||||||||||||
| 115 | 0 | ▶ | if($self->{_ua}->can('ssl_opts')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | 0 | $self->{_ua}->ssl_opts( verify_hostname => 0, ); | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | return $self; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =head2 responses | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | List all known response codes with their explaination. | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =cut | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | sub responses { | ||||||||||||||||||||||||||
|
Subroutine
responses: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 129 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | if(!$self->{_responses}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 0 | $self->{_responses} = $self->_init_responses(); | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | return $self->{_responses}; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 0 | ▶ | sub _init_responses { | ||||||||||||||||||||||||||
|
Subroutine
_init_responses: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 139 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | # see http://www.smstrade.de/pdf/SMS-Gateway_HTTP_API_v2_de.pdf, page 5 | ||||||||||||||||||||||||||||
| 142 | 0 | my $resp_ref = { | |||||||||||||||||||||||||||
| 143 | '10' => 'Destination Number not correct (Parameter: to)', | ||||||||||||||||||||||||||||
| 144 | '20' => 'Source Number not correct (Parameter: from)', | ||||||||||||||||||||||||||||
| 145 | '30' => 'Message not correct (Parameter: message)', | ||||||||||||||||||||||||||||
| 146 | '31' => 'Message type not correct (Parameter: messagetype)', | ||||||||||||||||||||||||||||
| 147 | '40' => 'SMS Route not correct (Parameter: route)', | ||||||||||||||||||||||||||||
| 148 | '50' => 'Identification failed (Parameter: key)', | ||||||||||||||||||||||||||||
| 149 | '60' => 'Insufficient Funds.', | ||||||||||||||||||||||||||||
| 150 | '70' => 'Destination Network not covered. Use another route.', | ||||||||||||||||||||||||||||
| 151 | '71' => 'Feature not available. Use another route.', | ||||||||||||||||||||||||||||
| 152 | '80' => 'Failed to submit to SMS-C. Use another route or contact support.', | ||||||||||||||||||||||||||||
| 153 | '100' => 'SMS successfull submitted.', | ||||||||||||||||||||||||||||
| 154 | }; | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | return $resp_ref; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | =head2 send_sms | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | Send an SMS. See L<SMS::Send> for the details. | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | =cut | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 0 | ▶ | sub send_sms { | ||||||||||||||||||||||||||
|
Subroutine
send_sms: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 166 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 167 | 0 | my %params = @_; | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | my $destination = $self->_clean_number($params{to}); | |||||||||||||||||||||||||||
| 170 | 0 | my $message = substr($params{text},0,159); | |||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | my %args = ( | ||||||||||||||||||||||||||||
| 173 | 'key' => $self->{_apikey}, | ||||||||||||||||||||||||||||
| 174 | 'message' => $message, | ||||||||||||||||||||||||||||
| 175 | 'to' => $destination, | ||||||||||||||||||||||||||||
| 176 | 'route' => $self->{_route}, | ||||||||||||||||||||||||||||
| 177 | 'from' => $self->{_from}, | ||||||||||||||||||||||||||||
| 178 | 0 | 'cost' => 1, | |||||||||||||||||||||||||||
| 179 | 'message_id' => 1, | ||||||||||||||||||||||||||||
| 180 | 'count' => 1, | ||||||||||||||||||||||||||||
| 181 | ); | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 0 | my $content = join('&', map { uri_escape($_).'='.uri_escape($args{$_}) } keys %args); | |||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 0 | my $url = $self->{_url}.'?'.$content; | |||||||||||||||||||||||||||
| 186 | 0 | my $req = HTTP::Request::->new( GET => $url, ); | |||||||||||||||||||||||||||
| 187 | 0 | my $res = $self->{_ua}->request($req); | |||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 0 | ▶ | print 'Requesting URL '.$url."\n" if $self->{_verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 0 | ▶ | if($res->is_success() && $res->content() =~ m/^100\D/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$res->is_success and $res->content =~ /^100\D/
MC/DC0%0/2
$res->is_success and $res->content =~ /^100\D/
$res->is_success
$res->content =~ /^100\D/
Truth table0%0/3
A and B
A= $res->is_successB= $res->content =~ /^100\D/
| |||||||||||||||||||||||||||||
| 192 | 0 | ▶ | print 'Sent '.$message.' to '.$destination."\n" if $self->{_verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | 0 | return 1; | |||||||||||||||||||||||||||
| 194 | } else { | ||||||||||||||||||||||||||||
| 195 | 0 | my $errstr = $res->content(); | |||||||||||||||||||||||||||
| 196 | 0 | ▶ | if($self->responses()->{$errstr}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | 0 | $errstr .= ' - '.$self->responses()->{$errstr}; | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | 0 | ▶ | warn 'Failed to send '.$message.' to '.$destination.'. Error: '.$errstr if $self->{_verbose}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | 0 | return; | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 0 | ▶ | sub _clean_number { | ||||||||||||||||||||||||||
|
Subroutine
_clean_number: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 205 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 206 | 0 | my $number = shift; | |||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | # strip all non-number chars | ||||||||||||||||||||||||||||
| 209 | 0 | $number =~ s/\D//g; | |||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | 0 | return $number; | |||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | Dominik Schulz, C<< <dominik.schulz at gauner.org> >> | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | =head1 BUGS | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | Please report any bugs or feature requests to C<bug-sms-send-smstrade at rt.cpan.org>, or through | ||||||||||||||||||||||||||||
| 221 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=SMS-Send-Smstrade>. I will be notified, and then you'll | ||||||||||||||||||||||||||||
| 222 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | perldoc SMS::Send::Smstrade | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | You can also look for information at: | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | =over 4 | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | =item * RT: CPAN's request tracker | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=SMS-Send-Smstrade> | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | L<http://annocpan.org/dist/SMS-Send-Smstrade> | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | L<http://cpanratings.perl.org/d/SMS-Send-Smstrade> | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | L<http://search.cpan.org/dist/SMS-Send-Smstrade/> | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | =back | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | Copyright 2012 Dominik Schulz. | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 261 | under the terms of either: the GNU General Public License as published | ||||||||||||||||||||||||||||
| 262 | by the Free Software Foundation; or the Artistic License. | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | See http://dev.perl.org/licenses/ for more information. | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | =cut | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 2 | 1; # End of SMS::Send::Smstrade | |||||||||||||||||||||||||||