Sha256: c77d52f4868cc4b5450bb2c4ef807f52ed998ceb85ee5d426c8985f9f7153629

Contents?: true

Size: 1.87 KB

Versions: 8

Compression:

Stored size: 1.87 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("//soap:operation")

      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

8 entries across 8 versions & 2 rubygems

Version Path
rubiii-savon-0.2.0 lib/savon/wsdl.rb
rubiii-savon-0.2.1 lib/savon/wsdl.rb
rubiii-savon-0.2.2 lib/savon/wsdl.rb
rubiii-savon-0.2.3 lib/savon/wsdl.rb
rubiii-savon-0.2.4 lib/savon/wsdl.rb
rubiii-savon-0.2.5 lib/savon/wsdl.rb
rubiii-savon-0.2.6 lib/savon/wsdl.rb
smacks-savon-0.2.0 lib/savon/wsdl.rb