Class: Collavre::HttpClient::Response
- Inherits:
-
Object
- Object
- Collavre::HttpClient::Response
- Defined in:
- app/services/collavre/http_client.rb
Overview
A minimal, read-only view over a Net::HTTP response.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
-
#initialize(net_response) ⇒ Response
constructor
A new instance of Response.
-
#json ⇒ Object
Parse the response body as JSON, or nil when the body is empty.
- #success? ⇒ Boolean
Constructor Details
#initialize(net_response) ⇒ Response
Returns a new instance of Response.
45 46 47 48 49 50 51 |
# File 'app/services/collavre/http_client.rb', line 45 def initialize(net_response) @net_response = net_response @code = net_response.code.to_i @message = net_response. @body = net_response.body @headers = net_response.to_hash end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
43 44 45 |
# File 'app/services/collavre/http_client.rb', line 43 def body @body end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
43 44 45 |
# File 'app/services/collavre/http_client.rb', line 43 def code @code end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
43 44 45 |
# File 'app/services/collavre/http_client.rb', line 43 def headers @headers end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
43 44 45 |
# File 'app/services/collavre/http_client.rb', line 43 def @message end |
Instance Method Details
#json ⇒ Object
Parse the response body as JSON, or nil when the body is empty.
58 59 60 61 62 |
# File 'app/services/collavre/http_client.rb', line 58 def json return nil if body.nil? || body.empty? JSON.parse(body) end |
#success? ⇒ Boolean
53 54 55 |
# File 'app/services/collavre/http_client.rb', line 53 def success? @net_response.is_a?(Net::HTTPSuccess) end |