Class: BlockchainNode::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/blockchain-node/client.rb

Defined Under Namespace

Classes: AuthToken, Details

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#configurationObject

Returns the value of attribute configuration.



10
11
12
# File 'lib/blockchain-node/client.rb', line 10

def configuration
  @configuration
end

#node_idObject

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_tokenObject



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

#detailsObject



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

#nodesObject

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