line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Nexmo::SMS; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
50262
|
use warnings; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
185
|
|
4
|
8
|
|
|
8
|
|
30
|
use strict; |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
120
|
|
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
2524
|
use Nexmo::SMS::BinaryMessage; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
180
|
|
7
|
8
|
|
|
8
|
|
3151
|
use Nexmo::SMS::TextMessage; |
|
8
|
|
|
|
|
12
|
|
|
8
|
|
|
|
|
177
|
|
8
|
8
|
|
|
8
|
|
2700
|
use Nexmo::SMS::WAPPushMessage; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
176
|
|
9
|
|
|
|
|
|
|
|
10
|
8
|
|
|
8
|
|
2566
|
use Nexmo::SMS::GetBalance; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
330
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# ABSTRACT: Module for the Nexmo SMS API! |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.10'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my @attrs = qw(server username password);; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
for my $attr ( @attrs ) { |
21
|
8
|
|
|
8
|
|
38
|
no strict 'refs'; |
|
8
|
|
|
|
|
34
|
|
|
8
|
|
|
|
|
3480
|
|
22
|
|
|
|
|
|
|
*{ __PACKAGE__ . '::' . $attr } = sub { |
23
|
43
|
|
|
43
|
|
66
|
my ($self,$value) = @_; |
24
|
|
|
|
|
|
|
|
25
|
43
|
|
|
|
|
74
|
my $key = '__' . $attr . '__'; |
26
|
43
|
100
|
|
|
|
99
|
$self->{$key} = $value if @_ == 2; |
27
|
43
|
|
|
|
|
97
|
return $self->{$key}; |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new { |
32
|
7
|
|
|
7
|
1
|
519
|
my ($class,%param) = @_; |
33
|
|
|
|
|
|
|
|
34
|
7
|
|
|
|
|
23
|
my $self = bless {}, $class; |
35
|
|
|
|
|
|
|
|
36
|
7
|
|
100
|
|
|
29
|
$param{server} ||= 'https://rest.nexmo.com/sms/json'; |
37
|
|
|
|
|
|
|
|
38
|
7
|
|
|
|
|
23
|
for my $attr ( @attrs ) { |
39
|
21
|
100
|
|
|
|
47
|
if ( exists $param{$attr} ) { |
40
|
19
|
|
|
|
|
58
|
$self->$attr( $param{$attr} ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
7
|
|
|
|
|
24
|
return $self; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub sms { |
49
|
8
|
|
|
8
|
1
|
3822
|
my ($self,%param) = @_; |
50
|
|
|
|
|
|
|
|
51
|
8
|
|
|
|
|
35
|
my %types = ( |
52
|
|
|
|
|
|
|
text => 'Nexmo::SMS::TextMessage', |
53
|
|
|
|
|
|
|
unicode => 'Nexmo::SMS::TextMessage', |
54
|
|
|
|
|
|
|
binary => 'Nexmo::SMS::BinaryMessage', |
55
|
|
|
|
|
|
|
wappush => 'Nexmo::SMS::WAPPushMessage', |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
8
|
|
|
|
|
18
|
my $requested_type = $param{type}; |
59
|
8
|
50
|
66
|
|
|
44
|
if ( exists $param{type} and !$types{$requested_type} ) { |
60
|
0
|
|
|
|
|
0
|
$self->errstr("Type $requested_type not supported (yet)!"); |
61
|
0
|
|
|
|
|
0
|
return; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
8
|
|
100
|
|
|
31
|
my $type = $requested_type || 'text'; |
65
|
8
|
|
|
|
|
15
|
my $module = $types{$type}; |
66
|
|
|
|
|
|
|
|
67
|
8
|
100
|
|
|
|
33
|
$param{type} = $type if $type ne 'text'; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# check for needed params |
70
|
8
|
|
|
|
|
17
|
my $sub_name = 'check_needed_params'; |
71
|
8
|
|
|
|
|
73
|
my $check_sub = $module->can( $sub_name ); |
72
|
8
|
50
|
|
|
|
24
|
if ( !$check_sub ) { |
73
|
0
|
|
|
|
|
0
|
$self->errstr("$module does not know about sub $sub_name"); |
74
|
0
|
|
|
|
|
0
|
return; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
8
|
|
66
|
|
|
34
|
$param{server} ||= $self->server; |
78
|
8
|
|
66
|
|
|
34
|
$param{username} ||= $self->username; |
79
|
8
|
|
66
|
|
|
32
|
$param{password} ||= $self->password; |
80
|
|
|
|
|
|
|
|
81
|
8
|
|
|
|
|
43
|
my $params_not_ok = $module->$sub_name( %param ); |
82
|
8
|
100
|
|
|
|
23
|
if ( $params_not_ok ) { |
83
|
3
|
|
|
|
|
8
|
$self->errstr("Check params $params_not_ok"); |
84
|
3
|
|
|
|
|
10
|
return; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# create new message |
88
|
5
|
|
|
|
|
26
|
my $message = $module->new( %param ); |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# return message |
91
|
5
|
|
|
|
|
26
|
return $message; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub errstr { |
96
|
6
|
|
|
6
|
1
|
12
|
my ($self,$message) = @_; |
97
|
|
|
|
|
|
|
|
98
|
6
|
100
|
|
|
|
11
|
$self->{__errstr__} = $message if @_ == 2; |
99
|
6
|
|
|
|
|
8
|
return $self->{__errstr__}; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub get_balance { |
104
|
1
|
|
|
1
|
1
|
390
|
my ($self,%param) = @_; |
105
|
|
|
|
|
|
|
|
106
|
1
|
|
33
|
|
|
5
|
$param{server} ||= $self->server; |
107
|
1
|
|
33
|
|
|
5
|
$param{username} ||= $self->username; |
108
|
1
|
|
33
|
|
|
4
|
$param{password} ||= $self->password; |
109
|
|
|
|
|
|
|
|
110
|
1
|
|
|
|
|
7
|
my $balance = Nexmo::SMS::GetBalance->new( |
111
|
|
|
|
|
|
|
%param, |
112
|
|
|
|
|
|
|
); |
113
|
|
|
|
|
|
|
|
114
|
1
|
|
|
|
|
4
|
return $balance->get_balance; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub get_pricing { |
119
|
0
|
|
|
0
|
1
|
|
warn "not implemented yet\n"; |
120
|
0
|
|
|
|
|
|
return; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; # End of Nexmo::SMS |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
__END__ |