Class: TaaS::TaaSClient

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, timeout_in_seconds = 1000) ⇒ TaaSClient

Returns a new instance of TaaSClient.



12
13
14
15
# File 'lib/taas_client.rb', line 12

def initialize(url, timeout_in_seconds=1000)
  @url = url
  @timeout = timeout_in_seconds * 10000
end

Instance Attribute Details

#timeoutObject

Returns the value of attribute timeout.



10
11
12
# File 'lib/taas_client.rb', line 10

def timeout
  @timeout
end

#urlObject

Returns the value of attribute url.



10
11
12
# File 'lib/taas_client.rb', line 10

def url
  @url
end

Instance Method Details

#execute_contract(params = {}) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/taas_client.rb', line 17

def execute_contract(params={})
  response_body = request_taas_server(params)

  raise "TaaS Request is false" unless OutputParser.valid_server_response?(response_body)

  OutputParser.parse_server_output(response_body)
end

#request_taas_server(params) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/taas_client.rb', line 27

def request_taas_server(params)
  uri = URI.parse(@url)
  http = Net::HTTP.new(uri.host, uri.port)

  request = Net::HTTP::Post.new(uri.request_uri)
  request.set_form_data(params)
  http.read_timeout = @timeout
  http.request(request).body
end