Class: K3cloud::WebApiClient

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

Direct Known Subclasses

K3cloudApi

Constant Summary collapse

ERROR_MARKERS =

金蝶 ExecuteBillQuery/ResponseError 中标识错误的关键字

%w[Message InnerExWrapper InnerException].freeze
XOR_SEC_KEY =

金蝶 app_id 内嵌 secret 的 XOR 密钥,协议固定值,来源见 README。 https://vip.kingdee.com/article/163905337846351872?productLineId=1

"0054f397c6234378b09ca7d3e5debce7"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = Configuration.default) ⇒ WebApiClient

Returns a new instance of WebApiClient.



24
25
26
27
# File 'lib/k3cloud/web_api_client.rb', line 24

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

Instance Attribute Details

#configObject

Returns the value of attribute config.



22
23
24
# File 'lib/k3cloud/web_api_client.rb', line 22

def config
  @config
end

Instance Method Details

#execute(service_name, parameters) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/k3cloud/web_api_client.rb', line 29

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

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

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