Class: Banano::Client
- Inherits:
-
Object
- Object
- Banano::Client
- Defined in:
- lib/banano/client.rb
Constant Summary collapse
- LOCAL_ENDPOINT =
'http://localhost:7072'
- DEFAULT_TIMEOUT =
30
Instance Attribute Summary collapse
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#initialize(uri: LOCAL_ENDPOINT, timeout: DEFAULT_TIMEOUT) ⇒ Client
constructor
A new instance of Client.
- #rpc_call(action:, params: {}) ⇒ Object
Constructor Details
#initialize(uri: LOCAL_ENDPOINT, timeout: DEFAULT_TIMEOUT) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/banano/client.rb', line 13 def initialize(uri: LOCAL_ENDPOINT, timeout: DEFAULT_TIMEOUT) @conn = Faraday.new(uri) do |builder| builder.adapter Faraday.default_adapter builder.request :url_encoded builder.[:open_timeout] = 5 builder.[:timeout] = timeout builder.headers['Content-Type'] = 'application/json' builder.headers['User-Agent'] = 'Banano RPC Client' builder.response :json, content_type: 'application/json' end end |
Instance Attribute Details
#timeout ⇒ Object
Returns the value of attribute timeout.
11 12 13 |
# File 'lib/banano/client.rb', line 11 def timeout @timeout end |
#uri ⇒ Object
Returns the value of attribute uri.
11 12 13 |
# File 'lib/banano/client.rb', line 11 def uri @uri end |
Instance Method Details
#rpc_call(action:, params: {}) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/banano/client.rb', line 25 def rpc_call(action:, params: {}) data = {action: action}.merge(params) response = @conn.post do |req| req.body = JSON.dump(data) end Util.symbolize_keys(response.body) end |