Class: Kitties::Response
- Inherits:
-
Object
- Object
- Kitties::Response
- Defined in:
- lib/kittyverse/api/client.rb
Overview
track last response
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#code ⇒ Object
Returns the value of attribute code.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#message ⇒ Object
Returns the value of attribute message.
Instance Method Summary collapse
-
#initialize(code, message, headers, body) ⇒ Response
constructor
A new instance of Response.
-
#ratelimit_limit ⇒ Object
ratelimit convenience helpers (for headers) note: all values of headers are arrays e.g.: {“x-ratelimit-limit”=>, “x-ratelimit-remaining”=>, “x-ratelimit-reset”=>, “content-length”=>, … }.
- #ratelimit_remaining ⇒ Object
- #ratelimit_reset ⇒ Object
- #ratelimit_reset? ⇒ Boolean
Constructor Details
#initialize(code, message, headers, body) ⇒ Response
Returns a new instance of Response.
29 30 31 |
# File 'lib/kittyverse/api/client.rb', line 29 def initialize( code, , headers, body ) @code, @message, @headers, @body = code, , headers, body end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
26 27 28 |
# File 'lib/kittyverse/api/client.rb', line 26 def body @body end |
#code ⇒ Object
Returns the value of attribute code.
26 27 28 |
# File 'lib/kittyverse/api/client.rb', line 26 def code @code end |
#headers ⇒ Object
Returns the value of attribute headers.
26 27 28 |
# File 'lib/kittyverse/api/client.rb', line 26 def headers @headers end |
#message ⇒ Object
Returns the value of attribute message.
26 27 28 |
# File 'lib/kittyverse/api/client.rb', line 26 def @message end |
Instance Method Details
#ratelimit_limit ⇒ Object
ratelimit convenience helpers (for headers)
note: all values of headers are arrays e.g.:
{"x-ratelimit-limit"=>["20"],
"x-ratelimit-remaining"=>["19"],
"x-ratelimit-reset"=>["1558206970"],
"content-length"=>["776"], ... }
40 41 42 43 |
# File 'lib/kittyverse/api/client.rb', line 40 def ratelimit_limit limit = @headers['x-ratelimit-limit'] limit ? limit[0].to_i : nil end |
#ratelimit_remaining ⇒ Object
45 46 47 48 |
# File 'lib/kittyverse/api/client.rb', line 45 def ratelimit_remaining remaining = @headers['x-ratelimit-remaining'] remaining ? remaining[0].to_i : nil end |
#ratelimit_reset ⇒ Object
56 57 58 59 60 |
# File 'lib/kittyverse/api/client.rb', line 56 def ratelimit_reset ## x-ratelimit-reset => 1558079593 ## - assume it's unix epoch time reset = @headers['x-ratelimit-reset'] reset ? Time.at(reset[0].to_i) : nil end |
#ratelimit_reset? ⇒ Boolean
50 51 52 53 54 |
# File 'lib/kittyverse/api/client.rb', line 50 def ratelimit_reset? ## x-ratelimit-reset => 1558079593 ## - assume it's unix epoch time reset = @headers['x-ratelimit-reset'] reset ? (reset[0].to_i < Time.now.to_i) : true ## always assume true (unlimited requests) end |