New Ruby Google Calendar API Gem: GCal4Ruby

UPDATE: This article is now pretty out of date.  Check out the project page for more up-to-date tutorials and examples.

I’ve written a few previous posts about using the Google Calendar API with Ruby and Ruby on Rails, but I’ve wanted to create my own library that includes the functionality I’ve had to monkey patch into others’.  So, I’ve gone ahead and created GCal4Ruby, a full featured Google Calendar API wrapper for Ruby available as a Gem.  You can download the source here or with ‘sudo gem install gcal4ruby’.  Some of the features:

  • Clean, ActiveRecord style syntax and code structure
  • Full querying of calendars and events
  • Full calendar creation, editing and deletion
  • Setting public/private permissions for calendars
  • Event creation/editing/deletion
  • Support for full event recurrence
  • Support for event reminders
  • Support for event attendees

All of the major features have been implemented, and over the next couple of days I hope to complete the smaller outstanding todos.  Any help testing is much appreciated.  Below are some example uses.  For more information, check out the documentation.

Get all calendars for an account

       service = Service.new
       service.authenticate("user@gmail.com", "password")
       calendars = service.calendars

Create a new Calendar

       cal = Calendar.new(service)

Find an existing Calendar

       cal = Calendar.find(service, "New Calendar", {:scope => :first})

Find all calendars containing the search term

       cal = Calendar.find(service, "Soccer Team")

Find a calendar by ID

       cal = Calendar.find(service, id)

Create a new Event

       event = Event.new(calendar)
       event.title = "Soccer Game"
       event.start = Time.parse("12-06-2009 at 12:30 PM")
       event.end = Time.parse("12-06-2009 at 1:30 PM")
       event.where = "Merry Playfields"
       event.save

Find an existing Event

       event = Event.find(cal, "Soccer Game", {:scope => :first})

Find all events containing the search term

       event = Event.find(cal, "Soccer Game")

Create a recurring event for every Saturday

       event = Event.new(calendar)
       event.title = "Baseball Game"
       event.where = "Municipal Stadium"
       event.recurrence = Recurrence.new
       event.recurrence.start = Time.parse("13-06-2009 at 4:30 PM")
       event.recurrence.end = Time.parse("13-06-2009 at 6:30 PM")
       event.recurrence.frequency = {"weekly" => ["SA"]}
       event.save

Create an event with a 15 minute email reminder

       event = Event.new(calendar)
       event.title = "Dinner with Kate"
       event.start = Time.parse("20-06-2009 at 5 pm")
       event.end = Time.parse("20-06-209 at 8 pm")
       event.where = "Luigi's"
       event.reminder = {:minutes => 15, :method => 'email'}
       event.save

Create an event with attendees

       event = Event.new(calendar)
       event.title = "Dinner with Kate"
       event.start = Time.parse("20-06-2009 at 5 pm")
       event.end = Time.parse("20-06-209 at 8 pm")
       event.attendees => {:name => "Kate", :email => "kate@gmail.com"}
       event.save
  • Share/Bookmark

Related Posts

52 Responses to “New Ruby Google Calendar API Gem: GCal4Ruby”


  • Thanks for the bug report! I’ll take a look and get it patched in the next version.

    -Mike

  • Hi,

    I am having some issues with getting single events to appear as I think they should. I created the ‘baseball game’ as per one of your examples and I am trying to list each event over a month period with the :single_events = ‘false’ option but i’m only getting one event returned.

    here is my code:

    @start = Time.parse(“19-04-2010 at 09:00 AM”)
    @end = Time.parse(“19-05-2010 at 09:00 AM”)

    @cal = GCal4Ruby::Event.find(calendar,”Baseball”,{:order_sort => ‘descending’, :single_events => false, :range => {:start => @start, :end => @end}})

    am I missing something i have tried :single_events => ‘false’ and :single_events = 0 and still nothing.

    Thanks,

    Jim

Leave a Reply