Class: Rbox::Response::File
- Inherits:
-
Object
- Object
- Rbox::Response::File
- Defined in:
- lib/rbox/response/items/file.rb
Constant Summary collapse
- ATTRIBUTES =
%w(id file_name shared sha1 size shared_link description user_id thumbnail small_thumbnail large_thumbnail larger_thumbnail preview_thumbnail permissions tags)
Instance Method Summary collapse
- #attributes ⇒ Object
- #download_url ⇒ Object
-
#initialize(attributes, client, parent_folder = nil) ⇒ File
constructor
A new instance of File.
- #public_share! ⇒ Object
- #public_share_url ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(attributes, client, parent_folder = nil) ⇒ File
Returns a new instance of File.
19 20 21 22 23 |
# File 'lib/rbox/response/items/file.rb', line 19 def initialize(attributes, client, parent_folder = nil) @attributes = attributes.dup @client = client @parent_folder = parent_folder end |
Instance Method Details
#attributes ⇒ Object
25 26 27 |
# File 'lib/rbox/response/items/file.rb', line 25 def attributes @attributes end |
#download_url ⇒ Object
29 30 31 |
# File 'lib/rbox/response/items/file.rb', line 29 def download_url @client.download_url(id) end |
#public_share! ⇒ Object
35 36 37 38 |
# File 'lib/rbox/response/items/file.rb', line 35 def public_share! @public_name ||= @client.public_share(self.id, 'file') true end |
#public_share_url ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/rbox/response/items/file.rb', line 40 def public_share_url if @public_link.nil? || @public_link.empty? public_share! "https://www.box.net/s/#{@public_name}" else @public_link end end |
#to_hash ⇒ Object
49 50 51 52 53 54 |
# File 'lib/rbox/response/items/file.rb', line 49 def to_hash hash = ATTRIBUTES.inject({}) {|h,k,v| h[k.to_sym]= @attributes[k]; h } hash[:type] = 'file' hash[:parent_folder_id] = @parent_folder.id if @parent_folder hash end |