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