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