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