lib/blockchain-node/client.rb in blockchain-node-0.0.4 vs lib/blockchain-node/client.rb in blockchain-node-0.0.5
- old
+ new
@@ -2,26 +2,28 @@
class Client
@@_auth_token
AuthToken = Struct.new(:token, :expires_at)
+ Details = Struct.new(:id, :blockchain, :network, :status, :height)
+
attr_accessor :node_id
attr_accessor :configuration
def initialize(node_id = nil)
@node_id = node_id
- # allow a different configuration per client instance
@configuration = BlockchainNode::Configuration.new
end
# convenience method to get nodes index
def nodes
request.get(path: node_index_path, auth_token: auth_token)
end
def details
- request.get(path: nodes_path, auth_token: auth_token)
+ 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
def auth_token
@@_auth_token ||= get_new_auth_token
@@_auth_token = get_new_auth_token if auth_token_expired?
@@ -35,10 +37,10 @@
data = { method: method, parameters: args }
request.post(path: nodes_path, data: data, auth_token: auth_token)
end
def auth_token_expired?
- @@_auth_token.nil? || @@_auth_token.expires_at < Time.now.utc - 30
+ @@_auth_token.nil? || @@_auth_token.expires_at < Time.now.utc + 30
end
def get_new_auth_token
data = {
grant_type: "client_credentials",