Class: GoogleCalendarAbilities::UserCalendar

Inherits:
Object
  • Object
show all
Defined in:
src/abilities/google_calendar_abilities.rb

Instance Method Summary collapse

Instance Method Details

#create_event(title, start_time, end_time, invite_emails: [], send_updates: true) ⇒ Google::Apis::CalendarV3::Event

Create a new calendar event

Parameters:

  • title (String)

    The event title

  • start_time (Time)

    The event start time

  • end_time (Time)

    The event end time

  • invite_emails (Array<String>)

    Emails of attendees to invite

  • send_updates (Boolean)

    Send email notifications to the attendees?

Returns:

  • (Google::Apis::CalendarV3::Event)

    The newly created event.

See Also:



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

Parameters:

  • event (Google::Apis::CalendarV3::Event)

    The event to delete

See Also:



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

Parameters:

  • limit (Integer)

    The number of events to fetch

Returns:

  • (Array<Google::Apis::CalendarV3::Event>)

See Also:



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

Parameters:

  • query (String)

    The query text

  • future (Boolean)

    Search only for future events

Returns:

  • (Array<Google::Apis::CalendarV3::Event>)

    The events.

See Also:



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