line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::API::Gett::Share; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Net::API::Gett::Share - Gett share object |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=cut |
8
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
30
|
use Moo; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
37
|
|
10
|
5
|
|
|
5
|
|
1614
|
use Carp qw(croak); |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
342
|
|
11
|
5
|
|
|
5
|
|
4821
|
use Array::Iterator; |
|
5
|
|
|
|
|
6197
|
|
|
5
|
|
|
|
|
170
|
|
12
|
5
|
|
|
5
|
|
41
|
use MooX::Types::MooseLike::Base qw(Int Str); |
|
5
|
|
|
|
|
92
|
|
|
5
|
|
|
|
|
6294
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '1.06'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 PURPOSE |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Encapsulate Gett shares. You normally shouldn't instantiate this class on its own, as the |
19
|
|
|
|
|
|
|
library will create and return this object as appropriate. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=over |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=item user |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
L object. C predicate. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=back |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has 'user' => ( |
34
|
|
|
|
|
|
|
is => 'rw', |
35
|
|
|
|
|
|
|
predicate => 'has_user', |
36
|
|
|
|
|
|
|
isa => sub { die "$_[0] is not Net::API::Gett::User" unless ref($_[0]) =~ /User/ }, |
37
|
|
|
|
|
|
|
lazy => 1, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=over |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=item request |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
L object. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=back |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
has 'request' => ( |
51
|
|
|
|
|
|
|
is => 'rw', |
52
|
|
|
|
|
|
|
isa => sub { die "$_[0] is not Net::API::Gett::Request" unless ref($_[0]) =~ /Request/ }, |
53
|
|
|
|
|
|
|
default => sub { Net::API::Gett::Request->new() }, |
54
|
|
|
|
|
|
|
lazy => 1, |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=over |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=item sharename |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Scalar string. Read only. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=item title |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Scalar string. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=item created |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Scalar integer. Read only. This value is in Unix epoch seconds, suitable for use in a call to C. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item getturl |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Scalar string. The URL to use in a browser to access a share. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=item files |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This attribute holds any L objects linked to a particular |
78
|
|
|
|
|
|
|
share instance. It returns a list of L objects if |
79
|
|
|
|
|
|
|
there are any, otherwise returns an empty list. See also |
80
|
|
|
|
|
|
|
C below. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=back |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=cut |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
has 'sharename' => ( |
87
|
|
|
|
|
|
|
is => 'ro', |
88
|
|
|
|
|
|
|
isa => Str, |
89
|
|
|
|
|
|
|
); |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
has 'title' => ( |
92
|
|
|
|
|
|
|
is => 'rw', |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
has 'created' => ( |
96
|
|
|
|
|
|
|
is => 'ro', |
97
|
|
|
|
|
|
|
isa => Int, |
98
|
|
|
|
|
|
|
); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
has 'getturl' => ( |
101
|
|
|
|
|
|
|
is => 'ro', |
102
|
|
|
|
|
|
|
isa => Str, |
103
|
|
|
|
|
|
|
); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub files { |
106
|
3
|
|
|
3
|
1
|
4852
|
my $self = shift; |
107
|
|
|
|
|
|
|
|
108
|
3
|
50
|
|
|
|
19
|
return () unless exists $self->{'files'}; |
109
|
|
|
|
|
|
|
|
110
|
3
|
|
|
|
|
6
|
return @{ $self->{'files'} }; |
|
3
|
|
|
|
|
19
|
|
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 METHODS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=over |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=item add_file() |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This method stores a new L object in the share object. |
120
|
|
|
|
|
|
|
It returns undef if the value passed is not an L object. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=back |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub add_file { |
127
|
16
|
|
|
16
|
1
|
29
|
my $self = shift; |
128
|
16
|
|
|
|
|
20
|
my $file = shift; |
129
|
|
|
|
|
|
|
|
130
|
16
|
50
|
|
|
|
66
|
return undef unless ref($file) =~ /File/; |
131
|
|
|
|
|
|
|
|
132
|
16
|
50
|
|
|
|
385
|
$file->sharename($self->sharename) unless $file->sharename; |
133
|
|
|
|
|
|
|
|
134
|
16
|
50
|
|
|
|
3112
|
$file->user($self->user) if $self->has_user; |
135
|
|
|
|
|
|
|
|
136
|
16
|
|
|
|
|
23
|
push @{ $self->{'files'} }, $file; |
|
16
|
|
|
|
|
86
|
|
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=over |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item file_iterator() |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
This method returns a L object on the files in this share. For full details |
144
|
|
|
|
|
|
|
about L please read its documentation. It supports standard iterator |
145
|
|
|
|
|
|
|
methods such as: |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=over |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item * next() |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item * has_next() |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item * get_next() |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item * peek() |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=back |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Example code using peek: |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
my $share = $gett->get_share("4ddsfds"); |
162
|
|
|
|
|
|
|
my $file_iter = $share->file_iterator(); |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
while ( $file_iter->has_next ) { |
165
|
|
|
|
|
|
|
if ( $file_iter->peek->size > 1_048_576 ) { |
166
|
|
|
|
|
|
|
# Skip big file |
167
|
|
|
|
|
|
|
warn $file_iter->peek->filename . " is too large, skipping\n"; |
168
|
|
|
|
|
|
|
$file_iter->next(); |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
else { |
171
|
|
|
|
|
|
|
my $file = $file_iter->next(); |
172
|
|
|
|
|
|
|
printf "name: %s\tsize: %d\n", $file->filename, $file->size; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Example code using get_next: |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
for my $file ( $file_iter->get_next() ) { |
179
|
|
|
|
|
|
|
say "name: " . $file->filename . "\tsize: " . $file->size; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=back |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
This method returns undef if there are no files associated with a share. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=cut |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
sub file_iterator { |
189
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
190
|
|
|
|
|
|
|
|
191
|
1
|
50
|
|
|
|
10
|
return undef unless exists $self->{'files'}; |
192
|
|
|
|
|
|
|
|
193
|
1
|
|
|
|
|
10
|
return Array::Iterator->new($self->{'files'}); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=over |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=item update() |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
This method updates share attributes. At present, only the share title can be changed (or deleted), |
201
|
|
|
|
|
|
|
so pass in a string to set a new title for a specific share. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Calling this method with an empty parameter list or explicitly passing C |
204
|
|
|
|
|
|
|
will B any title currently set on the share. |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Returns a L object with updated values. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=back |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=cut |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub update { |
213
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
214
|
|
|
|
|
|
|
|
215
|
0
|
0
|
|
|
|
|
croak "Cannot call update without a Net::API::Gett::User object" unless $self->has_user; |
216
|
|
|
|
|
|
|
|
217
|
0
|
|
|
|
|
|
my $title = shift; |
218
|
0
|
|
|
|
|
|
my $name = $self->sharename; |
219
|
|
|
|
|
|
|
|
220
|
0
|
0
|
|
|
|
|
$self->user->login unless $self->user->has_access_token; |
221
|
|
|
|
|
|
|
|
222
|
0
|
|
|
|
|
|
my $response = $self->request->post("/shares/$name/update?accesstoken=".$self->user->access_token, |
223
|
|
|
|
|
|
|
{ title => $title } ); |
224
|
|
|
|
|
|
|
|
225
|
0
|
0
|
|
|
|
|
if ( $response ) { |
226
|
0
|
|
|
|
|
|
$self->title( $response->{'title'} ); |
227
|
0
|
|
|
|
|
|
return $self; |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
else { |
230
|
0
|
|
|
|
|
|
return undef; |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=over |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=item destroy() |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
This method destroys the share and all of the share's files. Returns a true boolean |
239
|
|
|
|
|
|
|
on success. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=back |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=cut |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
sub destroy { |
246
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
247
|
|
|
|
|
|
|
|
248
|
0
|
0
|
|
|
|
|
croak "Cannot call destroy without a Net::API::Gett::User object" unless $self->has_user; |
249
|
|
|
|
|
|
|
|
250
|
0
|
|
|
|
|
|
my $name = $self->sharename; |
251
|
|
|
|
|
|
|
|
252
|
0
|
0
|
|
|
|
|
$self->user->login unless $self->user->has_access_token; |
253
|
|
|
|
|
|
|
|
254
|
0
|
|
|
|
|
|
my $response = $self->request->post("/shares/$name/destroy?accesstoken=".$self->user->access_token); |
255
|
|
|
|
|
|
|
|
256
|
0
|
0
|
|
|
|
|
if ( $response ) { |
257
|
0
|
|
|
|
|
|
return 1; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
else { |
260
|
0
|
|
|
|
|
|
return undef; |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
} |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=head1 SEE ALSO |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
L, L |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=cut |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
1; |