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
# File 'lib/rasper_client/client.rb', line 7

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

Instance Method Details

#add(options) ⇒ Object



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

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



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

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