line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
708
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
43
|
|
3
|
|
|
|
|
|
|
package Chat::Envolve; |
4
|
|
|
|
|
|
|
BEGIN { |
5
|
1
|
|
|
1
|
|
21
|
$Chat::Envolve::VERSION = '1.0007'; |
6
|
|
|
|
|
|
|
} |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
705
|
use Any::Moose; |
|
1
|
|
|
|
|
32560
|
|
|
1
|
|
|
|
|
7
|
|
9
|
1
|
|
|
1
|
|
1225
|
use MIME::Base64 qw(encode_base64url); |
|
1
|
|
|
|
|
1039
|
|
|
1
|
|
|
|
|
67
|
|
10
|
1
|
|
|
1
|
|
713
|
use Digest::HMAC_SHA1 qw(hmac_sha1_hex); |
|
1
|
|
|
|
|
6329
|
|
|
1
|
|
|
|
|
53
|
|
11
|
1
|
|
|
1
|
|
5424
|
use Encode qw(encode); |
|
1
|
|
|
|
|
18726
|
|
|
1
|
|
|
|
|
680
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has api_key => ( |
14
|
|
|
|
|
|
|
is => 'ro', |
15
|
|
|
|
|
|
|
required => 1, |
16
|
|
|
|
|
|
|
trigger => sub { |
17
|
|
|
|
|
|
|
my ($self, $value) = @_; |
18
|
|
|
|
|
|
|
confess 'EnvolveAPI: Invalid API Key' unless $value =~ m/\d+-\w+/; |
19
|
|
|
|
|
|
|
my @key_parts = split /-/, $self->api_key; |
20
|
|
|
|
|
|
|
$self->secret($key_parts[1]); |
21
|
|
|
|
|
|
|
$self->site_id($key_parts[0]); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has secret => ( |
26
|
|
|
|
|
|
|
is => 'rw', |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has site_id => ( |
30
|
|
|
|
|
|
|
is => 'rw', |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub get_tags { |
34
|
0
|
|
|
0
|
1
|
0
|
my ($self, $first_name, %options) = @_; |
35
|
0
|
0
|
|
|
|
0
|
my $command = ($first_name) ? $self->get_login_command($first_name, %options) : $self->get_logout_command; |
36
|
0
|
|
|
|
|
0
|
my $html = q{ |
37
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
}; |
43
|
0
|
|
|
|
|
0
|
return sprintf $html, $self->site_id, $command; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub get_login_command { |
47
|
0
|
|
|
0
|
1
|
0
|
my ($self, $first_name, %options) = @_; |
48
|
0
|
|
|
|
|
0
|
my %params = ( fn => $first_name ); |
49
|
0
|
0
|
|
|
|
0
|
$params{ln} = $options{last_name} if exists $options{last_name}; |
50
|
0
|
0
|
|
|
|
0
|
$params{pic} = $options{picture_url} if exists $options{picture_url}; |
51
|
0
|
0
|
0
|
|
|
0
|
$params{admin} = 't' if exists $options{is_admin} && $options{is_admin}; |
52
|
0
|
|
|
|
|
0
|
return $self->sign_command_string( |
53
|
|
|
|
|
|
|
$self->generate_command_string('login', %params) |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub get_logout_command { |
58
|
0
|
|
|
0
|
1
|
0
|
my ($self) = @_; |
59
|
0
|
|
|
|
|
0
|
return $self->sign_command_string( |
60
|
|
|
|
|
|
|
$self->generate_command_string('logout') |
61
|
|
|
|
|
|
|
); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub generate_command_string { |
65
|
1
|
|
|
1
|
0
|
4
|
my ($self, $command, %params) = @_; |
66
|
1
|
|
|
|
|
4
|
my $command_string = (time() * 1000) |
67
|
|
|
|
|
|
|
.';v=0.2' |
68
|
|
|
|
|
|
|
.',c='.$command; |
69
|
1
|
|
|
|
|
4
|
foreach my $key (keys %params) { |
70
|
1
|
50
|
|
|
|
8
|
my $value = ($key eq 'admin') ? $params{$key} : encode_base64url(encode("UTF-8",$params{$key})); |
71
|
1
|
|
|
|
|
199
|
$command_string .= ',' . $key . '=' . $value; |
72
|
1
|
|
|
|
|
5
|
chomp $command_string; |
73
|
|
|
|
|
|
|
} |
74
|
1
|
|
|
|
|
10
|
return $command_string; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub sign_command_string { |
78
|
1
|
|
|
1
|
0
|
1473
|
my ($self, $command_string) = @_; |
79
|
1
|
|
|
|
|
9
|
my $hash = hmac_sha1_hex( $command_string, $self->secret); |
80
|
1
|
|
|
|
|
58
|
return $hash . ';' . $command_string; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
1
|
|
|
1
|
|
9
|
no Any::Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
84
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 NAME |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Chat::Envolve - A Perl API for the Envolve web chat system. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 VERSION |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
version 1.0007 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 SYNOPSIS |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $chat = Chat::Envolve->new( |
98
|
|
|
|
|
|
|
api_key => $key, |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
my $html = $chat->get_tags('Joe'); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
my $command = $chat->get_login_command('Joe'); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 DESCRIPTION |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
This is a Perl API for the Envolve L chat system. If you'd like to see it in use, check out The Lacuna Expanse L. Currently Envolve has not exposed much functionality, but using this API will allow you to have your users automatically logged in/out of the chat based upon their web site logins. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head1 METHODS |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 new ( api_key => '111-xxx' ) |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Constructor. Requires both params. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=over |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item api_key |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
The API key provided by Envolve. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=back |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 get_login_command ( first_name , [ options ] ) |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Returns a signed login command string that can be used to log a user into a chat by calling some javascript. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
If you prefer you can just inline it into the web page using the C method. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=over |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=item first_name |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
A string, either the first name of the user, or their alias. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item options |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
A hash of optional parameters. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=over |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item last_name |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
A string, the last name of the user. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item picture_url |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
A url of a picture or avatar for the user. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item is_admin |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
If set to 1, the user will gain admin privileges, which currently means that if enabled in the Envolve settings they'll be able to create and close chats administratively. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=back |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=back |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 get_logout_command ( ) |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Returns a signed logout command string that can be used to log a user out of a chat by calling some javascript. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
If you prefer you can just inline it into the web page using the C method and pass no params to it. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head2 get_tags ( [ first_name, login_options, ] ) |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Returns some HTML tags that can be inlined into your web page to start the chat. If no parameters are passed in, then the user will be anonymous. If C is passed in then the user will be authenticated. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=over |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item first_name |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
See C |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item login_options |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
See C |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=back |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 EXCEPTIONS |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
Currently this module doesn't throw any exceptions. |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 TODO |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
Nothing is planned until Envolve releases more functionality. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 PREREQS |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
L |
205
|
|
|
|
|
|
|
L |
206
|
|
|
|
|
|
|
L |
207
|
|
|
|
|
|
|
L |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=head1 SUPPORT |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=over |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=item Repository |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
L |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=item Bug Reports |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
L |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=back |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 SEE ALSO |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
If you want to see this module in use, check out The Lacuna Expanse L. If you want to learn more about Envolve visit their web site L. |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 AUTHOR |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
JT Smith |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=head1 LEGAL |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
Chat::Envolve is Copyright 2010 Plain Black Corporation (L) and is licensed under the same terms as Perl itself. Envolve and its copyrights and trademarks are the property of Envolve, Inc. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=cut |