WWTLF
WWTLF

Reputation: 540

Google Calendar V3 Ruby API insert event

I am using example from https://developers.google.com/google-apps/calendar/v3/reference/events/insert

event = Google::Apis::CalendarV3::Event.new{
  summary:'Google I/O 2015',
  location:'800 Howard St., San Francisco, CA 94103',
  description:'A chance to hear more about Google\'s developer products.',
  start: {
    date_time: '2015-05-28T09:00:00-07:00',
    time_zone:'America/Los_Angeles',
  },
  end: {
    date_time:'2015-05-28T17:00:00-07:00',
    time_zone:'America/Los_Angeles',
  }
}

result = service.insert_event(calendar_id, event)

However, I got error:

wwtlf:~/workspace $ ruby test.rb 
/usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/http_command.rb:202:in `check_status': required: Missing end time. (Google::Apis::ClientError)
        from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/api_command.rb:103:in `check_status'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/http_command.rb:170:in `process_response'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/http_command.rb:275:in `execute_once'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/http_command.rb:107:in `block (2 levels) in execute'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/retriable-2.1.0/lib/retriable.rb:54:in `block in retriable'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/retriable-2.1.0/lib/retriable.rb:48:in `times'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/retriable-2.1.0/lib/retriable.rb:48:in `retriable'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/http_command.rb:104:in `block in execute'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/retriable-2.1.0/lib/retriable.rb:54:in `block in retriable'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/retriable-2.1.0/lib/retriable.rb:48:in `times'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/retriable-2.1.0/lib/retriable.rb:48:in `retriable'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/http_command.rb:96:in `execute'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/lib/google/apis/core/base_service.rb:267:in `execute_or_queue_command'
        from /usr/local/rvm/gems/ruby-2.3.0/gems/google-api-client-0.9.1/generated/google/apis/calendar_v3/service.rb:1207:in `insert_event'

What is wrong with event object from example? I tried to use dateTime insted of date_time, but error is the same.

UPD: The original example:

event = Google::Apis::CalendarV3::Event.new{
  summary: 'Google I/O 2015',
  location: '800 Howard St., San Francisco, CA 94103',
  description: 'A chance to hear more about Google\'s developer products.',
  start: {
    date_time: '2015-05-28T09:00:00-07:00',
    time_zone: 'America/Los_Angeles',
  },
  end: {
    date_time: '2015-05-28T17:00:00-07:00',
    time_zone: 'America/Los_Angeles',
  },
  recurrence: [
    'RRULE:FREQ=DAILY;COUNT=2'
  ],
  attendees: [
    {email: '[email protected]'},
    {email: '[email protected]'},
  ],
  reminders: {
    use_default: false,
    overrides: [
      {method' => 'email', 'minutes: 24 * 60},
      {method' => 'popup', 'minutes: 10},
    ],
  },
}

enter image description here Obviously, there are a lot of syntax errors. (missed ')method' => 'popup', 'minutes(missed '): 10

So, I decided to modify it:

event = Google::Apis::CalendarV3::Event.new{
  summary:'Google I/O 2015',
  location:'800 Howard St., San Francisco, CA 94103',
  description:'A chance to hear more about Google\'s developer products.',
  start: {
    date_time:'2015-05-28T09:00:00-07:00',
    time_zone:'America/Los_Angeles',
  },
  end: {
    date_time:'2015-05-28T17:00:00-07:00',
    time_zone:'America/Los_Angeles',
  },
  recurrence: [
    'RRULE:FREQ=DAILY;COUNT=2'
  ],
  attendees: [
    {email: '[email protected]'},
    {email: '[email protected]'},
  ],
  reminders: {
    use_default: false,
    overrides: [
      {'method' => 'email', 'minutes'=> 24 * 60},
      {'method' => 'popup', 'minutes'=> 10},
    ],
  }
}

But, I still got http_command.rb:202:in `check_status': required: Missing end time. (Google::Apis::ClientError)

Upvotes: 1

Views: 2724

Answers (4)

Kacper Perschke
Kacper Perschke

Reputation: 179

In reminders works :reminder_method.

Link here.

Example below

{   
    :summary=>"Never underestimate yourself!",                                                     
    :location=>"In my brain",
    :description=>"Never underestimate\nwhat you can acomplish\nwhen you believe in yourself.\n\nNever give up.\n\nhttp://www.youtube.com/watch?v=qX9FSZJu448",
    :attendees => [                                                                                
        {:email =>'[email protected]'},                                                        
    ],                                                                                             
    :start=>{                                                                                      
        :date_time=>"2019-05-12T11:30:00+02:00",                                                   
        :time_zone=>"Europe/Warsaw"                                                                
    },                                                                                             
    :end=>{                                                                                        
        :date_time=>"2019-05-12T11:30:15+02:00",                                                   
        :time_zone=>"Europe/Warsaw"
    },                                                              
    :reminders=>{                                                                                  
        :use_default=>false,                                                                       
        :overrides=>[                                                                              
            {:reminder_method=>"email", :minutes=>35}                                              
            {:reminder_method=>"popup", :minutes=>5}                                               
        ]                                                                                          
    }                                                                                              
}    

Upvotes: 0

siegy22
siegy22

Reputation: 4413

In your example you're creating a ruby block which is equal to:

Google::Apis::CalendarV3::Event.new do
  # something
end

But what you want, is to pass a hash like this:

Google::Apis::CalendarV3::Event.new({
  key: value
})

Upvotes: 3

Igor Dmitriev
Igor Dmitriev

Reputation: 41

For me, atm, works this syntax:

Google::Apis::CalendarV3::Event.new({
  :summary => 'event title',
  :location => 'event address',
  :description => 'event description',
  :start => {
    :date_time => 'event start time in rfc3339'
  },
  :end => {
    :date_time => 'event end time in rfc 3339'
  }
})

Upvotes: 4

WWTLF
WWTLF

Reputation: 540

I solved my issue. Event hash must be like this:

event = Google::Apis::CalendarV3::Event.new({
  'summary':'Google I/O 2015',
  'location':'800 Howard St., San Francisco, CA 94103',
  'description':'A chance to hear more about Google\'s developer products.',
  'start':{
    'date_time': DateTime.parse('2016-05-28T09:00:00-07:00'),
    'time_zone': 'America/Los_Angeles'
  },
  'end':{
    'date_time': DateTime.parse('2016-05-28T17:00:00-07:00'),
    'time_zone': 'America/Los_Angeles'
  }
})

Also don't forget to provide the access to your calendar by severice accaunt email from json file. "client_email": "[email protected]",

Upvotes: 2

Related Questions