Class: Wasabi::Document
- Inherits:
-
Object
- Object
- Wasabi::Document
- Defined in:
- lib/wasabi/document.rb
Overview
Wasabi::Document
Represents a WSDL document.
Constant Summary collapse
- ELEMENT_FORM_DEFAULTS =
[:unqualified, :qualified]
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#document ⇒ Object
(also: #document?)
Returns the value of attribute document.
-
#endpoint ⇒ Object
Returns the SOAP endpoint.
-
#namespace ⇒ Object
Returns the target namespace.
-
#request ⇒ Object
Returns the value of attribute request.
-
#service_name ⇒ Object
Returns the service name.
-
#xml ⇒ Object
Returns the raw WSDL document.
Class Method Summary collapse
-
.validate_element_form_default!(value) ⇒ Object
Validates if a given
valueis a valid elementFormDefault value.
Instance Method Summary collapse
-
#element_form_default ⇒ Object
Returns the value of elementFormDefault.
-
#element_form_default=(value) ⇒ Object
Sets the elementFormDefault value.
-
#endpoint_for_operation(operation_name, soap_version: nil) ⇒ Object
Returns the SOAP endpoint of the port serving the given SOAP operation.
-
#initialize(document = nil, adapter = nil) ⇒ Document
constructor
Accepts a WSDL
documentto parse. -
#operation_input_parameters(key) ⇒ Object
Returns a list of input parameters for a given
key. -
#operations ⇒ Object
Returns a map of SOAP operations.
-
#parser ⇒ Object
Parses the WSDL document and returns the Wasabi::Parser.
-
#soap_action(key) ⇒ Object
Returns the SOAP action for a given
key. -
#soap_action_parameters(key) ⇒ Object
Returns a list of parameter names for a given
key. -
#soap_actions ⇒ Object
Returns a list of available SOAP actions.
-
#soap_input(key) ⇒ Object
Returns the SOAP input for a given
key. - #type_definitions ⇒ Object
- #type_namespaces ⇒ Object
-
#user_defined(namespace) ⇒ Object
Returns whether the given
namespacewas defined manually.
Constructor Details
#initialize(document = nil, adapter = nil) ⇒ Document
Accepts a WSDL document to parse.
24 25 26 27 |
# File 'lib/wasabi/document.rb', line 24 def initialize(document = nil, adapter = nil) self.document = document self.adapter = adapter end |
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
29 30 31 |
# File 'lib/wasabi/document.rb', line 29 def adapter @adapter end |
#document ⇒ Object Also known as: document?
Returns the value of attribute document.
29 30 31 |
# File 'lib/wasabi/document.rb', line 29 def document @document end |
#endpoint ⇒ Object
Returns the SOAP endpoint.
36 37 38 |
# File 'lib/wasabi/document.rb', line 36 def endpoint @endpoint ||= parser.endpoint end |
#namespace ⇒ Object
Returns the target namespace.
57 58 59 |
# File 'lib/wasabi/document.rb', line 57 def namespace @namespace ||= parser.namespace end |
#request ⇒ Object
Returns the value of attribute request.
29 30 31 |
# File 'lib/wasabi/document.rb', line 29 def request @request end |
#service_name ⇒ Object
Returns the service name.
96 97 98 |
# File 'lib/wasabi/document.rb', line 96 def service_name @service_name ||= parser.service_name end |
#xml ⇒ Object
Returns the raw WSDL document. Can be used as a hook to extend the library.
162 163 164 |
# File 'lib/wasabi/document.rb', line 162 def xml @xml ||= Resolver.new(document, request, adapter).resolve end |
Class Method Details
.validate_element_form_default!(value) ⇒ Object
Validates if a given value is a valid elementFormDefault value.
Raises an ArgumentError if the value is not valid.
16 17 18 19 20 21 |
# File 'lib/wasabi/document.rb', line 16 def self.validate_element_form_default!(value) return if ELEMENT_FORM_DEFAULTS.include?(value) raise ArgumentError, "Invalid value for elementFormDefault: #{value}\n" \ "Must be one of: #{ELEMENT_FORM_DEFAULTS.inspect}" end |
Instance Method Details
#element_form_default ⇒ Object
Returns the value of elementFormDefault.
65 66 67 |
# File 'lib/wasabi/document.rb', line 65 def element_form_default @element_form_default ||= document ? parser.element_form_default : :unqualified end |
#element_form_default=(value) ⇒ Object
Sets the elementFormDefault value.
70 71 72 73 |
# File 'lib/wasabi/document.rb', line 70 def element_form_default=(value) self.class.validate_element_form_default!(value) @element_form_default = value end |
#endpoint_for_operation(operation_name, soap_version: nil) ⇒ Object
Returns the SOAP endpoint of the port serving the given SOAP operation.
Walks operation -> portType -> binding -> port, so WSDLs exposing
several ports resolve to the address of the port that actually serves
the operation instead of the first port's address. When soap_version
is given, a port for that SOAP version is preferred; otherwise the
first SOAP port for the operation is returned. Non-SOAP ports are
never returned. Returns nil when the operation has no SOAP ports,
so callers can fall back to #endpoint.
52 53 54 |
# File 'lib/wasabi/document.rb', line 52 def endpoint_for_operation(operation_name, soap_version: nil) service_ports.endpoint_for_operation(operation_name, soap_version: soap_version) end |
#operation_input_parameters(key) ⇒ Object
Returns a list of input parameters for a given key.
109 110 111 |
# File 'lib/wasabi/document.rb', line 109 def operation_input_parameters(key) parser.operations[key][:parameters] if operations[key] end |
#operations ⇒ Object
Returns a map of SOAP operations.
91 92 93 |
# File 'lib/wasabi/document.rb', line 91 def operations @operations ||= parser.operations end |
#parser ⇒ Object
Parses the WSDL document and returns the Wasabi::Parser.
167 168 169 |
# File 'lib/wasabi/document.rb', line 167 def parser @parser ||= guard_parse && parse end |
#soap_action(key) ⇒ Object
Returns the SOAP action for a given key.
81 82 83 |
# File 'lib/wasabi/document.rb', line 81 def soap_action(key) operations[key][:action] if operations[key] end |
#soap_action_parameters(key) ⇒ Object
Returns a list of parameter names for a given key
103 104 105 106 |
# File 'lib/wasabi/document.rb', line 103 def soap_action_parameters(key) params = operation_input_parameters(key) params&.keys end |
#soap_actions ⇒ Object
Returns a list of available SOAP actions.
76 77 78 |
# File 'lib/wasabi/document.rb', line 76 def soap_actions @soap_actions ||= parser.operations.keys end |
#soap_input(key) ⇒ Object
Returns the SOAP input for a given key.
86 87 88 |
# File 'lib/wasabi/document.rb', line 86 def soap_input(key) operations[key][:input] if operations[key] end |
#type_definitions ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/wasabi/document.rb', line 133 def type_definitions @type_definitions ||= begin result = [] if document parser.types.each do |ns, types| types.each do |type, info| element_keys(info).each do |field| field_type = info[field][:type] tag, namespace = field_type.split(":").reverse result << [[type, field], tag] if user_defined(namespace) end end end end result end end |
#type_namespaces ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/wasabi/document.rb', line 113 def type_namespaces @type_namespaces ||= begin namespaces = [] if document parser.types.each do |ns, types| types.each do |type, info| namespaces << [[type], info[:namespace]] element_keys(info).each do |field| namespaces << [[type, field], info[:namespace]] end end end end namespaces end end |
#user_defined(namespace) ⇒ Object
Returns whether the given namespace was defined manually.
155 156 157 158 |
# File 'lib/wasabi/document.rb', line 155 def user_defined(namespace) uri = parser.namespaces[namespace] !(uri =~ %r{^http://schemas.xmlsoap.org} || uri =~ %r{^http://www.w3.org}) end |