raiblocks_rpc 0.1.0 → 0.2.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 +4 -4
- data/README.md +10 -5
- data/bin/console +2 -2
- data/lib/raiblocks_rpc/client.rb +5 -6
- data/lib/raiblocks_rpc/errors.rb +7 -5
- data/lib/raiblocks_rpc/proxy.rb +1 -1
- data/lib/raiblocks_rpc/version.rb +1 -1
- data/lib/raiblocks_rpc.rb +6 -0
- 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: c3cfa99a8f0a713436a12c596c19a4d0dd14e97e009dbf453b61a7942e8e2478
|
4
|
+
data.tar.gz: 377bbe87b07b3ee6e9350890e277782ee3d498b3e61fdb575e610f6f047bc753
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23930616a9d0b4e5df158cd0efa32cbc049f47044b1f4286027eb52b160e738cc27e66c1d9612f587bce1501230cf1fbab773e334ffa5b5cb713e2889cd1cddc
|
7
|
+
data.tar.gz: 1714b0a6c510b787cb9ee8a3e578d193f9a36a187d1b4613ff1ff6396fd857f98d722d85b53f31c8f5759f709641503fd239c5e7bccd2be06bc06cea7cb78cc9
|
data/README.md
CHANGED
@@ -24,11 +24,16 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
There are two ways to use this gem. You can make direct calls to the RPC client or use the provided proxy objects.
|
26
26
|
|
27
|
-
In either case, the client should first be configured to connect to a RaiBlocks node. If you do not specify host or port
|
27
|
+
In either case, the client should first be configured to connect to a RaiBlocks node and instantiated. If you do not specify host or port, then `localhost:7076` will be used by default.
|
28
28
|
|
29
29
|
```ruby
|
30
|
-
RaiblocksRpc::Client.host
|
31
|
-
|
30
|
+
client = RaiblocksRpc::Client.new(host: 'myraiblocksnode', port: 1234)
|
31
|
+
````
|
32
|
+
|
33
|
+
If you're just using the default configuration, you can use the shorter
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
client = RaiblocksRpc.Client
|
32
37
|
````
|
33
38
|
|
34
39
|
### Raw RPC Calls
|
@@ -38,14 +43,14 @@ You can use the RPC client to make raw RPC calls to a RaiBlocks node according t
|
|
38
43
|
Every call requires an `action`, which is passed as the first argument to `call`. Depending on the action, there may be additional required or optional parameters that are passed as an options hash.
|
39
44
|
|
40
45
|
```ruby
|
41
|
-
|
46
|
+
client.call(:account_balance, account: 'xrb_someaddress1234')
|
42
47
|
# => {"balance"=>100, "pending"=>0}
|
43
48
|
````
|
44
49
|
|
45
50
|
Response data are provided as `Hashie` objects with integer coercion, indifferent access, and method access included so you have several options for accessing values.
|
46
51
|
|
47
52
|
```ruby
|
48
|
-
data =
|
53
|
+
data = client.call(:account_balance, account: 'xrb_someaddress1234')
|
49
54
|
# => {"balance"=>100, "pending"=>0}
|
50
55
|
data.balance
|
51
56
|
# => 100
|
data/bin/console
CHANGED
data/lib/raiblocks_rpc/client.rb
CHANGED
@@ -4,10 +4,11 @@ require 'rest-client'
|
|
4
4
|
require 'json'
|
5
5
|
|
6
6
|
class RaiblocksRpc::Client
|
7
|
-
|
7
|
+
attr_accessor :host, :port
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
def initialize(host: 'localhost', port: 7076)
|
10
|
+
@host = host
|
11
|
+
@port = port
|
11
12
|
end
|
12
13
|
|
13
14
|
def call(action, params = {})
|
@@ -27,9 +28,7 @@ class RaiblocksRpc::Client
|
|
27
28
|
end
|
28
29
|
|
29
30
|
def url
|
30
|
-
|
31
|
-
self.class.port ||= 7076
|
32
|
-
"http://#{self.class.host}:#{self.class.port}"
|
31
|
+
"http://#{host}:#{port}"
|
33
32
|
end
|
34
33
|
|
35
34
|
def ensure_status_success!(response)
|
data/lib/raiblocks_rpc/errors.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module RaiblocksRpc
|
3
|
-
class
|
4
|
-
|
5
|
-
class
|
6
|
-
class
|
7
|
-
class
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
class BadRequest < Error; end
|
6
|
+
class InvalidRequest < Error; end
|
7
|
+
class InvalidParameterType < Error; end
|
8
|
+
class ForbiddenParameter < Error; end
|
9
|
+
class MissingParameters < Error; end
|
8
10
|
end
|
data/lib/raiblocks_rpc/proxy.rb
CHANGED
@@ -76,7 +76,7 @@ class RaiblocksRpc::Proxy
|
|
76
76
|
self.class.send(:define_method, m) do |opts = {}|
|
77
77
|
set_accessors(m, opts)
|
78
78
|
populate_and_validate_params!
|
79
|
-
RaiblocksRpc
|
79
|
+
RaiblocksRpc.client.call(rpc_action, params)
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
data/lib/raiblocks_rpc.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: raiblocks_rpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.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-01-
|
11
|
+
date: 2018-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|