| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package WWW::Suffit::Client::NoAPI; | 
| 2 | 1 |  |  | 1 |  | 71078 | use warnings; | 
|  | 1 |  |  |  |  | 11 |  | 
|  | 1 |  |  |  |  | 36 |  | 
| 3 | 1 |  |  | 1 |  | 15 | use strict; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 26 |  | 
| 4 | 1 |  |  | 1 |  | 627 | use utf8; | 
|  | 1 |  |  |  |  | 15 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 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 VERSION | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | Version 1.00 | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | use WWW::Suffit::Client::NoAPI; | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | This library provides NoAPI methods for access to Suffit API servers | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | =head1 NOAPI METHODS | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | List of predefined the Suffit NoAPI methods | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | =head2 download | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | my $status = $client->download("file.txt", "/tmp/file.txt"); | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | Request for download an file from the server by file path. | 
| 33 |  |  |  |  |  |  | The method returns status of operation: 0 - Error; 1 - Ok | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | =head2 manifest | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | my $status = $client->manifest; | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | Gets list of files (manifest) from server | 
| 40 |  |  |  |  |  |  | The method returns status of operation: 0 - Error; 1 - Ok | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | =head2 remove | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | my $status = $client->remove("/foo/bar/file.txt"); | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | Request for deleting the file from server. | 
| 47 |  |  |  |  |  |  | The method returns status of operation: 0 - Error; 1 - Ok | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | =head2 upload | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | my $status = $clinet->upload("/tmp/file.txt", "/foo/bar/file.txt"); | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | Upload an file to the server by file path | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | =head1 DEPENDENCIES | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | L, L | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | =head1 TO DO | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | See C file | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | L, L | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | =head1 AUTHOR | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | Serż Minus (Sergey Lepenkov) L Eabalama@cpan.orgE | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | =head1 COPYRIGHT | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | Copyright (C) 1998-2023 D&D Corporation. All Rights Reserved | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | =head1 LICENSE | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or | 
| 78 |  |  |  |  |  |  | modify it under the same terms as Perl itself. | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | See C file and L | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | =cut | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | our $VERSION = '1.00'; | 
| 85 |  |  |  |  |  |  |  | 
| 86 | 1 |  |  | 1 |  | 511 | use parent qw/ WWW::Suffit::Client /; | 
|  | 1 |  |  |  |  | 362 |  | 
|  | 1 |  |  |  |  | 11 |  | 
| 87 |  |  |  |  |  |  |  | 
| 88 | 1 |  |  | 1 |  | 56 | use Mojo::Asset::File; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 7 |  | 
| 89 | 1 |  |  | 1 |  | 35 | use Mojo::File qw/path/; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 48 |  | 
| 90 |  |  |  |  |  |  |  | 
| 91 | 1 |  |  | 1 |  | 7 | use WWW::Suffit::Const qw/ :MIME /; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 89 |  | 
| 92 | 1 |  |  | 1 |  | 8 | use WWW::Suffit::Util qw/ md5sum /; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 532 |  | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | ## SUFFIT NoAPI METHODS | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | sub manifest { | 
| 97 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 98 | 0 |  |  |  |  |  | return $self->request(GET => $self->str2url("file"), # e.g.: api/file | 
| 99 |  |  |  |  |  |  | { # Headers | 
| 100 |  |  |  |  |  |  | Accept => CONTENT_TYPE_JSON, # "*/*" | 
| 101 |  |  |  |  |  |  | } | 
| 102 |  |  |  |  |  |  | ); | 
| 103 |  |  |  |  |  |  | } | 
| 104 |  |  |  |  |  |  | sub download { | 
| 105 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 106 | 0 |  |  |  |  |  | my $rfile = shift; # Remote file: t.txt | 
| 107 | 0 |  |  |  |  |  | my $lfile = shift; # Local file (full file path to save) | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | # Remote file | 
| 110 | 0 |  |  |  |  |  | $rfile =~ s/^\/+//; | 
| 111 | 0 |  |  |  |  |  | my $status = $self->request(GET => $self->str2url(sprintf("file/%s", $rfile))); | 
| 112 | 0 | 0 |  |  |  |  | return $status unless $status; | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | # Local file | 
| 115 | 0 |  |  |  |  |  | my $filepath = path($lfile); | 
| 116 | 0 |  |  |  |  |  | my $filename = $filepath->basename; | 
| 117 | 0 |  |  |  |  |  | $self->res->save_to($lfile); | 
| 118 | 0 | 0 |  |  |  |  | return 1 if $filepath->stat->size; | 
| 119 | 0 |  |  |  |  |  | $self->error("Can't download file $filename"); | 
| 120 | 0 |  |  |  |  |  | $self->status(0); | 
| 121 | 0 |  |  |  |  |  | return 0; | 
| 122 |  |  |  |  |  |  | } | 
| 123 |  |  |  |  |  |  | sub upload { | 
| 124 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 125 | 0 |  |  |  |  |  | my $lfile = shift; # Local file (full file path to save) | 
| 126 | 0 |  |  |  |  |  | my $rfile = shift; # Remote file: t.txt | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | # Local file | 
| 129 | 0 |  |  |  |  |  | my $filepath = path($lfile); | 
| 130 | 0 |  |  |  |  |  | my $filename = $filepath->basename; | 
| 131 | 0 |  |  |  |  |  | my $asset_file = Mojo::Asset::File->new(path => $filepath); | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | # Remote file | 
| 134 | 0 |  |  |  |  |  | $rfile =~ s/^\/+//; | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | # Request | 
| 137 | 0 |  |  |  |  |  | return $self->request(PUT => $self->str2url(sprintf("file/%s", $rfile)) => | 
| 138 |  |  |  |  |  |  | { # Headers | 
| 139 |  |  |  |  |  |  | 'Content-Type' => 'multipart/form-data', | 
| 140 |  |  |  |  |  |  | }, | 
| 141 |  |  |  |  |  |  | form => { | 
| 142 |  |  |  |  |  |  | size => $asset_file->size, | 
| 143 |  |  |  |  |  |  | md5 => md5sum($asset_file->path), | 
| 144 |  |  |  |  |  |  | fileraw => { | 
| 145 |  |  |  |  |  |  | file        => $asset_file, | 
| 146 |  |  |  |  |  |  | filename    => $filename, | 
| 147 |  |  |  |  |  |  | 'Content-Type' => 'application/octet-stream', | 
| 148 |  |  |  |  |  |  | }, | 
| 149 |  |  |  |  |  |  | }, | 
| 150 |  |  |  |  |  |  | ); | 
| 151 |  |  |  |  |  |  | } | 
| 152 |  |  |  |  |  |  | sub remove { | 
| 153 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 154 | 0 |  |  |  |  |  | my $rfile = shift; | 
| 155 | 0 |  |  |  |  |  | $rfile =~ s/^\/+//; | 
| 156 | 0 |  |  |  |  |  | return $self->request(DELETE => $self->str2url(sprintf("file/%s", $rfile))); | 
| 157 |  |  |  |  |  |  | } | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | 1; | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | __END__ |