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