App-dropboxapi

 view release on metacpan or  search on metacpan

META.json  view on Meta::CPAN

         "requires" : {
            "Test::CPAN::Meta" : "0",
            "Test::MinimumVersion::Fast" : "0.04",
            "Test::PAUSE::Permissions" : "0.04",
            "Test::Pod" : "1.41",
            "Test::Spellunker" : "v0.2.7"
         }
      },
      "runtime" : {
         "requires" : {
            "DateTime::Format::Strptime" : "0",
            "Encode::Locale" : "0",
            "Encode::UTF8Mac" : "0",
            "JSON" : "0",
            "Path::Class" : "0.26",
            "WebService::Dropbox" : "2.06",
            "perl" : "5.008001"
         }
      }
   },
   "provides" : {

META.yml  view on Meta::CPAN

    - share
    - eg
    - examples
    - author
    - builder
provides:
  App::dropboxapi:
    file: lib/App/dropboxapi.pm
    version: '2.13'
requires:
  DateTime::Format::Strptime: '0'
  Encode::Locale: '0'
  Encode::UTF8Mac: '0'
  JSON: '0'
  Path::Class: '0.26'
  WebService::Dropbox: '2.06'
  perl: '5.008001'
resources:
  bugtracker: https://github.com/s-aska/dropbox-api-command/issues
  homepage: https://github.com/s-aska/dropbox-api-command
  repository: git://github.com/s-aska/dropbox-api-command.git

README.md  view on Meta::CPAN

        %d ... is_dir ( d: dir, -: file )
        %i ... id
        %n ... name
        %p ... path_display
        %P ... path_lower
        %b ... bytes
        %s ... size (e.g., 1K 234M 2G)
        %t ... server_modified
        %c ... client_modified
        %r ... rev
        %Tk ... DateTime 'strftime' function (server_modified)
        %Ck ... DateTime 'strftime' function (client_modified)
```

[http://search.cpan.org/dist/DateTime/lib/DateTime.pm#strftime\_Patterns](http://search.cpan.org/dist/DateTime/lib/DateTime.pm#strftime_Patterns)

## ls

file list view.

- alias

    list

- syntax

README.md  view on Meta::CPAN

    %d ... is_dir ( d: dir, -: file )
    %i ... id
    %n ... name
    %p ... path_display
    %P ... path_lower
    %b ... bytes
    %s ... size (e.g., 1K 234M 2G)
    %t ... server_modified
    %c ... client_modified
    %r ... rev
    %Tk ... DateTime 'strftime' function (server_modified)
    %Ck ... DateTime 'strftime' function (client_modified)
```

[http://search.cpan.org/dist/DateTime/lib/DateTime.pm#strftime\_Patterns](http://search.cpan.org/dist/DateTime/lib/DateTime.pm#strftime_Patterns)

## find

recursive file list view.

- syntax

    dropbox-api find <dropbox\_path> \[options\]

### Example

cpanfile  view on Meta::CPAN

requires 'perl', '5.008001';

requires 'JSON';
requires 'Path::Class', 0.26;
requires 'WebService::Dropbox', 2.06;
requires 'DateTime::Format::Strptime';
requires 'Encode::Locale';

if ($^O eq 'darwin') {
	requires 'Encode::UTF8Mac';
}

lib/App/dropboxapi.pm  view on Meta::CPAN

            %d ... is_dir ( d: dir, -: file )
            %i ... id
            %n ... name
            %p ... path_display
            %P ... path_lower
            %b ... bytes
            %s ... size (e.g., 1K 234M 2G)
            %t ... server_modified
            %c ... client_modified
            %r ... rev
            %Tk ... DateTime 'strftime' function (server_modified)
            %Ck ... DateTime 'strftime' function (client_modified)

L<http://search.cpan.org/dist/DateTime/lib/DateTime.pm#strftime_Patterns>

=head2 ls

file list view.

=over 4

=item alias

list

lib/App/dropboxapi.pm  view on Meta::CPAN

        %d ... is_dir ( d: dir, -: file )
        %i ... id
        %n ... name
        %p ... path_display
        %P ... path_lower
        %b ... bytes
        %s ... size (e.g., 1K 234M 2G)
        %t ... server_modified
        %c ... client_modified
        %r ... rev
        %Tk ... DateTime 'strftime' function (server_modified)
        %Ck ... DateTime 'strftime' function (client_modified)

L<http://search.cpan.org/dist/DateTime/lib/DateTime.pm#strftime_Patterns>

=head2 find

recursive file list view.

=over 4

=item syntax

dropbox-api find <dropbox_path> [options]

script/dropbox-api  view on Meta::CPAN

#!/usr/bin/env perl

use strict;
use warnings;
use Cwd 'abs_path';
use DateTime;
use DateTime::Format::Strptime;
use Encode;
use Encode::Locale;
use File::Basename qw(dirname basename);
use File::Spec::Functions qw(abs2rel catfile);
use File::Temp;
use Getopt::Std;
use JSON;
use Path::Class;
use POSIX qw();
use WebService::Dropbox 2.06;

script/dropbox-api  view on Meta::CPAN

        }
    }
}

