I’ve written a few previous posts about using the Google Calendar API with Ruby and Ruby on Rail
s, 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
to CPAN or PEAR, the Gem infrastructure allows users to download additional libraries from a central online repository and install it locally. All you need to do is start a project at