File Coverage

blib/lib/Google/Client/Collection.pm
Criterion Covered Total %
statement 8 8 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod 1 1 100.0
total 12 12 100.0


line stmt bran cond sub pod time code
1             package Google::Client::Collection;
2             # ABSTRACT: Google Client Collection
3             $Google::Client::Collection::VERSION = '0.005';
4 16     16   1650430 use Moo;
  16         18287  
  16         77  
5              
6             # Available Google REST APIs
7 16     16   10474 use Google::Client::Files;
  16         28  
  16         1434  
8              
9             has cache => (is => 'ro', required => 1);
10             has cache_key => (is => 'rw', writer => 'set_cache_key');
11              
12             sub files {
13 16     16 1 937418 my $self = shift;
14 16         244 return Google::Client::Files->new(
15             cache => $self->cache,
16             cache_key => $self->cache_key
17             );
18             }
19              
20             =head1 NAME
21              
22             Google::Client::Collection - Collection of modules to talk with Googles REST API
23              
24             =head1 SYNOPSIS
25              
26             use Google::Client::Collection;
27              
28             my $google = Google::Client::Collection->new(
29             cache => CHI::Driver->new(), # ... or anything with a 'get($cache_key)' method
30             );
31              
32             # then before calling a google clients method, set the key to fetch the access_token from in the cache:
33             $google->set_cache_key('user-10-access-token');
34              
35             # eg: use a Google::Client::Files client:
36             my $json = $google->files->list(); # lists all files available by calling: GET https://www.googleapis.com/drive/v3/files
37              
38             =head1 DESCRIPTION
39              
40             A compilation of Google::Client::* clients used to connect to the many resources of L.
41             All such clients can be found in CPAN under the 'Google::Client' namespace (eg L).
42             Each client uses the same constructor arguments, so they can be used separately if desired.
43              
44             You should only ever have to instantiate C<< Google::Client::Collection >>, which will give you access to all the available REST clients (pull requests welcome to add more!).
45              
46             Requests to Googles API require authentication, which can be handled via L.
47              
48             Also, make sure you request the right scopes from the user during authentication before using a client, as you will get unauthorized errors from Google (intended behaviour).
49              
50             =head1 CONSTRUCTOR ARGS
51              
52             =head2 cache
53              
54             Required constructor argument. The cache can be any object
55             that provides a C<< get($cache_key) >> method to retrieve
56             the access token. It'll be responsible for eventually
57             expiring the access token so it's known when to
58             request a new one.
59              
60             =head1 METHODS
61              
62             =head2 cache_key
63              
64             The key to lookup the access token in the cache. Should be set
65             before calling any method in a Google Client. It's a good
66             idea to make this unique (per user maybe?).
67              
68             =head2 files
69              
70             A L client.
71              
72             =head1 AUTHOR
73              
74             Ali Zia, C<< >>
75              
76             =head1 REPOSITORY
77              
78             L
79              
80             =head1 COPYRIGHT AND LICENSE
81              
82             This is free software. You may use it and distribute it under the same terms as Perl itself.
83             Copyright (C) 2016 - Ali Zia
84              
85             =head1 TODO
86              
87             =over 2
88              
89             =item *
90              
91             Catch known Google API errors instead of giving that responsibility to the user of module
92              
93             =item *
94              
95             Add more clients
96              
97             =back
98              
99             =cut
100              
101             1;