Class: Etherlite::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/etherlite/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(_uri) ⇒ Connection

Returns a new instance of Connection.



3
4
5
# File 'lib/etherlite/connection.rb', line 3

def initialize(_uri)
  @uri = _uri
end

Instance Method Details

#ipc_call(_method, *_params) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/etherlite/connection.rb', line 7

def ipc_call(_method, *_params)
  id = new_unique_id
  payload = { jsonrpc: "2.0", method: _method, params: _params, id: id }

  # TODO: support ipc
  Net::HTTP.start(@uri.hostname, @uri.port) do |http|
    return handle_response http.post(
      @uri.path.empty? ? '/' : @uri.path,
      payload.to_json,
      "Content-Type" => "application/json"
    ), id
  end
end