lib/aliyun/connector/rpc_client.rb in aliyun-rails-0.1.21 vs lib/aliyun/connector/rpc_client.rb in aliyun-rails-0.1.22
- old
+ new
@@ -1,22 +1,24 @@
+# frozen_string_literal: true
+
require "set"
require "openssl"
require "faraday"
require "active_support/all"
module Aliyun
module Connector
class RPCClient
-
attr_accessor :endpoint, :api_version, :access_key_id, :access_key_secret,
:security_token, :codes, :opts, :verbose
# 对象初始化属性
def initialize(config, verbose = false)
-
+ # 参数校验
validate config
+ # 相关属性
self.endpoint = config[:endpoint]
self.api_version = config[:api_version]
self.access_key_id = config[:access_key_id] || Aliyun.access_key_id
self.access_key_secret = config[:access_key_secret] || Aliyun.access_key_secret
self.security_token = config[:security_token]
@@ -61,10 +63,11 @@
response_body = JSON.parse(response.body)
if response_body["Code"] && !response_body["Code"].to_s.empty? && !self.codes.include?(response_body["Code"])
raise StandardError, "Code: #{response_body['Code']}, Message: #{response_body['Message']}, URL: #{uri}"
end
+ # 返回数据
response_body
end
private
def connection(adapter = Faraday.default_adapter)
@@ -115,10 +118,10 @@
replace_repeat_list(target, key, value)
else
target[key.to_s] = value
end
end
- target.to_query
+ target
end
def normalize(params)
flat_params(params).sort.to_h.map { |key, value| [encode(key), encode(value)] }
end