#Google Calendar API connector for Nodejs
This node module provides a set of methods to interact against Google Calendar's API v3 services. The module was created as part of KidoZen project, as a connector for its Enterprise API feature.
##Installation
Use npm to install the module:
> npm install node-gcalendar-api
To create your application you must get familiar with Google Cloud Console and setup a new project
##API
Due to the asynchronous nature of Nodejs, this module uses callbacks in requests. All callbacks have 2 arguments: err and data.
function callback (err, data) {
// err contains an Error class instance, if any
// data contains the resulting data
}
##Constructor
The module exports a class and its constructor requires a configuration object with following properties
account
: Required string. This is the Email Address
key
: Required string. This is a private Key
To get this values you must create a Service Account for Authentication. Once you created the service account for your application you must use the new created Email Address
value for the account
property. To obtain the value for the key
property you must:
- Download the .p12 Google Service Account private's key file
- Convert the .p12 file to .pem:
openssl pkcs12 -in key.p12 -out key.pem -nocerts -nodes
- Copy the RSA Private Key. You sould get something like this:
-----BEGIN RSA PRIVATE KEY-----
...
...
-----END RSA PRIVATE KEY-----
##Methods
All public methods has the same signature. The signature has two arguments: options
and callback
.
options
: must be an object instance containig the properties specified in the Paramenters
section of the Google Api Reference
callback
: must be a function.
For example, to clear a Calendar:
var settings = {
account : "abc@developer.gserviceaccount.com",
key : "-----BEGIN RSA PRIVATE KEY-----..."
};
var gcal = new GoogleCalendar(settings);
var options = { calendarId:'primary' };
gcal.ClearCalendar(options, function(err, result) {
...
});
});
##Calendar Functions
######ClearCalendar(options, callback)
Implements this API
######DeleteSecondaryCalendar(options, callback)
Implements this API
######GetCalendar(options, callback)
Implements this API
######InsertCalendars(options, callback)
Implements this API
In options
supply a Calendars resource
######UpdateCalendar(options, callback)
Implements this API. In options
also supply a resource
property with a Calendars resource
######PatchCalendar(options, callback)
Implements this API. In options
also supply a resource
property with a Calendars resource
##Events Functions
######DeleteEvent(options, callback)
Implements this API
######GetEvent(options, callback)
Implements this API
######InsertEvent(options, callback)
Implements this API. In options
also supply a resource
property with a Events resource
######QuickAddEvent(options, callback)
Implements this API
######GetAllEvents(options, callback)
Implements this API
######GetEventInstances(options, callback)
Implements this API
######UpdateEvent(options, callback)
Implements this API. In options
supply a 'resource' property with a Events resource
######PatchEvent(options, callback)
Implements this API. In options
supply a 'resource' property with a Events resource
##FreeBusy Functions
######QueryFreebusy
Implements this API. In options
supply data with the structure specified in the documentation
##ACL Functions
######ListAcl
Implements this API
######GetAcl
Implements this API
######InsertAcl
Implements this API. In options
supply a rule
property with a ACL resource
######UpdateAcl
Implements this API. In options
supply a rule
property with a ACL resource
######PatchAcl
Implements this API. In options
supply a rule
property with a ACL resource
######DeleteAcl
Implements this API
##Settings Functions
######ListSettings
Implements this API
######GetSetting
Implements this API
##Colors Functions
######GetColors
Implements this API
Tests
In order to execute the tests, first set up an environment variable 'GOOGLE_ACCOUNT' with the your account, something like this: "abcdefghij@developer.gserviceaccount.com". You also have copy your .pem file to the 'test' folder and name it key.pem. Then run the tests using mocha or npm test.
Notice: these tests are going to be hitting your google calendar directly, so I recommend setting a tests project.