Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 437
y4ku Avatar asked Jul 08 '26 02:07

y4ku


1 Answers

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.

like image 144
DNNX Avatar answered Jul 10 '26 05:07

DNNX



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!