NAME
WebService::CloudPT - Perl interface to CloudPT API
SYNOPSIS
use WebService::CloudPT;
my $cloudpt = WebService::CloudPT->new({
key => '...', # App Key
secret => '...' # App Secret
});
# get access token
if (!$access_token or !$access_secret) {
my $url = $cloudpt->login($url_callback) or die $cloudpt->error;
warn "Please Access URL and press Enter: $url";
my $verifier = <STDIN>;
chomp $verifier;
$cloudpt->auth({'verifier' = $verifier ]) or die $cloudt->error;
warn "access_token: " . $cloudpt->access_token;
warn "access_secret: " . $cloudpt->access_secret;
} else {
$cloudpt->access_token($access_token);
$cloudpt->access_secret($access_secret);
}
my $info = $cloudpt->account_info or die $cloudpt->error;
# download
# https://cloudpt.pt/documentation#files
my $fh_get = IO::File->new('some file', '>');
$cloudpt->files('make_test_folder/test.txt', $fh_get) or die $cloudpt->error;
$fh_get->close;
# upload
# https://cloudpt.pt/documentation#files
my $fh_put = IO::File->new('some file');
$cloudpt->files_put('make_test_folder/test.txt', $fh_put) or die $cloudpt->error;
$fh_put->close;
# filelist(metadata)
# https://cloudpt.pt/documentation#metadata
my $data = $cloudpt->metadata('folder_a');
DESCRIPTION
WebService::CloudPT is Perl interface to CloudPT API https://cloudpt.pt
- Support CloudPT v1 REST API
- Support Furl (Fast!!!)
- Streaming IO (Low Memory)
- Default URI Escape (The specified path is utf8 decoded string)
API
login(callback_url) - get request token and request secret
my $callback_url = '...'; # optional
my $url = $cloudpt->login($callback_url) or die $cloudpt->error;
warn "Please Access URL and press Enter: $url";
auth - get access token and access secret
$cloudpt->auth or die $cloudpt->error;
warn "access_token: " . $cloudpt->access_token;
warn "access_secret: " . $cloudpt->access_secret;
root - set access type
# Access Type is App folder
# Your app only needs access to a single folder within the user's CloudPT
$cloudpt->root('sandbox');
# Access Type is Full CloudPT (default)
# Your app needs access to the user's entire CloudPT
$cloudpt->root('cloudpt');
account_info
my $info = $cloudpt->account_info or die $cloudpt->error;
https://cloudpt.pt/documentation#accountinfo
files(path, output, [params, opts]) - download (no file list, file list is metadata)
my $fh_get = IO::File->new('some file', '>');
$cloudpt->files('folder/file.txt', $fh_get) or die $cloudpt->error;
$fh_get->close;
https://cloudpt.pt/documentation#files
files_put(path, input) - Uploads a files
my $fh_put = IO::File->new('some file');
$cloudpt->files_put('folder/test.txt', $fh_put) or die $cloudpt->error;
$fh_put->close;
# To overwrite a file, you need to specifie Parent Rev
$cloudpt->files_put('folder/test.txt', $fh_put, { overwrite => 1, parent_rev => ... }) or die $cloudpt->error;
# conflict prevention
https://cloudpt.pt/documentation#files
copy(from_path or from_copy_ref, to_path)
# from_path
$cloudpt->copy('folder/test.txt', 'folder/test_copy.txt') or die $cloudpt->error;
# from_copy_ref
my $copy_ref = $cloudpt->copy_ref('folder/test.txt') or die $cloudpt->error;
$cloudpt->copy($copy_ref, 'folder/test_copy.txt') or die $cloudpt->error;
https://cloudpt.pt/documentation#copy
move(from_path, to_path)
$cloudpt->move('folder/test.txt', 'folder/test_move.txt') or die $cloudpt->error;
https://cloudpt.pt/documentation#move
delete(path)
# folder delete
$cloudpt->delete('folder') or die $cloudpt->error;
# file delete
$cloudpt->delete('folder/test.txt') or die $cloudpt->error;
https://cloudpt.pt/documentation#delete
create_folder(path)
$cloudpt->create_folder('some_folder') or die $cloudpt->error;
https://cloudpt.pt/documentation#createfolder
metadata(path, [params]) - get file list
my $data = $cloudpt->metadata('some_folder') or die $cloudpt->error;
my $data = $cloudpt->metadata('some_file') or die $cloudpt->error;
# 304
my $data = $cloudpt->metadata('some_folder', { hash => ... });
return if $cloudpt->code == 304; # not modified
die $cloudpt->error if $cloudpt->error;
return $data;
https://cloudpt.pt/documentation#metadata
delta([params]) - get file list
my $data = $cloudpt->delta() or die $cloudpt->error;
https://cloudpt.pt/documentation#delta
revisions(path, [params])
my $data = $cloudpt->revisions('some_file') or die $cloudpt->error;
https://cloudpt.pt/documentation#revisions
restore(path, [params])
# params rev is Required
my $data = $cloudpt->restore('some_file', { rev => $rev }) or die $cloudpt->error;
https://cloudpt.pt/documentation#restore
search(path, [params])
my $data = $cloudpt->search('/path', { query => $query }) or die $cloudpt->error;
https://cloudpt.pt/documentation#search
shares(path, [params])
my $data = $cloudpt->shares('some_file') or die $cloudpt->error;
https://cloudpt.pt/documentation#shares
media(path, [params])
my $data = $cloudpt->media('some_file') or die $cloudpt->error;
https://cloudpt.pt/documentation#media
copy_ref(path)
my $copy_ref = $cloudpt->copy_ref('folder/test.txt') or die $cloudpt->error;
$cloudpt->copy($copy_ref, 'folder/test_copy.txt') or die $cloudpt->error;
https://cloudpt.pt/documentation#copyref
thumbnails(path, output)
my $fh_get = File::Temp->new;
$cloudpt->thumbnails('folder/file.txt', $fh_get) or die $cloudpt->error;
$fh_get->flush;
$fh_get->seek(0, 0);
https://cloudpt.pt/documentation#thumbnails
list($path, {'param1' => 'value1', 'param2' => 'value2'....})
my $data = $cloudpt->list('/test', {'file_limit' => 10});
https://cloudpt.pt/documentation#list
list_links
my $data = $cloudpt->list_links();
https://cloudpt.pt/documentation#listlinks
share_folder
my $data = $cloudpt->share_folder('/some_folder', 'my_friend@somewhere.at');
print $data->{'req_id'}
https://cloudpt.pt/documentation#sharefolder
list_shared_folders
my $data = $cloudpt->list_shared_folders();
https://cloudpt.pt/documentation#listsharedfolders
env_proxy
enable HTTP_PROXY, NO_PROXY
$cloudpt->env_proxy;
AUTHOR
Bruno Martins <bruno-martins at telecom.pt>
, based on WebService::Dropbox by Shinichiro Aska
SEE ALSO
- https://cloudpt.pt/documentation
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.