Class: Httpsensible::Client::Response
- Inherits:
-
Object
- Object
- Httpsensible::Client::Response
- Defined in:
- lib/httpsensible/client/response.rb
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #available? ⇒ Boolean
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
-
#parsed_json_body ⇒ Object
sig { params(response: T.any(HTTPX::Response, HTTPX::ErrorResponse)).returns(T::Boolean) }.
- #raw_body ⇒ Object
-
#to_s ⇒ Object
sig { params(response: T.any(HTTPX::Response, HTTPX::ErrorResponse)).returns(String) }.
-
#unavailable? ⇒ Boolean
sig { params(response: T.any(HTTPX::Response, HTTPX::ErrorResponse)).returns(T::Boolean) }.
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
9 10 11 |
# File 'lib/httpsensible/client/response.rb', line 9 def initialize(response) @response = response end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/httpsensible/client/response.rb', line 7 def response @response end |
Instance Method Details
#available? ⇒ Boolean
45 46 47 |
# File 'lib/httpsensible/client/response.rb', line 45 def available? !unavailable? end |
#parsed_json_body ⇒ Object
sig { params(response: T.any(HTTPX::Response, HTTPX::ErrorResponse)).returns(T::Boolean) }
26 27 28 29 30 |
# File 'lib/httpsensible/client/response.rb', line 26 def parsed_json_body JSON.parse(raw_body) rescue JSON::ParserError {} end |
#raw_body ⇒ Object
32 33 34 |
# File 'lib/httpsensible/client/response.rb', line 32 def raw_body @raw_body ||= @response.body.read end |
#to_s ⇒ Object
sig { params(response: T.any(HTTPX::Response, HTTPX::ErrorResponse)).returns(String) }
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/httpsensible/client/response.rb', line 14 def to_s case @response when HTTPX::Response "#{@response.status}, #{@response.headers}, #{@response.body}" when HTTPX::ErrorResponse @response.error. else "" end end |
#unavailable? ⇒ Boolean
sig { params(response: T.any(HTTPX::Response, HTTPX::ErrorResponse)).returns(T::Boolean) }
37 38 39 40 41 42 43 |
# File 'lib/httpsensible/client/response.rb', line 37 def unavailable? return true if @response.nil? return true if @response.is_a?(HTTPX::ErrorResponse) return false if (200..299).cover?(@response.status) true if (400..599).cover?(@response.status) end |