Exception: Yapper::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Yapper::Error
- Defined in:
- lib/yapper/error.rb
Overview
Custom error class for rescuing from all Yammer errors
Direct Known Subclasses
BadGateway, BadRequest, Forbidden, InternalServerError, NotAcceptable, NotFound, ServiceUnavailable, TooManyRequests, Unauthorized
Instance Attribute Summary collapse
-
#http_headers ⇒ Object
readonly
Returns the value of attribute http_headers.
Instance Method Summary collapse
-
#initialize(message, http_headers) ⇒ Error
constructor
A new instance of Error.
- #ratelimit_limit ⇒ Object
- #ratelimit_remaining ⇒ Object
- #ratelimit_reset ⇒ Object
- #retry_after ⇒ Object
Constructor Details
#initialize(message, http_headers) ⇒ Error
Returns a new instance of Error.
54 55 56 57 |
# File 'lib/yapper/error.rb', line 54 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.
52 53 54 |
# File 'lib/yapper/error.rb', line 52 def http_headers @http_headers end |
Instance Method Details
#ratelimit_limit ⇒ Object
63 64 65 |
# File 'lib/yapper/error.rb', line 63 def ratelimit_limit @http_headers.values_at('x-ratelimit-limit', 'X-RateLimit-Limit').detect{|value| value}.to_i end |
#ratelimit_remaining ⇒ Object
67 68 69 |
# File 'lib/yapper/error.rb', line 67 def ratelimit_remaining @http_headers.values_at('x-ratelimit-remaining', 'X-RateLimit-Remaining').detect{|value| value}.to_i end |
#ratelimit_reset ⇒ Object
59 60 61 |
# File 'lib/yapper/error.rb', line 59 def ratelimit_reset Time.at(@http_headers.values_at('x-ratelimit-reset', 'X-RateLimit-Reset').detect{|value| value}.to_i) end |
#retry_after ⇒ Object
71 72 73 |
# File 'lib/yapper/error.rb', line 71 def retry_after [(ratelimit_reset - Time.now).ceil, 0].max end |