Class: Savon::WSDL::Parser

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

Overview

Savon::WSDL::Parser

Parses WSDL documents and remembers the parts of them we care about.

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

#initialize(nokogiri_document) ⇒ Parser

Returns a new instance of Parser.



15
16
17
18
19
20
21
# File 'lib/savon/wsdl/parser.rb', line 15

def initialize(nokogiri_document)
  @document = nokogiri_document
  @path = []
  @operations = {}
  @namespaces = {}
  @element_form_default = :unqualified
end

Instance Attribute Details

#element_form_defaultObject (readonly)

Returns the elementFormDefault value.



33
34
35
# File 'lib/savon/wsdl/parser.rb', line 33

def element_form_default
  @element_form_default
end

#endpointObject (readonly)

Returns the SOAP endpoint.



30
31
32
# File 'lib/savon/wsdl/parser.rb', line 30

def endpoint
  @endpoint
end

#namespaceObject (readonly)

Returns the namespace URI.



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

def namespace
  @namespace
end

#operationsObject (readonly)

Returns the SOAP operations.



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

def operations
  @operations
end

Instance Method Details

#parseObject



35
36
37
38
39
# File 'lib/savon/wsdl/parser.rb', line 35

def parse
  parse_namespaces
  parse_endpoint
  parse_operations
end

#parse_endpointObject



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/savon/wsdl/parser.rb', line 54

def parse_endpoint
  endpoint = @document.at_xpath(
    "s0:definitions/s0:service//soap11:address/@location",
    "s0" => "http://schemas.xmlsoap.org/wsdl/",
    "soap11" => "http://schemas.xmlsoap.org/wsdl/soap/")
  endpoint ||= @document.at_xpath(
    "s0:definitions/s0:service//soap12:address/@location",
    "s0" => "http://schemas.xmlsoap.org/wsdl/",
    "soap12" => "http://schemas.xmlsoap.org/wsdl/soap12/")
  @endpoint = URI(URI.escape(endpoint.to_s)) if endpoint
end

#parse_namespacesObject



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/savon/wsdl/parser.rb', line 41

def parse_namespaces
  element_form_default = @document.at_xpath(
    "s0:definitions/s0:types/xs:schema/@elementFormDefault",
    "s0" => "http://schemas.xmlsoap.org/wsdl/",
    "xs" => "http://www.w3.org/2001/XMLSchema")
  @element_form_default = element_form_default.to_s.to_sym if element_form_default

  namespace = @document.at_xpath(
    "s0:definitions/@targetNamespace",
    "s0" => "http://schemas.xmlsoap.org/wsdl/")
  @namespace = namespace.to_s if namespace
end

#parse_operationsObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/savon/wsdl/parser.rb', line 66

def parse_operations
  operations = @document.xpath(
    "s0:definitions/s0:binding/s0:operation",
    "s0" => "http://schemas.xmlsoap.org/wsdl/")
  operations.each do |operation|
    name = operation.attribute("name").to_s

    soap_action = operation.at_xpath(".//soap11:operation/@soapAction",
      "soap11" => "http://schemas.xmlsoap.org/wsdl/soap/"
    )
    soap_action ||= operation.at_xpath(".//soap12:operation/@soapAction",
      "soap12" => "http://schemas.xmlsoap.org/wsdl/soap12/"
    )
    if soap_action
      soap_action = soap_action.to_s

      action = !soap_action.blank? ? soap_action : name
      input = (!name || name.empty?) ? action.split("/").last : name

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