Module: XRBP::DSL
- Defined in:
- lib/xrbp/dsl.rb,
lib/xrbp/dsl/ledgers.rb,
lib/xrbp/dsl/accounts.rb,
lib/xrbp/dsl/webclient.rb,
lib/xrbp/dsl/websocket.rb,
lib/xrbp/dsl/validators.rb
Overview
The DSL namespace can be included in client logic to provide an easy-to-use mechanism to read and write XRP data.
Instance Method Summary collapse
-
#account_info(id) ⇒ Hash?
Return info for the specified account id.
-
#ledger(id = nil) ⇒ Hash?
Return ledger object for the specified id.
-
#subscribe_to_ledgers ⇒ Object
Subscribed to the ledger stream.
-
#validators ⇒ Array<Hash>
Return list of all validators.
-
#webclient ⇒ Object
Client which may be used to access HTTP resources.
-
#websocket ⇒ Object
Client which may be used to access websocket endpoints.
-
#websocket_endpoints ⇒ Object
Default websocket endpoints.
-
#websocket_msg(&bl) ⇒ Object
Register a callback to be invoked when messages are received via websocket connections.
-
#websocket_wait ⇒ Object
Block until all websocket connections are closed.
Instance Method Details
#account_info(id) ⇒ Hash?
Return info for the specified account id
7 8 9 10 11 |
# File 'lib/xrbp/dsl/accounts.rb', line 7 def account_info(id) websocket.add_plugin :autoconnect unless websocket.plugin?(:autoconnect) websocket.add_plugin :command_dispatcher unless websocket.plugin?(:command_dispatcher) websocket.cmd(WebSocket::Cmds::AccountInfo.new(id)) end |
#ledger(id = nil) ⇒ Hash?
Return ledger object for the specified id
7 8 9 10 11 |
# File 'lib/xrbp/dsl/ledgers.rb', line 7 def ledger(id=nil) websocket.add_plugin :autoconnect unless websocket.plugin?(:autoconnect) websocket.add_plugin :command_dispatcher unless websocket.plugin?(:command_dispatcher) websocket.cmd(WebSocket::Cmds::Ledger.new(id)) end |
#subscribe_to_ledgers ⇒ Object
Subscribed to the ledger stream.
After calling this, :ledger events will be emitted via the websocket connection object.
17 18 19 20 21 |
# File 'lib/xrbp/dsl/ledgers.rb', line 17 def subscribe_to_ledgers websocket.add_plugin :autoconnect unless websocket.plugin?(:autoconnect) websocket.add_plugin :command_dispatcher unless websocket.plugin?(:command_dispatcher) websocket.cmd(WebSocket::Cmds::Subscribe.new(:streams => ["ledger"])) end |
#validators ⇒ Array<Hash>
Return list of all validators
6 7 8 |
# File 'lib/xrbp/dsl/validators.rb', line 6 def validators Model::Validator.all :connection => webclient end |
#webclient ⇒ Object
Client which may be used to access HTTP resources
4 5 6 |
# File 'lib/xrbp/dsl/webclient.rb', line 4 def webclient @webclient ||= WebClient::Connection.new end |
#websocket ⇒ Object
Client which may be used to access websocket endpoints.
By default a RoundRobin strategy will be used to cycle through specified endpoints.
13 14 15 |
# File 'lib/xrbp/dsl/websocket.rb', line 13 def websocket @websocket ||= WebSocket::RoundRobin.new *websocket_endpoints end |
#websocket_endpoints ⇒ Object
Default websocket endpoints. Override to specify different ones.
5 6 7 |
# File 'lib/xrbp/dsl/websocket.rb', line 5 def websocket_endpoints ["wss://s1.ripple.com:443", "wss://s2.ripple.com:443"] end |
#websocket_msg(&bl) ⇒ Object
Register a callback to be invoked when messages are received via websocket connections
19 20 21 |
# File 'lib/xrbp/dsl/websocket.rb', line 19 def websocket_msg(&bl) websocket.on :message, &bl end |
#websocket_wait ⇒ Object
Block until all websocket connections are closed
24 25 26 |
# File 'lib/xrbp/dsl/websocket.rb', line 24 def websocket_wait websocket.wait_for_close end |