Class: Slack::Web::Api::Pagination::Cursor
- Inherits:
-
Object
- Object
- Slack::Web::Api::Pagination::Cursor
- Includes:
- Enumerable
- Defined in:
- lib/slack/web/pagination/cursor.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#max_retries ⇒ Object
readonly
Returns the value of attribute max_retries.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#sleep_interval ⇒ Object
readonly
Returns the value of attribute sleep_interval.
-
#verb ⇒ Object
readonly
Returns the value of attribute verb.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(client, verb, params = {}) ⇒ Cursor
constructor
A new instance of Cursor.
Constructor Details
#initialize(client, verb, params = {}) ⇒ Cursor
Returns a new instance of Cursor.
14 15 16 17 18 19 20 |
# File 'lib/slack/web/pagination/cursor.rb', line 14 def initialize(client, verb, params = {}) @client = client @verb = verb @params = params.dup @sleep_interval = @params.delete(:sleep_interval) @max_retries = @params.delete(:max_retries) || client.default_max_retries end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/slack/web/pagination/cursor.rb', line 8 def client @client end |
#max_retries ⇒ Object (readonly)
Returns the value of attribute max_retries.
11 12 13 |
# File 'lib/slack/web/pagination/cursor.rb', line 11 def max_retries @max_retries end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
12 13 14 |
# File 'lib/slack/web/pagination/cursor.rb', line 12 def params @params end |
#sleep_interval ⇒ Object (readonly)
Returns the value of attribute sleep_interval.
10 11 12 |
# File 'lib/slack/web/pagination/cursor.rb', line 10 def sleep_interval @sleep_interval end |
#verb ⇒ Object (readonly)
Returns the value of attribute verb.
9 10 11 |
# File 'lib/slack/web/pagination/cursor.rb', line 9 def verb @verb end |
Instance Method Details
#each ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/slack/web/pagination/cursor.rb', line 22 def each next_cursor = nil retry_count = 0 loop do query = { limit: client.default_page_size }.merge(params).merge(cursor: next_cursor) begin response = client.send(verb, query) rescue Slack::Web::Api::Errors::TooManyRequestsError => e raise e if retry_count >= max_retries client.logger.debug("#{self.class}##{__method__}") { e.to_s } retry_count += 1 sleep(e.retry_after.seconds) next end yield response break unless response. next_cursor = response..next_cursor break if next_cursor.blank? retry_count = 0 sleep(sleep_interval) if sleep_interval end end |