Class: Box::File
Overview
Represents a file stored on Box. Any attributes or actions typical to a Box file can be accessed through this class.
Instance Attribute Summary
Attributes inherited from Item
Class Method Summary collapse
-
.type ⇒ String
The string representation of this item.
Instance Method Summary collapse
-
#add_comment(message) ⇒ Comment
Add a comment to the file.
-
#download(path) ⇒ Object
Download this file to the specified path.
-
#embed_code(options = Hash.new) ⇒ String
Request the HTML embed code for this file.
-
#get_comments ⇒ Array
Get the comments left on this file.
-
#upload_copy(path) ⇒ File
Upload a new copy of this file.
-
#upload_overwrite(path) ⇒ File
Overwrite this file, using the file at the specified path.
Methods inherited from Item
#copy, #delete, #force_cached_info, #id, #info, #initialize, #method_missing, #move, #path, #rename, #respond_to?, #set_description, #share_private, #share_public, #type, #types, types, #unshare
Constructor Details
This class inherits a constructor from Box::Item
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Box::Item
Class Method Details
.type ⇒ String
Returns The string representation of this item.
9 |
# File 'lib/box/file.rb', line 9 def self.type; 'file'; end |
Instance Method Details
#add_comment(message) ⇒ Comment
Add a comment to the file.
57 58 59 60 61 |
# File 'lib/box/file.rb', line 57 def add_comment() response = @api.add_comment(type, id, ) Comment.create(@api, response['comment']).first end |
#download(path) ⇒ Object
Download this file to the specified path.
14 15 16 |
# File 'lib/box/file.rb', line 14 def download(path) @api.download(path, id) end |
#embed_code(options = Hash.new) ⇒ String
This function will share the file if it is not already shared.
Request the HTML embed code for this file.
71 72 73 74 75 76 77 78 |
# File 'lib/box/file.rb', line 71 def ( = Hash.new) begin @api.(id, )['file_embed_html'] rescue Api::NotShared share_public retry end end |
#get_comments ⇒ Array
Get the comments left on this file.
46 47 48 49 50 51 52 |
# File 'lib/box/file.rb', line 46 def get_comments comments = @api.get_comments(type, id)['comments'] comments = Comment.create(@api, comments['comment']) if comments @data['comments'] = comments || Array.new end |
#upload_copy(path) ⇒ File
Upload a new copy of this file. The name will be “file (#).ext” for the each additional copy.
36 37 38 39 40 41 |
# File 'lib/box/file.rb', line 36 def upload_copy(path) info = @api.new_copy(path, id)['files']['file'] parent.delete_info('files') self.class.new(api, parent, info) end |
#upload_overwrite(path) ⇒ File
Overwrite this file, using the file at the specified path
22 23 24 25 26 27 28 29 |
# File 'lib/box/file.rb', line 22 def upload_overwrite(path) info = @api.overwrite(path, id)['files']['file'] clear_info update_info(info) self end |