Class: AliyunSDK::RPCClient

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

Overview

The RPCClient class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ RPCClient

Returns a new instance of RPCClient.



58
59
60
61
62
63
64
65
66
67
# File 'lib/rpc_client.rb', line 58

def initialize(config)
  self.__access_key_id = config[:accessKeyId]
  self.__access_key_secret = config[:accessKeySecret]
  self.__version = config[:apiVersion]
  self.credential = config[:credential]
  self.__endpoint = config[:endpoint]
  self.__regionId = config[:regionId]
  self.codes = Set.new [200, '200', 'OK', 'Success']
  codes.merge config[:codes] if config[:codes]
end

Instance Attribute Details

#__access_key_idObject

Returns the value of attribute __access_key_id.



55
56
57
# File 'lib/rpc_client.rb', line 55

def __access_key_id
  @__access_key_id
end

#__access_key_secretObject

Returns the value of attribute __access_key_secret.



55
56
57
# File 'lib/rpc_client.rb', line 55

def __access_key_secret
  @__access_key_secret
end

#__endpointObject

Returns the value of attribute __endpoint.



55
56
57
# File 'lib/rpc_client.rb', line 55

def __endpoint
  @__endpoint
end

#__region_idObject

Returns the value of attribute __region_id.



55
56
57
# File 'lib/rpc_client.rb', line 55

def __region_id
  @__region_id
end

#__versionObject

Returns the value of attribute __version.



55
56
57
# File 'lib/rpc_client.rb', line 55

def __version
  @__version
end

#codesObject

Returns the value of attribute codes.



55
56
57
# File 'lib/rpc_client.rb', line 55

def codes
  @codes
end

#credentialObject

Returns the value of attribute credential.



55
56
57
# File 'lib/rpc_client.rb', line 55

def credential
  @credential
end

Instance Method Details

#__default(input, default) ⇒ Object



121
122
123
# File 'lib/rpc_client.rb', line 121

def __default(input, default)
  input || default
end

#__default_number(input, default) ⇒ Object



117
118
119
# File 'lib/rpc_client.rb', line 117

def __default_number(input, default)
  input || default
end

#__get_access_key_idObject



77
78
79
# File 'lib/rpc_client.rb', line 77

def __get_access_key_id
  __accessKeyId
end

#__get_access_key_secretObject



81
82
83
# File 'lib/rpc_client.rb', line 81

def __get_access_key_secret
  __accessKeySecret
end

#__get_endpoint(product, region_id) ⇒ Object



85
86
87
88
89
# File 'lib/rpc_client.rb', line 85

def __get_endpoint(product, region_id)
  return __endpoint if __endpoint

  "#{product}.#{region_id}.aliyuncs.com"
end

#__get_nonceObject



73
74
75
# File 'lib/rpc_client.rb', line 73

def __get_nonce
  SecureRandom.hex(16)
end

#__get_signature(request, access_key_secret) ⇒ Object



125
126
127
128
129
130
131
132
# File 'lib/rpc_client.rb', line 125

def __get_signature(request, access_key_secret)
  method = (request[:method] || 'GET').upcase
  normalized = AliyunSDK.normalize(request['query'])
  canonicalized = AliyunSDK.canonicalize(normalized)
  string2sign = "#{method}&#{AliyunSDK.encode('/')}&#{AliyunSDK.encode(canonicalized)}"
  key = access_key_secret + '&'
  Base64.encode64(OpenSSL::HMAC.digest('sha1', key, string2sign)).strip
end

#__get_timestampObject



69
70
71
# File 'lib/rpc_client.rb', line 69

def __get_timestamp
  Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
end

#__has_error(body) ⇒ Object



96
97
98
99
# File 'lib/rpc_client.rb', line 96

def __has_error(body)
  code = body['Code']
  code && !codes.include?(code)
end

#__is5xx(response) ⇒ Object



91
92
93
94
# File 'lib/rpc_client.rb', line 91

def __is5xx(response)
  code = response.code.to_i
  code >= 500 && code < 600
end

#__json(response) ⇒ Object



101
102
103
# File 'lib/rpc_client.rb', line 101

def __json(response)
  JSON.parse(response.body)
end

#__query(query) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
# File 'lib/rpc_client.rb', line 105

def __query(query)
  target = {}
  query.each do |key, value|
    if value.instance_of?(Array)
      replace_repeat_list(target, key, value)
    else
      target[key] = value.to_s
    end
  end
  target
end