line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SMS::Send::NexmoUnicode; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
20555
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
4
|
1
|
|
|
1
|
|
5
|
use base 'SMS::Send::Driver'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
857
|
|
5
|
1
|
|
|
1
|
|
1074
|
use Nexmo::SMS; |
|
1
|
|
|
|
|
4452699
|
|
|
1
|
|
|
|
|
40
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
9
|
use vars qw{$VERSION}; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
54
|
|
8
|
|
|
|
|
|
|
BEGIN { |
9
|
1
|
|
|
1
|
|
411
|
$VERSION = '0.02'; |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
0
|
|
|
0
|
1
|
|
my ($class, %params) = @_; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
foreach(qw/username password type from/) { |
16
|
0
|
0
|
|
|
|
|
Carp::croak("No $_ specified") unless(defined $params{"_$_"}); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $self = bless { %params }, $class; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub send_sms { |
25
|
0
|
|
|
0
|
1
|
|
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
|
0
|
|
|
|
|
from => $self->{"_from"}, |
44
|
|
|
|
|
|
|
) or die $nexmo->errstr; |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
if ('http' eq $self->{'_proxy_type'}) { |
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
|
|
|
|
|
|
|
sub _MESSAGE { |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
0
|
|
|
my $class = ref $_[0] ? ref shift : shift; |
58
|
0
|
|
|
|
|
|
my $message = shift; |
59
|
0
|
0
|
|
|
|
|
unless ( length($message) <= 160 ) { |
60
|
0
|
|
|
|
|
|
Carp::croak("Message length limit is 160 characters"); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
return $message; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _TO { |
67
|
0
|
0
|
|
0
|
|
|
my $class = ref $_[0] ? ref shift : shift; |
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; |
78
|
|
|
|
|
|
|
__END__ |