Class: GoogleCalendarAbilities::UserCalendar
- Inherits:
-
Object
- Object
- GoogleCalendarAbilities::UserCalendar
- Defined in:
- src/abilities/google_calendar_abilities.rb
Instance Method Summary collapse
-
#create_event(title, start_time, end_time, invite_emails: [], send_updates: true) ⇒ Google::Apis::CalendarV3::Event
Create a new calendar event.
-
#delete_event(event, send_updates:) ⇒ void
Delete calendar event.
-
#next_events(limit: n) ⇒ Array<Google::Apis::CalendarV3::Event>
Get a number of upcoming events, ordered by start time.
-
#search_events(query, future: true) ⇒ Array<Google::Apis::CalendarV3::Event>
Search calendar events matching a query.
Instance Method Details
#create_event(title, start_time, end_time, invite_emails: [], send_updates: true) ⇒ Google::Apis::CalendarV3::Event
Create a new calendar event
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'src/abilities/google_calendar_abilities.rb', line 54 def create_event(title, start_time, end_time, invite_emails: [], send_updates: true) @calendar.insert_event( @calendar_id, Google::Apis::CalendarV3::Event.new( guests_can_modify: true, summary: title, start: Google::Apis::CalendarV3::EventDateTime.new( date_time: start_time.iso8601 ), end: Google::Apis::CalendarV3::EventDateTime.new( date_time: end_time.iso8601 ), attendees: invite_emails.map { |email| Google::Apis::CalendarV3::EventAttendee.new(email: email) } ), send_updates: send_updates ? 'all' : 'none' ) end |
#delete_event(event, send_updates:) ⇒ void
This method returns an undefined value.
Delete calendar event
100 101 102 |
# File 'src/abilities/google_calendar_abilities.rb', line 100 def delete_event(event, send_updates:) @calendar.delete_event(@calendar_id, event.id, send_updates: send_updates ? 'all' : 'none') end |
#next_events(limit: n) ⇒ Array<Google::Apis::CalendarV3::Event>
Get a number of upcoming events, ordered by start time
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'src/abilities/google_calendar_abilities.rb', line 110 def next_events(limit: n) @calendar.fetch_all do |page_token| @calendar.list_events( @calendar_id, max_results: n, single_events: true, order_by: 'startTime', time_min: Time.now.iso8601, page_token: page_token, fields: 'items(id,summary,start),next_page_token' ) end.to_a end |
#search_events(query, future: true) ⇒ Array<Google::Apis::CalendarV3::Event>
Search calendar events matching a query
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'src/abilities/google_calendar_abilities.rb', line 79 def search_events(query, future: true) @calendar.fetch_all do |page_token| @calendar.list_events( @calendar_id, q: query, max_results: 100, single_events: true, order_by: 'startTime', time_min: future ? Time.now.iso8601 : nil, page_token: page_token, fields: 'items(id,summary,start),next_page_token' ) end.to_a end |