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>, post_process => <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 and Sheets APIs. It is used to send API requests to the Google API endpoint on behalf of the underlying API classes (Sheets and Drive).
- new(config_file => <path_to_config_file>, auth => <object|hash>, post_process => <coderef>, throttle => <int>);
config_file: Optional YAML configuration file that can specify any or all of the following args: auth: A hashref to create the specified auth class, or (outside the config file) an instance of the blessed class itself. post_process: A coderef to call after each API call. throttle: Used in development to sleep the number of seconds specified between API calls to avoid threshhold errors from Google.
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, or, for convenience sake, you can 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.
- api(uri => <uri_string>, method => <http_method_string>, headers => <headers_string_array>, params => <query_parameters_hash>, content => <body_hash>);
The ultimate Google API call for the underlying classes. Handles timeouts and retries etc.
uri: The Google API endpoint such as https://www.googleapis.com/drive/v3 along with any path segments added. method: The http method being used get|head|put|patch|post|delete. headers: Array ref of http headers. params: Http query params to be added to the uri. content: The body being sent for post/put etc. Will be encoded to JSON.
You would not normally call this directly unless you were making a Google API call not currently supported by this API framework.
Shows some statistics on how many get/put/post etc calls were made. Useful for performance tuning during development.
For specific use of this class, see:
Robin Murray firstname.lastname@example.org
Copyright (c) 2019, 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.