| 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 | 1 | ▶ | use 5.008001; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | ▶ | use base 'Yandex::Disk'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | #Class for Public actions under Yandex Disk files and folders | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | our $VERSION = '0.04'; | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | sub publicFile { | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
publicFile: called CC=3 SCAR=11.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | my %opt = @_; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | my $path = $opt{-path} || croak "Specify -path param"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opt{'-path'} || croak('Specify -path param')
MC/DC0%0/2
$opt{'-path'} || croak('Specify -path param')
$opt{'-path'}
croak('Specify -path param')
Truth table33%1/3
A || B
A= $opt{'-path'}B= croak('Specify -path param')
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | my $res = $self->__request('https://cloud-api.yandex.net/v1/disk/resources/publish?path=' . uri_escape($path), "PUT"); | |||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | my $code = $res->code; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | if ($code ne '200') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | croak "Cant public file $path. Error: " . $res->status_line; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | my $metainfo_href = $self->__fromJson($res->decoded_content)->{href}; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | my $res_get_metainfo = $self->__getPublicUrl($metainfo_href); | |||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | return $res_get_metainfo; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | sub unpublicFile { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unpublicFile: called CC=3 SCAR=11.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | my %opt = @_; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | $self->{public_info} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | my $path = $opt{-path} || croak "Specify -path param"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$opt{'-path'} || croak('Specify -path param')
MC/DC0%0/2
$opt{'-path'} || croak('Specify -path param')
$opt{'-path'}
croak('Specify -path param')
Truth table33%1/3
A || B
A= $opt{'-path'}B= croak('Specify -path param')
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | my $res = $self->__request('https://cloud-api.yandex.net/v1/disk/resources/unpublish?path=' . uri_escape($path), "PUT"); | |||||||||||||||||||||||||||||||||||||||||
| 54 | 1 | my $code = $res->code; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | if ($code ne '200') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | croak "Cant unpublic file $path. Error: " . $res->status_line; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | sub listPublished { | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
listPublished: called CC=8 SCAR=24.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | my %opt = @_; | |||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | my $limit = $opt{-limit}; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | my $offset = $opt{-offset} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opt{'-offset'} || 0
MC/DC0%0/1
$opt{'-offset'} || 0
$opt{'-offset'}
Truth table50%1/2
A
A= $opt{'-offset'}
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | my $type = $opt{-type}; | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | $limit = 999999 if not defined $limit; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | ▶ | if ($type && ($type ne 'dir' && $type ne 'file')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
$type and ($type ne "dir" and $type ne "file")
$type ne "dir" and $type ne "file"
MC/DC0%0/3
$type and ($type ne "dir" and $type ne "file")
$type
$type ne "dir"
$type ne "file"
Truth table25%1/4
A and B and C
A= $typeB= $type ne "dir"C= $type ne "file"
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | croak "Wrong -type value (dir/file)"; | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | my $param = "limit=$limit&offset=$offset"; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | ▶ | $param .= "&type=$type" if $type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | my $res = $self->__request('https://cloud-api.yandex.net/v1/disk/resources/public?' . $param, "GET"); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | my $code = $res->code; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | ▶ | if ($code ne '200') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | croak "Cant get listPublished. Error: " . $res->status_line; | |||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | my $items = $self->__fromJson($res->decoded_content)->{items}; | |||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | return $items; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | sub __getPublicUrl { | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | ▶ | my ($self, $href) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__getPublicUrl: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | my $res = $self->__request($href, "GET"); | |||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | my $code = $res->code; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | ▶ | if ($code ne '200') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | croak "Cant get public url by href: $href. Error: " . $res->status_line; | |||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | $self->{public_info} = $self->__fromJson($res->decoded_content); | |||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | sub publicUrl { | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 1 | ▶ | return shift->{public_info}->{public_url}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
publicUrl: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | sub publicType { | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | return shift->{public_info}->{type}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
publicType: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | __END__ | ||||||||||||||||||||||||||||||||||||||||||