Class: Savon::Response
- Inherits:
-
Object
- Object
- Savon::Response
- Defined in:
- lib/savon/response.rb
Instance Attribute Summary collapse
-
#globals ⇒ Object
readonly
Returns the value of attribute globals.
-
#http ⇒ Object
readonly
Returns the value of attribute http.
-
#http_error ⇒ Object
readonly
Returns the value of attribute http_error.
-
#locals ⇒ Object
readonly
Returns the value of attribute locals.
-
#soap_fault ⇒ Object
readonly
Returns the value of attribute soap_fault.
Instance Method Summary collapse
- #body ⇒ Object (also: #to_hash)
- #doc ⇒ Object
- #find(*path) ⇒ Object
- #hash ⇒ Object
- #header ⇒ Object
- #http_error? ⇒ Boolean
-
#initialize(http, globals, locals) ⇒ Response
constructor
A new instance of Response.
- #soap_fault? ⇒ Boolean
- #success? ⇒ Boolean (also: #successful?)
- #to_array(*path) ⇒ Object
- #xml ⇒ Object (also: #to_xml, #to_s)
- #xpath(path, namespaces = nil) ⇒ Object
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
#globals ⇒ Object (readonly)
Returns the value of attribute globals.
17 18 19 |
# File 'lib/savon/response.rb', line 17 def globals @globals end |
#http ⇒ Object (readonly)
Returns the value of attribute http.
17 18 19 |
# File 'lib/savon/response.rb', line 17 def http @http end |
#http_error ⇒ Object (readonly)
Returns the value of attribute http_error.
17 18 19 |
# File 'lib/savon/response.rb', line 17 def http_error @http_error end |
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
17 18 19 |
# File 'lib/savon/response.rb', line 17 def locals @locals end |
#soap_fault ⇒ Object (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
#body ⇒ Object Also known as: to_hash
36 37 38 |
# File 'lib/savon/response.rb', line 36 def body find('Body') end |
#doc ⇒ Object
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 |
#hash ⇒ Object
51 52 53 |
# File 'lib/savon/response.rb', line 51 def hash @hash ||= nori.parse(xml) end |
#header ⇒ Object
32 33 34 |
# File 'lib/savon/response.rb', line 32 def header find('Header') end |
#http_error? ⇒ Boolean
28 29 30 |
# File 'lib/savon/response.rb', line 28 def http_error? HTTPError.present? @http end |
#soap_fault? ⇒ Boolean
24 25 26 |
# File 'lib/savon/response.rb', line 24 def soap_fault? SOAPFault.present? @http end |
#success? ⇒ Boolean Also known as: successful?
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 |
#xml ⇒ Object 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 |