Class: B2::File
- Inherits:
-
Object
- Object
- B2::File
- Defined in:
- lib/b2/file.rb
Instance Attribute Summary collapse
-
#account_id ⇒ Object
readonly
Returns the value of attribute account_id.
-
#bucket_id ⇒ Object
readonly
Returns the value of attribute bucket_id.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#mime_type ⇒ Object
readonly
Returns the value of attribute mime_type.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sha1 ⇒ Object
readonly
Returns the value of attribute sha1.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#uploaded_at ⇒ Object
readonly
Returns the value of attribute uploaded_at.
Class Method Summary collapse
Instance Method Summary collapse
- #delete! ⇒ Object
-
#initialize(attrs, connection) ⇒ File
constructor
A new instance of File.
Constructor Details
#initialize(attrs, connection) ⇒ File
Returns a new instance of File.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/b2/file.rb', line 6 def initialize(attrs, connection) @id = attrs['fileId'] @name = B2::File.decode_filename(attrs['fileName']) @account_id = attrs['accountId'] @bucket_id = attrs['bucketId'] @size = attrs['contentLength'] @sha1 = attrs['contentSha1'] @mime_type = attrs['contentType'] @uploaded_at = attrs['uploadTimestamp'] @metadata = attrs['fileInfo'] @connection = connection end |
Instance Attribute Details
#account_id ⇒ Object (readonly)
Returns the value of attribute account_id.
4 5 6 |
# File 'lib/b2/file.rb', line 4 def account_id @account_id end |
#bucket_id ⇒ Object (readonly)
Returns the value of attribute bucket_id.
4 5 6 |
# File 'lib/b2/file.rb', line 4 def bucket_id @bucket_id end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/b2/file.rb', line 4 def id @id end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
4 5 6 |
# File 'lib/b2/file.rb', line 4 def @metadata end |
#mime_type ⇒ Object (readonly)
Returns the value of attribute mime_type.
4 5 6 |
# File 'lib/b2/file.rb', line 4 def mime_type @mime_type end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/b2/file.rb', line 4 def name @name end |
#sha1 ⇒ Object (readonly)
Returns the value of attribute sha1.
4 5 6 |
# File 'lib/b2/file.rb', line 4 def sha1 @sha1 end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
4 5 6 |
# File 'lib/b2/file.rb', line 4 def size @size end |
#uploaded_at ⇒ Object (readonly)
Returns the value of attribute uploaded_at.
4 5 6 |
# File 'lib/b2/file.rb', line 4 def uploaded_at @uploaded_at end |
Class Method Details
.decode_filename(str) ⇒ Object
24 25 26 |
# File 'lib/b2/file.rb', line 24 def self.decode_filename(str) URI.decode_www_form_component(str, Encoding::UTF_8) end |
.encode_filename(str) ⇒ Object
20 21 22 |
# File 'lib/b2/file.rb', line 20 def self.encode_filename(str) URI.encode_www_form_component(str.force_encoding(Encoding::UTF_8)).gsub("%2F", "/") end |
Instance Method Details
#delete! ⇒ Object
28 29 30 31 32 33 |
# File 'lib/b2/file.rb', line 28 def delete! @connection.post('/b2api/v1/b2_delete_file_version', { fileId: @id, fileName: @name }) end |