line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::FileCloud; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
54558
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
90
|
|
4
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
89
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
1308
|
use JSON; |
|
2
|
|
|
|
|
40402
|
|
|
2
|
|
|
|
|
18
|
|
7
|
2
|
|
|
2
|
|
2714
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
165609
|
|
|
2
|
|
|
|
|
103
|
|
8
|
2
|
|
|
2
|
|
2445
|
use HTTP::Request::Common qw( $DYNAMIC_FILE_UPLOAD ); |
|
2
|
|
|
|
|
5011
|
|
|
2
|
|
|
|
|
560
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.3'; |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
17
|
use constant BASE_URI => 'http://api.filecloud.io/'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
333
|
|
13
|
2
|
|
|
2
|
|
12
|
use constant FETCH_APIKEY_URI => 'https://secure.filecloud.io/api-fetch_apikey.api'; |
|
2
|
|
|
|
|
16
|
|
|
2
|
|
|
|
|
126
|
|
14
|
2
|
|
|
2
|
|
11
|
use constant FETCH_ACCOUNT_DETAILS_URI => BASE_URI . 'api-fetch_account_details.api'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
241
|
|
15
|
2
|
|
|
2
|
|
10
|
use constant PING_URI => BASE_URI . 'api-ping.api'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
111
|
|
16
|
2
|
|
|
2
|
|
10
|
use constant FETCH_UPLOAD_URL_URI => BASE_URI . 'api-fetch_upload_url.api'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
158
|
|
17
|
2
|
|
|
2
|
|
11
|
use constant CHECK_FILE_URI => BASE_URI . 'api-check_file.api'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
193
|
|
18
|
2
|
|
|
2
|
|
11
|
use constant FETCH_FILE_DETAILS_URI => BASE_URI . 'api-fetch_file_details.api'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
156
|
|
19
|
2
|
|
|
2
|
|
12
|
use constant FETCH_DOWNLOAD_URL_URI => BASE_URI . 'api-fetch_download_url.api'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
208
|
|
20
|
2
|
|
|
2
|
|
46
|
use constant FETCH_TAG_DETAILS_URI => BASE_URI . 'api-fetch_tag_details.api'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
3095
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub new { |
23
|
|
|
|
|
|
|
|
24
|
1
|
|
|
1
|
1
|
20
|
my $caller = shift; |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
3
|
my $class = ref( $caller ); |
27
|
1
|
50
|
|
|
|
6
|
$class = $caller if ( !$class ); |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
28
|
my $self = {'akey' => undef, |
30
|
|
|
|
|
|
|
'username' => undef, |
31
|
|
|
|
|
|
|
'password' => undef, |
32
|
|
|
|
|
|
|
'timeout' => undef, |
33
|
|
|
|
|
|
|
'error' => '', |
34
|
|
|
|
|
|
|
@_}; |
35
|
|
|
|
|
|
|
|
36
|
1
|
|
|
|
|
17
|
$self->{'ua'} = LWP::UserAgent->new( timeout => $self->{'timeout'} ); |
37
|
1
|
|
|
|
|
7479
|
$self->{'json'} = JSON->new(); |
38
|
|
|
|
|
|
|
|
39
|
1
|
|
|
|
|
6
|
bless( $self, $class ); |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
6
|
return $self; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub fetch_apikey { |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
0
|
1
|
|
my ( $self, %args ) = @_; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $username = $self->{'username'}; |
49
|
0
|
|
|
|
|
|
my $password = $self->{'password'}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# make sure they provided username and password arguments |
52
|
0
|
0
|
0
|
|
|
|
if ( !defined( $username ) || |
53
|
|
|
|
|
|
|
!defined( $password ) ) { |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
$self->{'error'} = "username and password arguments must be provided in constructor"; |
56
|
0
|
|
|
|
|
|
return; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $response = $self->{'ua'}->post( FETCH_APIKEY_URI, |
60
|
|
|
|
|
|
|
{'username' => $username, |
61
|
|
|
|
|
|
|
'password' => $password} ); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# detect request error |
64
|
0
|
0
|
|
|
|
|
if ( !$response->is_success() ) { |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$self->{'error'} = $response->status_line(); |
67
|
0
|
|
|
|
|
|
return; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
return $self->{'json'}->decode( $response->decoded_content() ); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub fetch_account_details { |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
0
|
1
|
|
my ( $self, %args ) = @_; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# make sure they provided an akey in the constuctor |
78
|
0
|
0
|
|
|
|
|
if ( !defined( $self->{'akey'} ) ) { |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
$self->{'error'} = "akey must be provided in constructor"; |
81
|
0
|
|
|
|
|
|
return; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
my $response = $self->{'ua'}->post( FETCH_ACCOUNT_DETAILS_URI, |
85
|
|
|
|
|
|
|
{'akey' => $self->{'akey'}} ); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# detect request error |
88
|
0
|
0
|
|
|
|
|
if ( !$response->is_success() ) { |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
$self->{'error'} = $response->status_line(); |
91
|
0
|
|
|
|
|
|
return; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
return $self->{'json'}->decode( $response->decoded_content() ); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub ping { |
98
|
|
|
|
|
|
|
|
99
|
0
|
|
|
0
|
1
|
|
my ( $self ) = @_; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my $response = $self->{'ua'}->post( PING_URI ); |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# detect request error |
104
|
0
|
0
|
|
|
|
|
if ( !$response->is_success() ) { |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
$self->{'error'} = $response->status_line(); |
107
|
0
|
|
|
|
|
|
return; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
return $self->{'json'}->decode( $response->decoded_content() ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub fetch_upload_url { |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
0
|
1
|
|
my ( $self ) = @_; |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
my $response = $self->{'ua'}->post( FETCH_UPLOAD_URL_URI ); |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# detect request error |
120
|
0
|
0
|
|
|
|
|
if ( !$response->is_success() ) { |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
$self->{'error'} = $response->status_line(); |
123
|
0
|
|
|
|
|
|
return; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
return $self->{'json'}->decode( $response->decoded_content() ); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub check_file { |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
0
|
1
|
|
my ( $self, %args ) = @_; |
132
|
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
my $ukey = $args{'ukey'}; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# make sure they provided the ukey argument |
136
|
0
|
0
|
|
|
|
|
if ( !defined( $ukey ) ) { |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
$self->{'error'} = "ukey argument required"; |
139
|
0
|
|
|
|
|
|
return; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
my $response = $self->{'ua'}->post( CHECK_FILE_URI, |
143
|
|
|
|
|
|
|
{'ukey' => $ukey} ); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# detect request error |
146
|
0
|
0
|
|
|
|
|
if ( !$response->is_success() ) { |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
$self->{'error'} = $response->status_line(); |
149
|
0
|
|
|
|
|
|
return; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
return $self->{'json'}->decode( $response->decoded_content() ); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub fetch_file_details { |
156
|
|
|
|
|
|
|
|
157
|
0
|
|
|
0
|
1
|
|
my ( $self, %args ) = @_; |
158
|
|
|
|
|
|
|
|
159
|
0
|
|
|
|
|
|
my $ukey = $args{'ukey'}; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# make sure they provided an akey in the constuctor |
162
|
0
|
0
|
|
|
|
|
if ( !defined( $self->{'akey'} ) ) { |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
$self->{'error'} = "akey must be provided in constructor"; |
165
|
0
|
|
|
|
|
|
return; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# make sure they provided the ukey argument |
169
|
0
|
0
|
|
|
|
|
if ( !defined( $ukey ) ) { |
170
|
|
|
|
|
|
|
|
171
|
0
|
|
|
|
|
|
$self->{'error'} = "ukey argument required"; |
172
|
0
|
|
|
|
|
|
return; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
0
|
|
|
|
|
|
my $response = $self->{'ua'}->post( FETCH_FILE_DETAILS_URI, |
176
|
|
|
|
|
|
|
{'akey' => $self->{'akey'}, |
177
|
|
|
|
|
|
|
'ukey' => $ukey} ); |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
# detect request error |
180
|
0
|
0
|
|
|
|
|
if ( !$response->is_success() ) { |
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
|
$self->{'error'} = $response->status_line(); |
183
|
0
|
|
|
|
|
|
return; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
return $self->{'json'}->decode( $response->decoded_content() ); |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub fetch_download_url { |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
0
|
1
|
|
my ( $self, %args ) = @_; |
192
|
|
|
|
|
|
|
|
193
|
0
|
|
|
|
|
|
my $ukey = $args{'ukey'}; |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
# make sure they provided an akey in the constuctor |
196
|
0
|
0
|
|
|
|
|
if ( !defined( $self->{'akey'} ) ) { |
197
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
$self->{'error'} = "akey must be provided in constructor"; |
199
|
0
|
|
|
|
|
|
return; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
# make sure they provided the ukey argument |
203
|
0
|
0
|
|
|
|
|
if ( !defined( $ukey ) ) { |
204
|
|
|
|
|
|
|
|
205
|
0
|
|
|
|
|
|
$self->{'error'} = "ukey argument required"; |
206
|
0
|
|
|
|
|
|
return; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
0
|
|
|
|
|
|
my $response = $self->{'ua'}->post( FETCH_DOWNLOAD_URL_URI, |
210
|
|
|
|
|
|
|
{'akey' => $self->{'akey'}, |
211
|
|
|
|
|
|
|
'ukey' => $ukey} ); |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
# detect request error |
214
|
0
|
0
|
|
|
|
|
if ( !$response->is_success() ) { |
215
|
|
|
|
|
|
|
|
216
|
0
|
|
|
|
|
|
$self->{'error'} = $response->status_line(); |
217
|
0
|
|
|
|
|
|
return; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
0
|
|
|
|
|
|
return $self->{'json'}->decode( $response->decoded_content() ); |
221
|
|
|
|
|
|
|
} |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
sub upload_file { |
224
|
|
|
|
|
|
|
|
225
|
0
|
|
|
0
|
1
|
|
my ( $self, %args ) = @_; |
226
|
|
|
|
|
|
|
|
227
|
0
|
|
|
|
|
|
my $filename = $args{'filename'}; |
228
|
0
|
|
|
|
|
|
my $url = $args{'url'}; |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
# make sure they provided the filename & url arguments |
231
|
0
|
0
|
0
|
|
|
|
if ( !defined( $filename ) || |
232
|
|
|
|
|
|
|
!defined( $url ) ) { |
233
|
|
|
|
|
|
|
|
234
|
0
|
|
|
|
|
|
$self->{'error'} = "filename and url arguments required"; |
235
|
0
|
|
|
|
|
|
return; |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
# make sure the filename exist |
239
|
0
|
0
|
|
|
|
|
if ( ! -e $filename ) { |
240
|
|
|
|
|
|
|
|
241
|
0
|
|
|
|
|
|
$self->{'error'} = "file $filename does not exist"; |
242
|
0
|
|
|
|
|
|
return; |
243
|
|
|
|
|
|
|
} |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
# avoid reading entire file into memory when uploading |
246
|
0
|
|
|
|
|
|
local $HTTP::Request::Common::DYNAMIC_FILE_UPLOAD = 1; |
247
|
|
|
|
|
|
|
|
248
|
0
|
|
|
|
|
|
my $response = $self->{'ua'}->post( $url, |
249
|
|
|
|
|
|
|
Content_Type => 'form-data', |
250
|
|
|
|
|
|
|
Content => ['Filedata' => [$filename], |
251
|
|
|
|
|
|
|
'akey' => $self->{'akey'}] ); |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
# detect request error |
254
|
0
|
0
|
|
|
|
|
if ( !$response->is_success() ) { |
255
|
|
|
|
|
|
|
|
256
|
0
|
|
|
|
|
|
$self->{'error'} = $response->status_line(); |
257
|
0
|
|
|
|
|
|
return; |
258
|
|
|
|
|
|
|
} |
259
|
|
|
|
|
|
|
|
260
|
0
|
|
|
|
|
|
return $self->{'json'}->decode( $response->decoded_content() ); |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
sub fetch_tag_details { |
264
|
|
|
|
|
|
|
|
265
|
0
|
|
|
0
|
1
|
|
my ( $self, %args ) = @_; |
266
|
|
|
|
|
|
|
|
267
|
0
|
|
|
|
|
|
my $tkey = $args{'tkey'}; |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
# make sure they provided an akey in the constuctor |
270
|
0
|
0
|
|
|
|
|
if ( !defined( $self->{'akey'} ) ) { |
271
|
|
|
|
|
|
|
|
272
|
0
|
|
|
|
|
|
$self->{'error'} = "akey must be provided in constructor"; |
273
|
0
|
|
|
|
|
|
return; |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
# make sure they provided the tkey argument |
277
|
0
|
0
|
|
|
|
|
if ( !defined( $tkey ) ) { |
278
|
|
|
|
|
|
|
|
279
|
0
|
|
|
|
|
|
$self->{'error'} = "tkey argument required"; |
280
|
0
|
|
|
|
|
|
return; |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
|
283
|
0
|
|
|
|
|
|
my $response = $self->{'ua'}->post( FETCH_TAG_DETAILS_URI, |
284
|
|
|
|
|
|
|
{'akey' => $self->{'akey'}, |
285
|
|
|
|
|
|
|
'tkey' => $tkey} ); |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
# detect request error |
288
|
0
|
0
|
|
|
|
|
if ( !$response->is_success() ) { |
289
|
|
|
|
|
|
|
|
290
|
0
|
|
|
|
|
|
$self->{'error'} = $response->status_line(); |
291
|
0
|
|
|
|
|
|
return; |
292
|
|
|
|
|
|
|
} |
293
|
|
|
|
|
|
|
|
294
|
0
|
|
|
|
|
|
return $self->{'json'}->decode( $response->decoded_content() ); |
295
|
|
|
|
|
|
|
} |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
sub error { |
298
|
|
|
|
|
|
|
|
299
|
0
|
|
|
0
|
1
|
|
my ( $self ) = @_; |
300
|
|
|
|
|
|
|
|
301
|
0
|
|
|
|
|
|
return $self->{'error'}; |
302
|
|
|
|
|
|
|
} |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
1; |