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