| 1 | package Google::RestApi::DocsApi1; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | our $VERSION = '2.2.5'; | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Google::RestApi::Setup; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Readonly; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use aliased 'Google::RestApi::DriveApi3'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use aliased 'Google::RestApi::DocsApi1::Document'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | Readonly our $Docs_Endpoint => 'https://docs.googleapis.com/v1/documents'; | |||||||||||||||||||||||||||
| 13 | 2 | Readonly our $Document_Id => $Google::RestApi::DriveApi3::Drive_File_Id; | |||||||||||||||||||||||||||
| 14 | 2 | Readonly our $Document_Filter => "mimeType = 'application/vnd.google-apps.document'"; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 41 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 41 | my $class = shift; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 41 | state $check = signature( | |||||||||||||||||||||||||||
| 20 | bless => !!0, | ||||||||||||||||||||||||||||
| 21 | named => [ | ||||||||||||||||||||||||||||
| 22 | api => HasApi, | ||||||||||||||||||||||||||||
| 23 | drive => HasMethods[qw(list)], { optional => 1 }, | ||||||||||||||||||||||||||||
| 24 | endpoint => Str, { default => $Docs_Endpoint }, | ||||||||||||||||||||||||||||
| 25 | ], | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | 41 | my $self = $check->(@_); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 40 | return bless $self, $class; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 4 | ▶ | sub api { | ||||||||||||||||||||||||||
|
Subroutine
api: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 34 | 4 | state $check = signature( | |||||||||||||||||||||||||||
| 35 | bless => !!0, | ||||||||||||||||||||||||||||
| 36 | named => [ | ||||||||||||||||||||||||||||
| 37 | uri => Str, { default => '' }, | ||||||||||||||||||||||||||||
| 38 | _extra_ => slurpy HashRef, | ||||||||||||||||||||||||||||
| 39 | ], | ||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||
| 41 | 4 | my $p = named_extra($check->(@_)); | |||||||||||||||||||||||||||
| 42 | 4 | my $uri = $self->{endpoint}; | |||||||||||||||||||||||||||
| 43 | 4 | ▶ | $uri .= "/$p->{uri}" if $p->{uri}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 4 | return $self->rest_api()->api(%$p, uri => $uri); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 1 | ▶ | sub create_document { | ||||||||||||||||||||||||||
|
Subroutine
create_document: called CC=5 SCAR=17.6
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1 | state $check = signature( | |||||||||||||||||||||||||||
| 51 | bless => !!0, | ||||||||||||||||||||||||||||
| 52 | named => [ | ||||||||||||||||||||||||||||
| 53 | title => Str, { optional => 1 }, | ||||||||||||||||||||||||||||
| 54 | name => Str, { optional => 1 }, | ||||||||||||||||||||||||||||
| 55 | _extra_ => slurpy HashRef, | ||||||||||||||||||||||||||||
| 56 | ], | ||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||
| 58 | 1 | my $p = named_extra($check->(@_)); | |||||||||||||||||||||||||||
| 59 | 1 | ▶ | $p->{title} || $p->{name} or LOGDIE "Either 'title' or 'name' should be supplied"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$$p{"title"} or $$p{"name"}
MC/DC0%0/2
$$p{"title"} or $$p{"name"}
$$p{"title"}
$$p{"name"}
Truth table33%1/3
A or B
A= $$p{"title"}B= $$p{"name"}
| |||||||||||||||||||||||||||||
| 60 | 1 | ▶ | $p->{title} ||= $p->{name}; | ||||||||||||||||||||||||||
|
Condition33%1/3
$$p{"title"} ||= $$p{"name"}
MC/DC0%0/2
$$p{"title"} ||= $$p{"name"}
$$p{"title"}
$$p{"name"}
Truth table33%1/3
A ||= B
A= $$p{"title"}B= $$p{"name"}
| |||||||||||||||||||||||||||||
| 61 | 1 | delete $p->{name}; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | my $result = $self->api( | ||||||||||||||||||||||||||||
| 64 | method => 'post', | ||||||||||||||||||||||||||||
| 65 | content => { title => $p->{title} }, | ||||||||||||||||||||||||||||
| 66 | 1 | ); | |||||||||||||||||||||||||||
| 67 | 1 | ▶ | $result->{documentId} or LOGDIE "No 'documentId' returned from creating document"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 1 | return $self->open_document(id => $result->{documentId}); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 37 | ▶ | sub open_document { Document->new(docs_api => shift, @_); } | ||||||||||||||||||||||||||
|
Subroutine
open_document: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub delete_document { | ||||||||||||||||||||||||||
|
Subroutine
delete_document: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 76 | 0 | my $id = $Document_Id; | |||||||||||||||||||||||||||
| 77 | 0 | state $check = signature(positional => [StrMatch[qr/$id/]]); | |||||||||||||||||||||||||||
| 78 | 0 | my ($document_id) = $check->(@_); | |||||||||||||||||||||||||||
| 79 | 0 | return $self->drive()->file(id => $document_id)->delete(); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub delete_all_documents_by_filters { | ||||||||||||||||||||||||||
|
Subroutine
delete_all_documents_by_filters: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | state $check = signature(positional => [ArrayRef->plus_coercions(Str, sub { [$_]; })]); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 86 | 0 | my ($filter) = $check->(@_); | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | my $count = 0; | |||||||||||||||||||||||||||
| 89 | 0 | foreach my $filter (@$filter) { | |||||||||||||||||||||||||||
| 90 | 0 | my @documents = $self->documents_by_filter(filter => $filter); | |||||||||||||||||||||||||||
| 91 | 0 | $count += scalar @documents; | |||||||||||||||||||||||||||
| 92 | 0 | DEBUG(sprintf("Deleting %d documents for filter '$filter'", scalar @documents)); | |||||||||||||||||||||||||||
| 93 | 0 | $self->delete_document($_->{id}) foreach (@documents); | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 0 | return $count; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub delete_all_documents { | ||||||||||||||||||||||||||
|
Subroutine
delete_all_documents: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 99 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 100 | 0 | my @names = @_; | |||||||||||||||||||||||||||
| 101 | 0 | @names = map { "name = '$_'"; } @names; | |||||||||||||||||||||||||||
| 102 | 0 | return $self->delete_all_documents_by_filters(@names); | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 2 | ▶ | sub documents_by_filter { | ||||||||||||||||||||||||||
|
Subroutine
documents_by_filter: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||
| 106 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 2 | state $check = signature( | |||||||||||||||||||||||||||
| 109 | bless => !!0, | ||||||||||||||||||||||||||||
| 110 | named => [ | ||||||||||||||||||||||||||||
| 111 | filter => Str, { optional => 1 }, | ||||||||||||||||||||||||||||
| 112 | max_pages => Int, { default => 0 }, | ||||||||||||||||||||||||||||
| 113 | page_callback => CodeRef, { optional => 1 }, | ||||||||||||||||||||||||||||
| 114 | params => HashRef, { default => {} }, | ||||||||||||||||||||||||||||
| 115 | ], | ||||||||||||||||||||||||||||
| 116 | ); | ||||||||||||||||||||||||||||
| 117 | 2 | my $p = $check->(@_); | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 2 | my $drive = $self->drive(); | |||||||||||||||||||||||||||
| 120 | 2 | my $filter = $Document_Filter; | |||||||||||||||||||||||||||
| 121 | 2 | ▶ | $filter .= " and ($p->{filter})" if $p->{filter}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | return $drive->list( | ||||||||||||||||||||||||||||
| 123 | filter => $filter, | ||||||||||||||||||||||||||||
| 124 | max_pages => $p->{max_pages}, | ||||||||||||||||||||||||||||
| 125 | params => $p->{params}, | ||||||||||||||||||||||||||||
| 126 | 2 | ▶ | ($p->{page_callback} ? (page_callback => $p->{page_callback}) : ()), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | ); | ||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 1 | ▶ | sub documents { | ||||||||||||||||||||||||||
|
Subroutine
documents: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 131 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 1 | state $check = signature( | |||||||||||||||||||||||||||
| 134 | bless => !!0, | ||||||||||||||||||||||||||||
| 135 | named => [ | ||||||||||||||||||||||||||||
| 136 | name => Str, { optional => 1 }, | ||||||||||||||||||||||||||||
| 137 | max_pages => Int, { default => 0 }, | ||||||||||||||||||||||||||||
| 138 | page_callback => CodeRef, { optional => 1 }, | ||||||||||||||||||||||||||||
| 139 | params => HashRef, { default => {} }, | ||||||||||||||||||||||||||||
| 140 | ], | ||||||||||||||||||||||||||||
| 141 | ); | ||||||||||||||||||||||||||||
| 142 | 1 | my $p = $check->(@_); | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 1 | my $name = delete $p->{name}; | |||||||||||||||||||||||||||
| 145 | 1 | ▶ | $p->{filter} = "name = '$name'" if $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 1 | return $self->documents_by_filter(%$p); | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 2 | ▶ | sub drive { | ||||||||||||||||||||||||||
|
Subroutine
drive: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 150 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 151 | 2 | ▶ | $self->{drive} //= DriveApi3->new(api => $self->rest_api()); | ||||||||||||||||||||||||||
|
Condition66%2/3
$$self{"drive"} //= "Google::RestApi::DriveApi3"->new("api", $self->rest_api)
MC/DC0%0/2
$$self{"drive"} //= "Google::RestApi::DriveApi3"->new("api", $self->rest_api)
$$self{"drive"}
"Google::RestApi::DriveApi3"->new("api", $self->rest_api)
Truth table66%2/3
A //= B
A= $$self{"drive"}B= "Google::RestApi::DriveApi3"->new("api", $self->rest_api)
| |||||||||||||||||||||||||||||
| 152 | 2 | return $self->{drive}; | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 6 | ▶ | sub rest_api { shift->{api}; } | ||||||||||||||||||||||||||
|
Subroutine
rest_api: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub transaction { shift->rest_api()->transaction(); } | ||||||||||||||||||||||||||
|
Subroutine
transaction: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 157 | 0 | ▶ | sub stats { shift->rest_api()->stats(); } | ||||||||||||||||||||||||||
|
Subroutine
stats: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 158 | 0 | ▶ | sub reset_stats { shift->rest_api->reset_stats(); } | ||||||||||||||||||||||||||
|
Subroutine
reset_stats: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 2 | 1; | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | __END__ | ||||||||||||||||||||||||||||