Class: ContextHubVault::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/context_hub_vault/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(host: ContextHubVault.host, auth_token: ContextHubVault.auth_token, version: ContextHubVault.version, app_id: ContextHubVault.app_id) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
14
15
16
17
# File 'lib/context_hub_vault/client.rb', line 8

def initialize(host: ContextHubVault.host, auth_token: ContextHubVault.auth_token, version: ContextHubVault.version, app_id: ContextHubVault.app_id)
  if http_prefix(host)
    self.class.base_uri "#{host}/api"
  else
    self.class.base_uri "https://#{host}/api"
  end
  self.class.headers('Authorization' => %Q[Token token="#{auth_token}"]) if auth_token
  self.class.headers('Accept' => "application/vnd.carbon.vault.v#{version}") if version
  self.class.headers('HTTP_CARBON_APP_ID' => app_id) if app_id
end

Instance Method Details

#create(container, data = {}) ⇒ Hash

Create new vault data

Parameters:

  • container (String)

    The name of the vault container

  • data (Hash) (defaults to: {})

    A hash of key/value pairs to store in the vault

Returns:

  • (Hash)

    The newly created vault



41
42
43
44
45
46
# File 'lib/context_hub_vault/client.rb', line 41

def create(container, data = {})
  fail 'Must include the container' unless container

  data.merge! container: container
  post '/vaults', body: data
end

#destroy(id, data = {}) ⇒ Object

Delete a vault by vault_id

Parameters:

  • id (String)

    vault_id



60
61
62
# File 'lib/context_hub_vault/client.rb', line 60

def destroy(id, data = {})
  delete "/vaults/#{id}"
end

#find_by_id(id) ⇒ Hash

Find a vault by it’s vault_id

Parameters:

  • id (String)

    vault_id

Returns:

  • (Hash)

    The full vault data structure that matches the vault_id



23
24
25
# File 'lib/context_hub_vault/client.rb', line 23

def find_by_id(id)
  search('vault_info.vault_id' => id).first
end

#search(query = {}) ⇒ Array

Search the vault for items that match your query params

Parameters:

  • query (Hash) (defaults to: {})

    search by keyword

  • query (String) (defaults to: {})

    javascript language search

Returns:

  • (Array)

    An array of the matching search results



32
33
34
# File 'lib/context_hub_vault/client.rb', line 32

def search(query = {})
  get '/vaults', body: { query: query }
end

#update(id, data = {}) ⇒ Hash

Update vault data

Parameters:

  • id (String)

    vault_id

  • data (Hash) (defaults to: {})

    Data to update the vault with

Returns:

  • (Hash)

    The updated vault data structure



53
54
55
# File 'lib/context_hub_vault/client.rb', line 53

def update(id, data = {})
  patch "/vaults/#{id}", body: data
end