Class: Box::File
Instance Attribute Summary
Attributes inherited from Item
#client, #metadata
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Item
#file?, find, #folder?, #initialize, type
Constructor Details
This class inherits a constructor from Box::Item
Class Method Details
.delete_existing(id) ⇒ Object
36
37
38
|
# File 'lib/box/file.rb', line 36
def self.delete_existing(id)
Box.client.delete("files/#{id}")
end
|
.download_uri(id, client = Box.client) ⇒ Object
5
6
7
8
9
10
|
# File 'lib/box/file.rb', line 5
def self.download_uri(id, client = Box.client)
response = client.get("/files/#{id}/content")
uri = nil
uri = response.['location'] if response.status == 302
uri
end
|
Instance Method Details
#copy_to(folder, options = {}) ⇒ Box::File
Ruby is such a pain in the ass with it’s loosy goosy type
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/box/file.rb', line 43
def copy_to(folder, options = {})
raise Box::ArgumentError, 'folder must be a Box::Folder' unless folder.is_a?(Box::Folder)
raise Box::ArgumentError, 'options must be a Hash' unless options.is_a?(Hash)
folder_id = folder.id
params = {parent: {id: folder_id}, name: options[:name]}
response = @client.post("files/#{id}/copy", params)
Box::File.new(@client, response.body)
end
|
#download_uri ⇒ Object
12
13
14
|
# File 'lib/box/file.rb', line 12
def download_uri
self.class.download_uri(self.id)
end
|
#move_to(folder, options = {}) ⇒ Object
Since this is just an update, this method is idempotent always returning a file
56
57
58
59
60
61
|
# File 'lib/box/file.rb', line 56
def move_to(folder, options = {})
folder_id = (folder.is_a?(Box::Folder)) ? folder.id : folder
response = @client.put("files/#{id}", parent:{id: folder_id})
Box::File.new(@client, response.body)
end
|
#path ⇒ Object
20
21
22
|
# File 'lib/box/file.rb', line 20
def path
"/" + path_names.join('/')
end
|
#path_names ⇒ Object
32
33
34
|
# File 'lib/box/file.rb', line 32
def path_names
paths.map {|path| path['name']}
end
|
#path_with_file ⇒ Object
24
25
26
|
# File 'lib/box/file.rb', line 24
def path_with_file
::File.join(path, name)
end
|
#paths ⇒ Object
28
29
30
|
# File 'lib/box/file.rb', line 28
def paths
@metadata['path_collection']['entries']
end
|
#size ⇒ Object
16
17
18
|
# File 'lib/box/file.rb', line 16
def size
@metadata['size']
end
|