forked from nylas/nylas-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththreads.rb
48 lines (35 loc) · 1.35 KB
/
threads.rb
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
45
46
47
require_relative '../helpers'
# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the API. It
# follows the rough structure of the [Nylas API Reference](https://docs.nylas.com/reference).
api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET'],
access_token: ENV['NYLAS_ACCESS_TOKEN'])
# How many threads are there?
demonstrate { api.threads.count }
thread = api.threads.first
# Threads have quite a bit of information
demonstrate { thread.to_h }
# Threads may be expanded
# demonstrate { api.threads.expanded.first }
# Threads may have their unread/starred statuses updated
demonstrate { thread.update(starred: true, unread: true) }
reloaded_thread = api.threads.first
demonstrate { { starred: reloaded_thread.starred, unread: reloaded_thread.unread } }
# Threads cannot be created
demonstrate do
begin
api.threads.create
rescue Nylas::ModelNotCreatableError => e
"#{e.class}: #{e.message}"
end
end
# Threads may not be destroyed
demonstrate do
begin
thread.destroy
rescue Nylas::ModelNotDestroyableError => e
"#{e.class}: #{e.message}"
end
end
# Threads may be searched.
# See https://docs.nylas.com/reference#search-threads and https://docs.nylas.com/reference#search
demonstrate { api.threads.search("That really important email").map(&:to_h) }