Class: Leash::CalendarClient

Inherits:
Object
  • Object
show all
Defined in:
lib/leash/calendar.rb

Overview

Client for Google Calendar operations via the Leash platform proxy.

Not instantiated directly – use Integrations#calendar instead.

Constant Summary collapse

PROVIDER =
"google_calendar"

Instance Method Summary collapse

Constructor Details

#initialize(call_fn) ⇒ CalendarClient

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of CalendarClient.



11
12
13
# File 'lib/leash/calendar.rb', line 11

def initialize(call_fn)
  @call = call_fn
end

Instance Method Details

#create_event(summary:, start:, end_time:, calendar_id: nil, description: nil, location: nil, attendees: nil) ⇒ Hash

Create a new calendar event.

Parameters:

  • summary (String)

    event title

  • start (Hash, String)

    start time – either an RFC 3339 string or a hash with keys “dateTime”, “date”, and/or “timeZone”

  • end_time (Hash, String)

    end time (same format as start)

  • calendar_id (String, nil) (defaults to: nil)

    calendar identifier (defaults to “primary”)

  • description (String, nil) (defaults to: nil)

    event description

  • location (String, nil) (defaults to: nil)

    event location

  • attendees (Array<Hash>, nil) (defaults to: nil)

    list of attendee hashes (e.g. [{ “email” => “a@b.com” }])

Returns:

  • (Hash)

    the created event object



53
54
55
56
57
58
59
60
# File 'lib/leash/calendar.rb', line 53

def create_event(summary:, start:, end_time:, calendar_id: nil, description: nil, location: nil, attendees: nil)
  params = { "summary" => summary, "start" => start, "end" => end_time }
  params["calendarId"] = calendar_id if calendar_id
  params["description"] = description if description
  params["location"] = location if location
  params["attendees"] = attendees if attendees
  @call.call(PROVIDER, "create-event", params)
end

#get_event(event_id, calendar_id: nil) ⇒ Hash

Get a single event by ID.

Parameters:

  • event_id (String)

    the event identifier

  • calendar_id (String, nil) (defaults to: nil)

    the calendar identifier

Returns:

  • (Hash)

    the event object



67
68
69
70
71
# File 'lib/leash/calendar.rb', line 67

def get_event(event_id, calendar_id: nil)
  params = { "eventId" => event_id }
  params["calendarId"] = calendar_id if calendar_id
  @call.call(PROVIDER, "get-event", params)
end

#list_calendarsHash

List all calendars accessible to the user.

Returns:

  • (Hash)

    hash with calendar list data



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

def list_calendars
  @call.call(PROVIDER, "list-calendars", {})
end

#list_events(calendar_id: nil, time_min: nil, time_max: nil, max_results: nil, single_events: nil, order_by: nil) ⇒ Hash

List events on a calendar.

Parameters:

  • calendar_id (String, nil) (defaults to: nil)

    calendar identifier (defaults to “primary” on the server)

  • time_min (String, nil) (defaults to: nil)

    lower bound for event start time (RFC 3339)

  • time_max (String, nil) (defaults to: nil)

    upper bound for event start time (RFC 3339)

  • max_results (Integer, nil) (defaults to: nil)

    maximum number of events to return

  • single_events (Boolean, nil) (defaults to: nil)

    whether to expand recurring events

  • order_by (String, nil) (defaults to: nil)

    sort order (e.g. “startTime”, “updated”)

Returns:

  • (Hash)

    hash with “items” list of events



31
32
33
34
35
36
37
38
39
40
# File 'lib/leash/calendar.rb', line 31

def list_events(calendar_id: nil, time_min: nil, time_max: nil, max_results: nil, single_events: nil, order_by: nil)
  params = {}
  params["calendarId"] = calendar_id if calendar_id
  params["timeMin"] = time_min if time_min
  params["timeMax"] = time_max if time_max
  params["maxResults"] = max_results if max_results
  params["singleEvents"] = single_events unless single_events.nil?
  params["orderBy"] = order_by if order_by
  @call.call(PROVIDER, "list-events", params)
end