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

@@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.



27
28
29
30
31
32
# File 'lib/savon/response.rb', line 27

def initialize(http)
  @http = http

  handle_soap_fault
  handle_http_error
end

Instance Attribute Details

#httpObject (readonly)

Returns the HTTP response object.



64
65
66
# File 'lib/savon/response.rb', line 64

def http
  @http
end

#http_errorObject (readonly)

Returns the HTTP error message.



51
52
53
# File 'lib/savon/response.rb', line 51

def http_error
  @http_error
end

#soap_error_codeObject (readonly)

Returns the SOAP error code



43
44
45
# File 'lib/savon/response.rb', line 43

def soap_error_code
  @soap_error_code
end

#soap_faultObject (readonly)

Returns the SOAP fault message.



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

def soap_fault
  @soap_fault
end

Class Method Details

.error_handler(&blk) ⇒ Object

Sets a specific handler for errors to raise.



22
23
24
# File 'lib/savon/response.rb', line 22

def self.error_handler(&blk)
  @@error_handler = blk
end

.raise_errors=(raise_errors) ⇒ Object

Sets the global setting of whether to raise errors.



12
13
14
# File 'lib/savon/response.rb', line 12

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)


17
18
19
# File 'lib/savon/response.rb', line 17

def self.raise_errors?
  @@raise_errors
end

Instance Method Details

#http_error?Boolean

Returns whether there was an HTTP error.

Returns:

  • (Boolean)


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

def http_error?
  @http_error ? true : false
end

#soap_fault?Boolean

Returns whether there was a SOAP fault.

Returns:

  • (Boolean)


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

def soap_fault?
  @soap_fault ? true : false
end

#to_hashObject

Returns the SOAP response body as a Hash.



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

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.



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

def to_xml
  @http.body
end