File-Dropbox
view release on metacpan or search on metacpan
lib/File/Dropbox.pm view on Meta::CPAN
sub putfile ($$$) {
my ($handle, $path, $data) = @_;
die 'GLOB reference expected'
unless ref $handle eq 'GLOB';
close $handle or return 0;
my $self = *$handle{'HASH'};
my $furl = $self->{'furl'};
my ($url, $length);
$url = 'https://';
$url .= join '/', $hosts->{'content'}, $version;
$url .= join '/', '/files_put', $self->{'root'}, $path;
{
use bytes;
$length = length $data;
}
my $response = $furl->put($url, $self->__headers__(), $data);
return $self->__error__($response)
if $response->code != 200;
$self->{'path'} = $path;
$self->{'meta'} = from_json($response->content());
return 1;
} # putfile
sub movefile ($$$) { __fileops__('move', @_) }
sub copyfile ($$$) { __fileops__('copy', @_) }
sub deletefile ($$) { __fileops__('delete', @_) }
sub createfolder ($$) { __fileops__('create_folder', @_) }
sub metadata ($) {
my ($handle) = @_;
die 'GLOB reference expected'
unless ref $handle eq 'GLOB';
my $self = *$handle{'HASH'};
die 'Meta is unavailable for incomplete upload'
if $self->{'mode'} eq '>';
return $self->{'meta'};
} # metadata
=head1 NAME
File::Dropbox - Convenient and fast Dropbox API abstraction
=head1 SYNOPSIS
use File::Dropbox;
use Fcntl;
# Application credentials
my %app = (
oauth2 => 1,
access_token => $access_token,
);
my $dropbox = File::Dropbox->new(%app);
# Open file for writing
open $dropbox, '>', 'example' or die $!;
while (<>) {
# Upload data using 4MB chunks
print $dropbox $_;
}
# Commit upload (optional, close will be called on reopen)
close $dropbox or die $!;
# Open for reading
open $dropbox, '<', 'example' or die $!;
# Download and print to STDOUT
# Buffered, default buffer size is 4MB
print while <$dropbox>;
# Reset file position
seek $dropbox, 0, Fcntl::SEEK_SET;
# Get first character (unbuffered)
say getc $dropbox;
close $dropbox;
=head1 DESCRIPTION
C<File::Dropbox> provides high-level Dropbox API abstraction based on L<Tie::Handle>. Code required to get C<access_token> and
C<access_secret> for signed OAuth 1.0 requests or C<access_token> for OAuth 2.0 requests is not included in this module.
To get C<app_key> and C<app_secret> you need to register your application with Dropbox.
At this moment Dropbox API is not fully supported, C<File::Dropbox> covers file read/write and directory listing methods. If you need full
API support take look at L<WebService::Dropbox>. C<File::Dropbox> main purpose is not 100% API coverage,
but simple and high-performance file operations.
Due to API limitations and design you can not do read and write operations on one file at the same time. Therefore handle can be in read-only
or write-only state, depending on last call to L<open|perlfunc/open>. Supported functions for read-only state are: L<open|perlfunc/open>,
L<close|perlfunc/close>, L<seek|perlfunc/seek>, L<tell|perlfunc/tell>, L<readline|perlfunc/readline>, L<read|perlfunc/read>,
L<sysread|perlfunc/sysread>, L<getc|perlfunc/getc>, L<eof|perlfunc/eof>. For write-only state: L<open|perlfunc/open>, L<close|perlfunc/close>,
L<syswrite|perlfunc/syswrite>, L<print|perlfunc/print>, L<printf|perlfunc/printf>, L<say|perlfunc/say>.
All API requests are done using L<Furl> module. For more accurate timeouts L<Net::DNS::Lite> is used, as described in L<Furl::HTTP>. Furl settings
can be overriden using C<furlopts>.
=head1 METHODS
=head2 new
my $dropbox = File::Dropbox->new(
access_secret => $access_secret,
access_token => $access_token,
app_secret => $app_secret,
( run in 0.880 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )