Managing Google Calendar Integration

Alright, I have an issue and I would love some advice. Here is the situation:

I am developing a site which syncs with Google Calendar. You can imagine, the whole bit: list of events, create events, delete events, all from this from our rails site.

My problem is the request times are just too slow for the initial listing of the events. Basically, the events are being listed on a primary profile page and I can't allow the user to have to wait that long to see their page.

I assume the answer to this is "offload to backgroundrb" or "load the event list using ajax" or a combination of both. I just want to hear opinions on how others would manage this.

Short Recap: User has a profile page which lists the next 5 upcoming events on their calendar as part of the page. I need this page to load reasonably fast but the request to GoogleCalendar takes very long.

Could someone explain the basic process for how to do this properly in rails. I know I need to load the Google Calendar using ajax or at least I guessed but what would be the "best practice" method to choose...

1) create an action in rails that parses google calendar lists into an array of events and then use an ajax request to query that action, get the array and then display it on the javascript end

2) create a background worker that queries google calendar and then create a rails action that starts up the background worker, gets the events and returns them to the page invoked from an ajax request.

3) have a background worker that is continously querying google calendar every 10 minutes for all the upcoming events for all the users and then store them in a hash in the worker. then just query the worker and be given the events immediately and print them to the screen

4) something inevitably smarter?

Please help. sorry this is long.

Hi Nathan

I'm in the process of scoping out a project which sounds identical to yours.

So far I've found two libraries out there, I think there may be more

sudo gem install googlecalendar

http://googlecalendar.rubyforge.org/plugins/doc/

I've built a simple app with googlecalendar and I'm in touch with Benjamin, he's being very patient with me :slight_smile: Still got some problems using it.

sudo gem install gcalapi http://rubyforge.org/projects/gcalapi/

Just found this one, I'll be looking at it today.

Maybe we could share how we're getting on?

It's a shame there isn't an official google one, I understand there may be some pressure on Google to do sort it out.

Matt

Hey Matt,

Thanks for the reply. I actually found "gcalapi" and started using it. gcalapi didn't have support for everything I needed but I worked with it and I have pulled off most of the google calendar actions that I needed. I can create calendars, create, edit, and remove events. gcalapi was a great start which got me going.

I am still having trouble with how to make Google Calendar processing faster. Adding events, querying calendars, etc takes forever. For now, I put off moving the actions to a background worker, but inevitably I will have to do this eventually.

I am definitely open to sharing any tips we come across. Let me know if there is any particular action you need help figuring out, particularly if you work with gcalapi.

Hey I didn't see this thread again until now, but let me try to go through here and cover a few things:

Matt mentioned a problem with dealing with non-default calendar. With the gcalapi this is actually quite easy. I am only familiar with the gcalapi library because it has worked out for me so far. Long story short, there is a method called 'calendars'

http://gcalapi.rubyforge.org/classes/GoogleCalendar/Calendar.html#M000012

This method returns a list of all the calendars for a given google account. Then I can create a new calendar like so:

GoogleCalendar::Calendar.new(@srv, feed)

and then query for events or create new events from there. It abstracts the need to mess with the URL manually.

I have not tried any alternatives but I was pretty satisfied with gcalapi. There are not too many tutorials. I learned how to use it through the rdocs

http://gcalapi.rubyforge.org/

and also just by straight up looking at the source code.

Overall tho, using it was pretty self explanatory.

As far as testing the google calendar implementation, this is where mocks/stubs come in handy. Check out the library 'mocha'

http://mocha.rubyforge.org/

You are right that you can't actually interact with GoogleCalendar. So instead you use mocks and stubs to 'simulate' the responses Google Calendar would give you in order to test your handling of the response.

Hope that helps

- Nathan

P.S. I am still not quite sure the proper method for offloading the event query