Class: Nylas::File
Overview
Structure to represent a the File Schema.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
Attributes included from Model
Instance Method Summary collapse
- #create ⇒ Object
-
#download ⇒ Tempfile
Downloads and caches a local copy of the file.
-
#download! ⇒ Object
Redownloads a file even if it's been cached.
- #save ⇒ Object
Methods included from Model
#destroy, #execute, included, #model_class, #persisted?, #reload, #resource_path, #resources_path, #save_all_attributes, #to_json, #update, #update_all_attributes
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
23 24 25 |
# File 'lib/nylas/file.rb', line 23 def file @file end |
Instance Method Details
#create ⇒ Object
43 44 45 |
# File 'lib/nylas/file.rb', line 43 def create save end |
#download ⇒ Tempfile
Downloads and caches a local copy of the file.
27 28 29 30 31 |
# File 'lib/nylas/file.rb', line 27 def download return file if file self.file = retrieve_file end |
#download! ⇒ Object
Redownloads a file even if it's been cached. Closes and unlinks the tempfile to help memory usage.
34 35 36 37 38 39 40 41 |
# File 'lib/nylas/file.rb', line 34 def download! return download if file.nil? file.close file.unlink self.file = nil download end |
#save ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/nylas/file.rb', line 47 def save raise ModelNotUpdatableError if persisted? response = api.execute(path: "/files", method: :post, headers: { multipart: true }, payload: { file: file }) attributes.merge(response.first) true end |