line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Nexmo::SMS::TextMessage; |
2
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
51
|
use strict; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
331
|
|
4
|
8
|
|
|
8
|
|
46
|
use warnings; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
390
|
|
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
50
|
use Nexmo::SMS::Response; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
699
|
|
7
|
|
|
|
|
|
|
|
8
|
8
|
|
|
8
|
|
50
|
use LWP::UserAgent; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
166
|
|
9
|
8
|
|
|
8
|
|
43
|
use JSON::PP; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
1354
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# ABSTRACT: Module that respresents a text message for the Nexmo SMS API! |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my %attrs = ( |
17
|
|
|
|
|
|
|
text => 'required', |
18
|
|
|
|
|
|
|
from => 'required', |
19
|
|
|
|
|
|
|
to => 'required', |
20
|
|
|
|
|
|
|
server => 'required', |
21
|
|
|
|
|
|
|
username => 'required', |
22
|
|
|
|
|
|
|
password => 'required', |
23
|
|
|
|
|
|
|
type => 'optional', |
24
|
|
|
|
|
|
|
status_report_req => 'optional', |
25
|
|
|
|
|
|
|
client_ref => 'optional', |
26
|
|
|
|
|
|
|
network_code => 'optional', |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
for my $attr ( keys %attrs ) { |
30
|
8
|
|
|
8
|
|
45
|
no strict 'refs'; |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
6173
|
|
31
|
|
|
|
|
|
|
*{ __PACKAGE__ . '::' . $attr } = sub { |
32
|
48
|
|
|
48
|
|
76
|
my ($self,$value) = @_; |
33
|
|
|
|
|
|
|
|
34
|
48
|
|
|
|
|
100
|
my $key = '__' . $attr . '__'; |
35
|
48
|
100
|
|
|
|
141
|
$self->{$key} = $value if @_ == 2; |
36
|
48
|
|
|
|
|
209
|
return $self->{$key}; |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub new { |
42
|
3
|
|
|
3
|
1
|
16
|
my ($class,%param) = @_; |
43
|
|
|
|
|
|
|
|
44
|
3
|
|
|
|
|
11
|
my $self = bless {}, $class; |
45
|
|
|
|
|
|
|
|
46
|
3
|
|
|
|
|
14
|
for my $attr ( keys %attrs ) { |
47
|
30
|
100
|
|
|
|
76
|
if ( exists $param{$attr} ) { |
48
|
18
|
|
|
|
|
61
|
$self->$attr( $param{$attr} ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$self->user_agent( |
53
|
3
|
|
|
|
|
50
|
LWP::UserAgent->new( |
54
|
|
|
|
|
|
|
agent => 'Perl module ' . __PACKAGE__ . ' ' . $VERSION, |
55
|
|
|
|
|
|
|
), |
56
|
|
|
|
|
|
|
); |
57
|
|
|
|
|
|
|
|
58
|
3
|
|
|
|
|
22
|
return $self; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub user_agent { |
63
|
6
|
|
|
6
|
1
|
12146
|
my ($self,$ua) = @_; |
64
|
|
|
|
|
|
|
|
65
|
6
|
100
|
|
|
|
34
|
$self->{__ua__} = $ua if @_ == 2; |
66
|
6
|
|
|
|
|
19
|
return $self->{__ua__}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub errstr { |
71
|
2
|
|
|
2
|
1
|
7
|
my ($self,$message) = @_; |
72
|
|
|
|
|
|
|
|
73
|
2
|
100
|
|
|
|
8
|
$self->{__errstr__} = $message if @_ == 2; |
74
|
2
|
|
|
|
|
10
|
return $self->{__errstr__}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub send { |
79
|
3
|
|
|
3
|
1
|
1915
|
my ($self) = shift; |
80
|
|
|
|
|
|
|
|
81
|
3
|
|
|
|
|
7
|
my %optional; |
82
|
3
|
50
|
|
|
|
14
|
$optional{'client-ref'} = $self->client_ref if $self->client_ref; |
83
|
3
|
50
|
|
|
|
15
|
$optional{'status-report-req'} = $self->status_report_req if $self->status_report_req; |
84
|
3
|
50
|
|
|
|
15
|
$optional{'network-code'} = $self->network_code if $self->network_code; |
85
|
3
|
50
|
|
|
|
15
|
$optional{'type'} = $self->type if $self->type; |
86
|
|
|
|
|
|
|
|
87
|
3
|
|
|
|
|
14
|
my $response = $self->user_agent->post( |
88
|
|
|
|
|
|
|
$self->server, |
89
|
|
|
|
|
|
|
{ |
90
|
|
|
|
|
|
|
%optional, |
91
|
|
|
|
|
|
|
username => $self->username, |
92
|
|
|
|
|
|
|
password => $self->password, |
93
|
|
|
|
|
|
|
from => $self->from, |
94
|
|
|
|
|
|
|
to => $self->to, |
95
|
|
|
|
|
|
|
text => $self->text, |
96
|
|
|
|
|
|
|
}, |
97
|
|
|
|
|
|
|
); |
98
|
|
|
|
|
|
|
|
99
|
3
|
50
|
33
|
|
|
54
|
if ( !$response || !$response->is_success ) { |
100
|
0
|
|
|
|
|
0
|
$self->errstr("Request was not successful: " . $response->status_line); |
101
|
0
|
0
|
|
|
|
0
|
warn $response->content if $response; |
102
|
0
|
|
|
|
|
0
|
return; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
3
|
|
|
|
|
68
|
my $json = $response->content; |
106
|
3
|
|
|
|
|
73
|
my $response_object = Nexmo::SMS::Response->new( json => $json ); |
107
|
|
|
|
|
|
|
|
108
|
3
|
100
|
|
|
|
21
|
if ( $response_object->is_error ) { |
109
|
1
|
|
|
|
|
3
|
$self->errstr( $response_object->errstr ); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
3
|
|
|
|
|
61
|
return $response_object; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub check_needed_params { |
117
|
4
|
|
|
4
|
1
|
18
|
my ($class,%params) = @_; |
118
|
|
|
|
|
|
|
|
119
|
4
|
|
|
|
|
7
|
my @params_not_ok; |
120
|
|
|
|
|
|
|
|
121
|
4
|
|
|
|
|
20
|
for my $attr ( keys %attrs ) { |
122
|
40
|
100
|
100
|
|
|
176
|
if ( $attrs{$attr} eq 'required' and !$params{$attr} ) { |
123
|
1
|
|
|
|
|
2
|
push @params_not_ok, $attr; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
4
|
|
|
|
|
24
|
return join ", ", @params_not_ok; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
__END__ |