line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::ZooTool; |
2
|
|
|
|
|
|
|
# ABSTRACT: a Moose interface to the Zootool API |
3
|
6
|
|
|
6
|
|
193167
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
with 'Net::ZooTool::Utils'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use Carp; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use Net::ZooTool::Auth; |
9
|
|
|
|
|
|
|
use Net::ZooTool::User; |
10
|
|
|
|
|
|
|
use Net::ZooTool::Item; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use namespace::autoclean; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.003'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has auth => ( |
17
|
|
|
|
|
|
|
isa => 'Net::ZooTool::Auth', |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
around BUILDARGS => sub { |
22
|
|
|
|
|
|
|
my $orig = shift; |
23
|
|
|
|
|
|
|
my $class = shift; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Transform normal params to hashref |
26
|
|
|
|
|
|
|
if ( !ref $_[0] ) { |
27
|
|
|
|
|
|
|
if ( scalar @_ == 1 ) { |
28
|
|
|
|
|
|
|
return $class->$orig( apikey => $_[0] ); |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
elsif ( scalar @_ == 3 ) { |
31
|
|
|
|
|
|
|
return $class->$orig( apikey => $_[0], user => $_[1], password => $_[2] ); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
else { |
34
|
|
|
|
|
|
|
croak "Unaccepted params"; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Hashref checkings |
39
|
|
|
|
|
|
|
if ( ref $_[0] and !$_[0]->{apikey} ) { |
40
|
|
|
|
|
|
|
croak "You have to provide at least the apikey as either parameter or hashref"; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# You need to provide username and password |
44
|
|
|
|
|
|
|
if ( defined $_[0]->{user} and !defined $_[0]->{password} ) { |
45
|
|
|
|
|
|
|
croak "If you provide user you also need to provide password"; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
if ( defined $_[0]->{password} and !defined $_[0]->{user} ) { |
49
|
|
|
|
|
|
|
croak "If you provide password you also need to provide username"; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# If you have reached here everything is good |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
return $class->$orig(@_); |
55
|
|
|
|
|
|
|
}; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub BUILD { |
58
|
|
|
|
|
|
|
my $self = shift; |
59
|
|
|
|
|
|
|
my $args = shift; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$self->{auth} = Net::ZooTool::Auth->new( |
62
|
|
|
|
|
|
|
{ |
63
|
|
|
|
|
|
|
apikey => $args->{apikey}, |
64
|
|
|
|
|
|
|
user => $args->{user}, |
65
|
|
|
|
|
|
|
password => $args->{password}, |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub user { |
71
|
|
|
|
|
|
|
my $self = shift; |
72
|
|
|
|
|
|
|
return Net::ZooTool::User->new({ auth => $self->auth }); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub item { |
76
|
|
|
|
|
|
|
my $self = shift; |
77
|
|
|
|
|
|
|
return Net::ZooTool::Item->new({ auth => $self->auth }); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub add { |
81
|
|
|
|
|
|
|
my ( $self, $args ) = @_; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$args->{apikey} = $self->auth->apikey; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $data = _fetch('/add/' . _hash_to_query_string($args), $self->auth); |
86
|
|
|
|
|
|
|
return $data; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
no Moose; |
90
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=pod |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 NAME |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Net::ZooTool - Moose interface to the Zootool API: http://zootool.com |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 SYNOPSIS |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
my $zoo = Net::ZooTool->new({ apikey => $config{apikey} }); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
my $weekly_popular = $zoo->item->popular({ type => "week" }); |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# Info about a specific item |
109
|
|
|
|
|
|
|
print Dumper($zoo->item->info({ uid => "6a80z" })); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
# Examples with authenticated calls |
112
|
|
|
|
|
|
|
my $auth_zoo = Net::ZooTool->new( |
113
|
|
|
|
|
|
|
{ |
114
|
|
|
|
|
|
|
apikey => $config{apikey}, |
115
|
|
|
|
|
|
|
user => $config{user}, |
116
|
|
|
|
|
|
|
password => $config{password}, |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
my $data = $auth_zoo->user->validate({ username => $config{user}, login => 'true' }); |
121
|
|
|
|
|
|
|
print Dumper($data); |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# In some methods authentication is optional. |
124
|
|
|
|
|
|
|
# Public items only |
125
|
|
|
|
|
|
|
my $public_items = $auth_zoo->user->items({ username => $config{user} }); |
126
|
|
|
|
|
|
|
# Include also your private items |
127
|
|
|
|
|
|
|
my $all_items = $auth_zoo->user->items({ username => $config{user}, login => 'true' }); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head1 DESCRIPTION |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Net::ZooTool is a wrapper to the Zootool bookmarking service. It attempts to follow the api defined in http://zootool.com/api/docs/general as much as possible. Please refer to their API Documentation site for more information. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 PACKAGE METHODS |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=over 1 |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item new(\%ARGS) |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Create a new Net::ZooTool object. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Parameters: |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=over 3 |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item * |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
B<apikey> |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
I<string>. Your Zootool apikey (required) |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item * |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
B<user> |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
I<string>. Your Zootool username (optional) |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item * |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
B<password> |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
I<string>. Your Zootool password (optional) |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=back |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=back |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 OBJECT METHODS |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=over 6 |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item $zoo->user() |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Net::ZooTool::User object |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=item $zoo->item() |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Net::ZooTool::Item object |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item $zoo->add(\%ARGS) |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Adds a new item to your zoo (authentication is required). |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Parameters: |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=over 8 |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=item * |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
B<apikey> |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
I<string>. Your Zootool api key (required) |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=item * |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
B<url> |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
I<string>. Url to add (required) |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=item * |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
B<title> |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
I<string>. Item title (required) |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=item * |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
B<tags> |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
I<string>. Comma separated if you want to include more than one (optional) |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=item * |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
B<description> |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
I<string>. Entry description (optional) |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=item * |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
B<referer> |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
I<string>. Entry referer, must be a valid url (optional) |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=item * |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
B<public> |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
I<string>. Whether or not the item is public ('y' or 'n') |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=item * |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
B<login> |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
I<boolean>. Add method requires authenticated call (required) |
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
=back |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=item $zoo->user->items(\%ARGS) |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
Get the latest items from all users or specify a username to get all items from a specific user. Authenticate to get all private items of a user as well. Use authentication if you want to get private items as well). |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Parameters: |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=over 6 |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
=item * |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
B<apikey> |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
I<string>. Your Zootool api key (required) |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=item * |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
B<username> |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
I<string>. Zootool username (required) |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=item * |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
B<login> |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
I<string>. must be true if you want to make an authenticated call via digest (optional). |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
=item * |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
B<tag> |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
I<string>. Tag search (optional) |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
=item * |
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
B<offset> |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
I<int>. Search offset (optional) |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=item * |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
B<limit> |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
I<int>. Search limit (optional) |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
=item * |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
B<login> |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
I<boolean>. Set to true to get private items as well. |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
=back |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
=item $zoo->user->info(\%ARGS) |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
Get info about a certain user. Authentication is optional (if you want to get the email address from the user, you need to sign in). |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
Parameters: |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
=over 3 |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=item * |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
B<apikey> |
300
|
|
|
|
|
|
|
|
301
|
|
|
|
|
|
|
I<string>. Your Zootool api key (required) |
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
=item * |
304
|
|
|
|
|
|
|
|
305
|
|
|
|
|
|
|
B<username> |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
I<string>. Zootool username (required) |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
=item * |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
B<login> |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
I<boolean>. Set to true to get email address |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
=back |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
=item $zoo->user->validate(\%ARGS) |
318
|
|
|
|
|
|
|
|
319
|
|
|
|
|
|
|
Validate the user credentials. Useful for logins. |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
Parameters: |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
=over 2 |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
=item * |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
B<apikey> |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
I<string>. Your Zootool api key (required) |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
=item * |
332
|
|
|
|
|
|
|
|
333
|
|
|
|
|
|
|
B<username> |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
I<string>. Your zootool username (required) |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
=back |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
=back |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
=head1 SEE ALSO |
342
|
|
|
|
|
|
|
|
343
|
|
|
|
|
|
|
http://zootool.com/ |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
http://zootool.com/api/docs |
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
=head1 AUTHOR |
348
|
|
|
|
|
|
|
|
349
|
|
|
|
|
|
|
Josep Roca, <quelcom@gmail.com> |
350
|
|
|
|
|
|
|
|
351
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
Copyright (C) 2011 by Josep Roca |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
356
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.10.1 or, |
357
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
=cut |
360
|
|
|
|
|
|
|
|