Sha256: 5c114db8798966502dd731f46e483c78143dc5f8cf02a1bd082dead0843042b3
Contents?: true
Size: 1.48 KB
Versions: 5
Compression:
Stored size: 1.48 KB
Contents
module Slack module Web module Api module Pagination class Cursor include Enumerable attr_reader :client attr_reader :verb attr_reader :sleep_interval attr_reader :max_retries attr_reader :params 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 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.response_metadata next_cursor = response.response_metadata.next_cursor break if next_cursor.blank? retry_count = 0 sleep(sleep_interval) if sleep_interval end end end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems