module GoogleOAuth::Calendar

Public Instance Methods

calendars() click to toggle source

Returns entries on the user’s calendar list. CalendarList#list

# File lib/google_oauth/calendar.rb, line 25
def calendars
  page_token = nil
  result = execute(:api_method => service.calendar_list.list)
  entries = []
  while true
    entries += result.data.items
    if !(page_token = result.data.next_page_token)
      break
    end
    result = execute(:api_method => service.calendar_list.list,
                     :parameters => {'pageToken' => page_token})
  end

  entries
end
clear_calendar() click to toggle source

Clears a primary calendar. This operation deletes all data associated with the primary calendar of an account and cannot be undone.

# File lib/google_oauth/calendar.rb, line 51
def clear_calendar
end
delete_calendar(calendar_id) click to toggle source

Deletes a secondary calendar.

# File lib/google_oauth/calendar.rb, line 55
def delete_calendar(calendar_id)
end
delete_calendar_list(calendar_id) click to toggle source

Deletes an entry on the user’s calendar list.

# File lib/google_oauth/calendar.rb, line 12
def delete_calendar_list(calendar_id)
end
delete_event(calendar_id = 'primary', event_id) click to toggle source

Deletes an event.

# File lib/google_oauth/calendar.rb, line 99
def delete_event(calendar_id = 'primary', event_id)
  execute(:api_method => service.events.delete,
          :parameters => {'calendarId' => calendar_id, 'eventId' => event_id})
end
event_instances(calendar_id, event_id) click to toggle source

Returns instances of the specified recurring event.

# File lib/google_oauth/calendar.rb, line 141
def event_instances(calendar_id, event_id)
end
events(calendar_id = 'primary', options = {}) click to toggle source
# File lib/google_oauth/calendar.rb, line 76
def events(calendar_id = 'primary', options = {})
  %w(timeMin timeMax).each do |time|
    options[time] = options[time].xmlschema if options[time]
  end

  params = { 'calendarId' => calendar_id }
  params.merge!(options)
  result = execute(:api_method => service.events.list,
                   :parameters => params)
  events = []
  while true
    events += result.data.items
    if !(params[:page_token] = result.data.next_page_token)
      break
    end
    result = execute(:api_method => service.events.list,
                     :parameters => params)
  end

  events
end
get_calendar(calendar_id = 'primary') click to toggle source

Returns metadata for a calendar

# File lib/google_oauth/calendar.rb, line 59
def get_calendar(calendar_id = 'primary')
  execute(:api_method => service.calendars.get, :parameters => { 'calendarId' => calendar_id }).data
end
get_event(calendar_id = 'primary', event_id) click to toggle source

Returns an event.

# File lib/google_oauth/calendar.rb, line 105
def get_event(calendar_id = 'primary', event_id)
  execute(:api_method => service.events.get,
          :parameters => {'calendarId' => calendar_id, 'eventId' => event_id})
end
import_event() click to toggle source

Imports an event.

# File lib/google_oauth/calendar.rb, line 111
def import_event
end
insert_calendar(opts = {}) click to toggle source

Creates a secondary calendar.

# File lib/google_oauth/calendar.rb, line 64
def insert_calendar(opts = {})
end
insert_calendar_list(opts = {}) click to toggle source

Adds an entry to the user’s calendar list.

# File lib/google_oauth/calendar.rb, line 20
def insert_calendar_list(opts = {})
end
insert_event(calendar_id = 'primary', event_hash) click to toggle source

Creates an event. 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'
},
'attendees' => [
  {
    'email' => 'attendeeEmail'
  },
  #...
]

}

# File lib/google_oauth/calendar.rb, line 131
def insert_event(calendar_id = 'primary', event_hash)
  convert_event_hash_timestamps!(event_hash)
  event = execute(:api_method => service.events.insert,
                  :parameters => {'calendarId' => calendar_id},
                  :body => [JSON.dump(event_hash)],
                  :headers => {'Content-Type' => 'application/json'})
  event ? event.data : nil
end
move_event(from_calendar_id = 'primary', to_calendar_id, event_id) click to toggle source

Moves an event to another calendar, i.e. changes an event’s organizer.

# File lib/google_oauth/calendar.rb, line 145
def move_event(from_calendar_id = 'primary', to_calendar_id, event_id)
  execute(:api_method => service.events.move,
          :parameters => {'calendarId' => from_calendar_id, 'eventId' => event_id,
                          'destination' => to_calendar_id})
end
patch_calendar(opts = {}) click to toggle source

Updates metadata for a calendar. This method supports patch semantics.

# File lib/google_oauth/calendar.rb, line 72
def patch_calendar(opts = {})
  update_calendar(opts)
end
patch_calendar_list(opts = {}) click to toggle source

Updates an entry on the user’s calendar list. This method supports patch semantics

# File lib/google_oauth/calendar.rb, line 46
def patch_calendar_list(opts = {})
  update_calendar_list
end
patch_event(calendar_id = 'primary', event_id, event_hash)

Updates an event. This method supports patch semantics.

Alias for: update_event
quick_add_event(calendar_id = 'primary', text) click to toggle source

Creates an event based on a simple text string.

# File lib/google_oauth/calendar.rb, line 152
def quick_add_event(calendar_id = 'primary', text)
  event = execute(:api_method => service.events.quick_add,
                  :parameters => {'calendarId' => calendar_id,
                                  'text' => text})
  event ? event.data : nil
end
update_calendar(opts = {}) click to toggle source

Updates metadata for a calendar.

# File lib/google_oauth/calendar.rb, line 68
def update_calendar(opts = {})
end
update_calendar_list(opts = {}) click to toggle source

Updates an entry on the user’s calendar list.

# File lib/google_oauth/calendar.rb, line 42
def update_calendar_list(opts = {})
end
update_event(calendar_id = 'primary', event_id, event_hash) click to toggle source

Updates an event.

# File lib/google_oauth/calendar.rb, line 160
def update_event(calendar_id = 'primary', event_id, event_hash)
  convert_event_hash_timestamps!(event_hash)
  event = execute(:api_method => service.events.update,
                  :parameters => {'calendarId' => calendar_id},
                  :body => [JSON.dump(event_hash)],
                  :headers => {'Content-Type' => 'application/json'})
  event ? event.data : nil
end
Also aliased as: patch_event

Private Instance Methods

convert_event_hash_timestamps!(event_hash) click to toggle source
# File lib/google_oauth/calendar.rb, line 174
def convert_event_hash_timestamps!(event_hash)
  event_hash['start']['dateTime'] = event_hash['start']['dateTime'].xmlschema if event_hash['start'] && event_hash['start']['dateTime']
  event_hash['end']['dateTime'] = event_hash['end']['dateTime'].xmlschema if event_hash['end'] && event_hash['end']['dateTime']
  event_hash
end