.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "File::Dropbox 3pm" .TH File::Dropbox 3pm "2022-06-13" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" File::Dropbox \- Convenient and fast Dropbox API abstraction .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& 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, \*(Aq>\*(Aq, \*(Aqexample\*(Aq 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, \*(Aq<\*(Aq, \*(Aqexample\*(Aq 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; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\f(CW\*(C`File::Dropbox\*(C'\fR provides high-level Dropbox \s-1API\s0 abstraction based on Tie::Handle. Code required to get \f(CW\*(C`access_token\*(C'\fR and \&\f(CW\*(C`access_secret\*(C'\fR for signed OAuth 1.0 requests or \f(CW\*(C`access_token\*(C'\fR for OAuth 2.0 requests is not included in this module. To get \f(CW\*(C`app_key\*(C'\fR and \f(CW\*(C`app_secret\*(C'\fR you need to register your application with Dropbox. .PP At this moment Dropbox \s-1API\s0 is not fully supported, \f(CW\*(C`File::Dropbox\*(C'\fR covers file read/write and directory listing methods. If you need full \&\s-1API\s0 support take look at WebService::Dropbox. \f(CW\*(C`File::Dropbox\*(C'\fR main purpose is not 100% \s-1API\s0 coverage, but simple and high-performance file operations. .PP Due to \s-1API\s0 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 open. Supported functions for read-only state are: open, close, seek, tell, readline, read, sysread, getc, eof. For write-only state: open, close, syswrite, print, printf, say. .PP All \s-1API\s0 requests are done using Furl module. For more accurate timeouts Net::DNS::Lite is used, as described in Furl::HTTP. Furl settings can be overridden using \f(CW\*(C`furlopts\*(C'\fR. .SH "METHODS" .IX Header "METHODS" .SS "new" .IX Subsection "new" .Vb 11 \& my $dropbox = File::Dropbox\->new( \& access_secret => $access_secret, \& access_token => $access_token, \& app_secret => $app_secret, \& app_key => $app_key, \& chunk => 8 * 1024 * 1024, \& root => \*(Aqdropbox\*(Aq, \& furlopts => { \& timeout => 20 \& } \& ); \& \& my $dropbox = File::Dropbox\->new( \& access_token => $access_token, \& oauth2 => 1 \& ); .Ve .PP Constructor, takes key-value pairs list .IP "access_secret" 4 .IX Item "access_secret" OAuth 1.0 access secret .IP "access_token" 4 .IX Item "access_token" OAuth 1.0 access token or OAuth 2.0 access token .IP "app_secret" 4 .IX Item "app_secret" OAuth 1.0 app secret .IP "app_key" 4 .IX Item "app_key" OAuth 1.0 app key .IP "oauth2" 4 .IX Item "oauth2" OAuth 2.0 switch, defaults to false. .IP "chunk" 4 .IX Item "chunk" Upload chunk size in bytes. Also buffer size for \f(CW\*(C`readline\*(C'\fR. Optional. Defaults to 4MB. .IP "root" 4 .IX Item "root" Access type, \f(CW\*(C`sandbox\*(C'\fR for app-folder only access and \f(CW\*(C`dropbox\*(C'\fR for full access. .IP "furlopts" 4 .IX Item "furlopts" Parameter hash, passed to Furl constructor directly. Default options .Sp .Vb 5 \& timeout => 10, \& inet_aton => \e&Net::DNS::Lite::inet_aton, \& ssl_opts => { \& SSL_verify_mode => SSL_VERIFY_PEER(), \& } .Ve .SH "FUNCTIONS" .IX Header "FUNCTIONS" All functions are not exported by default but can be exported on demand. .PP .Vb 1 \& use File::Dropbox qw{ contents metadata putfile }; .Ve .PP First argument for all functions should be \s-1GLOB\s0 reference, returned by \*(L"new\*(R". .SS "contents" .IX Subsection "contents" Arguments: \f(CW$dropbox\fR [, \f(CW$path\fR] .PP Function returns list of hashrefs representing directory content. Hash fields described in Dropbox \s-1API\s0 docs . \f(CW$path\fR defaults to \f(CW\*(C`/\*(C'\fR. If there is unfinished chunked upload on handle, it will be committed. .PP .Vb 4 \& foreach my $file (contents($dropbox, \*(Aq/data\*(Aq)) { \& next if $file\->{\*(Aqis_dir\*(Aq}; \& say $file\->{\*(Aqpath\*(Aq}, \*(Aq \- \*(Aq, $file\->{\*(Aqbytes\*(Aq}; \& } .Ve .SS "metadata" .IX Subsection "metadata" Arguments: \f(CW$dropbox\fR .PP Function returns stored metadata for read-only handle, closed write handle or after call to \*(L"contents\*(R" or \*(L"putfile\*(R". .PP .Vb 1 \& open $dropbox, \*(Aq<\*(Aq, \*(Aq/data/2013.dat\*(Aq or die $!; \& \& my $meta = metadata($dropbox); \& \& if ($meta\->{\*(Aqbytes\*(Aq} > 1024) { \& # Do something \& } .Ve .SS "putfile" .IX Subsection "putfile" Arguments: \f(CW$dropbox\fR, \f(CW$path\fR, \f(CW$data\fR .PP Function is useful for uploading small files (up to 150MB possible) in one request (at least two \s-1API\s0 requests required for chunked upload, used in open-write-close sequence). If there is unfinished chunked upload on handle, it will be committed. .PP .Vb 2 \& local $/; \& open my $data, \*(Aq<\*(Aq, \*(Aq2012.dat\*(Aq or die $!; \& \& putfile($dropbox, \*(Aq/data/2012.dat\*(Aq, <$data>) or die $!; \& \& say \*(AqUploaded \*(Aq, metadata($dropbox)\->{\*(Aqbytes\*(Aq}, \*(Aq bytes\*(Aq; \& \& close $data; .Ve .SS "copyfile" .IX Subsection "copyfile" Arguments: \f(CW$dropbox\fR, \f(CW$source\fR, \f(CW$target\fR .PP Function copies file or directory from one location to another. Metadata for copy can be accessed using \*(L"metadata\*(R" function. .PP .Vb 1 \& copyfile($dropbox, \*(Aq/data/2012.dat\*(Aq, \*(Aq/data/2012.dat.bak\*(Aq) or die $!; \& \& say \*(AqCreated backup with revision \*(Aq, metadata($dropbox)\->{\*(Aqrevision\*(Aq}; .Ve .SS "movefile" .IX Subsection "movefile" Arguments: \f(CW$dropbox\fR, \f(CW$source\fR, \f(CW$target\fR .PP Function moves file or directory from one location to another. Metadata for moved file can be accessed using \*(L"metadata\*(R" function. .PP .Vb 1 \& movefile($dropbox, \*(Aq/data/2012.dat\*(Aq, \*(Aq/data/2012.dat.bak\*(Aq) or die $!; \& \& say \*(AqCreated backup with size \*(Aq, metadata($dropbox)\->{\*(Aqsize\*(Aq}; .Ve .SS "deletefile" .IX Subsection "deletefile" Arguments: \f(CW$dropbox\fR, \f(CW$path\fR .PP Function deletes file or folder at specified path. Metadata for deleted item is accessible via \*(L"metadata\*(R" function. .PP .Vb 1 \& deletefile($dropbox, \*(Aq/data/2012.dat.bak\*(Aq) or die $!; \& \& say \*(AqDeleted backup with last modification \*(Aq, metadata($dropbox)\->{\*(Aqmodification\*(Aq}; .Ve .SS "createfolder" .IX Subsection "createfolder" Arguments: \f(CW$dropbox\fR, \f(CW$path\fR .PP Function creates folder at specified path. Metadata for created folder is accessible via \*(L"metadata\*(R" function. .PP .Vb 1 \& createfolder($dropbox, \*(Aq/data/backups\*(Aq) or die $!; \& \& say \*(AqCreated folder at path \*(Aq, metadata($dropbox)\->{\*(Aqpath\*(Aq}; .Ve .SH "SEE ALSO" .IX Header "SEE ALSO" Furl, Furl::HTTP, WebService::Dropbox, Dropbox \s-1API\s0 .SH "AUTHOR" .IX Header "AUTHOR" Alexander Nazarov .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright 2013\-2016 Alexander Nazarov .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.