line
stmt
bran
cond
sub
pod
time
code
1
2
package ImgurAPI::Client;
3
4
1
1
374818
use strict;
1
2
1
47
5
1
1
6
use warnings;
1
3
1
75
6
7
1
1
784
use Data::Dumper;
1
10714
1
97
8
1
1
821
use HTTP::Request::Common;
1
33371
1
122
9
1
1
1073
use JSON qw(decode_json encode_json);
1
14782
1
8
10
1
1
206
use List::Util qw(first);
1
3
1
84
11
1
1
870
use LWP::UserAgent;
1
44877
1
59
12
1
1
697
use Mozilla::CA;
1
373
1
43
13
1
1
7
use Scalar::Util;
1
1
1
57
14
1
1
852
use XML::LibXML;
1
62001
1
8
15
16
our $VERSION = '1.2.1';
17
18
1
9772
use constant ENDPOINTS => {
19
'IMGUR' => 'https://api.imgur.com/3',
20
'RAPIDAPI' => 'https://imgur-apiv3.p.rapidapi.com',
21
'OAUTH_AUTHORIZE' => 'https://api.imgur.com/oauth2/authorize',
22
'OAUTH_TOKEN' => 'https://api.imgur.com/oauth2/token',
23
1
1
287
};
1
4
24
25
sub new {
26
5
5
1
29510
my $self = shift;
27
5
100
63
my $args = shift // {};
28
my $vars = {
29
'auth' => 1,
30
'access_token' => $args->{'access_token'},
31
'oauth_cb_state' => $args->{'oauth_cb_state'},
32
'client_id' => $args->{'client_id'},
33
'client_secret' => $args->{'client_secret'},
34
'format_type' => $args->{'format_type'} || 'json',
35
'lwp' => LWP::UserAgent->new,
36
'rapidapi_key' => $args->{'rapidapi_key'},
37
'refresh_token' => $args->{'refresh_token'},
38
'response' => undef,
39
'ratelimit_hdrs' => {},
40
5
100
87
'user_agent' => $args->{'user_agent'} || "ImgurAPI::Client/$VERSION",
33
41
};
42
43
5
16263
return bless $vars, $self;
44
}
45
46
1
1
19
sub _lwp { shift->{'lwp'} }
47
48
sub request {
49
0
0
0
0
my ($self, $uri, $http_method, $data, $hdr, $debug) = @_;
50
51
0
0
0
$http_method = uc($http_method // 'GET');
52
53
0
0
0
my $endpoint = $self->{'rapidapi_key'} ? ENDPOINTS->{'RAPIDAPI'} . $uri : ($uri =~ /^\// ? ENDPOINTS->{'IMGUR'} . $uri : $uri);
0
54
55
0
0
0
$endpoint .= ($endpoint =~ /\?/ ? '&' : '?') . '_format=' . $self->{'format_type'} . "&_method=$http_method";
56
57
0
0
$self->_lwp->default_header('User-Agent' => "ImgurAPI::Client/$VERSION");
58
59
0
0
0
if ($self->{'auth'}) {
0
60
0
0
0
my $access_token = $self->{'access_token'} // die "Missing required access_token";
61
0
0
$self->_lwp->default_header('Authorization' => "Bearer $access_token");
62
} elsif ($self->{'client_id'}) {
63
0
0
$self->_lwp->default_header('Authorization' => "Client-ID " . $self->{'client_id'});
64
}
65
66
0
0
0
0
if ($http_method =~ /^GET|DELETE$/ && $data && ref($data) eq 'HASH') {
0
67
0
0
$endpoint .= "&$_=$data->{$_}" foreach keys %$data;
68
}
69
70
0
0
my $request;
71
0
0
0
if ($http_method eq 'POST') {
0
72
0
0
0
$request = HTTP::Request::Common::POST($endpoint, %{$hdr//{}}, Content => $data);
0
0
73
} elsif ($http_method eq 'PUT') {
74
0
0
0
$request = HTTP::Request::Common::PUT($endpoint, %{$hdr//{}}, Content => $data);
0
0
75
} else {
76
0
0
$request = HTTP::Request->new($http_method, $endpoint);
77
}
78
79
0
0
0
0
print Dumper $request if $ENV{'DEBUG'} || ($debug // 0);
0
80
81
0
0
my $response = $self->_lwp->request($request);
82
83
0
0
my @ratelimit_headers = qw(userlimit userremaining userreset clientlimit clientremaining);
84
0
0
foreach my $header (@ratelimit_headers) {
85
0
0
my $val = $response->header("x-ratelimit-$header");
86
0
0
0
0
$self->{'ratelimit_headers'}->{$header} = $val && $val =~ /^\d+$/ ? int $val : $val;
87
}
88
89
0
0
$self->{'response'} = $response;
90
0
0
$self->{'response_content'} = $response->decoded_content;
91
92
0
0
0
print Dumper $response if $ENV{'DEBUG'};
93
94
0
0
0
if ($self->format_type eq 'xml') {
95
0
0
return XML::LibXML->new->load_xml(string => $response->decoded_content);
96
} else {
97
0
0
my $decoded = eval { decode_json $response->decoded_content };
0
0
98
0
0
0
if (my $err = $@) {
99
0
0
die "An error occurred while trying to json decode imgur response: $err\n" . $response->decoded_content;
100
}
101
0
0
return $decoded;
102
}
103
}
104
105
sub refresh_access_token {
106
0
0
0
0
my $self = shift;
107
0
0
0
my $opts = shift // {};
108
109
0
0
0
0
my $refresh_token = $opts->{'refresh_token'} || $self->{'refresh_token'} or die "missing required refresh_token";
110
0
0
0
0
my $client_id = $opts->{'client_id'} || $self->{'client_id'} or die "missing required client_id";
111
0
0
0
0
my $client_secret = $opts->{'client_secret'} || $self->{'client_secret'} or die "missing required client_secret";
112
113
0
0
my $resp = $self->request(ENDPOINTS->{'OAUTH_TOKEN'}, 'POST', {
114
'refresh_token' => $refresh_token,
115
'client_id' => $client_id,
116
'client_secret' => $client_secret,
117
'grant_type' => 'refresh_token',
118
});
119
120
0
0
$self->{'access_token'} = $resp->{'access_token'};
121
0
0
$self->{'refresh_token'} = $resp->{'refresh_token'};
122
123
return {
124
access_token => $resp->{'access_token'},
125
0
0
refresh_token => $resp->{'refresh_token'}
126
}
127
}
128
129
# Setters
130
sub set_access_token {
131
1
1
1
9
my ($self, $access_token) = @_;
132
1
3
$self->{'access_token'} = $access_token;
133
}
134
135
sub set_client_id {
136
2
2
1
573
my ($self, $client_id) = @_;
137
2
8
$self->{'client_id'} = $client_id;
138
}
139
140
sub set_client_secret {
141
1
1
1
5
my ($self, $client_secret) = @_;
142
1
4
$self->{'client_secret'} = $client_secret;
143
}
144
145
sub set_format_type {
146
1
1
1
4
my ($self, $format_type) = @_;
147
1
4
$self->{'format_type'} = $format_type;
148
}
149
150
sub set_oauth_cb_state {
151
2
2
1
1093
my ($self, $oauth_cb_state) = @_;
152
2
9
$self->{'oauth_cb_state'} = $oauth_cb_state;
153
}
154
155
sub set_rapidapi_key {
156
1
1
1
5
my ($self, $rapidapi_key) = @_;
157
1
3
$self->{'rapidapi_key'} = $rapidapi_key;
158
}
159
160
sub set_refresh_token {
161
0
0
0
0
my ($self, $refresh_token) = @_;
162
0
0
$self->{'refresh_token'} = $refresh_token;
163
}
164
165
sub set_user_agent {
166
0
0
1
0
my ($self, $user_agent) = @_;
167
0
0
$self->{'user_agent'} = $user_agent;
168
}
169
170
# Getters
171
sub oauth2_authorize_url {
172
5
5
0
660
my $self = shift;
173
5
100
34
my $client_id = $self->{'client_id'} or die "missing required client_id";
174
4
100
17
my $state = $self->{'oauth_cb_state'} // '';
175
4
81
return (ENDPOINTS->{'OAUTH_AUTHORIZE'} . "?client_id=$client_id&response_type=token&state=$state");
176
}
177
178
sub access_token {
179
3
3
1
32
return shift->{'access_token'}
180
}
181
182
sub client_id {
183
3
3
1
26
return shift->{'client_id'};
184
}
185
186
sub client_secret {
187
3
3
1
19
return shift->{'client_secret'}
188
}
189
190
sub format_type {
191
3
3
1
21
return shift->{'format_type'}
192
}
193
194
sub oauth_cb_state {
195
3
3
1
17
return shift->{'oauth_cb_state'}
196
}
197
198
sub rapidapi_key {
199
3
3
1
20
return shift->{'rapidapi_key'}
200
}
201
202
sub response {
203
1
1
1
6
return shift->{'response'}
204
}
205
206
sub response_content {
207
0
0
1
return shift->{'response_content'}
208
}
209
210
sub ratelimit_headers {
211
0
0
1
return shift->{'ratelimit_headers'}
212
}
213
214
sub user_agent {
215
0
0
1
return shift->{'user_agent'}
216
}
217
218
# Account
219
sub account {
220
0
0
0
my $self = shift;
221
0
0
my $user = shift or die "missing required username";
222
0
return $self->request("/account/$user");
223
}
224
225
sub account_album {
226
0
0
0
my $self = shift;
227
0
0
my $user = shift or die "missing required username";
228
0
0
my $id = shift or die "missing required album id";
229
0
return $self->request("/account/$user/album/$id");
230
}
231
232
sub account_album_count {
233
0
0
0
my $self = shift;
234
0
0
my $user = shift or die "missing required username";
235
0
return $self->request("/account/$user/albums/count");
236
}
237
238
sub account_album_delete {
239
0
0
0
my $self = shift;
240
0
0
my $user = shift or die "missing required username";
241
0
0
my $id = shift or die "missing required album id";
242
0
return $self->request("/account/$user/album/$id", 'DELETE');
243
}
244
245
sub account_album_ids {
246
0
0
0
my $self = shift;
247
0
0
my $user = shift or die "missing requied username";
248
0
0
my $opts = shift // {};
249
0
0
my $page = $opts->{'page'} // 0;
250
0
return $self->request("/account/$user/albums/ids/$page");
251
}
252
253
sub account_albums {
254
0
0
0
my $self = shift;
255
0
0
my $user = shift or die "missing requied username";
256
0
0
my $opts = shift // {};
257
0
0
my $page = $opts->{'page'} // 0;
258
0
return $self->request("/account/$user/albums/$page");
259
}
260
261
sub account_block_status {
262
0
0
0
my $self = shift;
263
0
0
my $user = shift or die "missing required username";
264
0
return $self->request("https://api.imgur.com/account/v1/$user/block");
265
}
266
267
sub account_block_create {
268
0
0
0
my $self = shift;
269
0
0
my $user = shift or die "missing required username";
270
0
my $resp = eval { $self->request("https://api.imgur.com/account/v1/$user/block", 'POST') };
0
271
272
0
0
if (my $err = $@) {
273
# we have to check if the response was successful when it throws because the imgur api
274
# states it will return the same object we return just below upon blocking a user.. but they dont.
275
# so we end up trying to json decode an empty response which throws an error. if they just returned
276
# the object they said they would in their api doc, we wouldnt get a json decode error.
277
# 201 and 'Created' msg indicates success.
278
0
0
0
if ($self->{'response'}->code != 201 ||
279
$self->{'response'}->{'_msg'} ne 'Created') {
280
0
die $err;
281
}
282
$resp = {
283
0
'success' => 1,
284
'status' => 201,
285
'data' => {
286
'blocked' => 1,
287
}
288
};
289
}
290
0
return $resp;
291
}
292
293
sub account_block_delete {
294
0
0
0
my $self = shift;
295
0
0
my $user = shift or die "missing required username";
296
0
my $resp = eval { $self->request("https://api.imgur.com/account/v1/$user/block", 'DELETE') };
0
297
298
0
0
if (my $err = $@) {
299
# we have to check if the response was successful when it throws because the imgur api
300
# states it will return the same object we return just below upon unblocking a user.. but they dont.
301
# so we end up trying to json decode an empty response which throws an error. if they just returned
302
# the object they said they would in their api doc, we wouldnt get a json decode error.
303
# 204 rc indicates success.
304
0
0
if ($self->{'response'}->code == 204) {
305
return {
306
0
'success' => 1,
307
'status' => 204,
308
'data' => {
309
'blocked' => 0,
310
}
311
}
312
}
313
0
die $err;
314
}
315
316
0
return $resp;
317
}
318
319
sub account_blocks {
320
0
0
0
my $self = shift;
321
0
return $self->request("/account/me/block");
322
}
323
324
sub account_comment {
325
0
0
0
my $self = shift;
326
0
0
my $user = shift or die "missing required username";
327
0
0
my $id = shift or die "missing required comment id";
328
0
return $self->request("/account/$user/comment/$id");
329
}
330
331
sub account_comment_count {
332
0
0
0
my $self = shift;
333
0
0
my $user = shift or die "missing required username";
334
0
return $self->request("/account/$user/comments/count");
335
}
336
337
sub account_comment_delete {
338
0
0
0
my $self = shift;
339
0
0
my $user = shift or die "missing required username";
340
0
0
my $id = shift or die "missing required comment id";
341
0
return $self->request("/account/$user/comment/$id", 'DELETE');
342
}
343
344
sub account_comment_ids {
345
0
0
0
my $self = shift;
346
0
0
my $user = shift or die "missing required username";
347
0
0
my $opts = shift // {};
348
0
0
my $sort = $opts->{'sort'} // 'newest';
349
0
0
my $page = $opts->{'page'} // 0;
350
0
return $self->request("/account/$user/comments/ids/$sort/$page");
351
}
352
353
sub account_comments {
354
0
0
0
my $self = shift;
355
0
0
my $user = shift or die "missing required username";
356
0
0
my $opts = shift // {};
357
0
0
my $sort = $opts->{'sort'} // 'newest';
358
0
0
my $page = $opts->{'page'} // 0;
359
0
return $self->request("/account/$user/comments/$sort/$page");
360
}
361
362
sub account_delete {
363
0
0
0
my $self = shift;
364
0
0
my $client_id = shift or die "missing required client id";
365
0
0
my $body = shift or die "missing required post body";
366
0
return $self->request("/account/me/delete?client_id=$client_id", 'POST', $body);
367
}
368
369
sub account_favorites {
370
0
0
0
my $self = shift;
371
0
0
my $user = shift or die "missing required username";
372
0
0
my $opts = shift // {};
373
0
0
my $sort = $opts->{'sort'} // 'newest';
374
0
0
my $page = $opts->{'page'} // 0;
375
0
return $self->request("/account/$user/favorites/$page/$sort");
376
}
377
378
sub account_gallery_favorites {
379
0
0
0
my $self = shift;
380
0
0
my $user = shift or die "missing required username";
381
0
0
my $opts = shift // {};
382
0
0
my $sort = $opts->{'sort'} // 'newest';
383
0
0
my $page = $opts->{'page'} // 0;
384
0
return $self->request("/account/$user/gallery_favorites/$page/$sort");
385
}
386
387
sub account_image {
388
0
0
0
my $self = shift;
389
0
0
my $user = shift or die "missing required username";
390
0
0
my $id = shift or die "missing required image id";
391
0
return $self->request("/account/$user/image/$id");
392
}
393
394
sub account_image_count {
395
0
0
0
my $self = shift;
396
0
0
my $user = shift or die "missing required username";
397
0
return $self->request("/account/$user/images/count");
398
}
399
400
sub account_image_delete {
401
0
0
0
my $self = shift;
402
0
0
my $user = shift or die "missing required username";
403
0
0
my $id = shift or die "missing required image id";
404
0
return $self->request("/account/$user/image/$id", 'DELETE');
405
}
406
407
sub account_image_ids {
408
0
0
0
my $self = shift;
409
0
0
my $user = shift or die "missing required username";
410
0
0
my $opts = shift // {};
411
0
0
my $page = $opts->{'page'} // 0;
412
0
return $self->request("/account/$user/images/ids/$page");
413
}
414
415
sub account_images {
416
0
0
0
my $self = shift;
417
0
0
my $user = shift or die "missing required username";
418
0
0
my $opts = shift // {};
419
0
0
my $page = $opts->{'page'} // 0;
420
0
return $self->request("/account/$user/images/$page");
421
}
422
423
sub account_reply_notifications {
424
0
0
0
my $self = shift;
425
0
0
my $user = shift or die "missing required username";
426
0
0
my $opts = shift // {};
427
0
0
my $new = $opts->{'new'} // 1;
428
0
return $self->request("/account/$user/notifications/replies?new=$new");
429
}
430
431
sub account_settings {
432
0
0
0
my $self = shift;
433
0
0
my $user = shift or die "missing required username";
434
0
return $self->request("/account/$user/settings");
435
}
436
437
sub account_settings_update {
438
0
0
0
my $self = shift;
439
0
0
my $user = shift or die "missing required username";
440
0
0
my $settings = shift // {};
441
0
my @valid_settings = (qw(bio public_images messaging_enabled accepted_gallery_terms username show_mature newsletter_subscribed));
442
0
my %valid_settings_map = map { $_ => 1 } @valid_settings;
0
443
0
my $data = {};
444
445
0
foreach my $key (keys %{$settings}) {
0
446
0
0
$data->{$key} = $settings->{$key} if exists $valid_settings_map{$key};
447
}
448
449
0
return $self->request("/account/$user/settings", 'PUT', $data);
450
}
451
452
sub account_submissions {
453
0
0
0
my $self = shift;
454
0
0
my $user = shift or die "missing required username";
455
0
0
my $opts = shift // {};
456
0
0
my $page = $opts->{'page'} // 0;
457
0
return $self->request("/account/$user/submissions/$page");
458
}
459
460
sub account_tag_follow {
461
0
0
0
my $self = shift;
462
0
0
my $tag = shift or die "missing required tag";
463
0
return $self->request("/account/me/follow/tag/$tag", 'POST');
464
}
465
466
sub account_tag_unfollow {
467
0
0
0
my $self = shift;
468
0
0
my $tag = shift or die "missing required tag";
469
0
return $self->request("/account/me/follow/tag/$tag", 'DELETE');
470
}
471
472
sub account_verify_email_send {
473
0
0
0
my $self = shift;
474
0
0
my $user = shift or die "missing required username";
475
0
return $self->request("/account/$user/verifyemail", 'POST');
476
}
477
478
sub account_verify_email_status {
479
0
0
0
my $self = shift;
480
0
0
my $user = shift or die "missing required username";
481
0
return $self->request("/account/$user/verifyemail");
482
}
483
484
# Album
485
sub album {
486
0
0
0
my $self = shift;
487
0
0
my $id = shift or die "missing required album id";
488
0
return $self->request("/album/$id");
489
}
490
491
sub album_create {
492
0
0
0
my $self = shift;
493
0
0
my $opts = shift // {};
494
0
my @opt_keys = (qw(ids deletehashes title description cover));
495
0
my %valid_opts = map { $_ => 1 } @opt_keys;
0
496
0
my $data = {};
497
498
0
foreach my $opt (keys %{$opts}) {
0
499
0
0
if (exists $valid_opts{$opt}) {
500
0
0
0
my $key = $opt eq 'ids' || $opt eq 'deletehashes' ? $opt.'[]' : $opt;
501
0
$data->{$key} = $opts->{$opt};
502
}
503
}
504
505
0
return $self->request("/album", 'POST', $data);
506
}
507
508
sub album_delete {
509
0
0
0
my $self = shift;
510
0
0
my $id = shift or die "missing required album id";
511
0
return $self->request("/album/$id", 'DELETE');
512
}
513
514
sub album_favorite {
515
0
0
0
my $self = shift;
516
0
0
my $id = shift or die "missing required album id";
517
0
return $self->request("/album/$id/favorite", 'POST');
518
}
519
520
sub album_image {
521
0
0
0
my $self = shift;
522
0
0
my $album_id = shift or die "missing required album id";
523
0
0
my $image_id = shift or die "missing required image id";
524
0
return $self->request("/album/$album_id/image/$image_id");
525
}
526
527
sub album_images {
528
0
0
0
my $self = shift;
529
0
0
my $album_id = shift or die "missing required album id";
530
0
return $self->request("/album/$album_id/images");
531
}
532
533
sub album_images_add {
534
0
0
0
my $self = shift;
535
0
0
my $album_id = shift or die "missing required album_id";
536
0
0
my $image_ids = shift or die "missing required image_ids";
537
0
return $self->request("/album/$album_id/add", 'POST', {'ids[]' => $image_ids});
538
}
539
540
sub album_images_delete {
541
0
0
0
my $self = shift;
542
0
0
my $album_id = shift or die "missing required album_id";
543
0
0
my $image_ids = shift or die "missing required image_ids";
544
0
return $self->request("/album/$album_id/remove_images", 'DELETE', {'ids' => join(',', @$image_ids)});
545
}
546
547
sub album_images_set {
548
0
0
0
my $self = shift;
549
0
0
my $album_id = shift or die "missing required album_id";
550
0
0
my $image_ids = shift or die "missing required image_ids";
551
0
return $self->request("/album/$album_id", 'POST', {'ids[]' => $image_ids});
552
}
553
554
sub album_update {
555
0
0
0
my $self = shift;
556
0
0
my $album_id = shift or die "missing required album_id";
557
0
0
my $opts = shift // {};
558
0
my %valid_opts = map { $_ => 1 } (qw(ids deletehashes title description cover));
0
559
0
my $data = {};
560
561
0
foreach my $opt (keys %{$opts}) {
0
562
0
0
if (exists $valid_opts{$opt}) {
563
0
0
0
my $key = $opt eq 'ids' || $opt eq 'deletehashes' ? $opt.'[]' : $opt;
564
0
$data->{$key} = $opts->{$opt};
565
}
566
}
567
568
0
return $self->request("/album/$album_id", 'PUT', $data);
569
}
570
571
# Comment
572
sub comment {
573
0
0
0
my ($self, $id) = @_;
574
0
return $self->request("/comment/$id");
575
}
576
577
sub comment_create {
578
0
0
0
my $self = shift;
579
0
0
my $image_id = shift or die "missing required image id";
580
0
0
my $comment = shift or die "missing required comment";
581
0
my $parent_id = shift;
582
583
0
0
return $self->request("/comment", 'POST', {
584
'image_id' => $image_id,
585
'comment' => $comment,
586
($parent_id ? ('parent_id' => $parent_id) : ()),
587
});
588
}
589
590
sub comment_delete {
591
0
0
0
my $self = shift;
592
0
0
my $comment_id = shift or die "missing required comment id";
593
0
return $self->request("/comment/$comment_id", 'DELETE');
594
}
595
596
sub comment_replies {
597
0
0
0
my $self = shift;
598
0
0
my $comment_id = shift or die "missing required comment_id";
599
0
return $self->request("/comment/$comment_id/replies");
600
}
601
602
sub comment_reply {
603
0
0
0
my $self = shift;
604
0
0
my $image_id = shift or die "missing required image_id";
605
0
0
my $comment_id = shift or die "missing required comment_id";
606
0
0
my $comment = shift or die "missing required comment";
607
608
0
return $self->comment_create($image_id, $comment, $comment_id);
609
}
610
611
sub comment_report {
612
0
0
0
my $self = shift;
613
0
0
my $comment_id = shift or die "missing required comment_id";
614
0
my $reason = shift;
615
0
my $data = {};
616
617
0
0
$data->{'reason'} = $reason if $reason;
618
619
0
return $self->request("/comment/$comment_id/report", 'POST', $data);
620
}
621
622
sub comment_vote {
623
0
0
0
my $self = shift;
624
0
0
my $comment_id = shift or die "missing required comment_id";
625
0
0
my $vote = shift or die "missing required vote";
626
627
0
return $self->request("/comment/$comment_id/vote/$vote", 'POST');
628
}
629
630
# Credits
631
sub credits {
632
0
0
0
my $self = shift;
633
0
return $self->request("/credits");
634
}
635
636
# Gallery
637
sub gallery {
638
0
0
0
my $self = shift;
639
0
0
my $opts = shift // {};
640
641
0
0
die "optional data must be a hashref" if ref $opts ne 'HASH';
642
643
0
0
my $section = $opts->{'section'} // 'hot';
644
0
0
my $sort = $opts->{'sort'} // 'viral';
645
0
0
my $page = $opts->{'page'} // 0;
646
0
0
my $window = $opts->{'window'} // 'day';
647
0
0
my $show_viral = $opts->{'show_viral'} // 1;
648
0
0
my $album_prev = $opts->{'album_previews'} // 1;
649
650
0
0
return $self->request(("/gallery/$section/$sort/$window/$page?showViral=$show_viral&album_previews=" . ($album_prev ? 'true' : 'false')));
651
}
652
653
sub gallery_album {
654
0
0
0
my $self = shift;
655
0
0
my $album_id = shift or die "missing required album id";
656
0
return $self->request("/gallery/album/$album_id");
657
}
658
659
sub gallery_image {
660
0
0
0
my $self = shift;
661
0
0
my $image_id = shift or die "missing required image id";
662
0
return $self->request("/gallery/image/$image_id");
663
}
664
665
sub gallery_item_comment {
666
0
0
0
my $self = shift;
667
0
0
my $id = shift or die "missing required album/image id";
668
0
0
my $comment = shift or die "missing required comment";
669
0
return $self->request("/gallery/$id/comment", 'POST', {comment => $comment});
670
}
671
672
sub gallery_item_comment_info {
673
0
0
0
my $self = shift;
674
0
0
my $id = shift or die "missing required album/image id";
675
0
0
my $comment_id = shift or die "missing required comment id";
676
0
return $self->request("/gallery/$id/comment/$comment_id");
677
}
678
679
sub gallery_item_comments {
680
0
0
0
my $self = shift;
681
0
0
my $id = shift or die "missing required image/album id";
682
0
0
my $opts = shift // {};
683
0
0
my $sort = $opts->{'sort'} // 'best';
684
0
return $self->request("/gallery/$id/comments/$sort");
685
}
686
687
sub gallery_item_report {
688
0
0
0
my $self = shift;
689
0
0
my $id = shift or die "missing required image/album id";
690
0
0
my $opts = shift // {};
691
0
my $reason = $opts->{'reason'};
692
0
0
my %data = ($reason ? (reason => $reason) : ());
693
694
0
0
$data{'reason'} = $reason if $reason;
695
696
0
return $self->request("/gallery/image/$id/report", 'POST', \%data);
697
}
698
699
sub gallery_item_tags {
700
0
0
0
my $self = shift;
701
0
0
my $id = shift or die "missing required image/album id";
702
0
return $self->request("/gallery/$id/tags");
703
}
704
705
sub gallery_item_tags_update {
706
0
0
0
my $self = shift;
707
0
0
my $id = shift or die "missing required image/album id";
708
0
0
my $tags = shift or die "missing required tags";
709
0
return $self->request("/gallery/$id/tags", 'POST', {'tags' => $tags});
710
}
711
712
sub gallery_item_vote {
713
0
0
0
my $self = shift;
714
0
0
my $id = shift or die "missing required image/album id";
715
0
0
my $vote = shift or die "missing required vote";
716
0
return $self->request("/gallery/$id/vote/$vote", 'POST');
717
}
718
719
sub gallery_item_votes {
720
0
0
0
my $self = shift;
721
0
0
my $id = shift or die "missing required image/album id";
722
0
return $self->request("/gallery/$id/votes");
723
}
724
725
sub gallery_image_remove {
726
0
0
0
my $self = shift;
727
0
0
my $id = shift or die "missing required image id";
728
0
return $self->request("/gallery/$id", 'DELETE');
729
}
730
731
sub gallery_search {
732
0
0
0
my $self = shift;
733
0
0
my $opts = shift // {};
734
0
0
my $query = $opts->{'q'} // '';
735
0
0
my $adv = $opts->{'adv'} // 0;
736
0
0
my $sort = $opts->{'sort'} // 'time';
737
0
0
my $window = $opts->{'window'} // 'all';
738
0
0
my $page = $opts->{'page'} // 0;
739
0
my $data = {};
740
741
0
0
if ($adv) {
0
742
0
my %adv_keys = map { $_ => 1 } ('q_all', 'q_any', 'q_exactly', 'q_not', 'q_type', 'q_size_px');
0
743
0
foreach my $key (keys %{$adv}) {
0
744
0
0
$data->{$key} = $adv->{$key} unless ! exists($adv_keys{$key});
745
}
746
} elsif (!$query) {
747
0
die "must provide a query or adv search parameters";
748
}
749
750
0
print Dumper $data;
751
752
0
0
return $self->request("/gallery/search/$sort/$window/$page" . ($adv ? '' : "?q=$query"), 'GET', $data, undef, 1);
753
}
754
755
sub gallery_share_image {
756
0
0
0
my $self = shift;
757
0
0
my $image_id = shift or die "missing required image id";
758
0
0
my $title = shift or die "missing required title";
759
0
0
my $opts = shift // {};
760
0
my $data = {'title' => $title};
761
762
0
0
if ($opts) {
763
0
my @optional_keys = ('topic', 'terms', 'mature', 'tags');
764
0
foreach my $key (keys %{$opts}) {
0
765
0
0
0
if (first { $_ eq $key } @optional_keys) {
0
766
0
0
if ($key eq 'tags') {
767
0
0
if (ref $opts->{'tags'} eq 'ARRAY') {
768
0
$opts->{'tags'} = join(',', @{$opts->{'tags'}});
0
769
}
770
}
771
0
$data->{$key} = $opts->{$key};
772
}
773
}
774
}
775
776
0
return $self->request("/gallery/image/$image_id", "POST", $data);
777
}
778
779
sub gallery_share_album {
780
0
0
0
my $self = shift;
781
0
0
my $album_id = shift or die "missing required album id";
782
0
0
my $title = shift or die "missing required title";
783
0
0
my $opts = shift // {};
784
0
my $data = {'title' => $title};
785
786
0
0
if ($opts) {
787
0
my @optional_keys = ('topic', 'terms', 'mature', 'tags');
788
0
foreach my $key (keys %{$opts}) {
0
789
0
0
0
if (first { $_ eq $key } @optional_keys) {
0
790
0
0
if ($key eq 'tags') {
791
0
0
if (ref $opts->{'tags'} eq 'ARRAY') {
792
0
$opts->{'tags'} = join(',', @{$opts->{'tags'}});
0
793
}
794
}
795
0
$data->{$key} = $opts->{$key};
796
}
797
}
798
}
799
800
0
return $self->request("/gallery/album/$album_id", "POST", $data);
801
}
802
803
sub gallery_subreddit {
804
0
0
0
my $self = shift;
805
0
0
my $subreddit = shift or die "missing required subreddit";
806
0
0
my $opts = shift // {};
807
808
0
0
die "optional data must be a hashref" if ref $opts ne 'HASH';
809
810
0
0
my $sort = $opts->{'sort'} // 'time';
811
0
0
my $window = $opts->{'window'} // 'week';
812
0
0
my $page = $opts->{'page'} // 0;
813
814
0
0
return $self->request(("/gallery/r/$subreddit/$sort" . ($sort eq 'top' ? "/$window" : "") . "/$page"));
815
}
816
817
sub gallery_subreddit_image {
818
0
0
0
my $self = shift;
819
0
0
my $subreddit = shift or die "missing required subreddit";
820
0
0
my $image_id = shift or die "missing required image id";
821
822
0
return $self->request("/gallery/r/$subreddit/$image_id");
823
}
824
825
sub gallery_tag {
826
0
0
0
my $self = shift;
827
0
0
my $tag = shift or die "missing required tag";
828
0
0
my $opts = shift // {};
829
0
0
my $sort = $opts->{'sort'} // 'viral';
830
0
0
my $page = $opts->{'page'} // 0;
831
0
0
my $window = $opts->{'window'} // 'week';
832
833
0
0
return $self->request(("/gallery/t/$tag/$sort" . ($sort eq 'top' ? "/$window" : "") . "/$page"));
834
}
835
836
sub gallery_tag_info {
837
0
0
0
my $self = shift;
838
0
0
my $tag = shift or die "missing required tag";
839
0
return $self->request("/gallery/tag_info/$tag");
840
}
841
842
sub gallery_tags {
843
0
0
0
my $self = shift;
844
0
return $self->request("/tags");
845
}
846
847
# Image
848
sub image {
849
0
0
0
my $self = shift;
850
0
0
my $id = shift or die "missing required image id";
851
0
return $self->request("/image/$id");
852
}
853
854
sub image_upload {
855
0
0
0
my $self = shift;
856
0
0
my $src = shift or die "missing required image/video src";
857
0
0
my $type = shift or die "missing required image/video type";
858
0
0
my $opts = shift // {};
859
0
my $data = {'image' => $src, 'type' => $type};
860
0
my %hdr = ();
861
862
0
0
$data->{'title'} = $opts->{'title'} if $opts->{'title'};
863
0
0
$data->{'description'} = $opts->{'description'} if $opts->{'description'};
864
865
0
0
if ($type eq 'file') {
866
0
0
die "file doesnt exist at path: $src" unless -e $src;
867
0
0
die "provided src file path is not a file" unless -f $src;
868
0
$data->{'image'} = [$src];
869
0
%hdr = (Content_Type => 'form-data');
870
}
871
872
0
return $self->request("/image", 'POST', $data, \%hdr);
873
}
874
875
sub image_delete {
876
0
0
0
my $self = shift;
877
0
0
my $id = shift or die "missing required image id";
878
0
return $self->request("/image/$id", 'DELETE');
879
}
880
881
sub image_favorite {
882
0
0
0
my $self = shift;
883
0
0
my $id = shift or die "missing required image id";
884
0
return $self->request("/image/$id/favorite", 'POST');
885
}
886
887
sub image_update {
888
0
0
0
my $self = shift;
889
0
0
my $id = shift or die "missing required image id";
890
0
0
my $opts = shift // {};
891
0
return $self->request("/image/$id", 'POST', $opts);
892
}
893
894
# Feed
895
sub feed {
896
0
0
0
my $self = shift;
897
0
return $self->request("/feed");
898
}
899
900
=head1 NAME
901
902
ImgurAPI::Client - Imgur API client
903
904
=head1 DESCRIPTION
905
906
This is a client module for interfacing with the Imgur API.
907
908
=head1 SYNOPSIS
909
910
=head2 Instantiation
911
912
use ImgurAPI::Client;
913
914
my $client = ImgurAPI::Client->new({
915
'client_id' => 'your_client_id',
916
'access_token' => 'your_access_token'
917
});
918
919
my $upload = $client->image_upload("helloimgur.png", 'file', {title => 'title', description => 'desc'});
920
my $image_info = $client->image($upload->{'data'}->{'id'};
921
922
=head2 Authorization
923
924
Imgur uses OAuth 2.0 for authentication. OAuth 2.0 has four steps: registration, authorization, making authenticated requests and getting new access tokens after the initial one expires using a refresh token and client secret.
925
926
After registering a client application with Imgur L, the user will need to manually authorize it. Generate a authorization url using the C method and redirect the user to the generated url. The user will be prompted to authorize the application and upon authorization, the user will be redirected to the callback endpoint URL that was specified during application registration. The callback endpoint should collect the access token and refresh token and store them somewhere your code on the backend can pull the access token from and then pass it to the client. You can also visit the authorization url in the browser and manually pull the access token, refresh token and other parameters out of the redirect url and store them somewhere your code can pull them without having a collector endpoint setup. View the official imgur documentation for authorization L.
927
928
=head2 Authentication
929
930
The client can be authenticated by setting the access token and client id. Those can be set a couple of ways. The first way is to do it is by passing them to the constructor:
931
932
my $client = ImgurAPI::Client->new({
933
'client_id' => 'your_client_id',
934
'client_secret' => 'your_client_secret'
935
'access_token' => 'your_access_token'
936
});
937
938
The second way is to use the setter methods:
939
940
$client->set_access_token('your_access_token');
941
$client->set_client_id('your_client_id');
942
943
=head2 Refreshing Access Tokens
944
945
Access tokens expire after a period of time. To get a new access token, you can use the C method. This method requires the refresh token, client id and client secret. You can pass these values to the method or set them using the setter methods. If you don't pass them and they're not set, the method will die. If the function is successful it will update the internal access_token and refresh_token to use for subsequent requests and then return them in a hashref.
946
947
my %args = (
948
'refresh_token' => 'your_refresh_token',
949
'client_id' => 'your_client_id',
950
'client_secret' => 'your_client_secret'
951
);
952
my $refresh_token = get_refresh_token_from_datastore();
953
954
my $resp = $client->refresh_access_token(\%args);
955
my $new_refresh_token = $resp->{'refresh_token'};
956
957
# Store the new refresh token somewhere persistent so it can be used later when the new access token expires.
958
959
960
=head2 METHODS
961
962
=head3 new
963
964
$client = ImgurAPI::Client->new(\%args);
965
966
Valid constructor arguments are:
967
968
=over 4
969
970
=item *
971
972
C - Access token used to authenticate requests.
973
974
=item *
975
976
C - Client identifier used for authorization, refresh token requests and unauthenticated requests.
977
978
=item *
979
980
C - Client secret used for acquiring a refresh token.
981
982
=item *
983
984
C - Api endpoint response format type. Options are C (default) and C.
985
986
=item *
987
988
C - A parameter that's appended to the OAuth2 authorization callback URL. May be useful if you want to pass along a tracking value to the callback endpoint / collector.
989
990
=item *
991
992
C - Commercial use api key provided by RapidAPI.
993
994
=item *
995
996
C - User agent string to use for requests (default: 'ImgurAPI::Client/X.X.X')
997
998
=back
999
1000
A getter and setter method is provided for each constructor arg.
1001
1002
=head3 SETTER METHODS
1003
1004
1005
=head4 set_access_token
1006
1007
$client->set_access_token('your_access_token');
1008
1009
=head4 set_client_id
1010
1011
$client->set_client_id('your_client_id');
1012
1013
=head4 set_client_secret
1014
1015
$client->set_client_secret('your_client_secret');
1016
1017
=head4 set_format_type
1018
1019
$client->set_format_type('xml');
1020
1021
=head4 set_oauth_cb_state
1022
1023
$client->set_oauth_cb_state('your_oauth_cb_state');
1024
1025
=head4 set_rapidapi_key
1026
1027
$client->set_rapidapi_key('rapidapi_key');
1028
1029
=head4 set_user_agent
1030
1031
$client->set_user_agent('your_user_agent');
1032
1033
=head3 GETTER METHODS
1034
1035
=head4 access_token
1036
1037
$access_tok = $client->access_token;
1038
1039
=head4 client_id
1040
1041
$client_id = $client->client_id;
1042
1043
=head4 client_secret
1044
1045
$client_secret = $client->client_secret;
1046
1047
=head4 format_type
1048
1049
$format_type = $client->format_type;
1050
1051
=head4 oauth_cb_state
1052
1053
$oauth_cb_state = $client->oauth_cb_state;
1054
1055
=head4 rapidapi_key
1056
1057
$rapidapi_key = $client->rapidapi_key;
1058
1059
=head4 response
1060
1061
$response = $client->response;
1062
1063
This method will return the last response object from the last request.
1064
1065
=head4 response_content
1066
1067
$response_content = $client->response_content;
1068
1069
This method will return the last response content from the last request.
1070
1071
=head4 ratelimit_headers
1072
1073
$ratelimit_headers = $client->ratelimit_headers;
1074
1075
This method will return a hashref containing the rate limit headers from the last request. The keys returned are:
1076
1077
=head4 user_agent
1078
1079
$user_agent = $client->user_agent;
1080
1081
Returns the current user agent string.
1082
1083
=over 4
1084
1085
=item *
1086
1087
C - The total credits that can be allocated.
1088
1089
=item *
1090
1091
C - The total credits remaining.
1092
1093
=item *
1094
1095
C - Timestamp (unix epoch) for when the credits will be reset.
1096
1097
=item *
1098
1099
C - Total credits that can be allocated for the application in a day.
1100
1101
=item *
1102
1103
C - Total credits remaining for the application in a day.
1104
1105
=back
1106
1107
You can also get rate limit information by calling the C method.
1108
1109
1110
=head3 API REQUEST METHODS
1111
1112
1113
=head4 ACCOUNT
1114
1115
=head5 account
1116
1117
$resp = $client->account($username);
1118
1119
Get account information for a given username. Pass C as the username to get the account information for the authenticated user.
1120
1121
=head5 account_album
1122
1123
$resp = $client->account_album($username, $album_id);
1124
1125
Get information about a specific account album. Pass C as the username to get the account information for the authenticated user.
1126
1127
=head5 account_album_count
1128
1129
$resp = $client->account_album_count($username);
1130
1131
Get the total number of albums associated with an account. Pass C as the username to get the account information for the authenticated user.
1132
1133
=head5 account_album_delete
1134
1135
$resp = $client->account_album_delete($username, $album_id);
1136
1137
Delete a specific album. Pass C as the username to get the account information for the authenticated user.
1138
1139
=head5 account_album_ids
1140
1141
$resp = $client->account_album_ids($username, \%opts);
1142
1143
Get all the album ids associated with the account. Pass C as the username to get the account information for the authenticated user.
1144
1145
Valid C<\%opts> keys are:
1146
1147
=over 4
1148
1149
=item *
1150
1151
C - Page number
1152
1153
=back
1154
1155
=head5 account_albums
1156
1157
$resp = $client->account_albums($username, \%opts);
1158
1159
Valid C<\%opts> keys are:
1160
1161
=over 4
1162
1163
=item *
1164
1165
C - Page number
1166
1167
=back
1168
1169
=head5 account_block_status
1170
1171
$resp = $client->account_block_status($username);
1172
1173
Get the current block status for a user.
1174
1175
=head5 account_block_create
1176
1177
$resp = $client->account_block_create($username);
1178
1179
Block a user.
1180
1181
=head5 account_block_delete
1182
1183
$resp = $client->account_block_delete($username);
1184
1185
Unblock a user.
1186
1187
=head5 account_blocks
1188
1189
$resp = $client->account_blocks;
1190
1191
Get the list of usernames that have been blocked.
1192
1193
=head5 account_comment
1194
1195
$resp = $client->account_comment($username, $comment_id);
1196
1197
Get information about a specific account comment.
1198
1199
=head5 account_comment_count
1200
1201
$resp = $client->account_comment_count($username);
1202
1203
Get the total number of comments associated with the account username.
1204
1205
=head5 account_comment_delete
1206
1207
$resp = $client->account_comment_delete($username, $comment_id);
1208
1209
Delete a specific account comment.
1210
1211
=head5 account_comment_ids
1212
1213
$resp = $client->account_comment_ids($username, \%opts);
1214
1215
Valid C<\%opts> keys are:
1216
1217
=over 4
1218
1219
=item *
1220
1221
C - Page number
1222
1223
=item *
1224
1225
C - Sort order. Options are C, C and C (default)
1226
1227
=back
1228
1229
=head5 account_comments
1230
1231
$resp = $client->account_comments($username, \%opts);
1232
1233
Valid C<\%opts> keys are:
1234
1235
=over 4
1236
1237
=item *
1238
1239
C - Page number
1240
1241
=item *
1242
1243
C - Sort order. Options are C, C and C (default)
1244
1245
=back
1246
1247
=head5 account_delete
1248
1249
$resp = $client->account_delete($password, \%opts);
1250
1251
Valid C<\%opts> keys are:
1252
1253
=over 4
1254
1255
=item *
1256
1257
C - Array reference of reasons for deleting the account
1258
1259
=item *
1260
1261
C - Feedback in the form of a string for Imgur.
1262
1263
=back
1264
1265
=head5 account_favorites
1266
1267
$resp = $client->account_favorites($username, \%opts);
1268
1269
Valid C<\%opts> keys are:
1270
1271
=over 4
1272
1273
=item *
1274
1275
C - Page number
1276
1277
=item *
1278
1279
C - Sort order. Options are C or C (default)
1280
1281
=back
1282
1283
=head5 account_gallery_favorites
1284
1285
$resp = $client->account_gallery_favorites($username, \%opts);
1286
1287
Valid C<\%opts> keys are:
1288
1289
=over 4
1290
1291
=item *
1292
1293
C - Page number
1294
1295
=item *
1296
1297
C - Sort order. Options are C or C (default)
1298
1299
=back
1300
1301
=head5 account_image
1302
1303
$resp = $client->account_image($username, $image_id);
1304
1305
Get information about a specific image in the account.
1306
1307
=head5 account_image_count
1308
1309
$resp = $client->account_image_count($username);
1310
1311
Get the total number of images associated with the account.
1312
1313
=head5 account_image_delete
1314
1315
$resp = $client->account_image_delete($username, $image_id);
1316
1317
Delete a specific image.
1318
1319
=head5 account_image_ids
1320
1321
$resp = $client->account_image_ids($username, \%opts);
1322
1323
Valid C<\%opts> keys are:
1324
1325
=over 4
1326
1327
=item *
1328
1329
C - Page number
1330
1331
=back
1332
1333
=head5 account_images
1334
1335
$resp = $client->account_images($username, \%opts);
1336
1337
Valid C<\%opts> keys are:
1338
1339
=over 4
1340
1341
=item *
1342
1343
C - Page number
1344
1345
=back
1346
1347
=head5 account_reply_notifications
1348
1349
$resp = $client->account_reply_notifications($username, \%opts);
1350
1351
Valid C<\%opts> keys are:
1352
1353
=over 4
1354
1355
=item *
1356
1357
C - Boolean value. True for unviewed notifications and false for viewed notifications.
1358
1359
=back
1360
1361
=head5 account_settings
1362
1363
$resp = $client->account_settings($username);
1364
1365
Get account settings for a given username.
1366
1367
=head5 account_settings_update
1368
1369
$resp = $client->account_settings_update($username, \%opts);
1370
1371
Update an account's settings.
1372
1373
Valid C<\%opts> keys are:
1374
1375
=over 4
1376
1377
=item *
1378
1379
C - A string for the bio.
1380
1381
=item *
1382
1383
C - A boolean value to set images to public or not by default.
1384
1385
=item *
1386
1387
C - A boolean value to allow messaging or not.
1388
1389
=item *
1390
1391
C - A boolean value to accept the gallery terms.
1392
1393
=item *
1394
1395
C - A valid username between 4 and 63 alphanumeric characters.
1396
1397
=item *
1398
1399
C - A boolean value to show mature images in gallery list endpoints.
1400
1401
=item *
1402
1403
C - A boolean value, true to subscribe to the newsletter, false to unsubscribe from the newsletter.
1404
1405
=back
1406
1407
=head5 account_submissions
1408
1409
$resp = $client->account_submissions($username, \%opts);
1410
1411
Valid C<\%opts> keys are:
1412
1413
=over 4
1414
1415
=item *
1416
1417
C - Page number
1418
1419
=back
1420
1421
=head5 account_tag_follow
1422
1423
$resp = $client->account_tag_follow($tag);
1424
1425
Follow a tag.
1426
1427
=head5 account_tag_unfollow
1428
1429
$resp = $client->account_tag_unfollow($tag);
1430
1431
Unfollow a tag.
1432
1433
=head5 account_verify_email_send
1434
1435
$resp = $client->account_verify_email_send($username);
1436
1437
Send a verification email.
1438
1439
=head5 account_verify_email_status
1440
1441
$resp = $client->account_verify_email_status($username);
1442
1443
Get the status of the verification email.
1444
1445
=head4 ALBUM
1446
1447
=head5 album
1448
1449
$resp = $client->album($album_id);
1450
1451
Get information about a specific album.
1452
1453
=head5 album_create
1454
1455
$resp = $client->album_create(\%opts);
1456
1457
=over 4
1458
1459
=item *
1460
1461
C - Array reference of image ids.
1462
1463
=item *
1464
1465
C - Title of the album.
1466
1467
=item *
1468
1469
C - Description of the album.
1470
1471
=item *
1472
1473
C - Image id of the cover image.
1474
1475
=back
1476
1477
=head5 album_delete
1478
1479
$resp = $client->album_delete($album_id);
1480
1481
Delete an album.
1482
1483
=head5 album_favorite
1484
1485
$resp = $client->album_favorite($album_id);
1486
1487
Favorite an album.
1488
1489
=head5 album_image
1490
1491
$resp = $client->album_image($album_id, $image_id);
1492
1493
Get information about a specific image in an album.
1494
1495
=head5 album_images
1496
1497
$resp = $client->album_images($album_id);
1498
1499
Get all the images in an album.
1500
1501
=head5 album_images_add
1502
1503
$resp = $client->album_images_add($album_id, \@image_ids);
1504
1505
Add images to an album.
1506
1507
=head5 album_images_delete
1508
1509
$resp = $client->album_images_delete($album_id, \@image_ids);
1510
1511
Delete images from an album.
1512
1513
=head5 album_images_set
1514
1515
$resp = $client->album_images_set($album_id, \@image_ids);
1516
1517
Set the images for an album.
1518
1519
=head5 album_update
1520
1521
$resp = $client->album_update($album_id, \%opts);
1522
1523
Update an album. Valid C<\%opts> keys are:
1524
1525
=over 4
1526
1527
=item *
1528
1529
C - Array reference of image ids.
1530
1531
=item *
1532
1533
C - Title of the album.
1534
1535
=item *
1536
1537
C - Description of the album.
1538
1539
=item *
1540
1541
C - Image id of the cover image.
1542
1543
=back
1544
1545
=head4 COMMENT
1546
1547
=head5 comment
1548
1549
$resp = $client->comment($comment_id);
1550
1551
Get information about a specific comment.
1552
1553
=head5 comment_create
1554
1555
$resp = $client->comment_create($image_id, $comment);
1556
1557
Create a new comment on an image.
1558
1559
=head5 comment_delete
1560
1561
$resp = $client->comment_delete($comment_id);
1562
1563
Delete a comment.
1564
1565
=head5 comment_replies
1566
1567
$resp = $client->comment_replies($comment_id);
1568
1569
Get the replies for a specific comment.
1570
1571
=head5 comment_reply
1572
1573
$resp = $client->comment_reply($image_id, $comment_id, $comment);
1574
1575
Create a new reply to a comment.
1576
1577
=head5 comment_report
1578
1579
$resp = $client->comment_report($comment_id, $reason);
1580
1581
Report a comment with a reason. Valid reasons are:
1582
1583
=over 4
1584
1585
=item *
1586
1587
C<1> - Doesn't belong on Imgur
1588
1589
=item *
1590
1591
C<2> - Spam
1592
1593
=item *
1594
1595
C<3> - Abusive
1596
1597
=item *
1598
1599
C<4> - Mature content not marked as mature
1600
1601
=item *
1602
1603
C<5> - Pornography
1604
1605
=back
1606
1607
=head5 comment_vote
1608
1609
$resp = $client->comment_vote($comment_id, $vote);
1610
1611
Cast a vote on a comment. Valid vote values are C, C and C.
1612
1613
=head4 GALLERY
1614
1615
=head5 gallery
1616
1617
$resp = $client->gallery(\%opts);
1618
1619
Get gallery images.
1620
1621
Validation options are:
1622
1623
=over 4
1624
1625
=item *
1626
1627
C - Section. Options are C (default), C and C.
1628
1629
=item *
1630
1631
C - Sort order. Options are C (default), C, C, C.
1632
1633
=item *
1634
1635
C - Page number.
1636
1637
=item *
1638
1639
C - Time window. Options are C, C, C, C, C.
1640
1641
=item *
1642
1643
C - Show or hide viral images in the gallery. Default is C<1>.
1644
1645
=item *
1646
1647
C - Show or hide album previews in the gallery. Default is C<1>.
1648
1649
=back
1650
1651
=head5 gallery_album
1652
1653
$resp = $client->gallery_album($album_id);
1654
1655
Get additional information about an album in the gallery.
1656
1657
1658
Get information about a specific gallery album.
1659
1660
=head5 gallery_image
1661
1662
$resp = $client->gallery_image($image_id);
1663
1664
Get additional information about an image in the gallery.
1665
1666
=head5 gallery_item_comment
1667
1668
$resp = $client->gallery_item_comment($item_id, $comment);
1669
1670
Create a new comment on a gallery item.
1671
1672
=head5 gallery_item_comment_info
1673
1674
$resp = $client->gallery_item_comment_info($item_id, $comment_id);
1675
1676
Get information about a specific comment on a gallery item.
1677
1678
=head5 gallery_item_comments
1679
1680
$resp = $client->gallery_item_comments($item_id);
1681
1682
Get all the comments on a gallery item.
1683
1684
=head5 gallery_item_report
1685
1686
$resp = $client->gallery_item_report($item_id, \%opts);
1687
1688
Report an Image in the gallery
1689
1690
1691
Report a gallery item. Valid C<\%opts> keys are:
1692
1693
=over 4
1694
1695
=item *
1696
1697
C - Reason for reporting the item. Options are C<1> (doesn't belong on Imgur), C<2> (spam), C<3> (abusive), C<4> (mature content not marked as mature), C<5> (pornography).
1698
1699
=back
1700
1701
=head5 gallery_item_tags
1702
1703
$resp = $client->gallery_item_tags($item_id);
1704
1705
Get the tags for a gallery item.
1706
1707
=head5 gallery_item_tags_update
1708
1709
$resp = $client->gallery_item_tags_update($item_id, \@tags);
1710
1711
Update the tags for a gallery item.
1712
1713
=head5 gallery_item_vote
1714
1715
$resp = $client->gallery_item_vote($item_id, $vote);
1716
1717
Cast a vote on a gallery item. Valid vote values are C, C and C.
1718
1719
=head5 gallery_item_votes
1720
1721
$resp = $client->gallery_item_votes($item_id);
1722
1723
Get the votes for a gallery item.
1724
1725
=head5 gallery_image_remove
1726
1727
$resp = $client->gallery_image_remove($image_id);
1728
1729
Remove an image from the gallery.
1730
1731
=head5 gallery_search
1732
1733
$resp = $client->gallery_search(\%opts);
1734
1735
Search the gallery. Valid C<\%opts> keys are:
1736
1737
=over 4
1738
1739
=item *
1740
1741
C - Query string (ignored if C is set).
1742
1743
=item *
1744
1745
C - Sort order. Options are C (default), C, C, C.
1746
1747
=item *
1748
1749
C - Time window. Options are C (default), C, C, C, C.
1750
1751
=item *
1752
1753
C - Page number.
1754
1755
=item *
1756
1757
C - Advanced search options
1758
1759
=over 4
1760
1761
=item *
1762
1763
C - Search for all of these words.
1764
1765
=item *
1766
1767
C - Search for any of these words.
1768
1769
=item *
1770
1771
C - Search for exactly this word or phrase.
1772
1773
=item *
1774
1775
C - Exclude results matching this.
1776
1777
=item *
1778
1779
C - Show results for any file type, or specific file types. C, C, C, C (animated gif), C.
1780
1781
=item *
1782
1783
C - Return images that are greater or equal to the width/height you specify. C<300x300>.
1784
1785
=back
1786
1787
=back
1788
1789
=head5 gallery_share_image
1790
1791
$resp = $client->gallery_share_image($image_id, $title, \%opts);
1792
1793
Share an image. Valid C<\%opts> keys are:
1794
1795
=over 4
1796
1797
=item *
1798
1799
C - Topic of the shared image.
1800
1801
=item *
1802
1803
C - Terms of the shared image.
1804
1805
=item *
1806
1807
C - Boolean value to mark the shared image as mature.
1808
1809
=item *
1810
1811
C - Array reference of tags for the shared image.
1812
1813
=back
1814
1815
=head5 gallery_share_album
1816
1817
$resp = $client->gallery_share_album($album_id, $title, \%opts);
1818
1819
Share an album. Valid C<\%opts> keys are:
1820
1821
=over 4
1822
1823
=item *
1824
1825
C - Topic of the shared image.
1826
1827
=item *
1828
1829
C - Terms of the shared image.
1830
1831
=item *
1832
1833
C - Boolean value to mark the shared image as mature.
1834
1835
=item *
1836
1837
C - Array reference of tags for the shared image.
1838
1839
=back
1840
1841
=head5 gallery_subreddit
1842
1843
$resp = $client->gallery_subreddit($subreddit, \%opts);
1844
1845
Get images from a subreddit.
1846
1847
C<$subreddit> is the name of the subreddit to get images from.
1848
1849
Valid C<\%opts> keys are:
1850
1851
=over 4
1852
1853
=item *
1854
1855
C - Sort order. Options are C (default), C, C and C.
1856
1857
=item *
1858
1859
C - Page number (default is 0)
1860
1861
=item *
1862
1863
C - Window of time. Options are C, C (default), C, C, C.
1864
I can't wait until NY AG starts seizing trumps assets starting monday
1865
1866
=back
1867
1868
=head5 gallery_subreddit_image
1869
1870
$resp = $client->gallery_subreddit_image('subreddit', $image_id);
1871
1872
=head5 gallery_tag
1873
1874
$resp = $client->gallery_tag($tag, \%opts);
1875
1876
Returns tag metadata, and posts tagged with the C<$tag> provided
1877
1878
=over 4
1879
1880
=item *
1881
1882
C - Sort order. Options are C (default), C, C and C.
1883
1884
=item *
1885
1886
C - Page number (default is 0)
1887
1888
=item *
1889
1890
C - Window of time. Options are C, C (default), C, C, C.
1891
I can't wait until NY AG starts seizing trumps assets starting monday
1892
1893
=back
1894
1895
=head5 gallery_tag_info
1896
1897
$resp = $client->gallery_tag_info($tag);
1898
1899
Get gallery tag information.
1900
1901
=head5 gallery_tags
1902
1903
$resp = $client->gallery_tags;
1904
1905
Gets a list of default tags
1906
1907
=head4 IMAGE
1908
1909
=head5 image
1910
1911
$resp = $client->image($image_id);
1912
1913
Get information about a specific image.
1914
1915
=head5 image_upload
1916
1917
$resp = $client->image_upload($src, $type, \%opts);
1918
1919
Upload an image or video to imgur.
1920
1921
C<$src> Path, URL or Base64 encoding of the image or video file.
1922
C<$type> Content type can be either C, C or C.
1923
1924
Valid C<\%opts> keys are:
1925
1926
=over 4
1927
1928
=item *
1929
1930
C - Title of the image.
1931
1932
=item *
1933
1934
C - Description of the image.
1935
1936
=back
1937
1938
=head5 image_delete
1939
1940
$resp = $client->image_delete($image_id);
1941
1942
Delete an image.
1943
1944
=head5 image_favorite
1945
1946
$resp = $client->image_favorite($image_id);
1947
1948
Favorite an image.
1949
1950
=head5 image_update
1951
1952
$resp = $client->image_update($image_id, \%opts);
1953
1954
Update an image.
1955
1956
Valid C<\%opts> keys are:
1957
1958
=over 4
1959
1960
=item *
1961
1962
C - Title of the image.
1963
1964
=item *
1965
1966
C - Description of the image.
1967
1968
=back
1969
1970
=head4 FEED
1971
1972
=head5 feed
1973
1974
$resp = $client->feed;
1975
1976
Get the authenticated user's feed.
1977
1978
=head1 AUTHOR
1979
1980
Dillan Hildebrand
1981
1982
=head1 LICENSE
1983
1984
MIT
1985
1986
=cut
1987
1988
1;