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