/realtime-utils

A utility belt for the Google Drive Realtime API

Primary LanguageJavaScriptApache License 2.0Apache-2.0

Google Drive Realtime API Utility

Overview

The Google Drive Realtime API Utility is a lightweight JavaScript library aimed at simplifying authentication to Google Drive as well as various other features.

Simply pass in an object with the following properties

  1. appId - the appId of your project found in the developers console.

You can instantiate the utility by running the following code.

var util = new utils.RealtimeUtils({
	appId: 'YOUR APPID',
});

After instantiating the utility, start the authorization process by calling authorize and passing in a callback function for after authentication. authorize also accepts a boolean parameter, true to use a popup or false to try and authenticate without a popup.

After authentication, the realtime utiltiy has several helper functions. Outlined below are the various functions and parameters that can be called.

Documentation

RealtimeUtils.authorize(onAuthComplete, usePopup)

Name Type Description
onAuthComplete Function This function is a callback for the authorization process. Once completed, this function will be invoked. This function will have an authentication result object as an argument describing if the authentication was successful.
usePopup boolean If true, the user will be prompted to authenticate via a popup. The general authentication flow should only require this if it is the first time the user has authenticated. Subsequent authentications will not require a popup.

RealtimeUtils.createRealtimeFile(title, callback)

This function will create a new Realtime file and store it in Google Drive.

Name Type Description
title String The name of the newly created document. Note that all new files are created using the 'application/vnd.google-apps.drive-sdk' mime type. To override this mimetype, pass in mimeType and a string value as an option when instantiating RealtimeUtils.
callback Function This function will be invoked after the realtime file has been created in Drive. Note that you will still need to load a document after you have created one.

RealtimeUtils.load(documentId, onFileLoaded, initializeModel)

Load a new or existing document that is persisted in Google Drive.

Name Type Description
documentId String The id of the document as stored in Drive.
onFileLoaded Function The function that will be invoked after the file has been loaded. See the official Realtime documentation for more information regarding arguments.
initializeModel Function If this is the first time this document has been opened, the Realtime model will be initialized. See the official Realtime Documentation for more information regarding arguments.

RealtimeUtils.getParam(urlParam)

A convenience function for accessing a parameter in the URL.

Name Type Description
urlParam String The name of the parameter that is being retrieved from the URL.

Contributing

Before creating a pull request, please fill out either the individual or corporate Contributor License Agreement.

  • If you are an individual writing original source code and you're sure you own the intellectual property, then you'll need to sign an individual CLA.
  • If you work for a company that wants to allow you to contribute your work to this client library, then you'll need to sign a corporate CLA.

Follow either of the two links above to access the appropriate CLA and instructions for how to sign and return it. Once we receive it, we'll add you to the official list of contributors and be able to accept your patches.