Class: Savon::Response
- Inherits:
-
Object
- Object
- Savon::Response
- Defined in:
- lib/savon/response.rb
Constant Summary collapse
- CRLF =
/\r\n/
- WSP =
/[#{%Q|\x9\x20|}]/
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
- #attachments ⇒ Object
- #body ⇒ Object (also: #to_hash)
- #doc ⇒ Object
- #find(*path) ⇒ Object
- #full_hash ⇒ Object
- #header ⇒ Object
- #http_error? ⇒ Boolean
-
#initialize(http, 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(http, globals, locals) ⇒ Response
Returns a new instance of Response.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/savon/response.rb', line 11 def initialize(http, globals, locals) @http = http @globals = globals @locals = locals @attachments = [] @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.
23 24 25 |
# File 'lib/savon/response.rb', line 23 def globals @globals end |
#http ⇒ Object (readonly)
Returns the value of attribute http.
23 24 25 |
# File 'lib/savon/response.rb', line 23 def http @http end |
#http_error ⇒ Object (readonly)
Returns the value of attribute http_error.
23 24 25 |
# File 'lib/savon/response.rb', line 23 def http_error @http_error end |
#locals ⇒ Object (readonly)
Returns the value of attribute locals.
23 24 25 |
# File 'lib/savon/response.rb', line 23 def locals @locals end |
#soap_fault ⇒ Object (readonly)
Returns the value of attribute soap_fault.
23 24 25 |
# File 'lib/savon/response.rb', line 23 def soap_fault @soap_fault end |
Instance Method Details
#attachments ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/savon/response.rb', line 88 def if multipart? parse_body unless @has_parsed_body @attachments else [] end end |
#body ⇒ Object Also known as: to_hash
42 43 44 |
# File 'lib/savon/response.rb', line 42 def body find('Body') end |
#doc ⇒ Object
73 74 75 |
# File 'lib/savon/response.rb', line 73 def doc @doc ||= Nokogiri.XML(xml) end |
#find(*path) ⇒ Object
81 82 83 84 85 86 |
# File 'lib/savon/response.rb', line 81 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
57 58 59 |
# File 'lib/savon/response.rb', line 57 def full_hash @full_hash ||= nori.parse(xml) end |
#header ⇒ Object
38 39 40 |
# File 'lib/savon/response.rb', line 38 def header find('Header') end |
#http_error? ⇒ Boolean
34 35 36 |
# File 'lib/savon/response.rb', line 34 def http_error? HTTPError.present? @http end |
#multipart? ⇒ Boolean
97 98 99 |
# File 'lib/savon/response.rb', line 97 def multipart? !(http.headers['content-type'] =~ /^multipart/im).nil? end |
#soap_fault? ⇒ Boolean
30 31 32 |
# File 'lib/savon/response.rb', line 30 def soap_fault? SOAPFault.present?(@http, xml) end |
#success? ⇒ Boolean Also known as: successful?
25 26 27 |
# File 'lib/savon/response.rb', line 25 def success? !soap_fault? && !http_error? end |
#to_array(*path) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/savon/response.rb', line 48 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
61 62 63 64 65 66 67 68 |
# File 'lib/savon/response.rb', line 61 def xml if multipart? parse_body unless @has_parsed_body @xml else @http.body end end |
#xpath(path, namespaces = nil) ⇒ Object
77 78 79 |
# File 'lib/savon/response.rb', line 77 def xpath(path, namespaces = nil) doc.xpath(path, namespaces || xml_namespaces) end |