scale_rb 0.1.9 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/client/http_client.rb +27 -4
- data/lib/scale_rb/version.rb +1 -1
- data/lib/scale_rb.rb +5 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c7019e91465191e14eb99ca5b57435245b9cb533cc0b5eb7e9ee944f8485a8c
|
4
|
+
data.tar.gz: 8d9eb533ffb3046536f915c39271049d46b20a1417989e6844c6b3ba927bd1e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef65503ad4ccc4f26490c0ff9ed0715beb312ee50ca5ca6a1f4824a924a01cd833503bbd1f80e8c510eb26d12a6f400655a0fcc5bed12a505ef15cb1e686b69d
|
7
|
+
data.tar.gz: cf36689a9d7bf12c104f51e39483f3db58d073423d314692f07cfba1ce49e324032c57b4fbe122b207f85ac08af60bbdb44dc8e21fde0c558bbbd05bb255d40f
|
data/Gemfile.lock
CHANGED
data/lib/client/http_client.rb
CHANGED
@@ -4,24 +4,34 @@ require 'uri'
|
|
4
4
|
require 'net/http'
|
5
5
|
require 'json'
|
6
6
|
|
7
|
+
# TODO: method_name = cmd.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase
|
7
8
|
module ScaleRb
|
8
9
|
module HttpClient
|
9
10
|
extend RpcRequestBuilder
|
10
11
|
|
11
12
|
class << self
|
12
13
|
def request(url, body)
|
14
|
+
ScaleRb.logger.debug "url: #{url}"
|
15
|
+
ScaleRb.logger.debug "body: #{body}"
|
13
16
|
uri = URI(url)
|
14
17
|
req = Net::HTTP::Post.new(uri, 'Content-Type' => 'application/json')
|
15
18
|
req.body = body
|
16
19
|
http = Net::HTTP.new(uri.host, uri.port)
|
17
20
|
http.use_ssl = true if uri.instance_of? URI::HTTPS
|
18
21
|
res = http.request(req)
|
19
|
-
|
22
|
+
|
23
|
+
raise res.class.name unless res.is_a?(Net::HTTPSuccess)
|
20
24
|
|
21
25
|
result = JSON.parse(res.body)
|
22
|
-
|
26
|
+
ScaleRb.logger.debug result
|
27
|
+
raise result['error']['message'] if result['error']
|
23
28
|
|
24
29
|
result['result']
|
30
|
+
rescue StandardError => e
|
31
|
+
ScaleRb.logger.error e.message
|
32
|
+
ScaleRb.logger.error 'retry...'
|
33
|
+
sleep 2
|
34
|
+
request(url, body)
|
25
35
|
end
|
26
36
|
|
27
37
|
def json_rpc_call(url, method, *params)
|
@@ -34,7 +44,20 @@ module ScaleRb
|
|
34
44
|
end
|
35
45
|
|
36
46
|
def method_missing(method, *args)
|
37
|
-
|
47
|
+
ScaleRb.logger.debug "#{method}(#{args.join(', ')})"
|
48
|
+
# check if the first argument is a url
|
49
|
+
url_regex = %r{^https?://}
|
50
|
+
raise 'url format is not correct' unless args[0].match?(url_regex)
|
51
|
+
|
52
|
+
url = args[0]
|
53
|
+
raise NoMethodError, "undefined rpc method `#{method}'" unless rpc_methods(url).include?(method.to_s)
|
54
|
+
|
55
|
+
json_rpc_call(url, method, *args[1..])
|
56
|
+
end
|
57
|
+
|
58
|
+
def rpc_methods(url)
|
59
|
+
result = json_rpc_call(url, 'rpc_methods', [])
|
60
|
+
result['methods']
|
38
61
|
end
|
39
62
|
|
40
63
|
def get_metadata(url, at = nil)
|
@@ -157,4 +180,4 @@ module ScaleRb
|
|
157
180
|
end
|
158
181
|
end
|
159
182
|
end
|
160
|
-
end
|
183
|
+
end
|
data/lib/scale_rb/version.rb
CHANGED
data/lib/scale_rb.rb
CHANGED
@@ -32,16 +32,14 @@ require 'address'
|
|
32
32
|
|
33
33
|
module ScaleRb
|
34
34
|
class << self
|
35
|
-
|
36
|
-
|
37
|
-
def logger
|
38
|
-
@logger ||= Logger.new($stdout)
|
39
|
-
@logger.level = Logger::INFO
|
40
|
-
@logger
|
41
|
-
end
|
35
|
+
attr_accessor :logger
|
42
36
|
|
43
37
|
def debug(key, value)
|
44
38
|
logger.debug "#{key.rjust(15)}: #{value}"
|
45
39
|
end
|
46
40
|
end
|
47
41
|
end
|
42
|
+
|
43
|
+
logger = Logger.new($stdout)
|
44
|
+
logger.level = Logger::INFO
|
45
|
+
ScaleRb.logger = logger
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scale_rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aki Wu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: blake2b_rs
|