Class: Rbox::Response::File

Inherits:
Object
  • Object
show all
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

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

#attributesObject



25
26
27
# File 'lib/rbox/response/items/file.rb', line 25

def attributes
  @attributes
end

#download_urlObject



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_urlObject



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_hashObject



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