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.
-
#locals ⇒ Object
readonly
Returns the value of attribute locals.
Instance Method Summary collapse
- #body ⇒ Object (also: #to_hash)
- #doc ⇒ 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
- #to_xml ⇒ Object
- #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 |
# 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
#globals ⇒ Object (readonly)
Returns the value of attribute globals.
16 17 18 |
# File 'lib/savon/response.rb', line 16 def globals @globals end |
#http ⇒ Object (readonly)
Returns the value of attribute http.
16 17 18 |
# File 'lib/savon/response.rb', line 16 def http @http end |
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
16 17 18 |
# File 'lib/savon/response.rb', line 16 def locals @locals end |
Instance Method Details
#body ⇒ Object 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 |
#doc ⇒ Object
59 60 61 |
# File 'lib/savon/response.rb', line 59 def doc @doc ||= Nokogiri.XML(to_xml) end |
#hash ⇒ Object
51 52 53 |
# File 'lib/savon/response.rb', line 51 def hash @hash ||= nori.parse(to_xml) end |
#header ⇒ Object
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
27 28 29 |
# File 'lib/savon/response.rb', line 27 def http_error? HTTPError.present? @http end |
#soap_fault? ⇒ Boolean
23 24 25 |
# File 'lib/savon/response.rb', line 23 def soap_fault? SOAPFault.present? @http end |
#success? ⇒ Boolean Also known as: successful?
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_xml ⇒ Object
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 |