gapi-nano

1.0.1 • Public • Published

Summary

This is a wrapper for the Google API Client Library, providing opinionated syntactic sugar for client authentication and making requests to a Google Apps Script via the REST Execution API

See: https://developers.google.com/apps-script/guides/rest/quickstart/js

Basic Usage

In your html, include the browser build gapi-nano.js from the dist directory after https://apis.google.com/js/api.js

<script src="https://apis.google.com/js/api.js"></script>
<script src="/dist/gapi-nano.js"></script>

Then in another script below that, pass in some options to gapiNano.init to get started

<script>
  var options = {
    clientId: '[CLOUD PLATFORM CLIENT_ID]',
    discoveryDocs: ["https://script.googleapis.com/$discovery/rest?version=v1"],
    scope: '[SCOPE]',
    scriptId: '[SCRIPT_ID]'
  }
 
  gapiNano.init(options,function(signedIn){
    console.log("User signed in?", signedIn)
 
    gapiNano.run('sum',{a:1,b:2}).then(function(result){
      console.log('sum of 1 and 2 is', result)
    })
 
  })
</script> 

Functions

init(options, authListener)undefined

init - loads and authenticates gapi client using Auth2

run(fName, parameters)Promise

run - calls a function from the script specified by scriptId option during init()

init(options, authListener) ⇒ undefined

gapiNano.init - loads and authenticates gapi client using Auth2

Param Type Description
options object Auth2 options, including clientId and scope
authListener function (optional) callback with a single boolean parameter, called whenever the authentication status changes

run(fName, parameters) ⇒ Promise

gapiNano.run - calls a function from the script specified by scriptId option during init()

Returns: Promise - a Promise object resolved with result of the function call

Param Type Description
fName string the name of the function
parameters object (optional) the arguments passed to the function

Building Changes

To rebuild dist/gapi-nano.js from index.js, use the npm task:

$ npm run dist

Of course this requires browserify to be installed globally:

$ npm install -g browserify

Package Sidebar

Install

npm i gapi-nano

Weekly Downloads

2

Version

1.0.1

License

ISC

Last publish

Collaborators

  • json2d