This repository was archived by the owner on Sep 17, 2020. It is now read-only.
forked from nylas/nylas-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevents.rb
More file actions
45 lines (33 loc) · 1.57 KB
/
events.rb
File metadata and controls
45 lines (33 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require_relative '../helpers'
# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the Nylas
# Events API.
# See https://docs.nylas.com/reference#events
api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET'],
access_token: ENV['NYLAS_ACCESS_TOKEN'])
# Counting the events
demonstrate { api.events.count }
# Retrieving a few events
demonstrate { api.events.limit(2).map(&:to_h) }
# Expand recurring events into independent event objects
demonstrate { api.events.expand_recurring.map(&:to_h) }
# Include cancelled events
demonstrate { api.events.show_cancelled.map(&:to_h) }
# Retrieving a particular event
example_event = api.events.last
demonstrate { api.events.find(example_event.id).to_h }
calendar = api.calendars.reject(&:read_only?).first
# Creating an event
demonstrate { api.events.create(title: "A fun event!", location: "The Party Zone", calendar_id: calendar.id,
when: { start_time: Time.now + 60, end_time: Time.now + 120 }).to_h }
example_event = api.events.where(location: "The Party Zone").last
# Updating an event
demonstrate { example_event.update(location: "Somewhere else!") }
demonstrate { api.events.find(example_event.id).location }
# Deleting an event
demonstrate { example_event.destroy }
# RSVPing to an Event
calendar = api.calendars.select { |c| c.name == "Emailed events" }.first
event = calendar.events.first
event.rsvp(:yes, notify_participants: true)
event.rsvp(:no, notify_participants: true)
event.rsvp(:maybe, notify_participants: true)