nano_rpc 0.5.0 → 0.6.0

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: d10073bf6ebd0cca384ce4de513f53f7356bbf289731f8dcdf322496a6089e68
4
- data.tar.gz: '059b36ad240027dc29f655a9bdb07649b79e7279712472b508baeb09a31e5df1'
3
+ metadata.gz: a9978232fd9a93d80e7788e5199d61961c6e79984c38402c75a71582ed61eeef
4
+ data.tar.gz: 65239db16d0090666afe5cf1da64f9ef6fe2372e66a9ff9dae25c9321abaa99b
5
5
  SHA512:
6
- metadata.gz: 2de3f22e5b894b2e421fe93f5b424b646807b8ec9b1e3fda89108eaaa589a48c1ee46eecaf00f615d593a9d0d48f9fe234118773d686e03c21b732bceae44b3b
7
- data.tar.gz: cd8780df5f4ce82724aa42c12cc2183c9440e30d3961f5e9a25abe48895c124097f26e0d86b6b7ac5f98dd73357325045a857ee9e734cd2b7a1f46d58029ac21
6
+ metadata.gz: b6e9d40af5b66f3717e8216cfa339aa3341e71079a7c16c2a0e299b659ef201e52ac4f85acc1d6f5e685ea5fceccf393d0da774c19f7d375707958c09e255a88
7
+ data.tar.gz: 292204a915746ed0cd49435995eb3e47bd771cfd5de2cd53f7eb8e5992b17cf52354b5a3ad122e423c3f9c27874b32e2094f9f4376e1ffe7bd8fe00e02b33330
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ![Ruby Nano RPC Logo](https://i.imgur.com/ihmmYcp.png)
2
2
 
3
- Nano RPC is a Ruby wrapper for making Remote Procedure Calls against Nano digitial currency nodes. Arbitrary RPC access is provided along with proxy objects that expose helper methods ([Wiki](https://github.com/jcraigk/ruby_nano_rpc/wiki/Proxy-Object-Reference)).
3
+ Nano RPC is a Ruby wrapper for making Remote Procedure Calls against Nano digitial currency nodes. Arbitrary RPC access is provided along with proxy objects that expose helper methods ([Wiki](https://github.com/jcraigk/ruby_nano_rpc/wiki)).
4
4
 
5
5
  To run a Nano node locally, see [Nano Docker Docs](https://github.com/clemahieu/raiblocks/wiki/Docker-node).
6
6
 
@@ -40,7 +40,19 @@ client = Nano.client
40
40
  client = Nano::Client.new(host: 'mynanonode', port: 1234)
41
41
  ```
42
42
 
43
- Then make a `call`, passing the action and data:
43
+ If you're using [Nanode](https://www.nanode.co/) or similar service that requires `Authorization` key in HTTP header, you can specify it using `auth`.
44
+
45
+ ```ruby
46
+ client = Nano::Client.new(auth: 'someauthkey')
47
+ ```
48
+
49
+ You can also specify custom headers as a hash. These will be sent with every RPC request.
50
+
51
+ ```ruby
52
+ client = Nano::Client.new(headers: { 'Authorization' => 'someauthkey' })
53
+ ```
54
+
55
+ Once the client is created, make a `call`, passing the action and data:
44
56
 
45
57
  ```ruby
46
58
  client.call(:account_balance, account: 'xrb_someaddress1234')
@@ -10,11 +10,13 @@ module Nano
10
10
  class Client
11
11
  include Nano::ApplicationHelper
12
12
 
13
- attr_accessor :host, :port
13
+ attr_reader :host, :port, :auth, :headers
14
14
 
15
- def initialize(host: 'localhost', port: 7076)
15
+ def initialize(host: 'localhost', port: 7076, auth: nil, headers: nil)
16
16
  @host = host
17
17
  @port = port
18
+ @auth = auth
19
+ @headers = headers
18
20
  end
19
21
 
20
22
  # Condense host/port on object inspection
@@ -53,14 +55,21 @@ module Nano
53
55
  response = rest_client_post(url, params)
54
56
  ensure_status_success!(response)
55
57
 
56
- data = Nano::Response.new(JSON[response.body])
58
+ data = Nano::Response.new(JSON[response&.body])
57
59
  ensure_valid_response!(data)
58
60
 
59
61
  data
60
62
  end
61
63
 
64
+ def request_headers
65
+ h = headers || {}
66
+ h['Content-Type'] = 'json'
67
+ h['Authorization'] = auth unless auth.nil?
68
+ h
69
+ end
70
+
62
71
  def rest_client_post(url, params)
63
- RestClient.post(url, params.to_json)
72
+ RestClient.post(url, params, request_headers)
64
73
  rescue Errno::ECONNREFUSED
65
74
  raise Nano::NodeConnectionFailure,
66
75
  "Node connection failure at #{url}"
@@ -70,13 +79,17 @@ module Nano
70
79
  end
71
80
 
72
81
  def url
73
- "http://#{host}:#{port}"
82
+ if host.start_with?('http://', 'https://')
83
+ "#{host}:#{port}"
84
+ else
85
+ "http://#{host}:#{port}"
86
+ end
74
87
  end
75
88
 
76
89
  def ensure_status_success!(response)
77
- return if response.code == 200
90
+ return if response&.code == 200
78
91
  raise Nano::BadRequest,
79
- "Error response from node: #{JSON[response.body]}"
92
+ "Error response from node: #{JSON[response&.body]}"
80
93
  end
81
94
 
82
95
  def ensure_valid_response!(data)
@@ -60,6 +60,7 @@ module Nano::WalletHelper
60
60
  def enter_password(password:)
61
61
  password_enter(password: password).valid == 1
62
62
  end
63
+ alias unlock enter_password
63
64
 
64
65
  def export
65
66
  Nano::Response.new(JSON[wallet_export.json])
@@ -137,11 +138,12 @@ module Nano::WalletHelper
137
138
  end
138
139
  alias set_representative representative_set
139
140
 
140
- def send_nano(from:, to:, amount:, work: nil)
141
+ def send_nano(from:, to:, amount:, id: nil, work: nil)
141
142
  send_currency(
142
143
  source: from,
143
144
  destination: to,
144
145
  amount: amount,
146
+ id: id,
145
147
  work: work
146
148
  ).block
147
149
  end
@@ -33,7 +33,9 @@ class Nano::Wallet
33
33
  proxy_method :payment_init
34
34
  proxy_method :payment_end, required: %i[account]
35
35
  proxy_method :receive, required: %i[account block], optional: %i[work]
36
- proxy_method :send, required: %i[wallet source destination amount]
36
+ proxy_method :send,
37
+ required: %i[wallet source destination amount],
38
+ optional: %i[id work]
37
39
  proxy_method :search_pending
38
40
  proxy_method :wallet_add, required: %i[key], optional: %i[work]
39
41
  proxy_method :wallet_balance_total
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Nano
3
- VERSION = '0.5.0'
3
+ VERSION = '0.6.0'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nano_rpc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Craig-Kuhn (JCK)
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-10 00:00:00.000000000 Z
11
+ date: 2018-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -187,7 +187,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
187
187
  version: '0'
188
188
  requirements: []
189
189
  rubyforge_project:
190
- rubygems_version: 2.7.3
190
+ rubygems_version: 2.7.6
191
191
  signing_key:
192
192
  specification_version: 4
193
193
  summary: RPC wrapper for Nano digital nodes written in Ruby