Class: Wasabi::Document

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document = nil, adapter = nil) ⇒ Document

Accepts a WSDL document to parse.



26
27
28
29
# File 'lib/wasabi/document.rb', line 26

def initialize(document = nil, adapter = nil)
  self.document = document
  self.adapter  = adapter
end

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



31
32
33
# File 'lib/wasabi/document.rb', line 31

def adapter
  @adapter
end

#documentObject Also known as: document?

Returns the value of attribute document.



31
32
33
# File 'lib/wasabi/document.rb', line 31

def document
  @document
end

#endpointObject

Returns the SOAP endpoint.



38
39
40
# File 'lib/wasabi/document.rb', line 38

def endpoint
  @endpoint ||= parser.endpoint
end

#namespaceObject

Returns the target namespace.



46
47
48
# File 'lib/wasabi/document.rb', line 46

def namespace
  @namespace ||= parser.namespace
end

#requestObject

Returns the value of attribute request.



31
32
33
# File 'lib/wasabi/document.rb', line 31

def request
  @request
end

#service_nameObject

Returns the service name.



85
86
87
# File 'lib/wasabi/document.rb', line 85

def service_name
  @service_name ||= parser.service_name
end

#xmlObject

Returns the raw WSDL document. Can be used as a hook to extend the library.



143
144
145
# File 'lib/wasabi/document.rb', line 143

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.

Raises:

  • (ArgumentError)


18
19
20
21
22
23
# File 'lib/wasabi/document.rb', line 18

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_defaultObject

Returns the value of elementFormDefault.



54
55
56
# File 'lib/wasabi/document.rb', line 54

def element_form_default
  @element_form_default ||= document ? parser.element_form_default : :unqualified
end

#element_form_default=(value) ⇒ Object

Sets the elementFormDefault value.



59
60
61
62
# File 'lib/wasabi/document.rb', line 59

def element_form_default=(value)
  self.class.validate_element_form_default!(value)
  @element_form_default = value
end

#operation_input_parameters(key) ⇒ Object

Returns a list of input parameters for a given key.



98
99
100
# File 'lib/wasabi/document.rb', line 98

def operation_input_parameters(key)
  parser.operations[key][:parameters] if operations[key]
end

#operationsObject

Returns a map of SOAP operations.



80
81
82
# File 'lib/wasabi/document.rb', line 80

def operations
  @operations ||= parser.operations
end

#parserObject

Parses the WSDL document and returns the Wasabi::Parser.



148
149
150
# File 'lib/wasabi/document.rb', line 148

def parser
  @parser ||= guard_parse && parse
end

#soap_action(key) ⇒ Object

Returns the SOAP action for a given key.



70
71
72
# File 'lib/wasabi/document.rb', line 70

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



92
93
94
95
# File 'lib/wasabi/document.rb', line 92

def soap_action_parameters(key)
  params = operation_input_parameters(key)
  params.keys if params
end

#soap_actionsObject

Returns a list of available SOAP actions.



65
66
67
# File 'lib/wasabi/document.rb', line 65

def soap_actions
  @soap_actions ||= parser.operations.keys
end

#soap_input(key) ⇒ Object

Returns the SOAP input for a given key.



75
76
77
# File 'lib/wasabi/document.rb', line 75

def soap_input(key)
  operations[key][:input] if operations[key]
end

#type_definitionsObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/wasabi/document.rb', line 118

def type_definitions
  @type_definitions ||= begin
    result = []

    parser.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 if document

    result
  end
end

#type_namespacesObject



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/wasabi/document.rb', line 102

def type_namespaces
  @type_namespaces ||= begin
    namespaces = []

    parser.types.each do |type, info|
      namespaces << [[type], info[:namespace]]

      element_keys(info).each do |field|
        namespaces << [[type, field], info[:namespace]]
      end
    end if document

    namespaces
  end
end

#user_defined(namespace) ⇒ Object

Returns whether the given namespace was defined manually.



136
137
138
139
# File 'lib/wasabi/document.rb', line 136

def user_defined(namespace)
  uri = parser.namespaces[namespace]
  !(uri =~ %r{^http://schemas.xmlsoap.org} || uri =~ %r{^http://www.w3.org})
end