Exception: Twitter::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Twitter::Error
- Defined in:
- lib/twitter/error.rb
Overview
Custom error class for rescuing from all Twitter errors
Direct Known Subclasses
Defined Under Namespace
Classes: BadGateway, BadRequest, ClientError, EnhanceYourCalm, Forbidden, InternalServerError, NotAcceptable, NotFound, ServerError, ServiceUnavailable, Unauthorized
Instance Attribute Summary collapse
-
#http_headers ⇒ Object
readonly
Returns the value of attribute http_headers.
Instance Method Summary collapse
-
#initialize(message, http_headers) ⇒ Twitter::Error
constructor
Initializes a new Error object.
- #ratelimit_limit ⇒ Integer
- #ratelimit_remaining ⇒ Integer
- #ratelimit_reset ⇒ Time
- #retry_after ⇒ Integer
Constructor Details
#initialize(message, http_headers) ⇒ Twitter::Error
Initializes a new Error object
11 12 13 14 |
# File 'lib/twitter/error.rb', line 11 def initialize(, http_headers) @http_headers = Hash[http_headers] super() end |
Instance Attribute Details
#http_headers ⇒ Object (readonly)
Returns the value of attribute http_headers.
4 5 6 |
# File 'lib/twitter/error.rb', line 4 def http_headers @http_headers end |
Instance Method Details
#ratelimit_limit ⇒ Integer
22 23 24 |
# File 'lib/twitter/error.rb', line 22 def ratelimit_limit @http_headers.values_at('x-ratelimit-limit', 'X-RateLimit-Limit').detect{|value| value}.to_i end |
#ratelimit_remaining ⇒ Integer
27 28 29 |
# File 'lib/twitter/error.rb', line 27 def ratelimit_remaining @http_headers.values_at('x-ratelimit-remaining', 'X-RateLimit-Remaining').detect{|value| value}.to_i end |
#ratelimit_reset ⇒ Time
17 18 19 |
# File 'lib/twitter/error.rb', line 17 def ratelimit_reset Time.at(@http_headers.values_at('x-ratelimit-reset', 'X-RateLimit-Reset').detect{|value| value}.to_i) end |
#retry_after ⇒ Integer
32 33 34 |
# File 'lib/twitter/error.rb', line 32 def retry_after [(ratelimit_reset - Time.now).ceil, 0].max end |