Class: Infura::Call
- Inherits:
-
Object
- Object
- Infura::Call
- Defined in:
- lib/infura/call.rb
Constant Summary collapse
- BASE =
- { ‘from’ => ‘0x…’, ‘to’ => ‘0x…’ }, …
'https://api.infura.io'
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#http_method ⇒ Object
Returns the value of attribute http_method.
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(http_method, action) ⇒ Call
constructor
A new instance of Call.
Constructor Details
#initialize(http_method, action) ⇒ Call
Returns a new instance of Call.
12 13 14 15 |
# File 'lib/infura/call.rb', line 12 def initialize(http_method, action) @action = action @http_method = http_method end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
7 8 9 |
# File 'lib/infura/call.rb', line 7 def action @action end |
#http_method ⇒ Object
Returns the value of attribute http_method.
7 8 9 |
# File 'lib/infura/call.rb', line 7 def http_method @http_method end |
#params ⇒ Object
Returns the value of attribute params.
7 8 9 |
# File 'lib/infura/call.rb', line 7 def params @params end |
Instance Method Details
#fetch ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/infura/call.rb', line 17 def fetch path = "/v1/jsonrpc/#{Infura.chain}/#{action}" data = {} data[:token] = Infura.token data[:params] = params.to_json if params conn = Faraday.new(:url => BASE) Infura.logger.debug "#{http_method}: #{BASE}#{path}" Infura.logger.debug " params: #{params.to_json}" if params Infura.logger.debug " token: #{Infura.token}" if http_method == :post body = conn.post(path, data).body else body = conn.get(path, data).body end Infura.logger.debug " return: #{body}" data = JSON.parse(body) raise InfuraCallError, data['error'] if data['error'] data['result'] end |