Class: Slack::Cursor
- Inherits:
-
Object
- Object
- Slack::Cursor
- Defined in:
- lib/laziness/cursor.rb
Instance Attribute Summary collapse
-
#page ⇒ Object
readonly
Returns the value of attribute page.
Instance Method Summary collapse
-
#initialize(page) ⇒ Cursor
constructor
A new instance of Cursor.
- #paginate(&blk) ⇒ Object
Constructor Details
#initialize(page) ⇒ Cursor
Returns a new instance of Cursor.
5 6 7 8 9 |
# File 'lib/laziness/cursor.rb', line 5 def initialize(page) @page = page @max_retries = (page && page[:max_retries]) || 0 @sleep_interval = (page && page[:sleep_interval]) end |
Instance Attribute Details
#page ⇒ Object (readonly)
Returns the value of attribute page.
3 4 5 |
# File 'lib/laziness/cursor.rb', line 3 def page @page end |
Instance Method Details
#paginate(&blk) ⇒ Object
11 12 13 14 15 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 41 42 43 |
# File 'lib/laziness/cursor.rb', line 11 def paginate(&blk) responses = [] if block_given? pager = Pager.new(page) retries = 0 loop do begin response = blk.call(pager) rescue Slack::TooManyRequestsError => e raise e if retries >= max_retries retries += 1 sleep(e.retry_after_in_seconds) next end responses << response break unless has_cursor?(response) retries = 0 pager = pager.next(next_cursor(response)) sleep(sleep_interval) if sleep_interval end end responses end |