forked from nylas/nylas-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessages.rb
48 lines (38 loc) · 1.45 KB
/
messages.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 Nylas
# Messages API. See https://docs.nylas.com/reference#messages for API documentation
api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET'],
access_token: ENV['NYLAS_ACCESS_TOKEN'])
# Retrieving a count of messages
demonstrate { api.messages.count }
# Retrieving a message
demonstrate { api.messages.first.to_h }
# Retrieving an expanded message
demonstrate { api.messages.expanded.first.to_h }
message = api.messages.first
# Retrieving a raw message
demonstrate { api.messages.raw.find(message.id) }
# Starring and marking a message as unread
demonstrate { message.update(starred: true, unread: true) }
reloaded_message = api.messages.first
demonstrate { { starred: reloaded_message.starred, unread: reloaded_message.unread } }
# Messages cannot be created
demonstrate do
begin
api.messages.create
rescue Nylas::ModelNotCreatableError => e
"#{e.class}: #{e.message}"
end
end
# Messages cannot be destroyed
message = api.messages.first
demonstrate do
begin
message.destroy
rescue Nylas::ModelNotDestroyableError => e
"#{e.class}: #{e.message}"
end
end
# Messages may be searched.
# See https://docs.nylas.com/reference#messages-search and https://docs.nylas.com/reference#search
demonstrate { api.messages.search("That really important email").map(&:to_h) }