Class: Savon::Transport::Response
- Inherits:
-
Object
- Object
- Savon::Transport::Response
- Defined in:
- lib/savon/transport/response.rb
Overview
Transport-agnostic HTTP response value object.
Every transport produces a Transport::Response so that higher-level code never depends on transport-specific code. Immutable once constructed.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the response body string.
-
#code ⇒ Object
readonly
Returns the HTTP status code.
-
#headers ⇒ Object
readonly
Returns the response headers hash.
Class Method Summary collapse
-
.from_faraday(faraday_response) ⇒ Object
Creates a Transport::Response from a Faraday::Response.
-
.from_httpi(httpi_response) ⇒ Object
Creates a Transport::Response from an HTTPI::Response.
Instance Method Summary collapse
-
#error? ⇒ Boolean
Returns true when the HTTP status code indicates an error (>= 300).
-
#initialize(code, headers, body) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(code, headers, body) ⇒ Response
Returns a new instance of Response.
23 24 25 26 27 |
# File 'lib/savon/transport/response.rb', line 23 def initialize(code, headers, body) @code = code @headers = headers @body = body end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the response body string.
36 37 38 |
# File 'lib/savon/transport/response.rb', line 36 def body @body end |
#code ⇒ Object (readonly)
Returns the HTTP status code.
30 31 32 |
# File 'lib/savon/transport/response.rb', line 30 def code @code end |
#headers ⇒ Object (readonly)
Returns the response headers hash.
33 34 35 |
# File 'lib/savon/transport/response.rb', line 33 def headers @headers end |
Class Method Details
.from_faraday(faraday_response) ⇒ Object
Creates a Transport::Response from a Faraday::Response.
16 17 18 |
# File 'lib/savon/transport/response.rb', line 16 def self.from_faraday(faraday_response) new(faraday_response.status, faraday_response.headers.to_h, faraday_response.body) end |
.from_httpi(httpi_response) ⇒ Object
Creates a Transport::Response from an HTTPI::Response.
11 12 13 |
# File 'lib/savon/transport/response.rb', line 11 def self.from_httpi(httpi_response) new(httpi_response.code, httpi_response.headers, httpi_response.body) end |
Instance Method Details
#error? ⇒ Boolean
Returns true when the HTTP status code indicates an error (>= 300).
39 40 41 |
# File 'lib/savon/transport/response.rb', line 39 def error? @code >= 300 end |