Class: Seaweed::File
- Inherits:
-
Object
- Object
- Seaweed::File
- Defined in:
- lib/seaweed/file.rb
Instance Attribute Summary collapse
-
#attachment ⇒ Object
readonly
Returns the value of attribute attachment.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#volume_id ⇒ Object
readonly
Returns the value of attribute volume_id.
-
#volume_url ⇒ Object
readonly
Returns the value of attribute volume_url.
Instance Method Summary collapse
- #delete! ⇒ Object
-
#initialize(fid, volume_url: nil, attachment: nil) ⇒ File
constructor
A new instance of File.
- #pretty_url ⇒ Object
- #read ⇒ Object
- #upload! ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(fid, volume_url: nil, attachment: nil) ⇒ File
Returns a new instance of File.
5 6 7 8 9 10 |
# 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 = end |
Instance Attribute Details
#attachment ⇒ Object (readonly)
Returns the value of attribute attachment.
3 4 5 |
# File 'lib/seaweed/file.rb', line 3 def @attachment end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/seaweed/file.rb', line 3 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/seaweed/file.rb', line 3 def name @name end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
3 4 5 |
# File 'lib/seaweed/file.rb', line 3 def size @size end |
#volume_id ⇒ Object (readonly)
Returns the value of attribute volume_id.
3 4 5 |
# File 'lib/seaweed/file.rb', line 3 def volume_id @volume_id end |
#volume_url ⇒ Object (readonly)
Returns the value of attribute volume_url.
3 4 5 |
# File 'lib/seaweed/file.rb', line 3 def volume_url @volume_url end |
Instance Method Details
#delete! ⇒ Object
20 21 22 23 |
# File 'lib/seaweed/file.rb', line 20 def delete! res = Seaweed::HTTP.delete url !(Seaweed::HTTP.parse(res)[:size].nil?) end |
#pretty_url ⇒ Object
33 34 35 |
# File 'lib/seaweed/file.rb', line 33 def pretty_url "#{@volume_url}/#{@volume_id}/#{@key}#{@cookie}/#{@name}" end |
#upload! ⇒ Object
12 13 14 15 16 17 18 |
# 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 ⇒ Object
29 30 31 |
# File 'lib/seaweed/file.rb', line 29 def url "#{@volume_url}/#{@id}" end |