class Box::File
Public Class Methods
delete_existing(id)
click to toggle source
# File lib/box/file.rb, line 36 def self.delete_existing(id) Box.client.delete("files/#{id}") end
download_uri(id, client = Box.client)
click to toggle source
# 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.headers['location'] if response.status == 302 uri end
Public Instance Methods
copy_to(folder, options = {})
click to toggle source
Ruby is such a pain in the ass with it's loosy goosy type @return [Box::File] The newly created file on Box
# 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]} # This response is a Box file object response = @client.post("files/#{id}/copy", params) Box::File.new(@client, response.body) end
download_uri()
click to toggle source
# File lib/box/file.rb, line 12 def download_uri self.class.download_uri(self.id) end
move_to(folder, options = {})
click to toggle source
Since this is just an update, this method is idempotent always returning a file
# 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()
click to toggle source
# File lib/box/file.rb, line 20 def path "/" + path_names.join('/') end
path_names()
click to toggle source
# File lib/box/file.rb, line 32 def path_names paths.map {|path| path['name']} end
path_with_file()
click to toggle source
# File lib/box/file.rb, line 24 def path_with_file ::File.join(path, name) end
paths()
click to toggle source
# File lib/box/file.rb, line 28 def paths @metadata['path_collection']['entries'] end
size()
click to toggle source
# File lib/box/file.rb, line 16 def size @metadata['size'] end