rpc_client 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +8 -0
- data/lib/rpc_client.rb +134 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b8b16241f6144db2eda702bded0b1195f92f27244c142b38dd7001ef23496a63
|
4
|
+
data.tar.gz: 5494ba5d25629cb0bbe07ddaa284b94f52b879944caff3318af1b6c6488b8f15
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 98391aeac69e88be60751f185ba09755e4f0ea9cba1021e43766158f2c92b7db8cefedde1ddace1591d321093103a8213e4857d0c431a7fec29dffe0057d8cd8
|
7
|
+
data.tar.gz: 72ebcb51725728142ec5f2bcdddbde1519c0071d71d352bd41021c06c50cb7b4f1983e4437bb0e6e40985528b64fd70f2505e8f467cc7593ad58e333d17afa94
|
data/README.md
ADDED
data/lib/rpc_client.rb
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'securerandom'
|
4
|
+
require 'base64'
|
5
|
+
require 'openssl'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
# The AliyunSDK module
|
9
|
+
module AliyunSDK
|
10
|
+
VERSION = '0.0.1'
|
11
|
+
|
12
|
+
def replace_repeat_list(target, key, repeat)
|
13
|
+
repeat.each_with_index do |item, index|
|
14
|
+
if item&.instance_of?(Hash)
|
15
|
+
item.each_key do |k|
|
16
|
+
target["#{key}.#{index.next}.#{k}"] = item[k].to_s
|
17
|
+
end
|
18
|
+
else
|
19
|
+
target["#{key}.#{index.next}"] = item.to_s
|
20
|
+
end
|
21
|
+
end
|
22
|
+
target
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.flat_params(params)
|
26
|
+
target = {}
|
27
|
+
params.each do |key, value|
|
28
|
+
if value.instance_of?(Array)
|
29
|
+
replace_repeat_list(target, key, value)
|
30
|
+
else
|
31
|
+
target[key.to_s] = value
|
32
|
+
end
|
33
|
+
end
|
34
|
+
target
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.canonicalize(normalized)
|
38
|
+
normalized.map { |element| "#{element.first}=#{element.last}" }.join('&')
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.normalize(params)
|
42
|
+
flat_params(params)
|
43
|
+
.sort
|
44
|
+
.to_h
|
45
|
+
.map { |key, value| [encode(key), encode(value)] }
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.encode(string)
|
49
|
+
encoded = CGI.escape string
|
50
|
+
encoded.gsub(/[\+]/, '%20')
|
51
|
+
end
|
52
|
+
|
53
|
+
# The RPCClient class
|
54
|
+
class RPCClient
|
55
|
+
attr_accessor :__access_key_id, :__access_key_secret, :__region_id,
|
56
|
+
:__endpoint, :__version, :credential, :codes
|
57
|
+
|
58
|
+
def initialize(config)
|
59
|
+
self.__access_key_id = config[:accessKeyId]
|
60
|
+
self.__access_key_secret = config[:accessKeySecret]
|
61
|
+
self.__version = config[:apiVersion]
|
62
|
+
self.credential = config[:credential]
|
63
|
+
self.__endpoint = config[:endpoint]
|
64
|
+
self.__regionId = config[:regionId]
|
65
|
+
self.codes = Set.new [200, '200', 'OK', 'Success']
|
66
|
+
codes.merge config[:codes] if config[:codes]
|
67
|
+
end
|
68
|
+
|
69
|
+
def __get_timestamp
|
70
|
+
Time.now.utc.strftime('%Y-%m-%dT%H:%M:%SZ')
|
71
|
+
end
|
72
|
+
|
73
|
+
def __get_nonce
|
74
|
+
SecureRandom.hex(16)
|
75
|
+
end
|
76
|
+
|
77
|
+
def __get_access_key_id
|
78
|
+
__accessKeyId
|
79
|
+
end
|
80
|
+
|
81
|
+
def __get_access_key_secret
|
82
|
+
__accessKeySecret
|
83
|
+
end
|
84
|
+
|
85
|
+
def __get_endpoint(product, region_id)
|
86
|
+
return __endpoint if __endpoint
|
87
|
+
|
88
|
+
"#{product}.#{region_id}.aliyuncs.com"
|
89
|
+
end
|
90
|
+
|
91
|
+
def __is5xx(response)
|
92
|
+
code = response.code.to_i
|
93
|
+
code >= 500 && code < 600
|
94
|
+
end
|
95
|
+
|
96
|
+
def __has_error(body)
|
97
|
+
code = body['Code']
|
98
|
+
code && !codes.include?(code)
|
99
|
+
end
|
100
|
+
|
101
|
+
def __json(response)
|
102
|
+
JSON.parse(response.body)
|
103
|
+
end
|
104
|
+
|
105
|
+
def __query(query)
|
106
|
+
target = {}
|
107
|
+
query.each do |key, value|
|
108
|
+
if value.instance_of?(Array)
|
109
|
+
replace_repeat_list(target, key, value)
|
110
|
+
else
|
111
|
+
target[key] = value.to_s
|
112
|
+
end
|
113
|
+
end
|
114
|
+
target
|
115
|
+
end
|
116
|
+
|
117
|
+
def __default_number(input, default)
|
118
|
+
input || default
|
119
|
+
end
|
120
|
+
|
121
|
+
def __default(input, default)
|
122
|
+
input || default
|
123
|
+
end
|
124
|
+
|
125
|
+
def __get_signature(request, access_key_secret)
|
126
|
+
method = (request[:method] || 'GET').upcase
|
127
|
+
normalized = AliyunSDK.normalize(request['query'])
|
128
|
+
canonicalized = AliyunSDK.canonicalize(normalized)
|
129
|
+
string2sign = "#{method}&#{AliyunSDK.encode('/')}&#{AliyunSDK.encode(canonicalized)}"
|
130
|
+
key = access_key_secret + '&'
|
131
|
+
Base64.encode64(OpenSSL::HMAC.digest('sha1', key, string2sign)).strip
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rpc_client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alibaba Cloud SDK
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: RPC Core SDK for Ruby
|
14
|
+
email:
|
15
|
+
- sdk-team@alibabacloud.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- README.md
|
21
|
+
- lib/rpc_client.rb
|
22
|
+
homepage: http://www.alibabacloud.com/
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubygems_version: 3.0.4
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: RPC Core SDK for Ruby
|
45
|
+
test_files: []
|