Class: Cleversafe::Connection
- Inherits:
-
Object
- Object
- Cleversafe::Connection
- Defined in:
- lib/cleversafe/connection.rb
Instance Method Summary collapse
- #delete(path) ⇒ Object
- #get(path = '', options = {}) ⇒ Object
- #head(path = '', options = {}) ⇒ Object
-
#initialize(url, options = {}) ⇒ Connection
constructor
A new instance of Connection.
- #ping ⇒ Object
- #put(path, payload, options = {}) ⇒ Object
- #url ⇒ Object
- #url_for(*paths) ⇒ Object
- #vault(name) ⇒ Object
- #vaults ⇒ Object
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, = {}) @http = build_http_client(url, ) 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 = '', = {}) @http[path].get end |
#head(path = '', options = {}) ⇒ Object
35 36 37 |
# File 'lib/cleversafe/connection.rb', line 35 def head(path = '', = {}) @http[path].head end |
#ping ⇒ Object
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, = {}) @http[path].put payload, end |
#url ⇒ Object
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 |
#vaults ⇒ Object
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 |