Search code examples
rubyruby-on-rails-4google-calendar-apigoogle-api-client

Google api client calendarv3 event initialization argument error


I'm using google_api_client 0.10.3. I have this call:

Google::Apis::CalendarV3::Event.new({
  'summary' => summary,
  'description' => description,
  'start' => event_datetime(check_out_time),
  'end' =>   event_datetime(check_out_time),
})

Somehow I'm getting this error:

ArgumentError: wrong number of arguments (given 1, expected 0)
from .../gems/google-api-client-0.10.3/generated/google/apis/calendar_v3/classes.rb:964:in `initialize'

This is so perplexing, as the class definition in fact takes arguments:

def initialize(**args)

Any help?


Solution

  • Use symbols as keys in the hash, not strings.

    Google::Apis::CalendarV3::Event.new(
      summary: summary,
      description: description,
      start: event_datetime(check_out_time),
      end: event_datetime(check_out_time),
    )
    

    In ruby, the double splat operator (**) is for capturing keyword arguments - which, by design, must always be symbols.