Class: Limiter::ResponseHandler
- Inherits:
-
Object
- Object
- Limiter::ResponseHandler
- Defined in:
- lib/limiter/response_handler.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #allowed? ⇒ Boolean
- #exhausted? ⇒ Boolean (also: #exceeded?)
-
#initialize(response) ⇒ ResponseHandler
constructor
A new instance of ResponseHandler.
- #points ⇒ Object
- #remaining ⇒ Object
- #resets_at ⇒ Object
- #resets_in ⇒ Object
- #signed_request? ⇒ Boolean
Constructor Details
#initialize(response) ⇒ ResponseHandler
Returns a new instance of ResponseHandler.
8 9 10 |
# File 'lib/limiter/response_handler.rb', line 8 def initialize(response) @response = response end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
6 7 8 |
# File 'lib/limiter/response_handler.rb', line 6 def response @response end |
Instance Method Details
#allowed? ⇒ Boolean
17 18 19 |
# File 'lib/limiter/response_handler.rb', line 17 def allowed? signed_request? && @response.status == 200 end |
#exhausted? ⇒ Boolean Also known as: exceeded?
12 13 14 |
# File 'lib/limiter/response_handler.rb', line 12 def exhausted? signed_request? && @response.status == 429 end |
#points ⇒ Object
37 38 39 |
# File 'lib/limiter/response_handler.rb', line 37 def points response_data["points"] end |
#remaining ⇒ Object
33 34 35 |
# File 'lib/limiter/response_handler.rb', line 33 def remaining response_data["remaining"] end |
#resets_at ⇒ Object
29 30 31 |
# File 'lib/limiter/response_handler.rb', line 29 def resets_at response_data["resetsAt"] end |
#resets_in ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/limiter/response_handler.rb', line 21 def resets_in if signed_request? && !resets_at.nil? (Time.parse(resets_at) - Time.now) else 0 end end |
#signed_request? ⇒ Boolean
41 42 43 |
# File 'lib/limiter/response_handler.rb', line 41 def signed_request? @response.headers["X-Limiter-Signed"].to_s == "true" end |