| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WebService::Shutterstock::Customer; |
|
2
|
|
|
|
|
|
|
{ |
|
3
|
|
|
|
|
|
|
$WebService::Shutterstock::Customer::VERSION = '0.006'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: Class allowing API operations in the context of a specific customer |
|
7
|
|
|
|
|
|
|
|
|
8
|
9
|
|
|
9
|
|
55
|
use strict; |
|
|
9
|
|
|
|
|
19
|
|
|
|
9
|
|
|
|
|
462
|
|
|
9
|
9
|
|
|
9
|
|
62
|
use warnings; |
|
|
9
|
|
|
|
|
16
|
|
|
|
9
|
|
|
|
|
356
|
|
|
10
|
9
|
|
|
9
|
|
50
|
use Moo; |
|
|
9
|
|
|
|
|
24
|
|
|
|
9
|
|
|
|
|
75
|
|
|
11
|
9
|
|
|
9
|
|
9233
|
use WebService::Shutterstock::Subscription; |
|
|
9
|
|
|
|
|
27
|
|
|
|
9
|
|
|
|
|
375
|
|
|
12
|
9
|
|
|
9
|
|
71
|
use Carp qw(croak); |
|
|
9
|
|
|
|
|
20
|
|
|
|
9
|
|
|
|
|
492
|
|
|
13
|
9
|
|
|
9
|
|
50
|
use JSON qw(encode_json); |
|
|
9
|
|
|
|
|
15
|
|
|
|
9
|
|
|
|
|
76
|
|
|
14
|
9
|
|
|
9
|
|
13396
|
use WebService::Shutterstock::LicensedVideo; |
|
|
9
|
|
|
|
|
30
|
|
|
|
9
|
|
|
|
|
304
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
9
|
|
|
9
|
|
71
|
use WebService::Shutterstock::AuthedClient; |
|
|
9
|
|
|
|
|
36
|
|
|
|
9
|
|
|
|
|
32794
|
|
|
17
|
|
|
|
|
|
|
with 'WebService::Shutterstock::AuthedClient'; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub account_id { |
|
21
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
|
22
|
0
|
|
|
|
|
0
|
return $self->_info->{account_id}; |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub metadata_field_definitions { |
|
27
|
4
|
|
|
4
|
1
|
6
|
my $self = shift; |
|
28
|
4
|
|
|
|
|
102
|
return $self->_info->{metadata_field_definitions}; |
|
29
|
|
|
|
|
|
|
} |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
has _info => ( is => 'lazy' ); |
|
32
|
|
|
|
|
|
|
sub _build__info { |
|
33
|
2
|
|
|
2
|
|
464
|
my $self = shift; |
|
34
|
2
|
|
|
|
|
11
|
my $client = $self->client; |
|
35
|
2
|
|
|
|
|
14
|
$client->GET( sprintf( '/customers/%s.json', $self->username ), $self->with_auth_params ); |
|
36
|
2
|
|
|
|
|
14
|
my $data = $client->process_response; |
|
37
|
2
|
|
|
|
|
1220
|
return $data; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has subscriptions => ( is => 'lazy' ); |
|
42
|
|
|
|
|
|
|
sub _build_subscriptions { |
|
43
|
1
|
|
|
1
|
|
4247
|
my $self = shift; |
|
44
|
1
|
|
|
|
|
13
|
$self->client->GET( sprintf( '/customers/%s/subscriptions.json', $self->username ), $self->with_auth_params ); |
|
45
|
1
|
|
|
|
|
14
|
my $subscriptions = $self->client->process_response; |
|
46
|
1
|
|
|
|
|
66
|
return [ map { $self->new_with_auth( 'WebService::Shutterstock::Subscription', %$_ ) } @$subscriptions ] |
|
|
2
|
|
|
|
|
15636
|
|
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub subscription { |
|
51
|
2
|
|
|
2
|
1
|
5
|
my $self = shift; |
|
52
|
2
|
|
|
|
|
13
|
my ( $subscription, @extra ) = $self->find_subscriptions(@_); |
|
53
|
2
|
|
|
|
|
15
|
return $subscription; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub find_subscriptions { |
|
58
|
9
|
|
|
9
|
1
|
20
|
my $self = shift; |
|
59
|
9
|
|
|
|
|
33
|
my %criteria = @_; |
|
60
|
|
|
|
|
|
|
my $filter = sub { |
|
61
|
22
|
|
|
22
|
|
66
|
my $s = shift; |
|
62
|
22
|
|
|
|
|
67
|
foreach my $m(keys %criteria){ |
|
63
|
32
|
100
|
|
|
|
415
|
croak "Invalid subscription filter key '$m': no such attribute on WebService::Shutterstock::Subscription" if !$s->can($m); |
|
64
|
31
|
|
|
|
|
111
|
my $value = $s->$m; |
|
65
|
31
|
|
|
|
|
415
|
my $matcher = $criteria{$m}; |
|
66
|
31
|
100
|
|
|
|
90
|
if(ref $matcher eq 'CODE'){ |
|
|
|
100
|
|
|
|
|
|
|
67
|
2
|
|
|
|
|
4
|
local $_ = $value; |
|
68
|
2
|
50
|
|
|
|
7
|
return unless $matcher->($value); |
|
69
|
|
|
|
|
|
|
} elsif(ref $matcher eq 'Regexp'){ |
|
70
|
2
|
50
|
|
|
|
18
|
return unless $value =~ $matcher; |
|
71
|
|
|
|
|
|
|
} else { |
|
72
|
27
|
100
|
|
|
|
143
|
return unless $value eq $matcher; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
} |
|
75
|
8
|
|
|
|
|
53
|
return 1; |
|
76
|
9
|
|
|
|
|
54
|
}; |
|
77
|
9
|
|
|
|
|
19
|
return grep { $filter->($_) } @{ $self->subscriptions }; |
|
|
22
|
|
|
|
|
1855
|
|
|
|
9
|
|
|
|
|
13891
|
|
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub lightboxes { |
|
82
|
2
|
|
|
2
|
1
|
11702
|
my $self = shift; |
|
83
|
2
|
|
100
|
|
|
18
|
my $extended = shift || 0; |
|
84
|
2
|
100
|
|
|
|
22
|
$self->client->GET( |
|
85
|
|
|
|
|
|
|
sprintf( |
|
86
|
|
|
|
|
|
|
'/customers/%s/lightboxes%s.json', |
|
87
|
|
|
|
|
|
|
$self->username, $extended ? '/extended' : '' |
|
88
|
|
|
|
|
|
|
), |
|
89
|
|
|
|
|
|
|
$self->with_auth_params |
|
90
|
|
|
|
|
|
|
); |
|
91
|
2
|
|
|
|
|
24
|
my $lightboxes = $self->client->process_response; |
|
92
|
2
|
|
|
|
|
129
|
return [ map {$self->new_with_auth('WebService::Shutterstock::Lightbox', %$_) } @$lightboxes ]; |
|
|
4
|
|
|
|
|
34
|
|
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub lightbox { |
|
97
|
2
|
|
|
2
|
1
|
746
|
my $self = shift; |
|
98
|
2
|
|
|
|
|
4
|
my $id = shift; |
|
99
|
2
|
|
|
|
|
11
|
my $lightbox = $self->new_with_auth('WebService::Shutterstock::Lightbox', lightbox_id => $id); |
|
100
|
2
|
100
|
|
|
|
5
|
eval { $lightbox->load; 1 } or do { |
|
|
2
|
|
|
|
|
11
|
|
|
|
1
|
|
|
|
|
6
|
|
|
101
|
1
|
|
|
|
|
107
|
my $e = $@; |
|
102
|
1
|
50
|
33
|
|
|
3
|
if(eval { $e->isa('WebService::Shutterstock::Exception') } && ($e->code eq 404 || $e->code eq 500)){ |
|
|
1
|
|
33
|
|
|
18
|
|
|
103
|
1
|
|
|
|
|
1565
|
$lightbox = undef; |
|
104
|
|
|
|
|
|
|
} else { |
|
105
|
0
|
|
|
|
|
0
|
die $e; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
}; |
|
108
|
2
|
|
|
|
|
30
|
return $lightbox; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub downloads { |
|
113
|
3
|
|
|
3
|
1
|
3957
|
my $self = shift; |
|
114
|
3
|
|
|
|
|
10
|
my %args = @_; |
|
115
|
3
|
|
|
|
|
27
|
$self->client->GET( |
|
116
|
|
|
|
|
|
|
sprintf( '/customers/%s/images/downloads.json', $self->username ), |
|
117
|
|
|
|
|
|
|
$self->with_auth_params(%args) ); |
|
118
|
3
|
|
|
|
|
28
|
return $self->client->process_response; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub license_image { |
|
123
|
3
|
|
|
3
|
1
|
12313
|
my $self = shift; |
|
124
|
3
|
|
|
|
|
23
|
my %args = @_; |
|
125
|
|
|
|
|
|
|
|
|
126
|
3
|
50
|
|
|
|
20
|
my $image_id = $args{image_id} or croak "Must specify image_id to license"; |
|
127
|
|
|
|
|
|
|
|
|
128
|
3
|
|
50
|
|
|
23
|
my $editorial_acknowledgement = $args{editorial_acknowledgement} || 0; |
|
129
|
|
|
|
|
|
|
|
|
130
|
3
|
|
|
|
|
17
|
my $subscription = $self->_find_subscription_from_arg('photo', $args{subscription}); |
|
131
|
3
|
50
|
|
|
|
13
|
if(!$subscription){ |
|
132
|
0
|
|
|
|
|
0
|
croak "Must specify a subscription to license images under"; |
|
133
|
|
|
|
|
|
|
} |
|
134
|
|
|
|
|
|
|
|
|
135
|
3
|
|
|
|
|
18
|
my $metadata = $self->_valid_metadata($args{metadata}); |
|
136
|
|
|
|
|
|
|
|
|
137
|
2
|
|
|
|
|
120
|
my $size = $self->_valid_size_for_subscription($subscription, $args{size}); |
|
138
|
|
|
|
|
|
|
|
|
139
|
1
|
50
|
|
|
|
5
|
my $format = $size eq 'vector' ? 'eps' : 'jpg'; |
|
140
|
1
|
|
|
|
|
5
|
my $client = $self->client; |
|
141
|
|
|
|
|
|
|
|
|
142
|
1
|
50
|
|
|
|
27
|
$client->POST( |
|
143
|
|
|
|
|
|
|
sprintf( |
|
144
|
|
|
|
|
|
|
'/subscriptions/%s/images/%s/sizes/%s.json', |
|
145
|
|
|
|
|
|
|
$subscription->id, $image_id, $size |
|
146
|
|
|
|
|
|
|
), |
|
147
|
|
|
|
|
|
|
$self->with_auth_params( |
|
148
|
|
|
|
|
|
|
format => $format, |
|
149
|
|
|
|
|
|
|
editorial_acknowledgement => $editorial_acknowledgement, |
|
150
|
|
|
|
|
|
|
( $metadata ? ( metadata => encode_json($metadata) ) : () ), |
|
151
|
|
|
|
|
|
|
) |
|
152
|
|
|
|
|
|
|
); |
|
153
|
|
|
|
|
|
|
|
|
154
|
1
|
|
|
|
|
11
|
return WebService::Shutterstock::LicensedImage->new($client->process_response); |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub license_video { |
|
159
|
2
|
|
|
2
|
0
|
1733
|
my $self = shift; |
|
160
|
2
|
|
|
|
|
10
|
my %args = @_; |
|
161
|
|
|
|
|
|
|
|
|
162
|
2
|
50
|
|
|
|
10
|
my $video_id = $args{video_id} or croak "Must specify video_id to license"; |
|
163
|
|
|
|
|
|
|
|
|
164
|
2
|
|
50
|
|
|
13
|
my $editorial_acknowledgement = $args{editorial_acknowledgement} || 0; |
|
165
|
|
|
|
|
|
|
|
|
166
|
2
|
|
|
|
|
11
|
my $subscription = $self->_find_subscription_from_arg('video', $args{subscription}); |
|
167
|
1
|
50
|
|
|
|
6
|
if(!$subscription){ |
|
168
|
0
|
|
|
|
|
0
|
croak "Must specify a subscription to license videos under"; |
|
169
|
|
|
|
|
|
|
} |
|
170
|
|
|
|
|
|
|
|
|
171
|
1
|
|
|
|
|
7
|
my $metadata = $self->_valid_metadata($args{metadata}); |
|
172
|
|
|
|
|
|
|
|
|
173
|
1
|
|
|
|
|
8
|
my $size = $self->_valid_size_for_subscription($subscription, $args{size}); |
|
174
|
|
|
|
|
|
|
|
|
175
|
1
|
|
|
|
|
7
|
my $client = $self->client; |
|
176
|
|
|
|
|
|
|
|
|
177
|
1
|
50
|
|
|
|
27
|
$client->POST( |
|
178
|
|
|
|
|
|
|
sprintf( |
|
179
|
|
|
|
|
|
|
'/subscriptions/%s/videos/%s/sizes/%s.json', |
|
180
|
|
|
|
|
|
|
$subscription->id, $video_id, $size |
|
181
|
|
|
|
|
|
|
), |
|
182
|
|
|
|
|
|
|
$self->with_auth_params( |
|
183
|
|
|
|
|
|
|
editorial_acknowledgement => $editorial_acknowledgement, |
|
184
|
|
|
|
|
|
|
( $metadata ? ( metadata => encode_json($metadata) ) : () ), |
|
185
|
|
|
|
|
|
|
) |
|
186
|
|
|
|
|
|
|
); |
|
187
|
|
|
|
|
|
|
|
|
188
|
1
|
|
|
|
|
8
|
return WebService::Shutterstock::LicensedVideo->new($client->process_response); |
|
189
|
|
|
|
|
|
|
} |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub _find_subscription_from_arg { |
|
192
|
5
|
|
|
5
|
|
10
|
my $self = shift; |
|
193
|
5
|
|
|
|
|
9
|
my $type = shift; |
|
194
|
5
|
|
|
|
|
9
|
my $sub_arg = shift; |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
my $single_finder = sub { |
|
198
|
4
|
|
|
4
|
|
17
|
my %criteria = @_; |
|
199
|
4
|
|
|
|
|
30
|
my @matching = $self->find_subscriptions( %criteria, is_active => 1, site => "${type}_subscription" ); |
|
200
|
4
|
50
|
|
|
|
25
|
if ( @matching == 0 ) { |
|
|
|
50
|
|
|
|
|
|
|
201
|
0
|
|
|
|
|
0
|
croak "Unable to find a matching subscription to license ${type}s"; |
|
202
|
|
|
|
|
|
|
} elsif ( @matching > 1 ) { |
|
203
|
0
|
|
|
|
|
0
|
croak "You have more than one active subscription. Please provide a WebService::Shutterstock::Subscription object or specify unique critiria to identify which subscription you would like to use (i.e. { license => 'standard' } or { id => 26374582 } )"; |
|
204
|
|
|
|
|
|
|
} |
|
205
|
4
|
|
|
|
|
16
|
return $matching[0]; |
|
206
|
5
|
|
|
|
|
34
|
}; |
|
207
|
|
|
|
|
|
|
|
|
208
|
5
|
|
|
|
|
9
|
my $subscription; |
|
209
|
|
|
|
|
|
|
|
|
210
|
5
|
50
|
|
|
|
16
|
if($sub_arg){ |
|
211
|
5
|
100
|
|
|
|
256
|
if(!ref($sub_arg)){ |
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
212
|
1
|
|
|
|
|
5
|
$subscription = $self->subscription( id => $sub_arg ); |
|
213
|
|
|
|
|
|
|
} elsif(ref($sub_arg) eq 'HASH'){ |
|
214
|
4
|
|
|
|
|
828
|
$subscription = $single_finder->( %$sub_arg ); |
|
215
|
0
|
|
|
|
|
0
|
} elsif(eval { $sub_arg->isa('WebService::Shutterstock::Subscription') }){ |
|
216
|
0
|
|
|
|
|
0
|
$subscription = $sub_arg; |
|
217
|
|
|
|
|
|
|
} |
|
218
|
|
|
|
|
|
|
} else { |
|
219
|
0
|
|
|
|
|
0
|
$subscription = $single_finder->(); |
|
220
|
|
|
|
|
|
|
} |
|
221
|
5
|
100
|
66
|
|
|
51
|
if($subscription && $subscription->site ne "${type}_subscription"){ |
|
222
|
1
|
|
|
|
|
318
|
croak sprintf('The subscription specified is for the wrong "site" (needed "%s_subscription", found %s)', $type, $subscription->site); |
|
223
|
|
|
|
|
|
|
} |
|
224
|
4
|
|
|
|
|
31
|
return $subscription; |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
sub _valid_size_for_subscription { |
|
228
|
3
|
|
|
3
|
|
8
|
my $self = shift; |
|
229
|
3
|
|
|
|
|
7
|
my $subscription = shift; |
|
230
|
3
|
|
|
|
|
9
|
my $size = shift; |
|
231
|
|
|
|
|
|
|
|
|
232
|
3
|
|
|
|
|
19
|
my @valid_sizes = $subscription->sizes_for_licensing; |
|
233
|
|
|
|
|
|
|
|
|
234
|
3
|
100
|
66
|
|
|
16
|
if(!$size && @valid_sizes == 1){ |
|
235
|
1
|
|
|
|
|
4
|
$size = $valid_sizes[0]; |
|
236
|
|
|
|
|
|
|
} |
|
237
|
3
|
50
|
|
|
|
11
|
croak "Must specify size of video to license" if !$size; |
|
238
|
|
|
|
|
|
|
|
|
239
|
3
|
100
|
|
|
|
7
|
if ( !grep { $_ eq $size } @valid_sizes ) { |
|
|
3
|
|
|
|
|
15
|
|
|
240
|
1
|
|
|
|
|
2
|
my %uniq_sizes = map {$_ => 1} @valid_sizes; |
|
|
1
|
|
|
|
|
6
|
|
|
241
|
1
|
|
|
|
|
386
|
croak "Invalid size '$size', please specify a valid size: " . join(", ", keys %uniq_sizes); |
|
242
|
|
|
|
|
|
|
} |
|
243
|
2
|
|
|
|
|
8
|
return $size; |
|
244
|
|
|
|
|
|
|
} |
|
245
|
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
sub _valid_metadata { |
|
247
|
4
|
|
|
4
|
|
8
|
my $self = shift; |
|
248
|
4
|
|
|
|
|
26
|
my $metadata = shift; |
|
249
|
4
|
|
|
|
|
6
|
my $valid; |
|
250
|
4
|
100
|
|
|
|
20
|
if(my $metadata_definitions = $self->metadata_field_definitions){ |
|
251
|
3
|
|
100
|
|
|
43
|
$valid = $metadata || {}; |
|
252
|
3
|
|
|
|
|
6
|
my @missing; |
|
253
|
3
|
|
|
|
|
7
|
foreach my $md(@{ $metadata_definitions }){ |
|
|
3
|
|
|
|
|
11
|
|
|
254
|
3
|
100
|
|
|
|
16
|
$valid->{$md->{name_api}} = '' if !defined $valid->{$md->{name_api}}; |
|
255
|
3
|
100
|
66
|
|
|
35
|
if($md->{is_required} && $valid->{$md->{name_api}} eq ''){ |
|
256
|
1
|
|
|
|
|
6
|
push @missing, $md->{name_api}; |
|
257
|
|
|
|
|
|
|
} |
|
258
|
|
|
|
|
|
|
} |
|
259
|
3
|
100
|
|
|
|
14
|
if(@missing){ |
|
260
|
1
|
50
|
|
|
|
215
|
croak |
|
261
|
|
|
|
|
|
|
sprintf( |
|
262
|
|
|
|
|
|
|
'Missing required metadata field%s for licensing image: %s', |
|
263
|
|
|
|
|
|
|
@missing == 1 ? '' : 's', join ', ', @missing ); |
|
264
|
|
|
|
|
|
|
} |
|
265
|
|
|
|
|
|
|
} |
|
266
|
3
|
|
|
|
|
12
|
return $valid; |
|
267
|
|
|
|
|
|
|
} |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
1; |
|
270
|
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
__END__ |