Class: Box::Folder

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

Direct Known Subclasses

NullFolder

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(folder) ⇒ Folder

Returns a new instance of Folder


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

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

Instance Attribute Details

#etagObject (readonly)

Returns the value of attribute etag


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

def etag
  @etag
end

#folderObject (readonly)

Returns the value of attribute folder


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

def folder
  @folder
end

#idObject (readonly)

Returns the value of attribute id


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

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name


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

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type


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

def type
  @type
end

Class Method Details

.null_folderObject


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

def self.null_folder
  NullFolder.new
end

Instance Method Details

#filesObject


27
28
29
30
31
# File 'app/services/box/folder.rb', line 27

def files
  client.folder_items(@folder, fields: %i[id name]).files.map { |item| File.new(item) }
rescue StandardError => e
  Rails.logger.error("Box::Folder.files raised #{e}")
end

#foldersObject


21
22
23
24
25
# File 'app/services/box/folder.rb', line 21

def folders
  client.folder_items(@folder, fields: %i[id name]).folders.map { |item| Folder.new(item) }
rescue StandardError => e
  Rails.logger.error("Box::Folder.folders raised #{e}")
end

#upload(filepath) ⇒ Object


33
34
35
36
37
# File 'app/services/box/folder.rb', line 33

def upload(filepath)
  client.upload_file(filepath, @folder)
rescue StandardError => e
  Rails.logger.error("Box::Folder.upload(#{filepath}) raised #{e}")
end