Class: XRBP::WebSocket::Plugins::CommandPaginator
- Inherits:
-
PluginBase
- Object
- PluginBase
- XRBP::WebSocket::Plugins::CommandPaginator
- Defined in:
- lib/xrbp/websocket/plugins/command_paginator.rb
Overview
Handles multi-page responses, automatically issuing subsequent requests when more data is available and concatinating results.
This is most useful with account transaction and object lists where a single account may be associated with more data than can returned in a single result. In this case response will include pagination marker which we leverage here to retrieve all data.
Instance Attribute Summary
Attributes inherited from PluginBase
Instance Method Summary collapse
Methods inherited from PluginBase
Constructor Details
This class inherits a constructor from XRBP::PluginBase
Instance Method Details
#added ⇒ Object
12 13 14 |
# File 'lib/xrbp/websocket/plugins/command_paginator.rb', line 12 def added raise "Must also include CommandDispatcher plugin" unless connection.plugin?(CommandDispatcher) end |
#unlock!(cmd, res) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/xrbp/websocket/plugins/command_paginator.rb', line 16 def unlock!(cmd, res) return true unless cmd.respond_to?(:paginate?) && cmd.paginate? return true unless res["result"] # unlock if we cannot get result marker = res["result"]["marker"] page = res["result"][cmd.page_title] if marker && next_cmd = cmd.next_page(marker) connection.cmd next_cmd do page end else # XXX can't recursively use stack to unwind # callbacks as there may be too many pages. # Do it serially. res = Array.new(page) cmd.each_ancestor { |page_cmd| page_res = page_cmd.bl.call res res = page_res + res if page_cmd.prev_cmd } end false end |