Class: Evervault::Client
- Inherits:
-
Object
- Object
- Evervault::Client
- Defined in:
- lib/evervault/client.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
- #configure {|config| ... } ⇒ Object
- #create_run_token(function_name, data = {}) ⇒ Object
- #create_token(action, data, expiry = nil) ⇒ Object
- #decrypt(data) ⇒ Object
- #enable_outbound_relay(decryption_domains = nil) ⇒ Object
- #encrypt(data, role = nil) ⇒ Object
-
#initialize(app_uuid:, api_key:, **options, &block) ⇒ Client
constructor
A new instance of Client.
- #run(function_name, payload) ⇒ Object
Constructor Details
#initialize(app_uuid:, api_key:, **options, &block) ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 19 |
# File 'lib/evervault/client.rb', line 14 def initialize(app_uuid:, api_key:, **, &block) @config = Evervault::Config.new(app_id: app_uuid, api_key: api_key) (**) if .any? intercept.setup configure(&block) if block_given? end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
12 13 14 |
# File 'lib/evervault/client.rb', line 12 def config @config end |
Instance Method Details
#configure {|config| ... } ⇒ Object
61 62 63 |
# File 'lib/evervault/client.rb', line 61 def configure yield(config) end |
#create_run_token(function_name, data = {}) ⇒ Object
49 50 51 |
# File 'lib/evervault/client.rb', line 49 def create_run_token(function_name, data = {}) request_handler.post("v2/functions/#{function_name}/run-token", data) end |
#create_token(action, data, expiry = nil) ⇒ Object
35 36 37 38 |
# File 'lib/evervault/client.rb', line 35 def create_token(action, data, expiry = nil) payload = { payload: data, expiry: expiry, action: action } request_handler.post('client-side-tokens', payload, true, Evervault::Errors::ErrorMap) end |
#decrypt(data) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/evervault/client.rb', line 25 def decrypt(data) unless data.is_a?(String) || data.is_a?(Array) || data.is_a?(Hash) raise Evervault::Errors::EvervaultError, 'data is of invalid type' end payload = { data: data } response = request_handler.post('decrypt', payload, true, Evervault::Errors::ErrorMap) response['data'] end |
#enable_outbound_relay(decryption_domains = nil) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/evervault/client.rb', line 53 def enable_outbound_relay(decryption_domains = nil) if decryption_domains.nil? intercept.setup_outbound_relay_config else intercept.setup_decryption_domains(decryption_domains) end end |
#encrypt(data, role = nil) ⇒ Object
21 22 23 |
# File 'lib/evervault/client.rb', line 21 def encrypt(data, role = nil) crypto_client.encrypt(data, role) end |
#run(function_name, payload) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/evervault/client.rb', line 40 def run(function_name, payload) payload = { payload: payload } res = request_handler.post("functions/#{function_name}/runs", payload, true, Evervault::Errors::ErrorMap) return res if res['status'] == 'success' Evervault::Errors::ErrorMap.raise_function_error_on_failure(res) end |