line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Shutterstock; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$WebService::Shutterstock::VERSION = '0.006'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Easy access to Shutterstock's public API |
7
|
|
|
|
|
|
|
|
8
|
9
|
|
|
9
|
|
304057
|
use strict; |
|
9
|
|
|
|
|
25
|
|
|
9
|
|
|
|
|
518
|
|
9
|
9
|
|
|
9
|
|
53
|
use warnings; |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
424
|
|
10
|
|
|
|
|
|
|
|
11
|
9
|
|
|
9
|
|
24761
|
use Moo 1; |
|
9
|
|
|
|
|
312311
|
|
|
9
|
|
|
|
|
73
|
|
12
|
9
|
|
|
9
|
|
32570
|
use REST::Client; |
|
9
|
|
|
|
|
973330
|
|
|
9
|
|
|
|
|
435
|
|
13
|
9
|
|
|
9
|
|
33282
|
use MIME::Base64; |
|
9
|
|
|
|
|
33273
|
|
|
9
|
|
|
|
|
842
|
|
14
|
9
|
|
|
9
|
|
11888
|
use JSON qw(encode_json decode_json); |
|
9
|
|
|
|
|
162602
|
|
|
9
|
|
|
|
|
72
|
|
15
|
9
|
|
|
9
|
|
9637
|
use WebService::Shutterstock::Lightbox; |
|
9
|
|
|
|
|
34
|
|
|
9
|
|
|
|
|
333
|
|
16
|
9
|
|
|
9
|
|
6542
|
use WebService::Shutterstock::Client; |
|
9
|
|
|
|
|
33
|
|
|
9
|
|
|
|
|
289
|
|
17
|
9
|
|
|
9
|
|
7600
|
use WebService::Shutterstock::Customer; |
|
9
|
|
|
|
|
31
|
|
|
9
|
|
|
|
|
380
|
|
18
|
9
|
|
|
9
|
|
7225
|
use WebService::Shutterstock::SearchResults; |
|
9
|
|
|
|
|
44
|
|
|
9
|
|
|
|
|
339
|
|
19
|
9
|
|
|
9
|
|
68
|
use WebService::Shutterstock::Exception; |
|
9
|
|
|
|
|
20
|
|
|
9
|
|
|
|
|
204
|
|
20
|
9
|
|
|
9
|
|
6869
|
use WebService::Shutterstock::Video; |
|
9
|
|
|
|
|
30
|
|
|
9
|
|
|
|
|
6917
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has api_username => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
required => 1, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
has api_key => ( |
27
|
|
|
|
|
|
|
is => 'ro', |
28
|
|
|
|
|
|
|
required => 1, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
has client => ( |
31
|
|
|
|
|
|
|
is => 'lazy', |
32
|
|
|
|
|
|
|
clearer => 1, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _build_client { |
36
|
6
|
|
|
6
|
|
6412
|
my $self = shift; |
37
|
6
|
|
100
|
|
|
115
|
my $client = WebService::Shutterstock::Client->new( host => $ENV{SS_API_HOST} || 'https://api.shutterstock.com' ); |
38
|
6
|
|
|
|
|
472
|
$client->addHeader( |
39
|
|
|
|
|
|
|
Authorization => sprintf( |
40
|
|
|
|
|
|
|
'Basic %s', |
41
|
|
|
|
|
|
|
MIME::Base64::encode( |
42
|
|
|
|
|
|
|
join( ':', $self->api_username, $self->api_key ) |
43
|
|
|
|
|
|
|
) |
44
|
|
|
|
|
|
|
) |
45
|
|
|
|
|
|
|
); |
46
|
6
|
|
|
|
|
154
|
return $client; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub auth { |
52
|
7
|
|
|
7
|
1
|
20809
|
my $self = shift; |
53
|
7
|
|
|
|
|
27
|
my %args = @_; |
54
|
7
|
|
66
|
|
|
49
|
$args{username} ||= $self->api_username; |
55
|
7
|
100
|
|
|
|
29
|
if(!$args{password}){ |
56
|
1
|
|
|
|
|
9
|
die WebService::Shutterstock::Exception->new( error => "missing 'password' param for auth call"); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
$self->client->POST( |
59
|
6
|
|
|
|
|
139
|
'/auth/customer.json', |
60
|
|
|
|
|
|
|
{ |
61
|
|
|
|
|
|
|
username => $args{username}, |
62
|
|
|
|
|
|
|
password => $args{password} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
); |
65
|
6
|
|
|
|
|
156
|
my $auth_info = $self->client->process_response; |
66
|
3
|
100
|
|
|
|
212
|
if(ref($auth_info) eq 'HASH'){ |
67
|
2
|
|
|
|
|
56
|
return WebService::Shutterstock::Customer->new( auth_info => $auth_info, client => $self->client );; |
68
|
|
|
|
|
|
|
} else { |
69
|
1
|
|
|
|
|
25
|
die WebService::Shutterstock::Exception->new( |
70
|
|
|
|
|
|
|
response => $self->client->response, |
71
|
|
|
|
|
|
|
error => "Error authenticating $args{username}: $auth_info" |
72
|
|
|
|
|
|
|
); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub categories { |
78
|
1
|
|
|
1
|
1
|
3682
|
my $self = shift; |
79
|
1
|
|
|
|
|
6
|
$self->client->GET('/categories.json'); |
80
|
1
|
|
|
|
|
39
|
return $self->client->process_response; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub search { |
85
|
3
|
|
|
3
|
1
|
14319
|
my $self = shift; |
86
|
3
|
|
|
|
|
16
|
my %args = @_; |
87
|
3
|
|
100
|
|
|
26
|
my $type = delete $args{type} || 'image'; |
88
|
3
|
|
|
|
|
67
|
return WebService::Shutterstock::SearchResults->new( client => $self->client, query => \%args, type => $type ); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub search_images { |
93
|
0
|
|
|
0
|
1
|
|
return shift->search(@_, type => 'image'); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub search_videos { |
98
|
0
|
|
|
0
|
1
|
|
return shift->search(@_, type => 'video'); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub image { |
103
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
104
|
0
|
|
|
|
|
|
my $image_id = shift; |
105
|
0
|
|
|
|
|
|
my $image = WebService::Shutterstock::Image->new( image_id => $image_id, client => $self->client ); |
106
|
0
|
0
|
|
|
|
|
return $image->is_available ? $image : undef; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub video { |
111
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
112
|
0
|
|
|
|
|
|
my $video_id = shift; |
113
|
0
|
|
|
|
|
|
my $video = WebService::Shutterstock::Video->new( video_id => $video_id, client => $self->client ); |
114
|
0
|
0
|
|
|
|
|
return $video->is_available ? $video : undef; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
__END__ |