Class: Limiter::ResponseHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/limiter/response_handler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#responseObject (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

Returns:

  • (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?

Returns:

  • (Boolean)


12
13
14
# File 'lib/limiter/response_handler.rb', line 12

def exhausted?
  signed_request? && @response.status == 429
end

#pointsObject



37
38
39
# File 'lib/limiter/response_handler.rb', line 37

def points
  response_data["points"]
end

#remainingObject



33
34
35
# File 'lib/limiter/response_handler.rb', line 33

def remaining
  response_data["remaining"]
end

#resets_atObject



29
30
31
# File 'lib/limiter/response_handler.rb', line 29

def resets_at
  response_data["resetsAt"]
end

#resets_inObject



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

Returns:

  • (Boolean)


41
42
43
# File 'lib/limiter/response_handler.rb', line 41

def signed_request?
  @response.headers["X-Limiter-Signed"].to_s == "true"
end