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
# File 'lib/savon/response.rb', line 8

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

  raise_soap_and_http_errors! if @globals[:raise_errors]
end

Instance Attribute Details

#globalsObject (readonly)

Returns the value of attribute globals.



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

def globals
  @globals
end

#httpObject (readonly)

Returns the value of attribute http.



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

def http
  @http
end

#localsObject (readonly)

Returns the value of attribute locals.



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

def locals
  @locals
end

Instance Method Details

#bodyObject Also known as: to_hash



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

def body
  raise_invalid_response_error! unless hash.key? :envelope
  hash[:envelope][:body]
end

#docObject



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

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

#hashObject



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

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

#headerObject



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

def header
  raise_invalid_response_error! unless hash.key? :envelope
  hash[:envelope][:header]
end

#http_error?Boolean

Returns:

  • (Boolean)


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

def http_error?
  HTTPError.present? @http
end

#soap_fault?Boolean

Returns:

  • (Boolean)


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

def soap_fault?
  SOAPFault.present? @http
end

#success?Boolean Also known as: successful?

Returns:

  • (Boolean)


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

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

#to_xmlObject



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

def to_xml
  @http.body
end

#xpath(path, namespaces = nil) ⇒ Object



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

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