Client/NoAPI.pm

filter: Statementstmt 48.0% 25 / 52 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 8 / 12 Podpod 100% 4 / 4 totaltotal 51.3% 37 / 72 CC 3 SCAR 12.7
CC
3
Cov
45%
download
12.0
manifest
2.0
upload
2.0
CRAP 3.6
« Client.pm ↑ Summary
1 package WWW::Suffit::Client::NoAPI;
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =encoding utf-8
7  
8 =head1 NAME
9  
10 WWW::Suffit::Client::NoAPI - The Suffit API client library for NoAPI methods
11  
12 =head1 SYNOPSIS
13  
14 use WWW::Suffit::Client::NoAPI;
15  
16 =head1 DESCRIPTION
17  
18 This library provides NoAPI methods for access to Suffit API servers
19  
20 =head1 NOAPI METHODS
21  
22 List of predefined the Suffit NoAPI methods
23  
24 =head2 download
25  
26 my $status = $client->download("file.txt", "/tmp/file.txt");
27  
28 Request for download an file from the server by file path.
29 The method returns status of operation: 0 - Error; 1 - Ok
30  
31 =head2 manifest
32  
33 my $status = $client->manifest;
34  
35 Gets list of files (manifest) from server
36 The method returns status of operation: 0 - Error; 1 - Ok
37  
38 =head2 remove
39  
40 my $status = $client->remove("/foo/bar/file.txt");
41  
42 Request for deleting the file from server.
43 The method returns status of operation: 0 - Error; 1 - Ok
44  
45 =head2 upload
46  
47 my $status = $clinet->upload("/tmp/file.txt", "/foo/bar/file.txt");
48  
49 Upload an file to the server by file path
50  
51 =head1 DEPENDENCIES
52  
53 L<Mojolicious>, L<WWW::Suffit>
54  
55 =head1 TO DO
56  
57 See C<TODO> file
58  
59 =head1 SEE ALSO
60  
61 L<Mojo::UserAgent>, L<WWW::Suffit::UserAgent>
62  
63 =head1 AUTHOR
64  
65 Serż Minus (Sergey Lepenkov) L<https://www.serzik.com> E<lt>abalama@cpan.orgE<gt>
66  
67 =head1 COPYRIGHT
68  
69 Copyright (C) 1998-2026 D&D Corporation
70  
71 =head1 LICENSE
72  
73 This program is distributed under the terms of the Artistic License Version 2.0
74  
75 See the C<LICENSE> file or L<https://opensource.org/license/artistic-2-0> for details
76  
77 =cut
78  
79 1 ▶use parent qw/ WWW::Suffit::Client /;
Subroutine BEGIN: called CC=1 SCAR=0.0
80  
81 1 ▶use Mojo::Asset::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
82 1 ▶use Mojo::File qw/path/;
Subroutine BEGIN: called CC=1 SCAR=0.0
83  
84 1 ▶use WWW::Suffit::Const qw/ :MIME /;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 1 ▶use WWW::Suffit::Util qw/ md5sum /;
Subroutine BEGIN: called CC=1 SCAR=0.0
86  
87 ## SUFFIT NoAPI METHODS
88  
89 0 ▶sub manifest {
Subroutine manifest: not called CC=1 SCAR=6.9
Pod documented
90 0 my $self = shift;
91 0 return $self->request(GET => $self->str2url("file"), # e.g.: api/file
92 { # Headers
93 Accept => CONTENT_TYPE_JSON, # "*/*"
94 }
95 );
96 }
97 0 ▶sub download {
Subroutine download: not called CC=3 SCAR=24.8
Pod documented
98 0 my $self = shift;
99 0 my $rfile = shift; # Remote file: t.txt
100 0 my $lfile = shift; # Local file (full file path to save)
101  
102 # Remote file
103 0 $rfile =~ s/^\/+//;
104 0 my $status = $self->request(GET => $self->str2url(sprintf("file/%s", $rfile)));
105 0 ▶ return $status unless $status;
Branch: 1 branch
BranchTrueFalseTotal
unless $status 0 0 0
106  
107 # Local file
108 0 my $filepath = path($lfile);
109 0 my $filename = $filepath->basename;
110 0 $self->res->save_to($lfile);
111 0 ▶ return 1 if $filepath->stat->size;
Branch: 1 branch
BranchTrueFalseTotal
if $filepath->stat->size 0 0 0
112 0 $self->error("Can't download file $filename");
113 0 $self->status(0);
114 0 return 0;
115 }
116 0 ▶sub upload {
Subroutine upload: not called CC=1 SCAR=6.9
Pod documented
117 0 my $self = shift;
118 0 my $lfile = shift; # Local file (full file path to save)
119 0 my $rfile = shift; # Remote file: t.txt
120  
121 # Local file
122 0 my $filepath = path($lfile);
123 0 my $filename = $filepath->basename;
124 0 my $asset_file = Mojo::Asset::File->new(path => $filepath);
125  
126 # Remote file
127 0 $rfile =~ s/^\/+//;
128  
129 # Request
130 0 return $self->request(PUT => $self->str2url(sprintf("file/%s", $rfile)) =>
131 { # Headers
132 'Content-Type' => 'multipart/form-data',
133 },
134 form => {
135 size => $asset_file->size,
136 md5 => md5sum($asset_file->path),
137 fileraw => {
138 file => $asset_file,
139 filename => $filename,
140 'Content-Type' => 'application/octet-stream',
141 },
142 },
143 );
144 }
145 0 ▶sub remove {
Subroutine remove: not called CC=1 SCAR=6.9
Pod documented
146 0 my $self = shift;
147 0 my $rfile = shift;
148 0 $rfile =~ s/^\/+//;
149 0 return $self->request(DELETE => $self->str2url(sprintf("file/%s", $rfile)));
150 }
151  
152 1 1;
153  
154 __END__
« Client.pm ↑ Summary