class Seaweed::File
Attributes
attachment[R]
id[R]
name[R]
size[R]
volume_id[R]
volume_url[R]
Public Class Methods
new(fid, volume_url: nil, attachment: nil)
click to toggle source
# File lib/seaweed/file.rb, line 5 def initialize(fid, volume_url: nil, attachment: nil) @id = fid @volume_id, @key, @cookie = fid.match(/^(\d),(\w\w)(\w+)$/).captures @volume_url = volume_url @attachment = attachment end
Public Instance Methods
delete!()
click to toggle source
# File lib/seaweed/file.rb, line 20 def delete! res = Seaweed::HTTP.delete url !(Seaweed::HTTP.parse(res)[:size].nil?) end
pretty_url()
click to toggle source
# File lib/seaweed/file.rb, line 33 def pretty_url "#{@volume_url}/#{@volume_id}/#{@key}#{@cookie}/#{@name}" end
read()
click to toggle source
# File lib/seaweed/file.rb, line 25 def read Seaweed::HTTP.get url end
upload!()
click to toggle source
# File lib/seaweed/file.rb, line 12 def upload! response = Seaweed::HTTP.put url, file: File.new(@attachment, 'rb') data = Seaweed::HTTP.parse response @name = data[:name] @size = data[:size] self end
url()
click to toggle source
# File lib/seaweed/file.rb, line 29 def url "#{@volume_url}/#{@id}" end