Class: Fog::Backblaze::Storage::Files

Inherits:
Collection
  • Object
show all
Defined in:
lib/fog/backblaze/storage/models/files.rb

Instance Method Summary collapse

Instance Method Details

#_headers_to_attrs(file_response) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/fog/backblaze/storage/models/files.rb', line 55

def _headers_to_attrs(file_response)
  {
    'fileName'        => file_response.headers['x-bz-file-name'],
    'fileId'          => file_response.headers['x-bz-file-id'],
    'uploadTimestamp' => file_response.headers['X-Bz-Upload-Timestamp'],
    'contentType'     => file_response.headers['Content-Type'],
    'contentLength'   => file_response.headers['Content-Length']
  }
end

#all(options = {}) ⇒ Object



13
14
15
16
17
18
# File 'lib/fog/backblaze/storage/models/files.rb', line 13

def all(options = {})
  requires :directory

  body = service.list_objects(directory.key, options).body
  load(body["files"] || [])
end

#get(file_name) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/fog/backblaze/storage/models/files.rb', line 20

def get(file_name)
  requires :directory

  file_response = service.get_object(directory.key, file_name)
  file_data = _headers_to_attrs(file_response)

  new(file_data)
end

#get_https_url(file_name, expires, options) ⇒ Object

TODO: download url for private buckets



35
36
37
38
# File 'lib/fog/backblaze/storage/models/files.rb', line 35

def get_https_url(file_name, expires, options)
  requires :directory
  service.get_object_https_url(directory.key, file_name, expires, options)
end

#head(file_name, options = {}) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/fog/backblaze/storage/models/files.rb', line 46

def head(file_name, options = {})
  requires :directory
  data = service.head_object(directory.key, file_name, options)
  file_data = _headers_to_attrs(data)
  new(file_data)
rescue Excon::Errors::NotFound
  nil
end

#head_url(file_name, expires, options = {}) ⇒ Object

TODO: download url for private buckets



41
42
43
44
# File 'lib/fog/backblaze/storage/models/files.rb', line 41

def head_url(file_name, expires, options = {})
  requires :directory
  service.get_object_https_url(directory.key, key, expires, options)
end

#new(attributes = {}) ⇒ Object



29
30
31
32
# File 'lib/fog/backblaze/storage/models/files.rb', line 29

def new(attributes = {})
  requires :directory
  super({directory: directory}.merge!(attributes))
end