Class: K3cloud::WebApiClient

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

Direct Known Subclasses

K3cloudApi

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = Configuration.default) ⇒ WebApiClient

Returns a new instance of WebApiClient.



15
16
17
# File 'lib/k3cloud/web_api_client.rb', line 15

def initialize(config = Configuration.default)
  @config = config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



13
14
15
# File 'lib/k3cloud/web_api_client.rb', line 13

def config
  @config
end

Instance Method Details

#execute(service_name, parameters) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/k3cloud/web_api_client.rb', line 19

def execute(service_name, parameters)
  result = execute_json(service_name, parameters)
  if result.start_with?("response_error:")
    error = K3cloudError.parse(result)
    raise K3cloud::ResponseError, result if error.nil?

    message = error.inner_ex_wrapper.nil? ? error.message : "#{error.message} --> #{error.inner_ex_wrapper&.message}"
    raise K3cloud::ResponseError, message

  else
    begin
      JSON.parse(result)
    rescue JSON::ParserError
      raise K3cloud::ResponseError, "JSON parse error, response: [#{result}]"
    end
  end
end