forked from nylas/nylas-ruby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiles.rb
28 lines (21 loc) · 909 Bytes
/
files.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
require_relative '../helpers'
# An executable specification that demonstrates how to use the Nylas Ruby SDK to interact with the Nylas Files
# API.
# See https://docs.nylas.com/reference#files
api = Nylas::API.new(app_id: ENV['NYLAS_APP_ID'], app_secret: ENV['NYLAS_APP_SECRET'],
access_token: ENV['NYLAS_ACCESS_TOKEN'])
# Listing files
demonstrate { api.files.limit(2).map(&:to_h) }
# Retrieving file metadata
example_file = api.files.first
demonstrate { api.files.find(example_file.id).to_h }
# Downloading a particular file
demonstrate { example_file.download }
# Downloading a particular file is cached. Notice the path didn't change
demonstrate { example_file.download }
# Re-downloading a file, notice the path does change.
demonstrate { example_file.download! }
# Uploading a file
demonstrate do
api.files.create(file: File.open(File.expand_path(__FILE__), 'r')).to_h
end