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:) ⇒ FileVersion


5
6
7
8
9
10
11
# File 'lib/backblaze/b2/file_version.rb', line 5

def initialize(file_id:, size:, upload_timestamp:, action:, file_name:)
  @file_id = file_id
  @size = size
  @action = action
  @file_name = file_name
  @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

#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_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


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

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

#download_urlObject


23
24
25
# File 'lib/backblaze/b2/file_version.rb', line 23

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

#exists?Boolean


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

def exists?
  !@destroyed
end

#get_infoObject


13
14
15
16
17
18
19
20
21
# File 'lib/backblaze/b2/file_version.rb', line 13

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

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