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
#auth_method, #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.
29 30 31 |
# File 'lib/nylas/file.rb', line 29 def file @file end |
Instance Method Details
#create ⇒ Object
49 50 51 |
# File 'lib/nylas/file.rb', line 49 def create save end |
#download ⇒ Tempfile
Downloads and caches a local copy of the file.
33 34 35 36 37 |
# File 'lib/nylas/file.rb', line 33 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.
40 41 42 43 44 45 46 47 |
# File 'lib/nylas/file.rb', line 40 def download! return download if file.nil? file.close file.unlink self.file = nil download end |
#save ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/nylas/file.rb', line 53 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 |