App-dropboxapi
view release on metacpan or search on metacpan
script/dropbox-api view on Meta::CPAN
if ($command eq '-v') {
&help('version');
exit(0);
}
if ($command eq 'setup' || !-f $config_file) {
&setup();
}
# connect dropbox
my $config = decode_json($config_file->slurp);
$config->{key} or die 'please set config key.';
$config->{secret} or die 'please set config secret.';
$config->{access_token} or die 'please set config access_token.';
if ($config->{access_secret}) {
warn "Auto migration OAuth1 Token to OAuth2 token...";
my $oauth2_access_token = &token_from_oauth1($config->{key}, $config->{secret}, $config->{access_token}, $config->{access_secret});
if ($oauth2_access_token) {
delete $config->{access_secret};
$config->{access_token} = $oauth2_access_token;
$config_file->openw->print(encode_json($config));
warn "=> Suucess.";
} else {
die "please setup.";
}
}
if (my $access_level = delete $config->{access_level}) {
if ($access_level eq 'a') {
print "sandbox is gone, Are you sure you want to delete from the config the access_level? [y/n]: ";
chomp( my $y = <STDIN> );
if ($y =~ qr{ [yY] }xms) {
delete $config->{access_level};
$config_file->openw->print(encode_json($config));
warn "=> Suucess.";
} else {
die "cancelled.";
}
}
}
$ENV{HTTP_PROXY} = $ENV{http_proxy} if !$ENV{HTTP_PROXY} && $ENV{http_proxy};
$ENV{NO_PROXY} = $ENV{no_proxy} if !$ENV{NO_PROXY} && $ENV{no_proxy};
my $box = WebService::Dropbox->new($config);
$box->env_proxy if $env_proxy;
my $strp = new DateTime::Format::Strptime( pattern => '%Y-%m-%dT%T' );
my $strpz = new DateTime::Format::Strptime( pattern => '%Y-%m-%dT%TZ' );
my $format = {
i => 'id',
n => 'name',
b => 'size',
e => 'thumb_exists', # jpg, jpeg, png, tiff, tif, gif or bmp
d => 'is_dir', # Check if .tag = "folder"
p => 'path_display',
P => 'path_lower',
s => 'format_size',
t => 'server_modified',
c => 'client_modified', # For files, this is the modification time set by the desktop client when the file was added to Dropbox.
r => 'rev', # A unique identifier for the current revision of a file. This field is the same rev as elsewhere in the API and can be used to detect changes and avoid conflicts.
R => 'rev',
};
# ProgressBar
my $cols = 50;
if ($verbose) {
eval {
my $stty = `stty -a 2>/dev/null`;
if ($stty =~ m|columns (\d+)| || $stty =~ m|(\d+) columns|) {
$cols = $1;
}
};
}
my $exit_code = 0;
if ($command eq 'ls' or $command eq 'list') {
&list(@args);
} elsif ($command eq 'find') {
&find(@args);
} elsif ($command eq 'du') {
&du(@args);
} elsif ($command eq 'copy' or $command eq 'cp') {
©(@args);
} elsif ($command eq 'move' or $command eq 'mv') {
&move(@args);
} elsif ($command eq 'mkdir' or $command eq 'mkpath') {
&mkdir(@args);
} elsif ($command eq 'delete' or $command eq 'rm' or $command eq 'rmtree') {
&delete(@args);
} elsif ($command eq 'upload' or $command eq 'up' or $command eq 'put') {
&upload(@args);
} elsif ($command eq 'download' or $command eq 'dl' or $command eq 'get') {
&download(@args);
} elsif ($command eq 'sync') {
&sync(@args);
} elsif ($command eq 'help' or (not length $command)) {
&help(@args);
} else {
die "unknown command $command";
}
exit($exit_code);
sub help {
my ($command) = @_;
$command ||= '';
my $help;
if ($command eq 'ls' or $command eq 'list') {
$help = q{
Name
dropbox-api-ls - list directory contents
SYNOPSIS
dropbox-api ls <dropbox_path> [options]
Example
( run in 1.459 second using v1.01-cache-2.11-cpan-e1769b4cff6 )