$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',

script/dropbox-api  view on Meta::CPAN

                %d ... is_dir ( d: dir, -: file )
                %i ... id
                %n ... name
                %p ... path_display
                %P ... path_lower
                %b ... bytes
                %s ... size (e.g., 1K 234M 2G)
                %t ... server_modified
                %c ... client_modified
                %r ... rev
                %Tk ... DateTime 'strftime' function (server_modified)
                %Ck ... DateTime 'strftime' function (client_modified)
        };
    } elsif ($command eq 'find') {
        $help = q{
        Name
            dropbox-api-find - walk a file hierarchy

        SYNOPSIS
            dropbox-api find <dropbox_path> [options]

        Example

script/dropbox-api  view on Meta::CPAN

                %d ... is_dir ( d: dir, -: file )
                %i ... id
                %n ... name
                %p ... path_display
                %P ... path_lower
                %b ... bytes
                %s ... size (e.g., 1K 234M 2G)
                %t ... server_modified
                %c ... client_modified
                %r ... rev
                %Tk ... DateTime 'strftime' function (server_modified)
                %Ck ... DateTime 'strftime' function (client_modified)
        };
    } elsif ($command eq 'du') {
        $help = q{
        Name
            dropbox-api-du - list directory contents

        SYNOPSIS
            dropbox-api du <dropbox_path> [options]

        Example

script/dropbox-api  view on Meta::CPAN

        $remote_base = '';
    }
    my $list = $box->list_folder($remote_base) or die $box->error;
    for my $entry (@{ $list->{entries} }) {
        print &_line($entry);
    }
}

sub _line {
    my ($content) = @_;
    $strp ||= new DateTime::Format::Strptime( pattern => '%Y-%m-%dT%T' );
    my $dt;
    my $ct;
    my $get = sub {
        my $key = $format->{ $_[0] };
        if ($key eq 'format_size') {
            return exists $content->{size} ? format_bytes($content->{size}) : '   -';
        } elsif ($key eq 'is_dir') {
            $content->{'.tag'} eq 'folder' ? 'd' : '-';
        } elsif ($key eq 'thumb_exists') {
            if ($content->{path_display} =~ qr{ \.(?:jpg|jpeg|png|tiff|tif|gif|bmp) \z }xms && $content->{size} < 20 * 1024 * 1024) {

script/dropbox-api  view on Meta::CPAN

                    return;
                }

                if (has_change($local_path, $content)) {
                    printf "upload %s %s\n", $rel_path, $remote_path;
                    unless ($dry) {
                        if ($content->{size} == -s $local_path) {
                            $box->delete("$remote_path");
                        }
                        my $local_epoch = $local_path->stat->mtime;
                        &put($local_path, "$remote_path", { client_modified => $strp->format_datetime(DateTime->from_epoch( epoch => $local_epoch )) . 'Z' }) or die $box->error;
                    }
                    push @makedirs, $rel_path;
                } elsif ($verbose) {
                    printf "skip %s\n", $rel_path;
                }
            }

            # new file
            elsif (-f $local_path) {
                unless ($dry) {
                    my $local_epoch = $local_path->stat->mtime;
                    &put($local_path, "$remote_path", { client_modified => $strp->format_datetime(DateTime->from_epoch( epoch => $local_epoch )) . 'Z' });
                }
                if (!$dry && $box->error) {
                    warn "upload failure $rel_path $remote_path (" . $box->error . ")";
                } else {
                    printf "upload %s %s\n", $rel_path, $remote_path;
                    push @makedirs, $rel_path;
                }
            }

            # new directory

script/dropbox-api  view on Meta::CPAN

        }
        $remote_path = $content->{path_display};

        if (has_change($local_path, $content)) {
            printf "upload %s %s\n", $local_path, $remote_path;
            unless ($dry) {
                if ($content->{size} == -s $local_path) {
                    $box->delete("$remote_path");
                }
                my $local_epoch = $local_path->stat->mtime;
                &put($local_path, "$remote_path", { client_modified => $strp->format_datetime(DateTime->from_epoch( epoch => $local_epoch )) . 'Z' }) or die $box->error;
            }
        } elsif ($verbose) {
            printf "skip %s\n", $local_path;
        }
        return;
    }

    unless ($dry) {
        my $local_epoch = $local_path->stat->mtime;
        &put($local_path, "$remote_path", { client_modified => $strp->format_datetime(DateTime->from_epoch( epoch => $local_epoch )) . 'Z' });
    }

    printf "upload %s %s\n", $local_path, $remote_path;
}

sub has_change ($$) {
    my ($local_path, $content) = @_;

    my $remote_epoch = $strpz->parse_datetime($content->{client_modified})->epoch;
    my $local_epoch = $local_path->stat->mtime;



( run in 0.397 second using v1.01-cache-2.11-cpan-05444aca049 )