Google Calendar Integration with Ruby on Rails Development

Google calendar is a very robust application to create a calendar event. It allows users to add events, schedule meets, and track the timeline of any project. Integrating Google calendar in Ruby on Rails applications allows users to access the calendar from within the app and add or remove events. It is a useful app for tracking the progress of activities inside an application.

Ruby on Rails Application: Integrating Google Calendar API

There is an API to manage whole google calendar features programmatically. But it is challenging to work with the APIs as the API document is not comprehensive. There is no proper documentation for each piece in any library or SDK we use. In one of the Ruby on Rails projects, we needed to set up two-way communication between the Rails application and the user’s google calendar.

  1. When a user creates an event in the Rails app, we need to push that event to Google Calendar via API. We have written a comprehensive blog for this.
  2. When a user creates a Google Calendar event, we need to save that record in our database. We can achieve this in an async manner using the notification channel which Google Calendar provides.

What is the Notification Channel?

It is a channel through which the user will be notified through Google Calendar API for any of the changes in the watched resource i.e Calendars in Google Calendar API. There are some prerequisites to create and configure notification channels. 

1. Domain Registration in search console

Note:  To use this in the Ruby on Rails development environment, you simply need to use the ngrok URL for domain registration in developers and search console. If the host is being used anywhere in the Ruby on Rails application, the host value must be modified as well.

Add Property

2. Domain Registration in the developer’s console.

3. Create a notification channel to receive changes in the web app.

Note:  If there is a requirement to push google events for a particular user then we need to pass that user’s id(unique identifier) in the token which can be received in every notification callback as X-Goog-Channel-Token in request headers. 

4. Make a POST route for the watch event of the resource(Google Calendar) in your web app and receive notifications.

Note:

ALL SET!! You will now receive notifications in your web-app for the event created in the google calendar and customize as per your requirement. Additionally, if you want to revoke the Google Calendar access from the user, you should first stop the channel to receive the notifications and then revoke access. You can find the whole source code for 2 way communication for Google Calendar API here.

Conclusion

There are different alternatives to integrating the Google Calendar API with the Ruby on Rails application. But if you have followed the above structure correctly, you will be able to integrate it without any hassle. 

After the integration, you will be able to list events, list calendar, add new events, and add guests to the scheduled meeting - all with the application. It removes the task of going separately to the Google calendar and then add the tasks.

 

 

 

 

Top