Class: Savon::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http, globals, locals) ⇒ Response

Returns a new instance of Response.



8
9
10
11
12
13
14
15
# File 'lib/savon/response.rb', line 8

def initialize(http, globals, locals)
  @http    = http
  @globals = globals
  @locals  = locals

  build_soap_and_http_errors!
  raise_soap_and_http_errors! if @globals[:raise_errors]
end

Instance Attribute Details

#globalsObject (readonly)

Returns the value of attribute globals.



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

def globals
  @globals
end

#httpObject (readonly)

Returns the value of attribute http.



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

def http
  @http
end

#http_errorObject (readonly)

Returns the value of attribute http_error.



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

def http_error
  @http_error
end

#localsObject (readonly)

Returns the value of attribute locals.



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

def locals
  @locals
end

#soap_faultObject (readonly)

Returns the value of attribute soap_fault.



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

def soap_fault
  @soap_fault
end

Instance Method Details

#bodyObject Also known as: to_hash



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

def body
  find('Body')
end

#docObject



62
63
64
# File 'lib/savon/response.rb', line 62

def doc
  @doc ||= Nokogiri.XML(xml)
end

#find(*path) ⇒ Object



70
71
72
73
74
75
# File 'lib/savon/response.rb', line 70

def find(*path)
  envelope = nori.find(hash, 'Envelope')
  raise_invalid_response_error! unless envelope

  nori.find(envelope, *path)
end

#hashObject



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

def hash
  @hash ||= nori.parse(xml)
end

#headerObject



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

def header
  find('Header')
end

#http_error?Boolean

Returns:

  • (Boolean)


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

def http_error?
  HTTPError.present? @http
end

#soap_fault?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/savon/response.rb', line 24

def soap_fault?
  SOAPFault.present? @http
end

#success?Boolean Also known as: successful?

Returns:

  • (Boolean)


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

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

#to_array(*path) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/savon/response.rb', line 42

def to_array(*path)
  result = path.inject body do |memo, key|
    return [] if memo[key].nil?
    memo[key]
  end

  result.kind_of?(Array) ? result.compact : [result].compact
end

#xmlObject Also known as: to_xml, to_s



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

def xml
  @http.body
end

#xpath(path, namespaces = nil) ⇒ Object



66
67
68
# File 'lib/savon/response.rb', line 66

def xpath(path, namespaces = nil)
  doc.xpath(path, namespaces || xml_namespaces)
end