| 1 | package SMS::Send::NexmoUnicode; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use base 'SMS::Send::Driver'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Nexmo::SMS; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | use vars qw{$VERSION}; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | $VERSION = '0.02'; | |||||||||
| 10 | } | ||||||||||
| 11 | |||||||||||
| 12 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 13 | 0 | my ($class, %params) = @_; | |||||||||
| 14 | |||||||||||
| 15 | 0 | foreach(qw/username password type from/) { | |||||||||
| 16 | 0 | ▶ | Carp::croak("No $_ specified") unless(defined $params{"_$_"}); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | 0 | my $self = bless { %params }, $class; | |||||||||
| 20 | |||||||||||
| 21 | 0 | return $self; | |||||||||
| 22 | } | ||||||||||
| 23 | |||||||||||
| 24 | 0 | ▶ | sub send_sms { | ||||||||
|
Subroutine
send_sms: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 25 | 0 | my $self = shift; | |||||||||
| 26 | 0 | my %params = @_; | |||||||||
| 27 | 0 | my %options; | |||||||||
| 28 | |||||||||||
| 29 | # Get the message and destination | ||||||||||
| 30 | 0 | my $message = $self->_MESSAGE( $params{text} ); | |||||||||
| 31 | 0 | my $recipient = $self->_TO( delete $params{to} ); | |||||||||
| 32 | |||||||||||
| 33 | my $nexmo = Nexmo::SMS->new( | ||||||||||
| 34 | server => 'https://rest.nexmo.com/sms/json', | ||||||||||
| 35 | username => $self->{"_username"}, | ||||||||||
| 36 | 0 | password => $self->{"_password"}, | |||||||||
| 37 | ); | ||||||||||
| 38 | |||||||||||
| 39 | my $sms = $nexmo->sms( | ||||||||||
| 40 | text => $message, | ||||||||||
| 41 | to => $recipient, | ||||||||||
| 42 | type => $self->{"_type"}, | ||||||||||
| 43 | 0 | ▶ | from => $self->{"_from"}, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | ) or die $nexmo->errstr; | ||||||||||
| 45 | |||||||||||
| 46 | 0 | ▶ | if ('http' eq $self->{'_proxy_type'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 0 | $sms->user_agent->proxy(['http'], 'http://' . $self->{'_proxy_host'} . ':' . $self->{'_proxy_port'}); | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 0 | my $res = $sms->send; | |||||||||
| 51 | |||||||||||
| 52 | 0 | return $res->is_success; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | sub _MESSAGE { | ||||||||
|
Subroutine
_MESSAGE: not called CC=3 SCAR=24.8
| |||||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | my $class = ref $_[0] ? ref shift : shift; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | 0 | my $message = shift; | |||||||||
| 59 | 0 | ▶ | unless ( length($message) <= 160 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 0 | Carp::croak("Message length limit is 160 characters"); | |||||||||
| 61 | } | ||||||||||
| 62 | |||||||||||
| 63 | 0 | return $message; | |||||||||
| 64 | } | ||||||||||
| 65 | |||||||||||
| 66 | 0 | ▶ | sub _TO { | ||||||||
|
Subroutine
_TO: not called CC=2 SCAR=17.9
| |||||||||||
| 67 | 0 | ▶ | my $class = ref $_[0] ? ref shift : shift; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | 0 | my $to = shift; | |||||||||
| 69 | |||||||||||
| 70 | # International numbers need their + removed | ||||||||||
| 71 | 0 | $to =~ y/0123456789//cd; | |||||||||
| 72 | |||||||||||
| 73 | 0 | return $to; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | |||||||||||
| 77 | 1 | 1; | |||||||||
| 78 | __END__ | ||||||||||