Class: Savon::Response
- Inherits:
-
Object
- Object
- Savon::Response
- Defined in:
- lib/savon/response.rb
Constant Summary collapse
- CRLF =
/\r\n/- WSP =
/[\t ]/
Instance Attribute Summary collapse
-
#globals ⇒ Object
readonly
Returns the value of attribute globals.
-
#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
- #attachments ⇒ Object
- #body ⇒ Object (also: #to_hash)
- #doc ⇒ Object
- #find(*path) ⇒ Object
- #full_hash ⇒ Object
- #hash ⇒ Object
- #header ⇒ Object
- #http ⇒ Object
- #http_error? ⇒ Boolean
-
#initialize(transport_response, globals, locals) ⇒ Response
constructor
A new instance of Response.
- #multipart? ⇒ Boolean
- #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(transport_response, globals, locals) ⇒ Response
Returns a new instance of Response.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/savon/response.rb', line 12 def initialize(transport_response, globals, locals) @transport_response = transport_response @globals = globals @locals = locals = [] @xml = '' @has_parsed_body = false 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.
24 25 26 |
# File 'lib/savon/response.rb', line 24 def globals @globals end |
#http_error ⇒ Object (readonly)
Returns the value of attribute http_error.
24 25 26 |
# File 'lib/savon/response.rb', line 24 def http_error @http_error end |
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
24 25 26 |
# File 'lib/savon/response.rb', line 24 def locals @locals end |
#soap_fault ⇒ Object (readonly)
Returns the value of attribute soap_fault.
24 25 26 |
# File 'lib/savon/response.rb', line 24 def soap_fault @soap_fault end |
Instance Method Details
#attachments ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/savon/response.rb', line 99 def if multipart? parse_body unless @has_parsed_body else [] end end |
#body ⇒ Object Also known as: to_hash
47 48 49 |
# File 'lib/savon/response.rb', line 47 def body find('Body') end |
#doc ⇒ Object
84 85 86 |
# File 'lib/savon/response.rb', line 84 def doc @doc ||= Nokogiri.XML(xml) end |
#find(*path) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/savon/response.rb', line 92 def find(*path) envelope = nori.find(full_hash, 'Envelope') raise_invalid_response_error! unless envelope.is_a?(Hash) nori.find(envelope, *path) end |
#full_hash ⇒ Object
68 69 70 |
# File 'lib/savon/response.rb', line 68 def full_hash @full_hash ||= nori.parse(xml) end |
#hash ⇒ Object
63 64 65 66 |
# File 'lib/savon/response.rb', line 63 def hash warn "Savon::Response#hash is deprecated and will be removed in version 3 - use #full_hash instead", uplevel: 1 full_hash end |
#header ⇒ Object
43 44 45 |
# File 'lib/savon/response.rb', line 43 def header find('Header') end |
#http ⇒ Object
26 27 28 |
# File 'lib/savon/response.rb', line 26 def http @transport_response end |
#http_error? ⇒ Boolean
39 40 41 |
# File 'lib/savon/response.rb', line 39 def http_error? HTTPError.present? http end |
#multipart? ⇒ Boolean
108 109 110 |
# File 'lib/savon/response.rb', line 108 def multipart? !(http.headers['content-type'] =~ /^multipart/im).nil? end |
#soap_fault? ⇒ Boolean
35 36 37 |
# File 'lib/savon/response.rb', line 35 def soap_fault? SOAPFault.present?(http, xml) end |
#success? ⇒ Boolean Also known as: successful?
30 31 32 |
# File 'lib/savon/response.rb', line 30 def success? !soap_fault? && !http_error? end |
#to_array(*path) ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/savon/response.rb', line 53 def to_array(*path) result = path.inject(body) { |memo, key| return [] if memo[key].nil? memo[key] } result.is_a?(Array) ? result.compact : [result].compact end |
#xml ⇒ Object Also known as: to_xml, to_s
72 73 74 75 76 77 78 79 |
# File 'lib/savon/response.rb', line 72 def xml if multipart? parse_body unless @has_parsed_body @xml else http.body end end |
#xpath(path, namespaces = nil) ⇒ Object
88 89 90 |
# File 'lib/savon/response.rb', line 88 def xpath(path, namespaces = nil) doc.xpath(path, namespaces || xml_namespaces) end |