Class: Savon::Response

Inherits:
Object show all
Defined in:
lib/savon/response.rb

Overview

Savon::Response

Represents the HTTP and SOAP response.

Constant Summary collapse

MaxNonErrorResponseCode =

The maximum HTTP response code considered to be OK.

299
@@raise_errors =

The global setting of whether to raise errors.

true

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http) ⇒ Response

Expects a Net::HTTPResponse and handles errors.



25
26
27
28
29
30
# File 'lib/savon/response.rb', line 25

def initialize(http)
  @http = http

  handle_soap_fault
  handle_http_error
end

Instance Attribute Details

#httpObject (readonly)

Returns the HTTP response object.



59
60
61
# File 'lib/savon/response.rb', line 59

def http
  @http
end

#http_errorObject (readonly)

Returns the HTTP error message.



46
47
48
# File 'lib/savon/response.rb', line 46

def http_error
  @http_error
end

#soap_faultObject (readonly)

Returns the SOAP fault message.



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

def soap_fault
  @soap_fault
end

Class Method Details

.raise_errors=(raise_errors) ⇒ Object

Sets the global setting of whether to raise errors.



15
16
17
# File 'lib/savon/response.rb', line 15

def self.raise_errors=(raise_errors)
  @@raise_errors = raise_errors
end

.raise_errors?Boolean

Returns the global setting of whether to raise errors.

Returns:

  • (Boolean)


20
21
22
# File 'lib/savon/response.rb', line 20

def self.raise_errors?
  @@raise_errors
end

Instance Method Details

#http_error?Boolean

Returns whether there was an HTTP error.

Returns:

  • (Boolean)


41
42
43
# File 'lib/savon/response.rb', line 41

def http_error?
  !@http_error.blank?
end

#soap_fault?Boolean

Returns whether there was a SOAP fault.

Returns:

  • (Boolean)


33
34
35
# File 'lib/savon/response.rb', line 33

def soap_fault?
  !@soap_fault.blank?
end

#to_hashObject

Returns the SOAP response body as a Hash.



49
50
51
# File 'lib/savon/response.rb', line 49

def to_hash
  @body ||= (Crack::XML.parse(@http.body) rescue {}).find_soap_body
end

#to_xmlObject Also known as: to_s

Returns the SOAP response XML.



54
55
56
# File 'lib/savon/response.rb', line 54

def to_xml
  @http.body
end