Google::RestApi - Connection to Google REST APIs (currently Drive and Sheets).
use Google::RestApi; $rest_api = Google::RestApi->new( config_file => <path_to_config_file>, auth => <object|hashref>, timeout => <int>, throttle => <int>, api_callback => <coderef>, ); $response = $rest_api->api( uri => <google_api_url>, method => get|head|put|patch|post|delete, headers => [], params => <query_params>, content => <data_for_body>, ); use Google::RestApi::SheetsApi4; $sheets_api = Google::RestApi::SheetsApi4->new(api => $rest_api); $sheet = $sheets_api->open_spreadsheet(title => "payroll"); use Google::RestApi::DriveApi3; $drive = Google::RestApi::DriveApi3->new(api => $rest_api); $file = $drive->file(id => 'xxxx'); $copy = $file->copy(title => 'my-copy-of-xxx'); print YAML::Any::Dump($rest_api->stats());
Google Rest API is the foundation class used by the included Drive (Google::RestApi::DriveApi3) and Sheets (Google::RestApi::SheetsApi4) APIs. It is used to send API requests to the Google API endpoint on behalf of the underlying API classes.
Google::RestApi::DriveApi3
Google::RestApi::DriveApi3::File
Google::RestApi::SheetsApi4
Google::RestApi::SheetsApi4::Spreadsheet
Google::RestApi::SheetsApi4::Worksheet
Google::RestApi::SheetsApi4::Range
Google::RestApi::SheetsApi4::Range::All
Google::RestApi::SheetsApi4::Range::Col
Google::RestApi::SheetsApi4::Range::Row
Google::RestApi::SheetsApi4::Range::Cell
Google::RestApi::SheetsApi4::RangeGroup
Google::RestApi::SheetsApi4::RangeGroup::Iterator
Google::RestApi::SheetsApi4::RangeGroup::Tie
Google::RestApi::SheetsApi4::RangeGroup::Tie::Iterator
Google::RestApi::SheetsApi4::Request::Spreadsheet
Google::RestApi::SheetsApi4::Request::Spreadsheet::Worksheet
Google::RestApi::SheetsApi4::Request::Spreadsheet::Worksheet::Range
config_file <path_to_config_file>: Optional YAML configuration file that can specify any or all of the following args...
config_file
auth <hash|object>: A hashref to create the specified auth class, or (outside the config file) an instance of the blessed class itself. If this is an object, it must provide the 'params' and 'headers' subroutines to provide the appropriate Google authentication/authorization. See below for more details.
auth
api_callback <coderef>: A coderef to call after each API call.
api_callback
throttle <int>: Used in development to sleep the number of seconds specified between API calls to avoid rate limit violations from Google.
throttle
You can specify any of the arguments in the optional YAML config file. Any passed-in arguments will override what is in the config file.
The 'auth' arg can specify a pre-blessed class of one of the Google::RestApi::Auth::* classes (e.g. 'OAuth2Client'), or, for convenience sake, you may specify a hash of the required arguments to create an instance of that class:
auth: class: OAuth2Client client_id: xxxxxx client_secret: xxxxxx token_file: <path_to_token_file>
Note that the auth hash itself can also contain a config_file:
auth: class: OAuth2Client config_file: <path_to_oauth_config_file>
This allows you the option to keep the auth file in a separate, more secure place.
The ultimate Google API call for the underlying classes. Handles timeouts and retries etc. %args consists of:
uri <uri_string>: The Google API endpoint such as https://www.googleapis.com/drive/v3 along with any path segments added.
uri
method <http_method_string>: The http method being used get|head|put|patch|post|delete.
method
headers <headers_string_array>: Array ref of http headers.
headers
params <query_parameters_hash>: Http query params to be added to the uri.
params
content <payload hash>: The body being sent for post/put etc. Will be encoded to JSON.
content
You would not normally call this directly unless you were making a Google API call not currently supported by this API framework.
Returns the response hash from Google API.
coderef
The last transaction details are passed to the callback. What you do with this information is up to you. For an example of how this is used, see the t/tutorial/sheets/* scripts.
t/tutorial/sheets/*
Returns the previous callback, if any.
Returns the transaction information from the last Google API call. This is the same information that is provided by the callback above, but can be accessed directly if you have no need to provide a callback.
Returns some statistics on how many get/put/post etc calls were made. Useful for performance tuning during development.
This api is currently in beta status. It is incomplete. There may be design flaws that need to be addressed in later releases. Later releases may break this release. Not all api calls have been implemented.
Robin Murray mvsjes@cpan.org
Copyright (c) 2021, Robin Murray. All rights reserved.
This program is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
To install Google::RestApi, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Google::RestApi
CPAN shell
perl -MCPAN -e shell install Google::RestApi
For more information on module installation, please visit the detailed CPAN module installation guide.