Class: B2::File

Inherits:
Object
  • Object
show all
Defined in:
lib/b2/file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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_idObject (readonly)

Returns the value of attribute account_id.



4
5
6
# File 'lib/b2/file.rb', line 4

def 
  @account_id
end

#bucket_idObject (readonly)

Returns the value of attribute bucket_id.



4
5
6
# File 'lib/b2/file.rb', line 4

def bucket_id
  @bucket_id
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/b2/file.rb', line 4

def id
  @id
end

#metadataObject (readonly)

Returns the value of attribute metadata.



4
5
6
# File 'lib/b2/file.rb', line 4

def 
  @metadata
end

#mime_typeObject (readonly)

Returns the value of attribute mime_type.



4
5
6
# File 'lib/b2/file.rb', line 4

def mime_type
  @mime_type
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/b2/file.rb', line 4

def name
  @name
end

#sha1Object (readonly)

Returns the value of attribute sha1.



4
5
6
# File 'lib/b2/file.rb', line 4

def sha1
  @sha1
end

#sizeObject (readonly)

Returns the value of attribute size.



4
5
6
# File 'lib/b2/file.rb', line 4

def size
  @size
end

#uploaded_atObject (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