Class: Savon::Transport::Response

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, headers, body) ⇒ Response

Returns a new instance of Response.

Parameters:

  • code (Integer)

    HTTP status code

  • headers (Hash)

    response headers

  • body (String)

    response body



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

#bodyObject (readonly)

Returns the response body string.



36
37
38
# File 'lib/savon/transport/response.rb', line 36

def body
  @body
end

#codeObject (readonly)

Returns the HTTP status code.



30
31
32
# File 'lib/savon/transport/response.rb', line 30

def code
  @code
end

#headersObject (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).

Returns:

  • (Boolean)


39
40
41
# File 'lib/savon/transport/response.rb', line 39

def error?
  @code >= 300
end