line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SMS::Send::NexmoUnicode; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
30260
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
4
|
1
|
|
|
1
|
|
6
|
use base 'SMS::Send::Driver'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1019
|
|
5
|
1
|
|
|
1
|
|
1293
|
use Nexmo::SMS; |
|
1
|
|
|
|
|
149421
|
|
|
1
|
|
|
|
|
35
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
13
|
use vars qw{$VERSION}; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
54
|
|
8
|
|
|
|
|
|
|
BEGIN { |
9
|
1
|
|
|
1
|
|
1579
|
$VERSION = '0.01'; |
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
|
0
|
|
|
|
|
|
my $nexmo = Nexmo::SMS->new( |
34
|
|
|
|
|
|
|
server => 'http://rest.nexmo.com/sms/json', |
35
|
|
|
|
|
|
|
username => $self->{"_username"}, |
36
|
|
|
|
|
|
|
password => $self->{"_password"}, |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
my $sms = $nexmo->sms( |
40
|
|
|
|
|
|
|
text => $message, |
41
|
|
|
|
|
|
|
to => $recipient, |
42
|
|
|
|
|
|
|
type => $self->{"_type"}, |
43
|
|
|
|
|
|
|
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__ |