Class: BlockchainNode::Client
- Inherits:
-
Object
- Object
- BlockchainNode::Client
- Defined in:
- lib/blockchain-node/client.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#node_id ⇒ Object
Returns the value of attribute node_id.
Instance Method Summary collapse
- #auth_token ⇒ Object
- #details ⇒ Object
-
#initialize(node_id = nil) ⇒ Client
constructor
A new instance of Client.
-
#nodes ⇒ Object
convenience method to get nodes index.
Constructor Details
#initialize(node_id = nil) ⇒ Client
Returns a new instance of Client.
12 13 14 15 |
# File 'lib/blockchain-node/client.rb', line 12 def initialize(node_id = nil) @node_id = node_id @configuration = BlockchainNode::Configuration.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
catch all other method calls and assume its the RPC method call
36 37 38 39 |
# File 'lib/blockchain-node/client.rb', line 36 def method_missing(method, *args, &block) data = { method: method, parameters: args } request.post(path: nodes_path, data: data, auth_token: auth_token) end |
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
10 11 12 |
# File 'lib/blockchain-node/client.rb', line 10 def configuration @configuration end |
#node_id ⇒ Object
Returns the value of attribute node_id.
9 10 11 |
# File 'lib/blockchain-node/client.rb', line 9 def node_id @node_id end |
Instance Method Details
#auth_token ⇒ Object
27 28 29 30 31 |
# File 'lib/blockchain-node/client.rb', line 27 def auth_token @@_auth_token ||= get_new_auth_token @@_auth_token = get_new_auth_token if auth_token_expired? @@_auth_token.token end |
#details ⇒ Object
22 23 24 25 |
# File 'lib/blockchain-node/client.rb', line 22 def details r = request.get(path: nodes_path, auth_token: auth_token) Details.new(r["id"], r["blockchain"], r["network"], r["status"], Integer(r["height"] || 0)) end |
#nodes ⇒ Object
convenience method to get nodes index
18 19 20 |
# File 'lib/blockchain-node/client.rb', line 18 def nodes request.get(path: node_index_path, auth_token: auth_token) end |