forked from nylas/nylas-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrafts.rb
43 lines (33 loc) · 1.2 KB
/
drafts.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
require_relative '../helpers'
# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the Nylas
# Drafts API. See https://docs.nylas.com/reference#drafts 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 drafts
demonstrate { api.drafts.count }
# Retrieving drafts as a collection draft
demonstrate { api.drafts.limit(2).map(&:to_h) }
example_draft = api.drafts.first
# Retrieving a particular drafts
demonstrate { api.drafts.find(example_draft.id) }
# Creating a draft
demonstrate do
example_draft = api.drafts.create(subject: "A new draft!")
example_draft.to_h
end
# Sending a draft
demonstrate do
draft = api.drafts.create(to: [{ email: ENV.fetch('NYLAS_EXAMPLE_EMAIL', '[email protected]')}],
subject: "A new draft!")
draft.send!
end
# Updating a draft
demonstrate do
example_draft.to << { name: "Other person", email: "[email protected]" }
example_draft.save
api.drafts.find(example_draft.id).to.map(&:to_h)
end
# Destroying a draft
demonstrate do
example_draft.destroy
end