Sha256: 712e5c5dff9e0c8628ae85609fa4cd1c5ce5fb1c22f72e9131401cbdb4123d2d

Contents?: true

Size: 1.77 KB

Versions: 5

Compression:

Stored size: 1.77 KB

Contents

require "savon/soap/xml"
require "savon/soap/fault"
require "savon/http/error"

module Savon
  module SOAP

    # = Savon::SOAP::Response
    #
    # Represents the SOAP response and contains the HTTP response.
    class Response

      # Expects an <tt>HTTPI::Response</tt> and handles errors.
      def initialize(response)
        self.http = response
        raise_errors if Savon.raise_errors?
      end

      attr_accessor :http

      # Returns whether the request was successful.
      def success?
        !soap_fault? && !http_error?
      end

      # Returns whether there was a SOAP fault.
      def soap_fault?
        soap_fault.present?
      end

      # Returns the <tt>Savon::SOAP::Fault</tt>.
      def soap_fault
        @soap_fault ||= Fault.new http
      end

      # Returns whether there was an HTTP error.
      def http_error?
        http_error.present?
      end

      # Returns the <tt>Savon::HTTP::Error</tt>.
      def http_error
        @http_error ||= HTTP::Error.new http
      end

      # Returns the SOAP response header as a Hash.
      def header
        @header_hash ||= basic_hash.find_soap_header
      end

      # Returns the SOAP response body as a Hash.
      def to_hash
        @hash ||= Savon::SOAP::XML.to_hash basic_hash
      end

      # Returns the SOAP response body as an Array.
      def to_array(*path)
        Savon::SOAP::XML.to_array to_hash, *path
      end

      # Returns the complete SOAP response XML without normalization.
      def basic_hash
        @basic_hash ||= Savon::SOAP::XML.parse http.body
      end

      # Returns the SOAP response XML.
      def to_xml
        http.body
      end

    private

      def raise_errors
        raise soap_fault if soap_fault?
        raise http_error if http_error?
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
s-savon-0.8.6 lib/savon/soap/response.rb
savon-0.9.0 lib/savon/soap/response.rb
savon-0.8.6 lib/savon/soap/response.rb
savon-0.8.5 lib/savon/soap/response.rb
savon-0.8.4 lib/savon/soap/response.rb