Class: AliyunSDK::RPCClient
- Inherits:
-
Object
- Object
- AliyunSDK::RPCClient
- Defined in:
- lib/rpc_client.rb
Overview
The RPCClient class
Instance Attribute Summary collapse
-
#__access_key_id ⇒ Object
Returns the value of attribute __access_key_id.
-
#__access_key_secret ⇒ Object
Returns the value of attribute __access_key_secret.
-
#__endpoint ⇒ Object
Returns the value of attribute __endpoint.
-
#__protocol ⇒ Object
Returns the value of attribute __protocol.
-
#__region_id ⇒ Object
Returns the value of attribute __region_id.
-
#__version ⇒ Object
Returns the value of attribute __version.
-
#codes ⇒ Object
Returns the value of attribute codes.
-
#credential ⇒ Object
Returns the value of attribute credential.
Instance Method Summary collapse
- #__default(input, default) ⇒ Object
- #__default_number(input, default) ⇒ Object
- #__get_access_key_id ⇒ Object
- #__get_access_key_secret ⇒ Object
- #__get_endpoint(product, region_id) ⇒ Object
- #__get_nonce ⇒ Object
- #__get_signature(request, access_key_secret) ⇒ Object
- #__get_timestamp ⇒ Object
- #__has_error(body) ⇒ Object
- #__is5xx(response) ⇒ Object
- #__json(response) ⇒ Object
- #__query(query) ⇒ Object
-
#initialize(config) ⇒ RPCClient
constructor
A new instance of RPCClient.
Constructor Details
#initialize(config) ⇒ RPCClient
Returns a new instance of RPCClient.
58 59 60 61 62 63 64 65 66 67 68 |
# 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.__region_id = config[:regionId] self.__protocol = config[:protocol] self.codes = Set.new [200, '200', 'OK', 'Success'] codes.merge config[:codes] if config[:codes] end |
Instance Attribute Details
#__access_key_id ⇒ Object
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_secret ⇒ Object
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 |
#__endpoint ⇒ Object
Returns the value of attribute __endpoint.
55 56 57 |
# File 'lib/rpc_client.rb', line 55 def __endpoint @__endpoint end |
#__protocol ⇒ Object
Returns the value of attribute __protocol.
55 56 57 |
# File 'lib/rpc_client.rb', line 55 def __protocol @__protocol end |
#__region_id ⇒ Object
Returns the value of attribute __region_id.
55 56 57 |
# File 'lib/rpc_client.rb', line 55 def __region_id @__region_id end |
#__version ⇒ Object
Returns the value of attribute __version.
55 56 57 |
# File 'lib/rpc_client.rb', line 55 def __version @__version end |
#codes ⇒ Object
Returns the value of attribute codes.
55 56 57 |
# File 'lib/rpc_client.rb', line 55 def codes @codes end |
#credential ⇒ Object
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
122 123 124 |
# File 'lib/rpc_client.rb', line 122 def __default(input, default) input || default end |
#__default_number(input, default) ⇒ Object
118 119 120 |
# File 'lib/rpc_client.rb', line 118 def __default_number(input, default) input || default end |
#__get_access_key_id ⇒ Object
78 79 80 |
# File 'lib/rpc_client.rb', line 78 def __get_access_key_id __access_key_id end |
#__get_access_key_secret ⇒ Object
82 83 84 |
# File 'lib/rpc_client.rb', line 82 def __get_access_key_secret __access_key_secret end |
#__get_endpoint(product, region_id) ⇒ Object
86 87 88 89 90 |
# File 'lib/rpc_client.rb', line 86 def __get_endpoint(product, region_id) return __endpoint if __endpoint "#{product}.#{region_id}.aliyuncs.com" end |
#__get_nonce ⇒ Object
74 75 76 |
# File 'lib/rpc_client.rb', line 74 def __get_nonce SecureRandom.hex(16) end |
#__get_signature(request, access_key_secret) ⇒ Object
126 127 128 129 130 131 132 133 |
# File 'lib/rpc_client.rb', line 126 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_timestamp ⇒ Object
70 71 72 |
# File 'lib/rpc_client.rb', line 70 def Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ') end |
#__has_error(body) ⇒ Object
97 98 99 100 |
# File 'lib/rpc_client.rb', line 97 def __has_error(body) code = body['Code'] code && !codes.include?(code) end |
#__is5xx(response) ⇒ Object
92 93 94 95 |
# File 'lib/rpc_client.rb', line 92 def __is5xx(response) code = response.code.to_i code >= 500 && code < 600 end |
#__json(response) ⇒ Object
102 103 104 |
# File 'lib/rpc_client.rb', line 102 def __json(response) JSON.parse(response.body) end |
#__query(query) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/rpc_client.rb', line 106 def __query(query) target = {} query.each do |key, value| if value.instance_of?(Array) AliyunSDK.replace_repeat_list(target, key, value) else target[key] = value.to_s end end target end |