Class: Nylas::File

Inherits:
Object
  • Object
show all
Includes:
Model
Defined in:
lib/nylas/file.rb

Overview

Structure to represent a the File Schema.

Direct Known Subclasses

NeuralOcr

Instance Attribute Summary collapse

Attributes included from Model

#api

Instance Method Summary collapse

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

#fileObject

Returns the value of attribute file.



23
24
25
# File 'lib/nylas/file.rb', line 23

def file
  @file
end

Instance Method Details

#createObject



43
44
45
# File 'lib/nylas/file.rb', line 43

def create
  save
end

#downloadTempfile

Downloads and caches a local copy of the file.

Returns:

  • (Tempfile)
    • 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

#saveObject



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