2
votes

I am working on a simple rails-based volunteer management system. I would like to use Google calendar to render the scheduling information. To this end I am using the icalendar gem to generate a calendar from a list of shifts:

def generate_ical
  cal = Icalendar::Calendar.new
  @shifts.each do |shift|
    event = Icalendar::Event.new
    event.start = shift.start.strftime("%Y%m%dT%H%M%S")
    event.end = shift.end.strftime("%Y%m%dT%H%M%S")
    event.summary = shift.task.name if shift.task
    event.uid = shift_url(shift)

    cal.add event
  end

  cal.to_ical
end

This generates an output like this:

BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:iCalendar-Ruby
BEGIN:VEVENT
DTEND:20131122T230000
DTSTAMP:20131125T003944
DTSTART:20131122T220000
SEQUENCE:0
SUMMARY:Server
UID:http://vols.herokuapp.com/shifts/980190962
END:VEVENT
END:VCALENDAR

When I use that output as the import for a Google calendar, it shows no events. It checks correctly against a validator.

If I create a calendar with a test event in Google calendar, the ical for it looks like:

BEGIN:VCALENDAR
PRODID:-//Google Inc//Google Calendar 70.9054//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:Test Calendar
X-WR-TIMEZONE:America/New_York
X-WR-CALDESC:
BEGIN:VFREEBUSY
DTSTART:20131122T150000Z
DTEND:20131122T160000Z
DTSTAMP:20131124T221822Z
UID:[email protected]
ATTENDEE;X-NUM-GUESTS=0:mailto:[email protected]
SUMMARY:Busy
END:VFREEBUSY
END:VCALENDAR

It uses a different block name: VFREEBUSY instead of VEVENT. I've found references online to VEVENTs in Google calendars, so that probably isn't the issue. Does anyone have experience with connecting this gem to Google calendar who can point me to what I need to change?

2
Did you ever get to the bottom of this?Stephen
I never got a solution.dysbulic
Just leaving this here but it takes google up to 12-24 hours to sync those events to the calendar (not sure why or the technical reason behind it).n0rm

2 Answers

0
votes

Your problem is with your export settings on google calendar.Go to the calendar settings of the calendar you want to export. Under the "Calendar Address" section on the page, click on "Change sharing settings". Now untick the box thats labeled: "Share only my free/busy information (Hide details)".

0
votes

You need to make sure that you set the right headers:

def index
  respond_to do |format|
    format.ics do
      headers['Content-Type'] = "text/calendar; charset=UTF-8"  # Google Calendar likes this!
      render :text => @cal.to_ical
    end
  end
end

source: https://stackoverflow.com/a/493379

Edit:

This only worked temporarily for me, so there must be another factor.