Class: Cleversafe::Connection

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

Instance Method Summary collapse

Constructor Details

#initialize(url, options = {}) ⇒ Connection

Returns a new instance of Connection.



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

def initialize(url, options = {})
  @http = build_http_client(url, options)
end

Instance Method Details

#delete(path) ⇒ Object



47
48
49
# File 'lib/cleversafe/connection.rb', line 47

def delete(path)
  @http[path].delete
end

#get(path = '', options = {}) ⇒ Object



39
40
41
# File 'lib/cleversafe/connection.rb', line 39

def get(path = '', options = {})
  @http[path].get options
end

#head(path = '', options = {}) ⇒ Object



35
36
37
# File 'lib/cleversafe/connection.rb', line 35

def head(path = '', options = {})
  @http[path].head options
end

#pingObject



28
29
30
31
32
33
# File 'lib/cleversafe/connection.rb', line 28

def ping
  head
  true
rescue RestClient::Exception
  false
end

#put(path, payload, options = {}) ⇒ Object



43
44
45
# File 'lib/cleversafe/connection.rb', line 43

def put(path, payload, options = {})
  @http[path].put payload, options
end

#urlObject



9
10
11
# File 'lib/cleversafe/connection.rb', line 9

def url
  @http.url
end

#url_for(*paths) ⇒ Object



13
14
15
# File 'lib/cleversafe/connection.rb', line 13

def url_for(*paths)
  [ url, *paths ].join('/')
end

#vault(name) ⇒ Object



17
18
19
# File 'lib/cleversafe/connection.rb', line 17

def vault(name)
  Cleversafe::Vault.new(self, name)
end

#vaultsObject



21
22
23
24
25
26
# File 'lib/cleversafe/connection.rb', line 21

def vaults
  @vaults ||= begin
    data = JSON.parse get.to_s
    data['vaults'].map { |v| v['vault_name'] }
  end
end