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)
-
+ (String) type
The string representation of this item.
Instance Method Summary (collapse)
-
- (Comment) add_comment(message)
Add a comment to the file.
-
- (Object) download(path)
Download this file to the specified path.
-
- (String) embed_code(options = Hash.new)
Request the HTML embed code for this file.
-
- (Array) get_comments
Get the comments left on this file.
-
- (File) upload_copy(path)
Upload a new copy of this file.
-
- (File) upload_overwrite(path)
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
+ (String) type
The string representation of this item.
9 |
# File 'lib/box/file.rb', line 9 def self.type; 'file'; end |
Instance Method Details
- (Comment) add_comment(message)
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 |
- (Object) download(path)
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 |
- (String) embed_code(options = Hash.new)
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 |
- (Array) get_comments
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 |
- (File) upload_copy(path)
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 |
- (File) upload_overwrite(path)
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 |