lib/savon/response.rb in smacks-savon-0.1.0 vs lib/savon/response.rb in smacks-savon-0.1.1

- old
+ new

@@ -5,15 +5,15 @@ module Savon # Savon::Response represents the HTTP response. class Response - # The HTTP or SOAP fault message. - attr_reader :fault + # The HTTP error or SOAP fault message. + attr_reader :error_message - # The HTTP or SOAP fault code. - attr_reader :fault_code + # The HTTP error or SOAP fault code. + attr_reader :error_code # Initializer expects the HTTP response and checks for HTTP or SOAP faults. # # === Parameters # @@ -23,27 +23,27 @@ validate end # Returns true if the request was successful, false otherwise. def success? - @fault_code.nil? + @error_code.nil? end # Returns true if there was a HTTP or SOAP fault, false otherwise. - def fault? - !@fault_code.nil? + def error? + !@error_code.nil? end # Returns the SOAP response message as a Hash. Call with XPath expession # (Hpricot search) to define a custom +root_node+ to start parsing at. # Defaults to "//return". The root node will not be included in the Hash. # # === Parameters # # * +root_node+ - Optional. Custom root node to start parsing at. def to_hash(root_node = "//return") - return nil if fault? + return nil if error? ApricotEatsGorilla[@response.body, root_node] end # Returns the SOAP response message as a Savon::Mash object. Call with # XPath expession to define a custom +root_node+. Defaults to "//return". @@ -51,11 +51,11 @@ # # === Parameters # # * +root_node+ - Optional. Custom root node to start parsing at. def to_mash(root_node = "//return") - return nil if fault? + return nil if error? hash = to_hash(root_node) Savon::Mash.new(hash) end # Returns the SOAP response XML. @@ -63,17 +63,17 @@ @response.body end private - # Checks for HTTP and SOAP faults. + # Checks for HTTP errors and SOAP faults. def validate if @response.code.to_i >= 300 - @fault, @fault_code = @response.message, @response.code + @error_message, @error_code = @response.message, @response.code else - fault = to_hash("//soap:Fault") - @fault = fault[:faultstring] unless fault.nil? - @fault_code = fault[:faultcode] unless fault.nil? + soap_fault = to_hash("//soap:Fault") + @error_message = soap_fault[:faultstring] unless soap_fault.nil? + @error_code = soap_fault[:faultcode] unless soap_fault.nil? end end end end \ No newline at end of file