Class: Backblaze::B2::FileVersion

Inherits:
Base
  • Object
show all
Defined in:
lib/backblaze/b2/file_version.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#get, #head, #post, #put

Methods included from Utils

#camelize, included, #underscore

Constructor Details

#initialize(file_id:, size:, upload_timestamp:, action:, file_name:, content_length:, content_sha1:, content_type:, file_info: {}, **unneeded_args) ⇒ FileVersion

Returns a new instance of FileVersion.



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/backblaze/b2/file_version.rb', line 6

def initialize(file_id:, size:, upload_timestamp:, action:, file_name:,
               content_length:, content_sha1:, content_type:, file_info: {}, **unneeded_args)
  @file_id = file_id
  @size = size
  @action = action
  @file_name = file_name
  @content_length = content_length
  @content_sha1 = content_sha1
  @content_type = content_type
  @file_info = file_info
  @upload_timestamp = Time.at(upload_timestamp / 1000.0)
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



3
4
5
# File 'lib/backblaze/b2/file_version.rb', line 3

def action
  @action
end

#content_lengthObject (readonly)

Returns the value of attribute content_length.



3
4
5
# File 'lib/backblaze/b2/file_version.rb', line 3

def content_length
  @content_length
end

#content_sha1Object (readonly)

Returns the value of attribute content_sha1.



3
4
5
# File 'lib/backblaze/b2/file_version.rb', line 3

def content_sha1
  @content_sha1
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



3
4
5
# File 'lib/backblaze/b2/file_version.rb', line 3

def content_type
  @content_type
end

#file_idObject (readonly)

Returns the value of attribute file_id.



3
4
5
# File 'lib/backblaze/b2/file_version.rb', line 3

def file_id
  @file_id
end

#file_infoObject (readonly)

Returns the value of attribute file_info.



3
4
5
# File 'lib/backblaze/b2/file_version.rb', line 3

def file_info
  @file_info
end

#file_nameObject (readonly)

Returns the value of attribute file_name.



3
4
5
# File 'lib/backblaze/b2/file_version.rb', line 3

def file_name
  @file_name
end

#sizeObject (readonly)

Returns the value of attribute size.



3
4
5
# File 'lib/backblaze/b2/file_version.rb', line 3

def size
  @size
end

#upload_timestampObject (readonly)

Returns the value of attribute upload_timestamp.



3
4
5
# File 'lib/backblaze/b2/file_version.rb', line 3

def upload_timestamp
  @upload_timestamp
end

Instance Method Details

#destroy!Object



33
34
35
36
37
# File 'lib/backblaze/b2/file_version.rb', line 33

def destroy!
  response = post('/b2_delete_file_version', body: { fileName: file_name, fileId: file_id }.to_json)
  raise Backblaze::FileError, response unless response.code == 200
  @destroyed = true
end

#download_urlObject



29
30
31
# File 'lib/backblaze/b2/file_version.rb', line 29

def download_url
  "#{Backblaze::B2.download_url}#{Backblaze::B2.api_path}b2_download_file_by_id?fileId=#{file_id}"
end

#exists?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/backblaze/b2/file_version.rb', line 39

def exists?
  !@destroyed
end

#get_infoObject



19
20
21
22
23
24
25
26
27
# File 'lib/backblaze/b2/file_version.rb', line 19

def get_info
  unless defined?(@get_info)
    response = post('/b2_get_file_info', body: { fileId: file_id }.to_json)
    raise Backblaze::FileError, response unless response.code == 200

    @get_info = Hash[response.map { |k, v| [Backblaze::Utils.underscore(k).to_sym, v] }]
  end
  @get_info
end