Class: RasperClient::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rasper_client/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Client

Returns a new instance of Client.



7
8
9
10
# File 'lib/rasper_client/client.rb', line 7

def initialize(options)
  @host, @port, @timeout = options.values_at(:host, :port, :timeout)
  @request_params = build_request_params
end

Instance Method Details

#add(options) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/rasper_client/client.rb', line 12

def add(options)
  symbolize_keys(options)
  encode_options(options)
  response = execute_request(:add, options)
  JSON.parse(response.body) == { 'success' => true }
rescue Errno::ECONNREFUSED
  raise ConnectionRefusedError
end

#generate(options) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/rasper_client/client.rb', line 21

def generate(options)
  symbolize_keys(options)
  options = encode_data(options)
  response = execute_request(:generate, options)
  result = JSON.parse(response.body)
  Base64.decode64(result['content'])
end