line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
#=============================================================================== |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# FILE: Public.pm |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# DESCRIPTION: |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# FILES: --- |
9
|
|
|
|
|
|
|
# BUGS: --- |
10
|
|
|
|
|
|
|
# NOTES: --- |
11
|
|
|
|
|
|
|
# AUTHOR: YOUR NAME (), |
12
|
|
|
|
|
|
|
# ORGANIZATION: |
13
|
|
|
|
|
|
|
# VERSION: 1.0 |
14
|
|
|
|
|
|
|
# CREATED: 01.10.2017 12:34:59 |
15
|
|
|
|
|
|
|
# REVISION: --- |
16
|
|
|
|
|
|
|
#=============================================================================== |
17
|
|
|
|
|
|
|
package Yandex::Disk::Public; |
18
|
|
|
|
|
|
|
|
19
|
2
|
|
|
2
|
|
94589
|
use 5.008001; |
|
2
|
|
|
|
|
15
|
|
20
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
47
|
|
21
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
39
|
|
22
|
2
|
|
|
2
|
|
608
|
use utf8; |
|
2
|
|
|
|
|
17
|
|
|
2
|
|
|
|
|
9
|
|
23
|
2
|
|
|
2
|
|
917
|
use URI::Escape; |
|
2
|
|
|
|
|
2872
|
|
|
2
|
|
|
|
|
122
|
|
24
|
2
|
|
|
2
|
|
13
|
use Carp 'croak'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
92
|
|
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
2
|
|
11
|
use base 'Yandex::Disk'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1302
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#Class for Public actions under Yandex Disk files and folders |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub publicFile { |
33
|
1
|
|
|
1
|
1
|
439
|
my $self = shift; |
34
|
1
|
|
|
|
|
5
|
my %opt = @_; |
35
|
1
|
|
33
|
|
|
5
|
my $path = $opt{-path} || croak "Specify -path param"; |
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
|
|
5
|
my $res = $self->__request('https://cloud-api.yandex.net/v1/disk/resources/publish?path=' . uri_escape($path), "PUT"); |
38
|
1
|
|
|
|
|
8
|
my $code = $res->code; |
39
|
1
|
50
|
|
|
|
22
|
if ($code ne '200') { |
40
|
0
|
|
|
|
|
0
|
croak "Cant public file $path. Error: " . $res->status_line; |
41
|
|
|
|
|
|
|
} |
42
|
1
|
|
|
|
|
13
|
my $metainfo_href = $self->__fromJson($res->decoded_content)->{href}; |
43
|
1
|
|
|
|
|
9
|
my $res_get_metainfo = $self->__getPublicUrl($metainfo_href); |
44
|
1
|
|
|
|
|
30
|
return $res_get_metainfo; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub unpublicFile { |
48
|
1
|
|
|
1
|
1
|
1980
|
my $self = shift; |
49
|
1
|
|
|
|
|
7
|
my %opt = @_; |
50
|
1
|
|
|
|
|
16
|
$self->{public_info} = {}; |
51
|
1
|
|
33
|
|
|
9
|
my $path = $opt{-path} || croak "Specify -path param"; |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
8
|
my $res = $self->__request('https://cloud-api.yandex.net/v1/disk/resources/unpublish?path=' . uri_escape($path), "PUT"); |
54
|
1
|
|
|
|
|
5
|
my $code = $res->code; |
55
|
1
|
50
|
|
|
|
14
|
if ($code ne '200') { |
56
|
0
|
|
|
|
|
0
|
croak "Cant unpublic file $path. Error: " . $res->status_line; |
57
|
|
|
|
|
|
|
} |
58
|
1
|
|
|
|
|
17
|
return 1; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub listPublished { |
62
|
1
|
|
|
1
|
1
|
1498
|
my $self = shift; |
63
|
1
|
|
|
|
|
4
|
my %opt = @_; |
64
|
1
|
|
|
|
|
5
|
my $limit = $opt{-limit}; |
65
|
1
|
|
50
|
|
|
12
|
my $offset = $opt{-offset} || 0; |
66
|
1
|
|
|
|
|
3
|
my $type = $opt{-type}; |
67
|
|
|
|
|
|
|
|
68
|
1
|
50
|
|
|
|
8
|
$limit = 999999 if not defined $limit; |
69
|
|
|
|
|
|
|
|
70
|
1
|
0
|
0
|
|
|
9
|
if ($type && ($type ne 'dir' && $type ne 'file')) { |
|
|
|
33
|
|
|
|
|
71
|
0
|
|
|
|
|
0
|
croak "Wrong -type value (dir/file)"; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
7
|
my $param = "limit=$limit&offset=$offset"; |
75
|
1
|
50
|
|
|
|
7
|
$param .= "&type=$type" if $type; |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
10
|
my $res = $self->__request('https://cloud-api.yandex.net/v1/disk/resources/public?' . $param, "GET"); |
78
|
1
|
|
|
|
|
8
|
my $code = $res->code; |
79
|
1
|
50
|
|
|
|
22
|
if ($code ne '200') { |
80
|
0
|
|
|
|
|
0
|
croak "Cant get listPublished. Error: " . $res->status_line; |
81
|
|
|
|
|
|
|
} |
82
|
1
|
|
|
|
|
7
|
my $items = $self->__fromJson($res->decoded_content)->{items}; |
83
|
1
|
|
|
|
|
29
|
return $items; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub __getPublicUrl { |
87
|
1
|
|
|
1
|
|
5
|
my ($self, $href) = @_; |
88
|
1
|
|
|
|
|
7
|
my $res = $self->__request($href, "GET"); |
89
|
1
|
|
|
|
|
6
|
my $code = $res->code; |
90
|
1
|
50
|
|
|
|
22
|
if ($code ne '200') { |
91
|
0
|
|
|
|
|
0
|
croak "Cant get public url by href: $href. Error: " . $res->status_line; |
92
|
|
|
|
|
|
|
} |
93
|
1
|
|
|
|
|
10
|
$self->{public_info} = $self->__fromJson($res->decoded_content); |
94
|
1
|
|
|
|
|
52
|
return 1; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub publicUrl { |
98
|
1
|
|
|
1
|
1
|
655
|
return shift->{public_info}->{public_url}; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub publicType { |
102
|
0
|
|
|
0
|
1
|
|
return shift->{public_info}->{type}; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__END__ |