Added changes, readme, makefile

This commit is contained in:
vrag
2019-05-23 17:33:09 +03:00
parent 9f3121a582
commit f25463a6da
4 changed files with 141 additions and 24 deletions

5
Changes Normal file
View File

@@ -0,0 +1,5 @@
Revision history for Perl extension Mediafire::Api.
0.01 Thu May 23 17:26:40 2019
- original version
-b 5.8.1 -XAn Mediafir::Api

35
Makefile.PL Normal file
View File

@@ -0,0 +1,35 @@
use 5.008001;
use strict;
use warnings;
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
NAME => 'Mediafire::Api',
LICENSE => 'perl_5',
AUTHOR => 'Pavel Andryushin',
VERSION_FROM => 'lib/Mediafire/Api.pm', # finds $VERSION, requires EU::MM from perl >= 5.5
PREREQ_PM => {
'URI::Escape' => 3.31,
'LWP::UserAgent' => 6.27,
'LWP::Protocol::https' => 6.06,
'JSON::XS' => 3.04,
'File::Basename' => 2.85,
'Encode' => 2.60,
'Carp' => 1.3301,
'MIME::Detect' => 0.10,
'HTTP::Request' => 6.00,
'Crypt::Digest::SHA256' => 0.061,
},
META_MERGE => {
requires => { perl => '5.008008' },
resources => {
license => 'http://dev.perl.org/licenses/',
repository => 'https://github.com/vrag86/Mediafire-Api',
bugtracker => 'https://github.com/vrag86/Mediafire-Api/issues'
},
},
AUTHOR => 'vrag <vrag867@gmail.com>',
LICENSE => 'perl',
);

100
README Normal file
View File

@@ -0,0 +1,100 @@
NAME
Mediafire::Api - Upload and Download files from mediafire.com file
sharing
VERSION
version 0.01
SYNOPSYS
METHODS
use Mediafire::Api;
# Create Mediafire::Api object
my $mediafire = Mediafire::Api->new();
# Login on service
$mediafire->login(
-login => $login,
-password => $password,
);
# Upload file to server
my $remote_dir = 'myfiles'; # Directory name on server
my $filename = '/tmp/test_file.zip'; # Full file path to upload
# Upload file on server. Return Mediafire::Api::UploadFile object
my $mediafire_file = $mediafire->uploadFile(
-file => $filename,
-path => $remote_dir,
);
# Get uploaded file key
print "Uploaded file key: " . $mediafire_file->getDouploadKey() . "\n";
# Find file on mediafire.com by name. Return arrayref to Mediafire::Api::File objects
my $find_result = $mediafire->findFileByName(
-filename => 'file_to_find.txt',
);
if (@$find_result) {
print "Found files: " . join(' ', map {$_->name()} @$find_result);
}
# Download file from mediafire.com
$mediafire->downloadFile(
-mediafire_file => $mediafire_file,
-dest_file => './test_file.zip',
);
Upload Files to server
new()
login(%opt)
Mediafire::Api::File
name
Set/Get name of file $mediafire_file->name("New name"); my $name =
$mediafire->name;
key
Set/Get download key of file
$mediafire_file->key("downloadfilekey");
my $key = $mediafire_file->key;
size
Set/Get size of file
$mediafire->size(2343);
my $size = $mediafire->size;
hash
Set/Get sha256sum hashsum of file
$mediafire_file->hash('dffdf');
my $hash = $mediafire_file->hash;
Find files on mediafire.com
findFileByName(%opt)
Return arrayref with Mediafire::Api::file objects
%opt:
-filename => Name of file to find
Download files from mediafire.com
downloadFile(%opt)
Download file from mediafire.com to $dest_file
%opt:
-mediafire_file => Mediafire::Api::File object to download
-dest_file => Name of file on local disk, in which will be downloaded mediafire file
DEPENDENCE
LWP::UserAgent, JSON::XS, URI::Escape, Encode, HTTP::Request, Carp,
File::Basename, MIME::Detect, HTTP::Request, Crypt::Digest::SHA256
AUTHORS
* Pavel Andryushin <vrag867@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2019 by Pavel Andryushin.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

View File

@@ -244,29 +244,6 @@ sub downloadFile {
} }
=pod Вынести в отдельный класс с проверкой наличия такой директории
sub createDir {
my ($self, %opt) = @_;
my $dirname = $opt{-dirname} // croak "You must specify '-dirname' param";
my $url = 'https://www.mediafire.com/api/1.4/folder/create.php';
my %param = (
'r' => 'sloe',
'foldername' => $dirname,
'parent_key' => '',
'session_token' => $self->{session_token},
'response_format' => 'json',
);
$url . = '?' . join('&', map {"$_=" . uri_escape($param{$_})} keys %param);
my $res = $self->{ua}->get($url);
my $code = $res->code;
if ($code ne '200') {
croak "Can't create dir '$dirname'. Code: $code";
}
my $json_res = decode_json($res->decoded_content);
p $json_res;
}
=cut
1; 1;
@@ -383,7 +360,7 @@ Download file from mediafire.com to $dest_file
=head1 DEPENDENCE =head1 DEPENDENCE
L<LWP::UserAgent>, L<JSON::XS>, L<URI::Escape>, L<Encode>, L<HTTP::Request>, L<Carp>, L<File::Basename>, L<MIME::Detect> L<LWP::UserAgent>, L<JSON::XS>, L<URI::Escape>, L<Encode>, L<HTTP::Request>, L<Carp>, L<File::Basename>, L<MIME::Detect>, L<HTTP::Request>, L<Crypt::Digest::SHA256>
=head1 AUTHORS =head1 AUTHORS