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
|
|
59305
|
use 5.008001; |
|
2
|
|
|
|
|
14
|
|
20
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
35
|
|
21
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
40
|
|
22
|
2
|
|
|
2
|
|
508
|
use utf8; |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
10
|
|
23
|
2
|
|
|
2
|
|
883
|
use URI::Escape; |
|
2
|
|
|
|
|
2714
|
|
|
2
|
|
|
|
|
120
|
|
24
|
2
|
|
|
2
|
|
13
|
use Carp 'croak'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
108
|
|
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
2
|
|
12
|
use base 'Yandex::Disk'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1266
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#Class for Public actions under Yandex Disk files and folders |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub publicFile { |
33
|
1
|
|
|
1
|
1
|
447
|
my $self = shift; |
34
|
1
|
|
|
|
|
5
|
my %opt = @_; |
35
|
1
|
|
33
|
|
|
4
|
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
|
|
|
|
|
3
|
my $code = $res->code; |
39
|
1
|
50
|
|
|
|
11
|
if ($code ne '200') { |
40
|
0
|
|
|
|
|
0
|
croak "Cant public file $path. Error: " . $res->status_line; |
41
|
|
|
|
|
|
|
} |
42
|
1
|
|
|
|
|
7
|
my $metainfo_href = $self->__fromJson($res->decoded_content)->{href}; |
43
|
1
|
|
|
|
|
6
|
my $res_get_metainfo = $self->__getPublicUrl($metainfo_href); |
44
|
1
|
|
|
|
|
16
|
return $res_get_metainfo; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub unpublicFile { |
48
|
1
|
|
|
1
|
1
|
11940
|
my $self = shift; |
49
|
1
|
|
|
|
|
4
|
my %opt = @_; |
50
|
1
|
|
|
|
|
9
|
$self->{public_info} = {}; |
51
|
1
|
|
33
|
|
|
5
|
my $path = $opt{-path} || croak "Specify -path param"; |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
5
|
my $res = $self->__request('https://cloud-api.yandex.net/v1/disk/resources/unpublish?path=' . uri_escape($path), "PUT"); |
54
|
1
|
|
|
|
|
4
|
my $code = $res->code; |
55
|
1
|
50
|
|
|
|
12
|
if ($code ne '200') { |
56
|
0
|
|
|
|
|
0
|
croak "Cant unpublic file $path. Error: " . $res->status_line; |
57
|
|
|
|
|
|
|
} |
58
|
1
|
|
|
|
|
14
|
return 1; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub listPublished { |
62
|
1
|
|
|
1
|
1
|
820
|
my $self = shift; |
63
|
1
|
|
|
|
|
4
|
my %opt = @_; |
64
|
1
|
|
|
|
|
2
|
my $limit = $opt{-limit}; |
65
|
1
|
|
50
|
|
|
6
|
my $offset = $opt{-offset} || 0; |
66
|
1
|
|
|
|
|
2
|
my $type = $opt{-type}; |
67
|
|
|
|
|
|
|
|
68
|
1
|
50
|
|
|
|
3
|
$limit = 999999 if not defined $limit; |
69
|
|
|
|
|
|
|
|
70
|
1
|
0
|
0
|
|
|
6
|
if ($type && ($type ne 'dir' && $type ne 'file')) { |
|
|
|
33
|
|
|
|
|
71
|
0
|
|
|
|
|
0
|
croak "Wrong -type value (dir/file)"; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
3
|
my $param = "limit=$limit&offset=$offset"; |
75
|
1
|
50
|
|
|
|
3
|
$param .= "&type=$type" if $type; |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
5
|
my $res = $self->__request('https://cloud-api.yandex.net/v1/disk/resources/public?' . $param, "GET"); |
78
|
1
|
|
|
|
|
4
|
my $code = $res->code; |
79
|
1
|
50
|
|
|
|
12
|
if ($code ne '200') { |
80
|
0
|
|
|
|
|
0
|
croak "Cant get listPublished. Error: " . $res->status_line; |
81
|
|
|
|
|
|
|
} |
82
|
1
|
|
|
|
|
6
|
my $items = $self->__fromJson($res->decoded_content)->{items}; |
83
|
1
|
|
|
|
|
14
|
return $items; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub __getPublicUrl { |
87
|
1
|
|
|
1
|
|
2
|
my ($self, $href) = @_; |
88
|
1
|
|
|
|
|
5
|
my $res = $self->__request($href, "GET"); |
89
|
1
|
|
|
|
|
4
|
my $code = $res->code; |
90
|
1
|
50
|
|
|
|
21
|
if ($code ne '200') { |
91
|
0
|
|
|
|
|
0
|
croak "Cant get public url by href: $href. Error: " . $res->status_line; |
92
|
|
|
|
|
|
|
} |
93
|
1
|
|
|
|
|
6
|
$self->{public_info} = $self->__fromJson($res->decoded_content); |
94
|
1
|
|
|
|
|
29
|
return 1; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub publicUrl { |
98
|
1
|
|
|
1
|
1
|
404
|
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__ |