| 1 | package SMS::Send::UK::AA; | ||||||||||||||||||||
| 2 | { | ||||||||||||||||||||
| 3 | 2 | $SMS::Send::UK::AA::VERSION = '0.004'; | |||||||||||||||||||
| 4 | } | ||||||||||||||||||||
| 5 | # ABSTRACT: Send SMS messages using Andrews and Arnold's gateway | ||||||||||||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 2 | ▶ | use parent qw(SMS::Send::Driver); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 2 | ▶ | use Carp qw(croak); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 2 | ▶ | use LWP::UserAgent 6.00; # We need proper SSL support | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 2 | ▶ | use HTTP::Request::Common; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 2 | ▶ | use URI 1.53; # ->secure | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 2 | ▶ | use SMS::Send::UK::AA::Response; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 2 | ▶ | use constant DEFAULT_ENDPOINT => "https://sms.aa.net.uk/sms.cgi"; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 2 | my @supported_params = qw( | |||||||||||||||||||
| 19 | limit sendtime replace flash report costcentre private originator udh iccid | ||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | sub new { | ||||||||||||||||||||
| 23 | 3 | ▶ | my($class, %args) = @_; | ||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.2
Pod
documented
| |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | my $self = bless { | ||||||||||||||||||||
| 26 | _endpoint => delete $args{_endpoint} || DEFAULT_ENDPOINT, | ||||||||||||||||||||
| 27 | _username => delete $args{_login}, | ||||||||||||||||||||
| 28 | _password => delete $args{_password}, | ||||||||||||||||||||
| 29 | 3 | ▶ | }, $class; | ||||||||||||||||||
|
Condition100%2/2
delete $args{'_endpoint'} || 'https://sms.aa.net.uk/sms.cgi'
MC/DC100%1/1
delete $args{'_endpoint'} || 'https://sms.aa.net.uk/sms.cgi'
delete $args{'_endpoint'}
Truth table100%2/2
A
A= delete $args{'_endpoint'}
| |||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 3 | ▶ | my $ssl_verify = exists $args{_ssl_verify} ? delete $args{_ssl_verify} : 1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 32 | 3 | $self->{ua} = $self->_create_ua($ssl_verify); | |||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 3 | for my $param(@supported_params) { | |||||||||||||||||||
| 35 | 30 | ▶ | if(exists $args{"_" . $param}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | 0 | $self->{"_" . $param} = delete $args{"_" . $param}; | |||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | } | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 3 | ▶ | if(%args) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | 1 | croak "Unknown arguments: ", join ",", keys %args; | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 2 | return $self; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | sub send_sms { | ||||||||||||||||||||
| 48 | 3 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
send_sms: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | # send_sms params can also be set in the constructor | ||||||||||||||||||||
| 51 | 3 | my $request = _construct_request(%$self, @_); | |||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 3 | my $response = $self->{ua}->request($request); | |||||||||||||||||||
| 54 | 3 | ▶ | my $okay = $response->is_success && $response->content =~ /^OK:/m; | ||||||||||||||||||
|
Condition66%2/3
$response->is_success && $response->content =~ /^OK:/m
MC/DC50%1/2
$response->is_success && $response->content =~ /^OK:/m
$response->is_success
$response->content =~ /^OK:/m
Truth table66%2/3
A && B
A= $response->is_successB= $response->content =~ /^OK:/m
| |||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | # This is rather yuck -- the SMS::Send API is basically true/false, I could | ||||||||||||||||||||
| 57 | # just stick the error in $@ but that seems a bit untidy, so instead return a | ||||||||||||||||||||
| 58 | # magic thing that can be false but still contain a string. | ||||||||||||||||||||
| 59 | 3 | return SMS::Send::UK::AA::Response->new($okay, $response->content); | |||||||||||||||||||
| 60 | } | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | sub _create_ua { | ||||||||||||||||||||
| 63 | 3 | ▶ | my($self, $ssl_verify) = @_; | ||||||||||||||||||
|
Subroutine
_create_ua: called CC=4 SCAR=14.0
| |||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | 3 | my $ua = LWP::UserAgent->new; | |||||||||||||||||||
| 66 | 3 | $ua->env_proxy; | |||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 3 | ▶ | if(URI->new($self->{_endpoint})->secure) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 69 | 2 | require LWP::Protocol::https; | |||||||||||||||||||
| 70 | 2 | ▶ | require CACertOrg::CA if $ssl_verify; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | 2 | ▶ | $ua->ssl_opts( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | verify_hostname => $ssl_verify, | ||||||||||||||||||||
| 74 | $ssl_verify ? (SSL_ca_file => CACertOrg::CA::SSL_ca_file()) : () | ||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | 3 | return $ua; | |||||||||||||||||||
| 79 | } | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | sub _construct_request { | ||||||||||||||||||||
| 82 | 3 | ▶ | my(%params) = @_; | ||||||||||||||||||
|
Subroutine
_construct_request: called CC=4 SCAR=13.9
| |||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 3 | my $endpoint = delete $params{_endpoint}; | |||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 3 | my %data; | |||||||||||||||||||
| 87 | 3 | $data{message} = delete $params{text}; | |||||||||||||||||||
| 88 | 3 | $data{destination} = delete $params{to}; | |||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 3 | for my $name(keys %params) { | |||||||||||||||||||
| 91 | 10 | ▶ | next unless $name =~ /^_/; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 92 | 7 | $data{substr $name, 1} = $params{$name}; | |||||||||||||||||||
| 93 | } | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | 3 | ▶ | if(exists $data{iccid}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 96 | 1 | delete $data{destination}; | |||||||||||||||||||
| 97 | } | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | 3 | return POST $endpoint, \%data; | |||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | 2 | 1; | |||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | __END__ | ||||||||||||||||||||