neb 0.1.1 → 0.1.2
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 +4 -4
- data/README.md +5 -0
- data/lib/neb/client/api.rb +6 -4
- data/lib/neb/client/request.rb +24 -9
- data/lib/neb/configuration.rb +2 -2
- data/lib/neb/version.rb +1 -1
- 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: 1a880f00eae3845fb0996f1edf94c55bc8fb44ffbb3248cbfdcfec5e91df24f5
|
4
|
+
data.tar.gz: 309a0fe68006cb4c9d53e8cbd1de7f8022f8c4b5f78f9a24b5b836bf83575a03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc0a6a85857980e79d27504478e3a414cd8065598c46414a29d4f1b2627c86784661982ea8af9b98645e4fca7f395fd46fbe4d34253a3ce5da779ea6b01f0789
|
7
|
+
data.tar.gz: 738ffd28ff5dc3a8d27e96893d62aa0de191381551d57c8dd45146efdcaba4688fc4b0ef25542f046dfc86f2ad8574b24c9ee06b0c73eb37140a72f6e1c23b5f
|
data/README.md
CHANGED
@@ -35,6 +35,11 @@ resp.code # => 200
|
|
35
35
|
resp.success? # => true
|
36
36
|
resp.result # => {:chain_id=>100, :tail=>"xxxx", :lib=>"xxxx", :height=>"1085", :protocol_version=>"/neb/1.0.0", :synchronized=>false, :version=>"1.0.1"}
|
37
37
|
|
38
|
+
client.api.subscribe(
|
39
|
+
topics: ["chain.pendingTransaction"],
|
40
|
+
on_download_progress: ->(c) { puts c }
|
41
|
+
)
|
42
|
+
|
38
43
|
resp = client.admin.accounts
|
39
44
|
resp.code # => 200
|
40
45
|
resp.success? # => true
|
data/lib/neb/client/api.rb
CHANGED
@@ -61,8 +61,10 @@ module Neb
|
|
61
61
|
send_request(:post, "/getTransactionByContract", address: address)
|
62
62
|
end
|
63
63
|
|
64
|
-
|
65
|
-
|
64
|
+
# topics: ["chain.pendingTransaction"]
|
65
|
+
# on_download_progress: ->(chunk) { print(chunk) }
|
66
|
+
def subscribe(topics:, on_download_progress:)
|
67
|
+
send_request(:post, "/subscribe", { topics: topics }, on_download_progress)
|
66
68
|
end
|
67
69
|
|
68
70
|
def get_gas_price
|
@@ -95,9 +97,9 @@ module Neb
|
|
95
97
|
|
96
98
|
private
|
97
99
|
|
98
|
-
def send_request(action, url, payload = {})
|
100
|
+
def send_request(action, url, payload = {}, block = nil)
|
99
101
|
request_url = host + api_version + endpoint + url
|
100
|
-
Request.new(action, request_url, payload).execute
|
102
|
+
Request.new(action, request_url, payload, block).execute
|
101
103
|
end
|
102
104
|
end
|
103
105
|
end
|
data/lib/neb/client/request.rb
CHANGED
@@ -4,13 +4,13 @@
|
|
4
4
|
module Neb
|
5
5
|
class Client
|
6
6
|
class Request
|
7
|
-
attr_reader :action, :url, :payload
|
7
|
+
attr_reader :action, :url, :payload, :block
|
8
8
|
|
9
|
-
def initialize(action, url, payload = {},
|
9
|
+
def initialize(action, url, payload = {}, block = nil)
|
10
10
|
@action = action
|
11
11
|
@url = url
|
12
12
|
@payload = payload
|
13
|
-
@
|
13
|
+
@block = custom_block(block)
|
14
14
|
end
|
15
15
|
|
16
16
|
def to_s
|
@@ -18,26 +18,41 @@ module Neb
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def request_args
|
21
|
-
{
|
21
|
+
args = {
|
22
22
|
method: action,
|
23
23
|
url: url,
|
24
24
|
payload: payload.deep_camelize_keys(:lower).to_json,
|
25
|
-
headers: { content_type: :json, accept: :json }
|
25
|
+
headers: { content_type: :json, accept: :json },
|
26
|
+
timeout: CONFIG[:timeout]
|
26
27
|
}
|
28
|
+
args.merge!(block_response: block) if block.present?
|
29
|
+
args
|
27
30
|
end
|
28
31
|
|
29
32
|
def execute
|
30
33
|
Neb.logger.debug(self.to_s)
|
31
|
-
|
32
|
-
|
34
|
+
if block.present?
|
35
|
+
::RestClient::Request.execute(request_args)
|
36
|
+
else
|
37
|
+
::RestClient::Request.execute(request_args, &default_block)
|
33
38
|
end
|
34
39
|
end
|
35
40
|
|
36
41
|
private
|
37
42
|
|
38
|
-
def
|
39
|
-
{
|
43
|
+
def default_block
|
44
|
+
Proc.new { |resp, _, _| Response.new(resp) }
|
40
45
|
end
|
46
|
+
|
47
|
+
def custom_block(block)
|
48
|
+
return nil if block.blank?
|
49
|
+
Proc.new do |resp|
|
50
|
+
resp.read_body do |chunk|
|
51
|
+
block.call(chunk.force_encoding('utf-8'))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
41
56
|
end
|
42
57
|
end
|
43
58
|
end
|
data/lib/neb/configuration.rb
CHANGED
@@ -7,8 +7,8 @@ module Neb
|
|
7
7
|
def_delegators :@hash, :to_hash, :[], :[]=, :==, :fetch, :delete, :has_key?
|
8
8
|
|
9
9
|
DEFAULTS = {
|
10
|
-
host: "http://
|
11
|
-
timeout:
|
10
|
+
host: "http://127.0.0.1:8685",
|
11
|
+
timeout: 600,
|
12
12
|
api_version: "/v1",
|
13
13
|
log: "log/neb.log",
|
14
14
|
api_endpoint: "/user",
|
data/lib/neb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Spirit
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|