line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Polycom::App::Push;
|
2
|
1
|
|
|
1
|
|
4175
|
use strict;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
4
|
1
|
|
|
1
|
|
1142
|
use LWP::UserAgent;
|
|
1
|
|
|
|
|
242854
|
|
|
1
|
|
|
|
|
39
|
|
5
|
1
|
|
|
1
|
|
12
|
use base qw(Class::Accessor);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1151
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = 0.04;
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
###################
|
10
|
|
|
|
|
|
|
# Basic Accessors
|
11
|
|
|
|
|
|
|
###################
|
12
|
|
|
|
|
|
|
Polycom::App::Push->mk_accessors(qw(address username password));
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
###################
|
15
|
|
|
|
|
|
|
# Constructors
|
16
|
|
|
|
|
|
|
###################
|
17
|
|
|
|
|
|
|
sub new
|
18
|
|
|
|
|
|
|
{
|
19
|
1
|
|
|
1
|
1
|
455
|
my ($class, %args) = @_;
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
11
|
my $self = {
|
22
|
|
|
|
|
|
|
address => $args{address},
|
23
|
|
|
|
|
|
|
username => $args{username},
|
24
|
|
|
|
|
|
|
password => $args{password},
|
25
|
|
|
|
|
|
|
ua => LWP::UserAgent->new,
|
26
|
|
|
|
|
|
|
};
|
27
|
|
|
|
|
|
|
|
28
|
1
|
50
|
33
|
|
|
60310
|
if (!defined $self->{address} || $self->{address} eq '')
|
29
|
|
|
|
|
|
|
{
|
30
|
0
|
|
|
|
|
0
|
warn "No 'address' attribute specified";
|
31
|
|
|
|
|
|
|
}
|
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
|
|
14
|
return bless $self, $class;
|
34
|
|
|
|
|
|
|
}
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
###################
|
37
|
|
|
|
|
|
|
# Public Methods
|
38
|
|
|
|
|
|
|
###################
|
39
|
|
|
|
|
|
|
sub push_message
|
40
|
|
|
|
|
|
|
{
|
41
|
1
|
|
|
1
|
1
|
17
|
my ($self, @messages) = @_;
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Push all of the messages to the phone
|
44
|
1
|
|
|
|
|
3
|
my $messagesSent = 0;
|
45
|
1
|
|
|
|
|
6
|
foreach my $msg (@messages)
|
46
|
|
|
|
|
|
|
{
|
47
|
1
|
50
|
33
|
|
|
19
|
my $priority = (defined $msg->{priority} && lc($msg->{priority}) eq 'critical') ? 'critical' : 'normal';
|
48
|
1
|
|
|
|
|
3
|
my $content_type;
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Generate the XML message to send to the phone
|
51
|
1
|
|
|
|
|
3
|
my $xml = '';
|
52
|
1
|
50
|
|
|
|
41
|
if (defined $msg->{url})
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
53
|
|
|
|
|
|
|
{
|
54
|
0
|
|
|
|
|
0
|
$xml .= qq($msg->{url});
|
55
|
0
|
|
|
|
|
0
|
$content_type = 'application/x-com-polycom-spipx';
|
56
|
|
|
|
|
|
|
}
|
57
|
|
|
|
|
|
|
elsif (defined $msg->{data})
|
58
|
|
|
|
|
|
|
{
|
59
|
0
|
|
|
|
|
0
|
$xml .= qq($msg->{data});
|
60
|
0
|
|
|
|
|
0
|
$content_type = 'application/xhtml+xml';
|
61
|
|
|
|
|
|
|
}
|
62
|
|
|
|
|
|
|
elsif (defined $msg->{uri_data})
|
63
|
|
|
|
|
|
|
{
|
64
|
0
|
|
|
|
|
0
|
$xml .= qq($msg->{uri_data});
|
65
|
0
|
|
|
|
|
0
|
$content_type = 'application/x-com-polycom-spipx';
|
66
|
|
|
|
|
|
|
}
|
67
|
1
|
|
|
|
|
6
|
$xml .= '';
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Verify that at least one of the required url, data, or uri_data parameters are specified
|
70
|
1
|
50
|
|
|
|
13
|
if (!defined $content_type)
|
71
|
|
|
|
|
|
|
{
|
72
|
1
|
|
|
|
|
21
|
die 'Exactly one of url, data, or uri_data must be specified';
|
73
|
|
|
|
|
|
|
}
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Configure the user agent to communicate with the phone
|
76
|
0
|
|
|
|
|
|
$self->{ua}->credentials($self->{address} . ':80', 'PUSH Authentication', $self->{username}, $self->{password});
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Send the push request to the phone
|
79
|
0
|
|
|
|
|
|
my $response = $self->{ua}->post(
|
80
|
|
|
|
|
|
|
'http://' . $self->{address} . '/push',
|
81
|
|
|
|
|
|
|
'Content-Type' => $content_type,
|
82
|
|
|
|
|
|
|
Content => $xml,
|
83
|
|
|
|
|
|
|
);
|
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
if ($response->is_success)
|
86
|
|
|
|
|
|
|
{
|
87
|
0
|
|
|
|
|
|
$messagesSent++;
|
88
|
|
|
|
|
|
|
}
|
89
|
|
|
|
|
|
|
else
|
90
|
|
|
|
|
|
|
{
|
91
|
0
|
|
|
|
|
|
print "Unable to send push request to http://$self->{address}/push. The response from the phone was:\n"
|
92
|
|
|
|
|
|
|
. $response->as_string;
|
93
|
|
|
|
|
|
|
}
|
94
|
|
|
|
|
|
|
}
|
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
return $messagesSent;
|
97
|
|
|
|
|
|
|
}
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 NAME
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Polycom::App::Push - Module for sending push requests to Polycom's SoundPoint IP and VVX series VoIP phones
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
use Polycom::App::Push;
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
my $phone = Polycom::App::Push->new(address => '172.23.8.100', username => 'Bob', password => '1234');
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# Send a simple XHTML message to a Polycom phone that will pop-up on the screen
|
110
|
|
|
|
|
|
|
$phone->push_message({priority => 'normal', data => 'Fire drill at 2:00pm!'});
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# Request that the phone show the specified web page, relative to the URL specified in the "apps.push.serverRootURL" configuration parameter
|
113
|
|
|
|
|
|
|
$phone->push_message({priority => 'critical', url => '/announcement.xhtml'});
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Request that the phone execute the specified internal URI, or prompt the user to dial the specified "tel:" or "sip:" URI
|
116
|
|
|
|
|
|
|
$phone->push_message({priority => 'critical', uri_data => 'sip:172.23.8.100'});
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
The C class is for writing web applications for Polycom's SoundPoint IP and VVX series VoIP phones. It provides a mechanism to push messages to a phone for display to the user.
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Note that to use the C method, the phone must be configured with the following parameters, where the values of each parameters should be customized based on your requirements:
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
apps.push.messageType="5"
|
126
|
|
|
|
|
|
|
apps.push.serverRootURL="http://192.168.1.11"
|
127
|
|
|
|
|
|
|
apps.push.username="Polycom"
|
128
|
|
|
|
|
|
|
apps.push.password="456" />
|
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
The value of the 'C' parameter is very important, because it determines how the phone will filter incoming push messages based on their 'C' attributes. The allowable values for the 'C' parameter are:
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
0 - Don't show any push messages
|
133
|
|
|
|
|
|
|
1 - Show messages with 'priority="normal"'
|
134
|
|
|
|
|
|
|
2 - Show messages with 'priority="important"'
|
135
|
|
|
|
|
|
|
3 - Show messages with 'priority="high"'
|
136
|
|
|
|
|
|
|
4 - Show messages with 'priority="critical"'
|
137
|
|
|
|
|
|
|
5 - Show all messages, regardless of their 'priority' value
|
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
The 'C' parameter is used as the base URL for the relative URL passed to 'C' method in its 'C' parameter.
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
The 'C' and 'C' parameters must match the 'C' and 'C' parameters passed to the 'C' method.
|
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head1 CONSTRUCTOR
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 new ( %fields )
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
use Polycom::App::Push;
|
148
|
|
|
|
|
|
|
my $phone = Polycom::App::Push->new(address => '172.23.8.100', username => 'Polycom', password => '456');
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Returns a newly created C object. The following parameters are required:
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
address - the IP address of the phone.
|
153
|
|
|
|
|
|
|
username - the user name configured on the phone with the "apps.push.username" parameter.
|
154
|
|
|
|
|
|
|
password - the password configured on the phone with the "apps.push.password" parameter.
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 ACCESSORS
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 address
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
my $ip_address = $phone->address
|
161
|
|
|
|
|
|
|
$phone->address('172.23.8.100'); # Set the address to "172.23.8.100"
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head2 username
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
my $username = $phone->username;
|
166
|
|
|
|
|
|
|
$phone->username('Bob'); # Set the username to 'Bob'
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head2 password
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
my $password = $phone->password;
|
171
|
|
|
|
|
|
|
$phone->password('1234'); # Set the password to '1234'
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 METHODS
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head2 push_message
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
if (!$phone->push_message({priority => "critical", url => "/announcements/happy_birthday.xhtml"});)
|
178
|
|
|
|
|
|
|
{
|
179
|
|
|
|
|
|
|
print "Failed to send push message\n";
|
180
|
|
|
|
|
|
|
}
|
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
This method can be used to send a push request to a Polycom IP phone that will trigger it to display the supplied message or URL in its web browser. The following parameters are supported:
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
priority - the priority of the message (either "critical" or "normal"). If not specified, "normal" is assumed.
|
185
|
|
|
|
|
|
|
url - the URL to display on the phone, relative to the "apps.push.serverRootURL" configuration parameter.
|
186
|
|
|
|
|
|
|
data - a URI-escaped HTML document to display on the phone.
|
187
|
|
|
|
|
|
|
uri_data - an internal URI to execute, or a "sip:" or "tel:" URI to prompt the user to dial
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Note that either C or C must be specified, but not both. Returns C<1> if the message was sent successfully, or C<0> otherwise.
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 SEE ALSO
|
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
I - L
|
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
I - L
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
C - A module that can be used to generate XHTML documents for displaying custom softkeys and hyperlinks using internal URIs for Polycom phones.
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head1 AUTHOR
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
Zachary Blair, Ezblair@cpan.orgE
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE
|
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Copyright (C) 2012 by Zachary Blair
|
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify
|
208
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.8 or,
|
209
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available.
|
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=cut
|
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
'Together. Great things happen.';
|