raiblocks_rpc 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80b65b8a94a9de27dc3c58f9c04b69b7b3a40e8395db0fbad5f2a9e764951628
4
- data.tar.gz: 6bb5855728354d9ae1cfaf2e5fca3ac6c61fd82e8db08f9f3a8e34744320d105
3
+ metadata.gz: c3cfa99a8f0a713436a12c596c19a4d0dd14e97e009dbf453b61a7942e8e2478
4
+ data.tar.gz: 377bbe87b07b3ee6e9350890e277782ee3d498b3e61fdb575e610f6f047bc753
5
5
  SHA512:
6
- metadata.gz: c4ab4f72e63fe1c86fe82d2ee77b238705e735103768e0a9e1375ca98881e1e5adb9e481b08ade5ba3349a58ba758327b95422b63ede2a61d67f877d7fa93301
7
- data.tar.gz: 403d5679bc3b9717bb2d6cc540e649ba54eae73d52c68999e96834f06bbf55f596c186183e8091863fdc0faefd2ec5ec98202fb5103555ea682f9ba4be558c70
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 before using the client, then `localhost:7076` will be used by default.
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 = 'localhost'
31
- RaiblocksRpc::Client.port = 7076
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
- RaiblocksRpc::Client.instance.call(:account_balance, account: 'xrb_someaddress1234')
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 = RaiblocksRpc::Client.instance.call(:account_balance, account: 'xrb_someaddress1234')
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
@@ -3,5 +3,5 @@
3
3
  require 'bundler/setup'
4
4
  require 'raiblocks_rpc'
5
5
 
6
- require 'irb'
7
- IRB.start(__FILE__)
6
+ require 'pry'
7
+ Pry.start
@@ -4,10 +4,11 @@ require 'rest-client'
4
4
  require 'json'
5
5
 
6
6
  class RaiblocksRpc::Client
7
- include Singleton
7
+ attr_accessor :host, :port
8
8
 
9
- class << self
10
- attr_accessor :host, :port
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
- self.class.host ||= 'localhost'
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)
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
  module RaiblocksRpc
3
- class BadRequest < StandardError; end
4
- class InvalidRequest < StandardError; end
5
- class InvalidParameterType < StandardError; end
6
- class ForbiddenParameter < StandardError; end
7
- class MissingParameters < StandardError; end
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
@@ -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::Client.instance.call(rpc_action, params)
79
+ RaiblocksRpc.client.call(rpc_action, params)
80
80
  end
81
81
  end
82
82
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module RaiblocksRpc
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
data/lib/raiblocks_rpc.rb CHANGED
@@ -10,3 +10,9 @@ require 'raiblocks_rpc/proxies/network'
10
10
  require 'raiblocks_rpc/proxies/node'
11
11
  require 'raiblocks_rpc/proxies/util'
12
12
  require 'raiblocks_rpc/proxies/wallet'
13
+
14
+ module RaiblocksRpc
15
+ def self.client
16
+ @client ||= Client.new
17
+ end
18
+ end
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.1.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-21 00:00:00.000000000 Z
11
+ date: 2018-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler