Class: Savon::SOAP::Response

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

Overview

Savon::SOAP::Response

Represents the SOAP response and contains the HTTP response.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Expects an HTTPI::Response and handles errors.



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

def initialize(response)
  self.http = response
  raise_errors if Savon.raise_errors?
end

Instance Attribute Details

#httpObject

Returns the value of attribute http.



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

def http
  @http
end

Instance Method Details

#http_errorObject

Returns the Savon::HTTP::Error.



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

def http_error
  @http_error ||= HTTP::Error.new http
end

#http_error?Boolean

Returns whether there was an HTTP error.

Returns:

  • (Boolean)


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

def http_error?
  http_error.present?
end

#soap_faultObject

Returns the Savon::SOAP::Fault.



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

def soap_fault
  @soap_fault ||= Fault.new http
end

#soap_fault?Boolean

Returns whether there was a SOAP fault.

Returns:

  • (Boolean)


27
28
29
# File 'lib/savon/soap/response.rb', line 27

def soap_fault?
  soap_fault.present?
end

#success?Boolean

Returns whether the request was successful.

Returns:

  • (Boolean)


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

def success?
  !soap_fault? && !http_error?
end

#to_array(*path) ⇒ Object

Traverses the SOAP response Hash for a given path of Hash keys and returns the value as an Array. Defaults to return an empty Array in case the path does not exist or returns nil.



54
55
56
57
58
59
60
61
# File 'lib/savon/soap/response.rb', line 54

def to_array(*path)
  value = path.inject to_hash do |memo, key|
    return [] unless memo[key]
    memo[key]
  end
  
  value.kind_of?(Array) ? value.compact : [value].compact
end

#to_hashObject

Returns the SOAP response body as a Hash.



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

def to_hash
  @hash ||= Savon::SOAP::XML.to_hash to_xml
end

#to_xmlObject

Returns the SOAP response XML.



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

def to_xml
  http.body
end