WWW::Google::Docs::Upload - Upload documents to Google Docs


WWW-Google-Docs-Upload documentation Contained in the WWW-Google-Docs-Upload distribution.

Index


Code Index:

NAME

Top

WWW::Google::Docs::Upload - Upload documents to Google Docs

SYNOPSIS

Top

    use WWW::Google::Docs::Upload;

    my $docs = WWW::Google::Docs::Upload->new(
        email  => 'your email',
        passwd => 'your password'
    );
    $docs->upload('/path/to/yourfile.doc');

DESCRIPTION

Top

This module helps you to upload your local document files to Google Docs.

METHODS

Top

upload($filename, \%option)

Upload document file (named $filename) to Google Docs.

\%option is hashref and allowed key is:

name

Filename what you want to call (if different than the filename)

AUTHOR

Top

Daisuke Murase <typester@cpan.org>

COPYRIGHT

Top


WWW-Google-Docs-Upload documentation Contained in the WWW-Google-Docs-Upload distribution.

package WWW::Google::Docs::Upload;
use Moose;

use WWW::Mechanize;

our $VERSION = '0.02';

has email  => ( is => 'rw', required => 1 );
has passwd => ( is => 'rw', required => 1 );

has mech => (
    is  => 'rw',
    isa => 'WWW::Mechanize',
    default => sub {
        my $mech = WWW::Mechanize->new( stack_depth => 1 );
        $mech->env_proxy;
        $mech->agent_alias('Windows IE 6');
        $mech->timeout(10);
        $mech;
    },
);

sub upload {
    my ($self, $file, $option) = @_;

    confess q{required filename to upload} unless $file;
    confess qq{no such file "$file"} unless -e $file && -f _;

    my $mech = $self->mech;
    $mech->get('http://docs.google.com/DocAction?action=updoc&hl=en');

    if ($mech->res->base =~ /ServiceLogin/) {
        $mech->submit_form(
            fields => {
                Email  => $self->email,
                Passwd => $self->passwd,
            },
        );
        $mech->follow_link( tag => 'meta' );
        confess 'login failed' unless $mech->res->base->host eq 'docs.google.com';
    }

    $mech->submit_form(
        fields => {
            uploadedFile => $file,
            $option->{name} ? (DocName => $option->{name}) : (),
        },
    );

    $mech->res;
}

1;