Net::Google::DocumentsList::Role::Exportable - implementation of download items


Net-Google-DocumentsList documentation Contained in the Net-Google-DocumentsList distribution.

Index


Code Index:

NAME

Top

Net::Google::DocumentsList::Role::Exportable - implementation of download items

SYNOPSIS

Top

  use Net::Google::DocumentsList;

  my $client = Net::Google::DocumentsList->new(
    username => 'myname@gmail.com',
    password => 'p4$$w0rd'
  );

  # pickup one document
  my $d = $client->item;

  # download and set to variable
  my $content = $d->export(
    {
        format => 'txt',
    }
  );

  # download to a file
  $d->export(
    {
        format => 'txt',
        file => '/path/to/download.txt',
    }
  );

DESCRIPTION

Top

This module implements download functionality.

METHODS

Top

export

downloads the item. available formats are seen in http://code.google.com/intl/en/apis/documents/docs/3.0/developers_guide_protocol.html#DownloadingDocs.

AUTHOR

Top

Noubo Danjou <nobuo.danjou@gmail.com>

SEE ALSO

Top

Net::Google::DocumentsList

Net::Google::DocumentsList::Item

Net::Google::DocumentsList::Revision

http://code.google.com/intl/en/apis/documents/docs/3.0/developers_guide_protocol.html#DownloadingDocs.

LICENSE

Top

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


Net-Google-DocumentsList documentation Contained in the Net-Google-DocumentsList distribution.

package Net::Google::DocumentsList::Role::Exportable;
use Any::Moose '::Role';
use File::Slurp;

requires 'item_feedurl', 'kind';

sub export {
    my ($self, $args) = @_;

    $self->kind eq 'folder' 
        and confess "You can't export folder";
    my $format = delete $args->{format};
    my $file = delete $args->{file};
    my $res = $self->service->request(
        {
            uri => $self->item_feedurl,
            query => {
                %{$args || {}},
                exportFormat => $format,
            },
        }
    );
    if ($res->is_success) {
        if ( $file ) {
            my $content = $res->content_ref;
            return write_file( $file, {binmode => ':raw'}, $content );
        }
        return $res->decoded_content;
    }
}

1;
__END__