Class: KHL::HTTP::Response
- Inherits:
-
Object
- Object
- KHL::HTTP::Response
- Defined in:
- lib/khl/http/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#http_code ⇒ Object
readonly
Returns the value of attribute http_code.
Instance Method Summary collapse
-
#code ⇒ Object
The code in the response body.
- #data ⇒ Object
- #error? ⇒ Boolean
-
#initialize(raw_response) ⇒ Response
constructor
A new instance of Response.
- #limit? ⇒ Boolean
- #limit_bucket ⇒ Object
- #max_request_limit ⇒ Object
- #message ⇒ Object
- #page ⇒ Object
- #page_size ⇒ Object
- #page_total ⇒ Object
- #remain_request_limit ⇒ Object
- #reset_limit_time ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(raw_response) ⇒ Response
Returns a new instance of Response.
9 10 11 12 13 |
# File 'lib/khl/http/response.rb', line 9 def initialize(raw_response) @raw_response = raw_response @http_code = raw_response.code.to_i @body = JSON.parse(@raw_response.body) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
6 7 8 |
# File 'lib/khl/http/response.rb', line 6 def body @body end |
#http_code ⇒ Object (readonly)
Returns the value of attribute http_code.
6 7 8 |
# File 'lib/khl/http/response.rb', line 6 def http_code @http_code end |
Instance Method Details
#code ⇒ Object
The code in the response body
20 21 22 |
# File 'lib/khl/http/response.rb', line 20 def code @body["code"] end |
#data ⇒ Object
15 16 17 |
# File 'lib/khl/http/response.rb', line 15 def data @body["data"] end |
#error? ⇒ Boolean
48 49 50 |
# File 'lib/khl/http/response.rb', line 48 def error? !success? end |
#limit? ⇒ Boolean
40 41 42 |
# File 'lib/khl/http/response.rb', line 40 def limit? @http_code == 429 || !@raw_response["X-Rate-Limit-Global"].nil? end |
#limit_bucket ⇒ Object
36 37 38 |
# File 'lib/khl/http/response.rb', line 36 def limit_bucket @raw_response["X-Rate-Limit-Bucket"] end |
#max_request_limit ⇒ Object
24 25 26 |
# File 'lib/khl/http/response.rb', line 24 def max_request_limit @raw_response["X-Rate-Limit-Limit"].to_i end |
#message ⇒ Object
52 53 54 |
# File 'lib/khl/http/response.rb', line 52 def @body["message"] end |
#page ⇒ Object
56 57 58 |
# File 'lib/khl/http/response.rb', line 56 def page data.dig("meta", "page") || 0 end |
#page_size ⇒ Object
60 61 62 |
# File 'lib/khl/http/response.rb', line 60 def page_size data.dig("meta", "page_size") || 0 end |
#page_total ⇒ Object
64 65 66 |
# File 'lib/khl/http/response.rb', line 64 def page_total data.dig("meta", "total") || 0 end |
#remain_request_limit ⇒ Object
28 29 30 |
# File 'lib/khl/http/response.rb', line 28 def remain_request_limit @raw_response["X-Rate-Limit-Remaining"].to_i end |
#reset_limit_time ⇒ Object
32 33 34 |
# File 'lib/khl/http/response.rb', line 32 def reset_limit_time @raw_response["X-Rate-Limit-Reset"].to_i end |
#success? ⇒ Boolean
44 45 46 |
# File 'lib/khl/http/response.rb', line 44 def success? http_code == 200 && code.zero? end |