Hello everyone
Does anyone have any experience of accessing the Google Calendar API
with Rails?
I'm using Ben's page as a starting point.
http://benjamin.francisoud.googlepages.com/googlecalendar
I've installed the libraries but I can get data, I can add data, good
start.
I'm now starting to use the get_calendars method of the gdata class
and I'm having problems.
Namely, this bit of code
require 'googlecalendar'
g = GData.new
g.login('REPLACE_WITH_YOUR_MAIL@gmail.com',
'REPLACE_WITH_YOUR_PASSWORD')
calendar_list = g.get_calendars()
print calendar_list
Now I'm getting back a 200 OK message object back, I thought I'd be
getting an array of calendars I'm a member of.
Has anyone been down this track?
Any information would be helpful and I'll gladly share my experience
of setting this up with anyone else.
A bit more information, if I output this instead I can see exactly
what I'm getting back.
print calendar_list.inspect
This gives me back
#<Net::HTTPOK 200 OK readbody=true>
calendar_list.each { |key, value| print key + ' = ' + value + "\n" }
gives me back
<Net::HTTPOK 200 OK readbody=true>last-modified = Thu, 10 Apr 2008
11:32:57 GMT
cache-control = max-age=0, must-revalidate, private
connection = Close
date = Thu, 10 Apr 2008 11:32:57 GMT
content-type = application/atom+xml; charset=UTF-8
server = GFE/1.3
transfer-encoding = chunked
I'm starting to think that the get_calendars method is not doing what
it describes itself doing in it's own logic here
http://pastie.caboo.se/178486
Although it's much more likely a syntaxical errror on my behalf
Con
(Con)
April 10, 2008, 12:03pm
3
Hi, I would recommend trying to invoke the following code in the console:
require ‘googlecalendar’
g = GData.new
g.login(‘REPLACE_WITH_YOUR_MAIL@gmail.com’,
‘REPLACE_WITH_YOUR_PASSWORD’)
calendar_list = g.get_calendars()
print calendar_list
Good luck,
-Conrad
Hi Conrad, thanks for getting back to me.
The code you suggested I try is exactly the same code that I pasted
into the ticket initially
I found the problem.
In the get_calendars() method the redirect_response was being
returned, not the redirect_data.
Changing that line to return redirect_data gives me exactly what I was
looking for, a list of calendars that I have access to.
Thanks anyway Conrad.
Ahh
Don't listen to me
There's nothing wrong with the redirect_response line, I wasn't using
the right syntax to get at the data.
print calendar_list.body
That's the puppy.
Worked it out in the end.
Here's how you access your GData get_calendars() data and strip out
the ID of each entry(calendar) and the name of each entry and create a
hash out of the data to use somewhere else.
require 'hpricot'
require 'googlecalendar'
k = GData.new
k.login('youraddress@gmail.com', 'yourpassword')
bcalendar_list = k.get_calendars()
calendar_list = bcalendar_list.body
doc = Hpricot(bcalendar_list.body.to_s)
@cal_names = Hash.new
(doc/:entry).each do |item|
@cal_names [item/:id] = item/:name
end