Class: Box::File

Inherits:
Object
  • Object
show all
Defined in:
app/services/box/file.rb

Direct Known Subclasses

NullFile

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ File

Returns a new instance of File


13
14
15
16
17
18
19
# File 'app/services/box/file.rb', line 13

def initialize(file)
  @file = file
  @etag = file[:etag]
  @id = file[:id]
  @name = file[:name]
  @type = file[:type]
end

Instance Attribute Details

#etagObject (readonly)

Returns the value of attribute etag


7
8
9
# File 'app/services/box/file.rb', line 7

def etag
  @etag
end

#fileObject (readonly)

Returns the value of attribute file


7
8
9
# File 'app/services/box/file.rb', line 7

def file
  @file
end

#idObject (readonly)

Returns the value of attribute id


7
8
9
# File 'app/services/box/file.rb', line 7

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name


7
8
9
# File 'app/services/box/file.rb', line 7

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type


7
8
9
# File 'app/services/box/file.rb', line 7

def type
  @type
end

Class Method Details

.null_fileObject


9
10
11
# File 'app/services/box/file.rb', line 9

def self.null_file
  NullFile.new
end

Instance Method Details

#contentObject


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/services/box/file.rb', line 21

def content
  error = nil
  buffer = nil
  3.times do
    next if buffer

    buffer = client.download_file(@file)
  rescue StandardError => e
    error = e
    buffer = nil
  end
  buffer || error
end