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
- #failed? ⇒ 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.
12 13 14 15 16 |
# File 'lib/khl/http/response.rb', line 12 def initialize(raw_response) @raw_response = raw_response @http_code = raw_response.code.to_i @body = ActiveSupport::HashWithIndifferentAccess.new(JSON.parse(@raw_response.body)) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
9 10 11 |
# File 'lib/khl/http/response.rb', line 9 def body @body end |
#http_code ⇒ Object (readonly)
Returns the value of attribute http_code.
9 10 11 |
# File 'lib/khl/http/response.rb', line 9 def http_code @http_code end |
Instance Method Details
#code ⇒ Object
The code in the response body
23 24 25 |
# File 'lib/khl/http/response.rb', line 23 def code @body[:code] end |
#data ⇒ Object
18 19 20 |
# File 'lib/khl/http/response.rb', line 18 def data @body[:data] end |
#failed? ⇒ Boolean
51 52 53 |
# File 'lib/khl/http/response.rb', line 51 def failed? !success? end |
#limit? ⇒ Boolean
43 44 45 |
# File 'lib/khl/http/response.rb', line 43 def limit? @http_code == 429 || !@raw_response["X-Rate-Limit-Global"].nil? end |
#limit_bucket ⇒ Object
39 40 41 |
# File 'lib/khl/http/response.rb', line 39 def limit_bucket @raw_response["X-Rate-Limit-Bucket"] end |
#max_request_limit ⇒ Object
27 28 29 |
# File 'lib/khl/http/response.rb', line 27 def max_request_limit @raw_response["X-Rate-Limit-Limit"].to_i end |
#message ⇒ Object
55 56 57 |
# File 'lib/khl/http/response.rb', line 55 def @body[:message] end |
#page ⇒ Object
59 60 61 |
# File 'lib/khl/http/response.rb', line 59 def page data.dig(:meta, :page) || 0 end |
#page_size ⇒ Object
63 64 65 |
# File 'lib/khl/http/response.rb', line 63 def page_size data.dig(:meta, :page_size) || 0 end |
#page_total ⇒ Object
67 68 69 |
# File 'lib/khl/http/response.rb', line 67 def page_total data.dig(:meta, :total) || 0 end |
#remain_request_limit ⇒ Object
31 32 33 |
# File 'lib/khl/http/response.rb', line 31 def remain_request_limit @raw_response["X-Rate-Limit-Remaining"].to_i end |
#reset_limit_time ⇒ Object
35 36 37 |
# File 'lib/khl/http/response.rb', line 35 def reset_limit_time @raw_response["X-Rate-Limit-Reset"].to_i end |
#success? ⇒ Boolean
47 48 49 |
# File 'lib/khl/http/response.rb', line 47 def success? http_code == 200 && code.zero? end |