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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4231688a1c708c3ca6de7c716f23893fe79d624b2135a662a515c507aa2d559e
4
- data.tar.gz: 91e23d11720a940fa9d71f5ca4248dfa96cd6dcb6b53b1ce861422de070c1ba1
3
+ metadata.gz: 1a880f00eae3845fb0996f1edf94c55bc8fb44ffbb3248cbfdcfec5e91df24f5
4
+ data.tar.gz: 309a0fe68006cb4c9d53e8cbd1de7f8022f8c4b5f78f9a24b5b836bf83575a03
5
5
  SHA512:
6
- metadata.gz: e9167cf800cdb84517947b8c9f80bbb61673609d05fa2818f63ce53a6ea394ba465ca7aed2e28e356ecaae4a9123952f2d3f1e9d50225059dba46d0126bb021a
7
- data.tar.gz: 835a3e8c56a6e95251b6b5feb1261bfbc34b40f156329c49098d6c98385c2e0e494b48fe603c24e035984cf6facc8316d4860bbf2d31425d3eb713d2601a3c3c
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
@@ -61,8 +61,10 @@ module Neb
61
61
  send_request(:post, "/getTransactionByContract", address: address)
62
62
  end
63
63
 
64
- def subscribe(topics: [])
65
- send_request(:post, "/subscribe", topics: topics)
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
@@ -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 = {}, headers = {})
9
+ def initialize(action, url, payload = {}, block = nil)
10
10
  @action = action
11
11
  @url = url
12
12
  @payload = payload
13
- @headers = headers.blank? ? default_headers : headers
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
- ::RestClient::Request.execute(request_args) do |resp, _, _|
32
- Response.new(resp)
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 default_headers
39
- { content_type: :json, accept: :json }
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
@@ -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://localhost:8685",
11
- timeout: "0",
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
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Neb
5
- VERSION = "0.1.1".freeze
5
+ VERSION = "0.1.2".freeze
6
6
  end
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.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-18 00:00:00.000000000 Z
11
+ date: 2018-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler