Class: Savon::WSDL::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/savon/wsdl/parser.rb

Overview

Savon::WSDL::Parser

Serves as a stream listener for parsing WSDL documents.

Constant Summary collapse

Sections =

The main sections of a WSDL document.

%w(definitions types message portType binding service)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParser

Returns a new instance of Parser.



15
16
17
# File 'lib/savon/wsdl/parser.rb', line 15

def initialize
  @path, @operations, @namespaces = [], {}, {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Catches calls to unimplemented hook methods.



85
86
# File 'lib/savon/wsdl/parser.rb', line 85

def method_missing(method, *args)
end

Instance Attribute Details

#endpointObject (readonly)

Returns the SOAP endpoint.



26
27
28
# File 'lib/savon/wsdl/parser.rb', line 26

def endpoint
  @endpoint
end

#namespaceObject (readonly)

Returns the namespace URI.



20
21
22
# File 'lib/savon/wsdl/parser.rb', line 20

def namespace
  @namespace
end

#operationsObject (readonly)

Returns the SOAP operations.



23
24
25
# File 'lib/savon/wsdl/parser.rb', line 23

def operations
  @operations
end

Instance Method Details

#depthObject

Returns our current depth in the WSDL document.



50
51
52
# File 'lib/savon/wsdl/parser.rb', line 50

def depth
  @path.size
end

#operation_from(tag, attrs) ⇒ Object

Stores available operations from a given tag name and attrs.



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/savon/wsdl/parser.rb', line 72

def operation_from(tag, attrs)
  @input = attrs["name"] if attrs["name"]

  if attrs["soapAction"]
    @action = !attrs["soapAction"].blank? ? attrs["soapAction"] : @input
    @input = @action.split("/").last if !@input || @input.empty?

    @operations[@input.snakecase.to_sym] = { :action => @action, :input => @input }
    @input, @action = nil, nil
  end
end

#read_namespaces(attrs) ⇒ Object

Reads namespace definitions from a given attrs Hash.



55
56
57
58
59
# File 'lib/savon/wsdl/parser.rb', line 55

def read_namespaces(attrs)
  attrs.each do |key, value|
    @namespaces[key.strip_namespace] = value if key.starts_with? "xmlns:"
  end
end

#tag_end(tag) ⇒ Object

Hook method called when the stream parser encounters a closing tag.



62
63
64
65
66
67
68
69
# File 'lib/savon/wsdl/parser.rb', line 62

def tag_end(tag)
  @path.pop

  if @section == :binding && @input && tag.strip_namespace == "operation"
    # no soapAction attribute found till now
    operation_from tag, "soapAction" => @input
  end
end

#tag_start(tag, attrs) ⇒ Object

Hook method called when the stream parser encounters a starting tag.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/savon/wsdl/parser.rb', line 29

def tag_start(tag, attrs)
  # read xml namespaces if root element
  read_namespaces(attrs) if @path.empty?

  tag, namespace = tag.split(":").reverse
  @path << tag

  if @section == :binding && tag == "binding"
    # ensure that we are in an wsdl/soap namespace
    @section = nil unless @namespaces[namespace].starts_with? "http://schemas.xmlsoap.org/wsdl/soap"
  end

  @section = tag.to_sym if Sections.include?(tag) && depth <= 2

  @namespace ||= attrs["targetNamespace"] if @section == :definitions
  @endpoint ||= URI(URI.escape(attrs["location"])) if @section == :service && tag == "address"

  operation_from tag, attrs if @section == :binding && tag == "operation"
end