Node.js wrapper for Google Calendar API
This is a small wrapper to make working with Google Calendar API mor convenient and faster.
The main focus is to abstract the authentication process and management.
! Attention !
The authentication process requires the first-time user to click on a link in their terminal, accept access to their calendar and copy a verification code into their terminal. At this point it isn't possible to do this another way. That's why the use cases are mostly command line tools right now.
npm install calenduh
Google requires you to register an application in order to work with their APIs.
You can use this guide to generate a client_secret.json
which will contain all necessary information.
With the secret file you can instantiate Calenduh:
const Calenduh = require('calenduh');
const cal = new Calenduh('./path/to/client_secret.json');
Returns a promise with and array of all calendars of the authenticated user.
cal.calendarList()
.then((lists) => {
// ...
});
Returns all events from a specific calendar. The options are passed directly to the Google Calendar API, all defaults and parameters can be found here.
cal.events(calendarId, {
timeMin: (new Date('2017-02-01')).toISOString(),
timeMax: (new Date('2017-02-28')).toISOString(),
}).then((events) => {
// ...
});
Returns a list of all events from all calendars.
Options behave the same way as in events()
.
cal.allEvents({})
.then((events) => {
// ...
});
Create a new calendar with the passed name. Returns new calendar.
cal.createCalendar('My new Calendar')
.then((calendar) => {
// ...
});
Checks if calendar with passed name already exists. If it does it will be returned. If not the calendar will be created and returned.
cal.findOrCreateCalendar('My Calendar')
.then((calendar) => {
// ...
});
Creates an event for a specific calendar and returns it.
startDateTime
and endDateTime
are required, additonal data can be passed in opts
object.
Full list of available options can be found in the official documentation.
cal.createEvent(
calendarId,
'My Event',
'2017-02-21T10:00:00.000Z',
'2017-02-21T12:00:00.000Z',
{
location: 'My Location',
}
).then((event) => {
// ...
});
Creates multiple events. There is an artificial timeout between each request to give the api time to process, currently there is no better solution for this.
events
is an array, each object has to have the following structure:
{
name: 'Name of event',
start: '2017-02-21T10:00:00.000Z',
end: '2017-02-21T10:00:00.000Z',
opts: {
location: 'My Location',
}
}
Usage:
cal.createEvents(calendarId, events)
.then(() => {
// ...
});
Deletes single event by Id, requires the Id of the parent calendar.
cal.deleteEvent(calendarId, eventId)
.then(() => {
// ...
});
Deletes multiple events by Id. This is simply a convenient function which performs multiple deleteEvent() calls.
cal.deleteEvents(calendarId, eventIds)
.then(() => {
// ...
});