Class: BlockchainNode::Client

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

Defined Under Namespace

Classes: AuthToken

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node_id) ⇒ Client

Returns a new instance of Client.



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

def initialize(node_id)
  @node_id = node_id
  # allow a different configuration per client instance
  @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



30
31
32
33
# File 'lib/blockchain-node/client.rb', line 30

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.



8
9
10
# File 'lib/blockchain-node/client.rb', line 8

def configuration
  @configuration
end

#node_idObject (readonly)

Returns the value of attribute node_id.



7
8
9
# File 'lib/blockchain-node/client.rb', line 7

def node_id
  @node_id
end

Instance Method Details

#auth_tokenObject



21
22
23
24
25
# File 'lib/blockchain-node/client.rb', line 21

def auth_token
  @@_auth_token ||= get_new_auth_token
  @@_auth_token = get_new_auth_token if auth_token_expired?
  @@_auth_token.token
end

#nodesObject

convenience method to get nodes index



17
18
19
# File 'lib/blockchain-node/client.rb', line 17

def nodes
  request.get(path: node_index_path, auth_token: auth_token)
end