Class: GoogleAPI::Calendar

Inherits:
Base
  • Object
show all
Includes:
ClearTestCalendar
Defined in:
lib/google_api/calendar.rb,
lib/google_api/calendar/clear_test_calendar.rb

Defined Under Namespace

Modules: ClearTestCalendar

Constant Summary collapse

SERVICE_CLASS =
Google::Apis::CalendarV3::CalendarService

Instance Method Summary collapse

Methods included from ClearTestCalendar

#clear_test_calendar

Methods inherited from Base

#initialize

Methods included from Base::Authorization

#authorize!

Constructor Details

This class inherits a constructor from GoogleAPI::Base

Instance Method Details

#create(calendar_id, event_options = {}) ⇒ Object



14
15
16
# File 'lib/google_api/calendar.rb', line 14

def create(calendar_id, event_options = {})
  call(:insert_event, calendar_id, event(event_options), conference_data_version: 1)
end

#delete(calendar_id, event_id) ⇒ Object



30
31
32
33
34
# File 'lib/google_api/calendar.rb', line 30

def delete(calendar_id, event_id)
  call(:delete_event, calendar_id, event_id)
rescue Google::Apis::ClientError
  :event_not_found
end

#get(calendar_id, event_id) ⇒ Object



22
23
24
# File 'lib/google_api/calendar.rb', line 22

def get(calendar_id, event_id)
  call(:get_event, calendar_id, event_id)
end

#list(calendar_id, max_results: 2500, page_token: nil) ⇒ Object



18
19
20
# File 'lib/google_api/calendar.rb', line 18

def list(calendar_id, max_results: 2500, page_token: nil)
  call(:list_events, calendar_id, max_results: max_results, page_token: page_token)
end

#permit(calendar, user = nil, email: nil) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/google_api/calendar.rb', line 36

def permit(calendar, user = nil, email: nil)
  email ||= user&.email

  rule = Google::Apis::CalendarV3::AclRule.new(
    scope: { type: 'user', value: email }, role: 'writer'
  )

  user&.update(calendar_rule_id: call(:insert_acl, calendar, rule).id)
end

#unpermit(calendar, user = nil, calendar_rule_id: nil) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/google_api/calendar.rb', line 46

def unpermit(calendar, user = nil, calendar_rule_id: nil)
  calendar_rule_id ||= user&.calendar_rule_id

  call(:delete_acl, calendar, calendar_rule_id)
rescue Google::Apis::ClientError
  :permission_not_found
ensure
  user&.update(calendar_rule_id: nil)
end

#update(calendar_id, event_id, event_options = {}) ⇒ Object



26
27
28
# File 'lib/google_api/calendar.rb', line 26

def update(calendar_id, event_id, event_options = {})
  call(:update_event, calendar_id, event_id, event(event_options))
end