module XRBP::DSL
The DSL
namespace can be included in client logic to provide an easy-to-use mechanism to read and write XRP data.
@example Retrieve ledger, subscribe to updates
include XRBP::DSL puts "Genesis ledger: " puts ledger(32570) websocket_msg do |msg| puts "Ledger received:" puts msg end subscribe_to_ledgers
Public Instance Methods
Return info for the specified account id
@param id [String] account id to query @return [Hash, nil] the account info or nil otherwise
# 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
Return ledger object for the specified id
@param id [Integer] id of the ledger to query @return [Hash, nil] the ledger object retrieved or nil otherwise
# 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
Subscribed to the ledger stream.
After calling this, :ledger events will be emitted via the websocket connection object.
# 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
Return list of all validators
@return [Array<Hash>] list of validators retrieved
# File lib/xrbp/dsl/validators.rb, line 6 def validators Model::Validator.all :connection => webclient end
Client which may be used to access HTTP resources
# File lib/xrbp/dsl/webclient.rb, line 4 def webclient @webclient ||= WebClient::Connection.new end
Client which may be used to access websocket endpoints.
By default a RoundRobin strategy will be used to cycle through specified endpoints.
# File lib/xrbp/dsl/websocket.rb, line 13 def websocket @websocket ||= WebSocket::RoundRobin.new *websocket_endpoints end
Default websocket endpoints. Override to specify different ones.
# File lib/xrbp/dsl/websocket.rb, line 5 def websocket_endpoints ["wss://s1.ripple.com:443", "wss://s2.ripple.com:443"] end
Register a callback to be invoked when messages are received via websocket connections
# File lib/xrbp/dsl/websocket.rb, line 19 def websocket_msg(&bl) websocket.on :message, &bl end
Block until all websocket connections are closed
# File lib/xrbp/dsl/websocket.rb, line 24 def websocket_wait websocket.wait_for_close end