#!/usr/local/bin/perl -w
###########################################
# google-drive-files
# Mike Schilli, 2014 (cpan@perlmeister.com)
###########################################
use strict;
use OAuth::Cmdline::GoogleDrive;
use LWP::UserAgent;
use JSON qw( from_json );
use Log::Log4perl qw(:easy);
Log::Log4perl->easy_init($DEBUG);

my $oauth = OAuth::Cmdline::GoogleDrive->new( );

my $ua = LWP::UserAgent->new();
$ua->default_header( 
    $oauth->authorization_headers );

my $resp = $ua->get( "https://www.googleapis.com/drive/v2/files" );

if( $resp->is_error ) {
    die "Error: ", $resp->message();
}

my $result = from_json( $resp->content() );

for my $item ( @{ $result->{ items } } ) {
    my $key = "originalFilename";

    if( exists $item->{ $key } ) {
        print "$item->{ $key }\n";
    }
}

__END__

=head1 NAME

    google-drive-files

=head1 SYNOPSIS

    google-drive-files

=head1 DESCRIPTION

Ask the Google Drive API for a list of files.

Requires that you create a ~/.google-drive.yml file first by running 
eg/google-drive-token-init after acquiring a client ID and secret as
described in the Google Drive API guide.

=head1 LEGALESE

Copyright 2014 by Mike Schilli, all rights reserved.
This program is free software, you can redistribute it and/or
modify it under the same terms as Perl itself.

=head1 AUTHOR

2014, Mike Schilli <cpan@perlmeister.com>
