Sha256: c8c9d53ddcc1f6c67a2405d02791ad8d89ad3dda5f8de90484381a8efeacdd1c

Contents?: true

Size: 1.86 KB

Versions: 9

Compression:

Stored size: 1.86 KB

Contents

module Savon

  # Savon::WSDL represents the WSDL document.
  class WSDL

    # Returns the namespace URI.
    def namespace_uri
      @namespace ||= parse_namespace_uri
    end

    # Returns an Array of available SOAP actions.
    def soap_actions
      @soap_actions ||= parse_soap_actions
    end

    # Returns an Array of choice elements.
    def choice_elements
      @choice_elements ||= parse_choice_elements
    end

    # Initializer expects the endpoint +uri+ and a Net::HTTP instance (+http+).
    def initialize(uri, http)
      @uri, @http = uri, http
    end

    # Returns the body of the Net::HTTPResponse from the WSDL request.
    def to_s
      @response ? @response.body : nil
    end

  private

    # Returns an Hpricot::Document of the WSDL. Retrieves the WSDL from the
    # endpoint URI in case it wasn't retrieved already.
    def document
      unless @document
        @response = @http.get("#{@uri.path}?#{@uri.query}")
        @document = Hpricot.XML(@response.body)
        raise ArgumentError, "Unable to find WSDL at: #{@uri}" if
          !soap_actions || soap_actions.empty?
      end
      @document
    end

    # Parses the WSDL for the namespace URI.
    def parse_namespace_uri
      definitions = document.at("//wsdl:definitions")
      definitions.get_attribute("targetNamespace") if definitions
    end

    # Parses the WSDL for available SOAP actions.
    def parse_soap_actions
      soap_actions = document.search("[@soapAction]")

      soap_actions.collect do |soap_action|
        soap_action.parent.get_attribute("name")
      end if soap_actions
    end

    # Parses the WSDL for choice elements.
    def parse_choice_elements
      choice_elements = document.search("//xs:choice//xs:element")

      choice_elements.collect do |choice_element|
        choice_element.get_attribute("ref").sub(/(.+):/, "")
      end if choice_elements
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
savon-0.3.2 lib/savon/wsdl.rb
savon-0.3.1 lib/savon/wsdl.rb
savon-0.3.0 lib/savon/wsdl.rb
savon-0.2.12 lib/savon/wsdl.rb
savon-0.2.11 lib/savon/wsdl.rb
savon-0.2.10 lib/savon/wsdl.rb
savon-0.2.9 lib/savon/wsdl.rb
savon-0.2.8 lib/savon/wsdl.rb
savon-0.2.7 lib/savon/wsdl.rb