Top Level Namespace

Defined Under Namespace

Classes: SubstrateClient

Instance Method Summary collapse

Instance Method Details

#ws_request(url, payload) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/substrate_client.rb', line 11

def ws_request(url, payload)
  result = nil
  Kontena::Websocket::Client.connect(url, {}) do |client|
    client.send(payload.to_json)

    client.read do |message|
      result = JSON.parse message
      client.close(1000)
    end
  end

  return result
rescue Kontena::Websocket::CloseError => e
  raise SubstrateClient::WebsocketError, e.reason
rescue Kontena::Websocket::Error => e
  raise SubstrateClient::WebsocketError, e.reason
end