Exception: X::TooManyRequests

Inherits:
ClientError show all
Defined in:
lib/x/errors/too_many_requests.rb

Constant Summary

Constants inherited from HTTPError

HTTPError::JSON_CONTENT_TYPE_REGEXP

Instance Attribute Summary

Attributes inherited from HTTPError

#code, #response

Instance Method Summary collapse

Methods inherited from HTTPError

#error_message, #initialize, #json?, #message_from_json_response

Constructor Details

This class inherits a constructor from X::HTTPError

Instance Method Details

#rate_limitObject



6
7
8
# File 'lib/x/errors/too_many_requests.rb', line 6

def rate_limit
  rate_limits.max_by(&:reset_at)
end

#rate_limitsObject



10
11
12
13
14
# File 'lib/x/errors/too_many_requests.rb', line 10

def rate_limits
  @rate_limits ||= RateLimit::TYPES.filter_map do |type|
    RateLimit.new(type: type, response: response) if response["x-#{type}-remaining"].eql?("0")
  end
end

#reset_atObject



16
17
18
# File 'lib/x/errors/too_many_requests.rb', line 16

def reset_at
  rate_limit&.reset_at || Time.at(0)
end

#reset_inObject Also known as: retry_after



20
21
22
# File 'lib/x/errors/too_many_requests.rb', line 20

def reset_in
  [(reset_at - Time.now).ceil, 0].max
end