forked from mschilli/net-google-drive-simple
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Simple.pm
955 lines (701 loc) · 24.6 KB
/
Simple.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
###########################################
package Net::Google::Drive::Simple;
###########################################
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Headers;
use HTTP::Request::Common;
use Sysadm::Install qw( slurp );
use File::Basename;
use YAML qw( LoadFile DumpFile );
use JSON qw( from_json to_json );
use Test::MockObject;
use Log::Log4perl qw(:easy);
use Data::Dumper;
use File::MMagic;
use OAuth::Cmdline::GoogleDrive;
our $VERSION = "0.13";
###########################################
sub new {
###########################################
my($class, %options) = @_;
my $self = {
init_done => undef,
api_file_url => "https://www.googleapis.com/drive/v2/files",
api_upload_url => "https://www.googleapis.com/upload/drive/v2/files",
oauth => OAuth::Cmdline::GoogleDrive->new( ),
error => undef,
%options,
};
bless $self, $class;
}
###########################################
sub error {
###########################################
my( $self, $set ) = @_;
if( defined $set ) {
$self->{ error } = $set;
}
return $self->{ error };
}
###########################################
sub init {
###########################################
my( $self, $path ) = @_;
if( $self->{ init_done } ) {
return 1;
}
DEBUG "Testing API";
if( !$self->api_test() ) {
LOGDIE "api_test failed";
}
$self->{ init_done } = 1;
return 1;
}
###########################################
sub api_test {
###########################################
my( $self ) = @_;
my $url = $self->file_url( { maxResults => 1 } );
my $ua = LWP::UserAgent->new();
my $req = HTTP::Request->new(
GET => $url->as_string,
);
$req->header( $self->{ oauth }->authorization_headers() );
DEBUG "Fetching $url";
my $resp = $ua->request( $req );
if( $resp->is_success() ) {
DEBUG "API tested OK";
return 1;
}
$self->error( $resp->message() );
ERROR "API error: ", $resp->message();
return 0;
}
###########################################
sub file_url {
###########################################
my( $self, $opts ) = @_;
$opts = {} if !defined $opts;
my $default_opts = {
maxResults => 3000,
};
$opts = {
%$default_opts,
%$opts,
};
my $url = URI->new( $self->{ api_file_url } );
$url->query_form( $opts );
return $url;
}
###########################################
sub files {
###########################################
my( $self, $opts, $search_opts ) = @_;
if( !defined $search_opts ) {
$search_opts = {};
}
$search_opts = {
page => 1,
%$search_opts,
};
if( !defined $opts ) {
$opts = {};
}
$self->init();
my @docs = ();
while( 1 ) {
my $url = $self->file_url( $opts );
my $data = $self->http_json( $url );
if( !defined $data ) {
return undef;
}
my $next_item = $self->item_iterator( $data );
while( my $item = $next_item->() ) {
if( $item->{ kind } eq "drive#file" ) {
my $file = $item->{ originalFilename };
if( !defined $file ) {
DEBUG "Skipping $item->{ title } (no originalFilename)";
next;
}
push @docs, $self->data_factory( $item );
} else {
DEBUG "Skipping $item->{ title } ($item->{ kind })";
}
}
if( $search_opts->{ page } and $data->{ nextPageToken } ) {
$opts->{ pageToken } = $data->{ nextPageToken };
} else {
last;
}
}
return \@docs;
}
###########################################
sub folder_create {
###########################################
my( $self, $title, $parent ) = @_;
return $self->file_create( $title, "application/vnd.google-apps.folder", $parent );
}
###########################################
sub file_create {
###########################################
my( $self, $title, $mime_type, $parent ) = @_;
my $url = URI->new( $self->{ api_file_url } );
my $data = $self->http_json( $url, {
title => $title,
parents => [ { id => $parent } ],
mimeType => $mime_type,
} );
if( ! defined $data ) {
return undef;
}
return $data->{ id };
}
###########################################
sub file_upload {
###########################################
my( $self, $file, $parent_id, $file_id ) = @_;
# Since a file upload can take a long time, refresh the token
# just in case.
$self->{ oauth }->token_expire();
my $title = basename $file;
# First, insert the file placeholder, according to
# http://stackoverflow.com/questions/10317638
my $file_data = slurp $file;
my $mime_type = $self->file_mime_type( $file );
my $url;
if( ! defined $file_id ) {
$url = URI->new( $self->{ api_file_url } );
my $data = $self->http_json( $url,
{ mimeType => $mime_type,
parents => [ { id => $parent_id } ],
title => $title,
}
);
if( ! defined $data ) {
return undef;
}
$file_id = $data->{ id };
}
$url = URI->new( $self->{ api_upload_url } . "/$file_id" );
$url->query_form( uploadType => "media" );
my $req = &HTTP::Request::Common::PUT(
$url->as_string,
$self->{ oauth }->authorization_headers(),
"Content-Type" => $mime_type,
Content => $file_data,
);
my $resp = $self->http_loop( $req );
if( $resp->is_error() ) {
$self->error( $self->message() );
return undef;
}
DEBUG $resp->as_string;
return $file_id;
}
###########################################
sub file_mvdir {
###########################################
my( $self, $path, $target_folder ) = @_;
my $url;
if( !defined $path or !defined $target_folder ) {
LOGDIE "Missing parameter";
}
# Determine the file's parent in the path
my( $file_id, $folder_id ) = $self->path_resolve( $path );
if( !defined $file_id ) {
LOGDIE "Cannot find source file: $path";
}
my( $target_folder_id ) = $self->path_resolve( $target_folder );
if( !defined $target_folder_id ) {
LOGDIE "Cannot find destination path: $target_folder";
}
print "file_id=$file_id\n";
print "folder_id=$folder_id\n";
print "target_folder_id=$target_folder_id\n";
# Delete it from the current parent
$url = URI->new( $self->{ api_file_url } .
"/$folder_id/children/$file_id" );
if( !$self->http_delete( $url ) ) {
LOGDIE "Failed to remove $path from parent folder.";
}
# Add a new parent
$url = URI->new( $self->{ api_file_url } .
"/$target_folder_id/children" );
if( !$self->http_json( $url, { id => $file_id } ) ) {
LOGDIE "Failed to insert $path into $target_folder.";
}
return 1;
}
###########################################
sub path_resolve {
###########################################
my( $self, $path, $search_opts ) = @_;
$search_opts = {} if !defined $search_opts;
my @parts = split '/', $path;
my @ids = ();
my $parent = $parts[0] = "root";
DEBUG "Parent: $parent";
my $folder_id = shift @parts;
push @ids, $folder_id;
PART: for my $part ( @parts ) {
DEBUG "Looking up part $part (folder_id=$folder_id)";
my $children = $self->children_by_folder_id( $folder_id,
{ maxResults => 100, # path resolution maxResults is different
},
{ %$search_opts, title => $part },
);
if( ! defined $children ) {
return undef;
}
for my $child ( @$children ) {
DEBUG "Found child ", $child->title();
if( $child->title() eq $part ) {
$folder_id = $child->id();
unshift @ids, $folder_id;
$parent = $folder_id;
DEBUG "Parent: $parent";
next PART;
}
}
my $msg = "Child $part not found";
$self->error( $msg );
ERROR $msg;
return undef;
}
if( @ids == 1 ) {
# parent of root is root
return( @ids, @ids );
}
return( @ids );
}
###########################################
sub file_delete {
###########################################
my( $self, $file_id ) = @_;
my $url;
LOGDIE 'Deletion requires file_id' if( ! defined $file_id );
$url = URI->new( $self->{ api_file_url } . "/$file_id" );
if( $self->http_delete( $url ) ) {
return $file_id;
}
return undef;
}
###########################################
sub http_delete {
###########################################
my( $self, $url ) = @_;
my $req = &HTTP::Request::Common::DELETE(
$url,
$self->{ oauth }->authorization_headers(),
);
my $resp = $self->http_loop( $req );
DEBUG $resp->as_string;
if( $resp->is_error ) {
$self->error( $resp->message() );
return undef;
}
return 1;
}
###########################################
sub children_by_folder_id {
###########################################
my( $self, $folder_id, $opts, $search_opts ) = @_;
$self->init();
if( !defined $search_opts ) {
$search_opts = {};
}
$search_opts = {
page => 1,
%$search_opts,
};
if( !defined $opts ) {
$opts = {
maxResults => 100,
};
}
my $url = URI->new( $self->{ api_file_url } );
$opts->{ q } = "'$folder_id' in parents";
if( $search_opts->{ title } ) {
$opts->{ q } .= " AND title = '$search_opts->{ title }'";
}
my @children = ();
while( 1 ) {
$url->query_form( $opts );
my $data = $self->http_json( $url );
if( ! defined $data ) {
return undef;
}
my $next_item = $self->item_iterator( $data );
while( my $item = $next_item->() ) {
push @children, $self->data_factory( $item );
}
if( $search_opts->{ page } and $data->{ nextPageToken } ) {
$opts->{ pageToken } = $data->{ nextPageToken };
} else {
last;
}
}
return \@children;
}
###########################################
sub children {
###########################################
my( $self, $path, $opts, $search_opts ) = @_;
DEBUG "Determine children of $path";
if( !defined $path ) {
LOGDIE "No $path given";
}
if( !defined $search_opts ) {
$search_opts = {};
}
my( $folder_id, $parent ) = $self->path_resolve( $path, $search_opts );
if( !defined $folder_id ) {
return undef;
}
DEBUG "Getting content of folder $folder_id";
my $children = $self->children_by_folder_id( $folder_id, $opts,
$search_opts );
if( ! defined $children ) {
return undef;
}
if( wantarray ) {
return( $children, $parent );
} else {
return $children;
}
}
###########################################
sub search {
###########################################
my( $self, $opts, $search_opts, $query ) = @_;
$search_opts||= { page => 1 };
$self->init();
if( !defined $opts ) {
$opts = {
maxResults => 100,
};
}
my $url = URI->new( $self->{ api_file_url } );
$opts->{ q }= $query;
my @children = ();
while( 1 ) {
$url->query_form( $opts );
my $data = $self->http_json( $url );
if( ! defined $data ) {
return undef;
}
my $next_item = $self->item_iterator( $data );
while( my $item = $next_item->() ) {
push @children, $self->data_factory( $item );
}
if( $search_opts->{ page } and $data->{ nextPageToken } ) {
$opts->{ pageToken } = $data->{ nextPageToken };
} else {
last;
}
}
return \@children;
}
###########################################
sub data_factory {
###########################################
my( $self, $data ) = @_;
my $mock = Test::MockObject->new();
for my $key ( keys %$data ) {
# DEBUG "Adding method $key";
$mock->mock( $key , sub { $data->{ $key } } );
}
return $mock;
}
###########################################
sub download {
###########################################
my( $self, $url, $local_file ) = @_;
if( ref $url ) {
$url = $url->downloadUrl();
}
my $req = HTTP::Request->new(
GET => $url,
);
$req->header( $self->{ oauth }->authorization_headers() );
my $ua = LWP::UserAgent->new();
my $resp = $ua->request( $req, $local_file );
if( $resp->is_error() ) {
my $msg = "Can't download $url (" . $resp->message() . ")";
ERROR $msg;
$self->error( $msg );
return undef;
}
if( $local_file ) {
return 1;
}
return $resp->content();
}
###########################################
sub http_loop {
###########################################
my( $self, $req, $noinit ) = @_;
my $ua = LWP::UserAgent->new();
my $resp;
my $RETRIES = 3;
my $SLEEP_INTERVAL = 10;
{
# refresh token if necessary
if( ! $noinit ) {
$self->init();
}
DEBUG "Fetching ", $req->url->as_string();
$resp = $ua->request( $req );
if( ! $resp->is_success() ) {
$self->error( $resp->message() );
warn "Failed with ", $resp->code(), ": ", $resp->message();
if( --$RETRIES >= 0 ) {
ERROR "Retrying in $SLEEP_INTERVAL seconds";
sleep $SLEEP_INTERVAL;
redo;
} else {
ERROR "Out of retries.";
return $resp;
}
}
DEBUG "Successfully fetched ", length( $resp->content() ), " bytes.";
}
return $resp;
}
###########################################
sub http_json {
###########################################
my( $self, $url, $post_data ) = @_;
my $req;
if( $post_data ) {
$req = &HTTP::Request::Common::POST(
$url->as_string,
$self->{ oauth }->authorization_headers(),
"Content-Type"=> "application/json",
Content => to_json( $post_data ),
);
} else {
$req = HTTP::Request->new(
GET => $url->as_string,
);
$req->header( $self->{ oauth }->authorization_headers() );
}
my $resp = $self->http_loop( $req );
if( $resp->is_error() ) {
$self->error( $resp->message() );
return undef;
}
my $data = from_json( $resp->content() );
return $data;
}
###########################################
sub file_mime_type {
###########################################
my( $self, $file ) = @_;
# There don't seem to be great implementations of mimetype
# detection on CPAN, so just use this one for now.
if( !$self->{ magic } ) {
$self->{ magic } = File::MMagic->new();
}
return $self->{ magic }->checktype_filename( $file );
}
###########################################
sub item_iterator {
###########################################
my( $self, $data ) = @_;
my $idx = 0;
if( !defined $data ) {
die "no data in item_iterator";
}
return sub {
{
my $next_item = $data->{ items }->[ $idx++ ];
return if !defined $next_item;
if( $next_item->{ labels }->{ trashed } ) {
DEBUG "Skipping $next_item->{ title } (trashed)";
redo;
}
return $next_item;
}
};
}
1;
__END__
=head1 NAME
Net::Google::Drive::Simple - Simple modification of Google Drive data
=head1 SYNOPSIS
use Net::Google::Drive::Simple;
# requires a ~/.google-drive.yml file with an access token,
# see description below.
my $gd = Net::Google::Drive::Simple->new();
my $children = $gd->children( "/folder/path" );
for my $child ( @$children ) {
next if $child->kind() ne 'drive#file';
next if !$child->can( "downloadUrl" );
print $child->originalFilename(),
" can be downloaded at ",
$child->downloadUrl(),
"\n";
}
=head1 DESCRIPTION
Net::Google::Drive::Simple authenticates with a user's Google Drive and
offers several convenience methods to list, retrieve, and modify the data
stored in the 'cloud'. See C<eg/google-drive-upsync> as an example on how
to keep a local directory in sync with a remote directory on Google Drive.
=head2 GETTING STARTED
To get the access token required to access your Google Drive data via
this module, you need to run the script C<eg/google-drive-init> in this
distribution.
Before you run it, you need to register your 'app' with Google Drive
and obtain a client_id and a client_secret from Google:
https://developers.google.com/drive/web/enable-sdk
Click on "Enable the Drive API and SDK", and find "Create an API project in
the Google APIs Console". On the API console, create a new project, click
"Services", and enable "Drive API" (leave "drive SDK" off). Then, under
"API Access" in the navigation bar, create a client ID, and make sure to
register a an "installed application" (not a "web application"). "Redirect
URIs" should contain "http://localhost". This will get you a "Client ID"
and a "Client Secret".
Then, replace the following lines in C<eg/google-drive-init> with the
values received:
# You need to obtain a client_id and a client_secret from
# https://developers.google.com/drive to use this.
my $client_id = "XXX";
my $client_secret = "YYY";
Then run the script. It'll start a web server on port 8082 on your local
machine. When you point your browser at http://localhost:8082, you'll see a
link that will lead you to Google Drive's login page, where you authenticate
and then allow the app (specified by client_id and client_secret above) access
to your Google Drive data. The script will then receive an access token from
Google Drive and store it in ~/.google-drive.yml from where other scripts can
pick it up and work on the data stored on the user's Google Drive account. Make
sure to limit access to ~/.google-drive.yml, because it contains the access
token that allows everyone to manipulate your Google Drive data. It also
contains a refresh token that this library uses to get a new access token
transparently when the old one is about to expire.
=head1 METHODS
=over 4
=item C<new()>
Constructor, creates a helper object to retrieve Google Drive data
later.
=item C<my $children = $gd-E<gt>children( "/path/to" )>
Return the entries under a given path on the Google Drive as a reference
to an array. Each entry
is an object composed of the JSON data returned by the Google Drive API.
Each object offers methods named like the fields in the JSON data, e.g.
C<originalFilename()>, C<downloadUrl>, etc.
Will return all entries found unless C<maxResults> is set:
my $children = $gd->children( "/path/to", { maxResults => 3 } )
Due to the somewhat capricious ways Google Drive handles its directory
structures, the method needs to traverse the path component by component
and determine the ID of each directory to get to the next level. To speed
up subsequent lookups, it also returns the ID of the last component to the
caller:
my( $children, $parent ) = $gd->children( "/path/to" );
If the caller now wants to e.g. insert a file into the directory, its
ID is available in $parent.
Each child comes back as a files#resource type and gets mapped into
an object that offers access to the various fields via methods:
for my $child ( @$children ) {
print $child->kind(), " ", $child->title(), "\n";
}
Please refer to
https://developers.google.com/drive/v2/reference/files#resource
for details on which fields are available.
=item C<my $files = $gd-E<gt>files( )>
Return all files on the drive as a reference to an array.
Will return all entries found unless C<maxResults> is set:
my $files = $gd->files( { maxResults => 3 } )
Note that Google limits the number of entries returned by default to
100, and seems to restrict the maximum number of files returned
by a single query to 3,500, even if you specify higher values for
C<maxResults>.
Each file comes back as an object that offers access to the Google
Drive item's fields, according to the API (see C<children()>).
=item C<my $id = $gd-E<gt>folder_create( "folder-name", $parent_id )>
Create a new folder as a child of the folder with the id C<$parent_id>.
Returns the ID of the new folder or undef in case of an error.
=item C<my $id = $gd-E<gt>file_create( "folder-name", "mime-type", $parent_id )>
Create a new file with the given mime type as a child of the folder with the id C<$parent_id>.
Returns the ID of the new file or undef in case of an error.
Example to create an empty google spreadsheet:
my $id = $gd->file_create( "Quarter Results", "application/vnd.google-apps.spreadsheet", "root" );
=item C<$gd-E<gt>file_upload( $file, $dir_id )>
Uploads the content of the file C<$file> into the directory with the ID
$dir_id on Google Drive. Uses C<$file> as the file name.
To overwrite an existing file on Google Drive, specify the file's ID as
an optional parameter:
$gd->file_upload( $file, $dir_id, $file_id );
=item C<$gd-E<gt>download( $item, [$local_filename] )>
Downloads an item found via C<files()> or C<children()>. Also accepts
the downloadUrl of an item. If C<$local_filename> is not specified,
C<download()> will return the data downloaded (this might be undesirable
for large files). If C<$local_filename> is specified, C<download()> will
store the downloaded data under the given file name.
my $gd = Net::Google::Drive::Simple->new();
my $files = $gd->files( { maxResults => 20 }, { page => 0 } );
for my $file ( @$files ) {
my $name = $file->originalFilename();
print "Downloading $name\n";
$gd->download( $file, $name ) or die "failed: $!";
}
Be aware that only documents like PDF or png can be downloaded directly. Google Drive Documents like spreadsheets or (text) documents need to be exported into one of the available formats.
Check for "exportLinks" on a file given. In case of a document that can be exported you will receive a hash in the form:
{
'format_1' => 'download_link_1',
'format_2' => 'download_link_2',
...
}
Choose your download link and use it as an argument to the download() function which can also take urls directly.
my $gd = Net::Google::Drive::Simple->new();
my $children = $gd->children( '/path/to/folder/on/google/drive' );
for my $child ( @$children ) {
if ($child->can( 'exportLinks' )){
my $type_chosen;
foreach my $type (keys %{$child->exportLinks()}){
# Take any type you can get..
$type_chosen = $type;
# ..but choose your preferred format, opendocument here:
last if $type =~/oasis\.opendocument/;
}
my $url = $child->exportLinks()->{$type_chosen};
$gd->download($url, 'my/local/file');
}
}
=item C<my $files = $gd-E<gt>search( )>
my $children= $gd->search({ maxResults => 20 },{ page => 0 },
"title contains 'Futurama'");
Search files for attributes. See
L<https://developers.google.com/drive/web/search-parameters>
for a definition of the attributes.
To list all available files, those on the drive, those directly shared
with the user, and those generally available to the user, use an
empty search:
my $children= $gd->search({},{ page => 0 },"");
=item C<$gd-E<gt>file_delete( file_id )>
Delete the file with the specified ID from Google Drive.
=item C<$gd-E<gt>drive_mvdir( "/gdrive/path/to/file", "/path/to/new/folder" )>
Move an existing file to a new folder. Removes the file's "parent"
setting (pointing to the old folder) and then adds the new folder as a
new parent.
=back
=head1 Error handling
In case of an error while retrieving information from the Google Drive
API, the methods above will return C<undef> and a more detailed error
message can be obtained by calling the C<error()> method:
print "An error occurred: ", $gd->error();
=head1 LOGGING/DEBUGGING
Net::Google::Drive::Simple is Log4perl-enabled.
To find out what's going on under the hood, turn on Log4perl:
use Log::Log4perl qw(:easy);
Log::Log4perl->easy_init($DEBUG);
=head1 LEGALESE
Copyright 2012 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
2012, Mike Schilli <cpan@perlmeister.com>