Class: YetisNode::JsonRpcTransport

Inherits:
BaseTransport show all
Defined in:
lib/yetis_node/json_rpc_transport.rb

Constant Summary

Constants inherited from BaseTransport

BaseTransport::DEFAULT_TIMEOUT

Instance Attribute Summary

Attributes inherited from BaseTransport

#options, #uri

Instance Method Summary collapse

Methods inherited from BaseTransport

#initialize

Constructor Details

This class inherits a constructor from YetisNode::BaseTransport

Instance Method Details

#json_rpcObject



16
17
18
19
20
# File 'lib/yetis_node/json_rpc_transport.rb', line 16

def json_rpc
  @json_rpc ||= ::JRPC::TcpClient.new uri,
                        namespace: 'yeti.',
                        timeout: options.fetch(:timeout, BaseTransport::DEFAULT_TIMEOUT)
end

#rpc_send(*args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/yetis_node/json_rpc_transport.rb', line 5

def rpc_send(*args)
  begin
    json_rpc.connect if json_rpc.closed?
    result = json_rpc.invoke_request(*args)
    json_rpc.close
    result
  rescue ::JRPC::Error => e
    raise Error.new("JSON RPC Error: #{"(#{e.code}) " if e.respond_to?(:code)}#{e.message}")
  end
end