Class: Cleversafe::Vault

Inherits:
Object
  • Object
show all
Defined in:
lib/cleversafe/vault.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, name) ⇒ Vault

Returns a new instance of Vault.



5
6
7
8
# File 'lib/cleversafe/vault.rb', line 5

def initialize(connection, name)
  @connection = connection
  @name = name
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



3
4
5
# File 'lib/cleversafe/vault.rb', line 3

def connection
  @connection
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/cleversafe/vault.rb', line 3

def name
  @name
end

Instance Method Details

#bytes_usedObject



14
15
16
# File 'lib/cleversafe/vault.rb', line 14

def bytes_used
  ['vault_usage']['used_size']
end

#create_object(payload, options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/cleversafe/vault.rb', line 31

def create_object(payload, options = {})
  response = connection.put(name, payload, options)
  id = response.to_s.strip

  if response.headers[:x_content_digest]
    { :id => id, :x_content_digest => response.headers[:x_content_digest] }
  else
    id
  end
end

#metadataObject



10
11
12
# File 'lib/cleversafe/vault.rb', line 10

def 
  @metadata ||= JSON.parse connection.get(name).to_s
end

#object(key) ⇒ Object Also known as: []



18
19
20
# File 'lib/cleversafe/vault.rb', line 18

def object(key)
  Cleversafe::Object.new(self, key)
end

#objects(params = {}) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/cleversafe/vault.rb', line 23

def objects(params = {})
  options = {}
  options['X-Operation'] = "list"
  options['X-List-Length-Limit'] = params[:limit] if params[:limit]
  options['X-Start-Id'] = params[:start_id] if params[:start_id]
  connection.get(name, options).to_s.split("\n")
end