Thursday, June 1, 2017

Creating a Google Calendar Reminder with Ballerina

Ballerina makes it easy to use and tape together different API to create mashup applications and services. This example explores how ballerina can be used to invoke the Google Calendar API to create events that can work as a simple task reminder.

In order access Google API, you must create an application in the developer console[1], subscribe to the API you wish to use(in this case the calendar API) and generate Oauth credentials which can then be utilized to create an API key with the scopes needed for the API. Conversely, you could use the google playground application[2] to generate an API key to try out the example. To generate an API key this way,

  1. Select the calendar API with “” (this scope is needed to create new calendar events) from the drop down found in step 1.
  2. Authorize API to generate an Authorization code along with an access token and a refresh token.

Execute the program passing in the following information in the order specified.
  • Access token
  • Event end date time in rfc3339[3] format(look to the example execution found below)
  • Event start date time in rfc3339 format.
  • Description for the event
  • Event title.

ballerina run main calendarAPI/sample/CalendarEventCreator.bal "ya29.XXXXXXXXOEyIODzSIvcnH4xkGCZBjPaRNJTzobPnLOo8a-5fzOnUILeFryHvbIVr8PX_DCFksmZf7ek3fFbRxvBVrB3K9wEQIwGbwXCD9_yJYy8w9EHdXXXXXXXX" "2017-06-02T12:30:00+07:00" "2017-06-02T12:10:00+07:00" "yet another google calendar API test" "test one two"

A new google calendar event will get created based on the values passed in and a pop up reminder will be displayed 15 mins prior to the starting time.

You may follow a similar formula to utilize any other google API with ballerina. In a future post we will discuss how the google calendar API invocation logic may be abstracted into its own connector so that it can be conveniently utilized in other ballerina programs.

Note: this example was written for ballerina 0.86 and it may not work with other versions.

No comments:

Post a Comment