y4ku
y4ku

Reputation: 513

Google Calendar Ruby API

I'm working on an app that needs to update a google calendar.

By following the Google Calendar Developer Guide at:

http://code.google.com/apis/calendar/v3/using.html#creating_events

event = {
  'summary' => 'Appointment',
  'location' => 'Somewhere',
  'start' => {
     'dateTime' => '2011-06-03T10:00:00.000-07:00'
  },
  'end' => {
     'dateTime' => '2011-06-03T10:25:00.000-07:00'
  }
}
result = client.execute(:api_method => service.events.insert,
                    :parameters => {'calendarId' => 'primary'},
                    :body => JSON.dump(event),
                    :headers => {'Content-Type' => 'application/json'})

I get the following error:

TypeError (Expected body to respond to :each.):

I have tried to do event.to_json as well.

Upvotes: 3

Views: 2637

Answers (1)

DNNX
DNNX

Reputation: 6255

Just a couple of suggestions from the top of my head which may help. Please try them and inform us if these help.

Wrap :body into array:

result = client.execute(:api_method => service.events.insert,
                    :parameters => {'calendarId' => 'primary'},
                    :body => [JSON.dump(event)],
                    :headers => {'Content-Type' => 'application/json'})

Or use:body_object instead of body, and don't jsonify the event hash:

result = client.execute(:api_method => service.events.insert,
                    :parameters => {'calendarId' => 'primary'},
                    :body_object => event,
                    :headers => {'Content-Type' => 'application/json'})

Take a look at http://code.google.com/p/google-api-ruby-client/source/browse/lib/google/api_client/reference.rb, and you'll understand how I came up with these suggestions.

Upvotes: 5

Related Questions