class LolSoap::WSDL

Attributes

endpoint[R]

The SOAP endpoint URL

namespaces[R]

Hash of namespaces to generated prefixes

prefixes[R]

Hash of generated prefixes to namespaces

soap_version[R]

The version of SOAP detected.

Public Class Methods

new(parser, options={}) click to toggle source
# File lib/lolsoap/wsdl.rb, line 32
def initialize(parser, options={})
  @prefixes = generate_prefixes(parser)
  @namespaces = prefixes.invert
  @abstract_types = load_types(parser.abstract_types)
  @types = load_types(parser.types)
  @operations = load_operations(parser)
  @endpoint = parser.endpoint
  @soap_version = parser.soap_version
  @allow_abstract_types = options[:allow_abstract_types]
end
parse(raw, options={}) click to toggle source

Create a new instance by parsing a raw string of XML

# File lib/lolsoap/wsdl.rb, line 16
def self.parse(raw, options={})
  new(WSDLParser.parse(raw), options)
end

Public Instance Methods

abstract_type(namespace, name) click to toggle source

Get a single abstract type, or a NullType if the type doesn't exist

# File lib/lolsoap/wsdl.rb, line 63
def abstract_type(namespace, name)
  @abstract_types.fetch([namespace, name]) { NullType.new }
end
abstract_types() click to toggle source

Hash of abstract types declared by the service

# File lib/lolsoap/wsdl.rb, line 49
def abstract_types
  Hash[@abstract_types.values.map { |t| [t.name, t] }]
end
inspect() click to toggle source
# File lib/lolsoap/wsdl.rb, line 82
def inspect
  "<#{self.class} " \
  "namespaces=#{namespaces.inspect} " \
  "operations=#{operations.inspect} " \
  "types=#{types.inspect}>"
end
operation(name) click to toggle source

Get a single operation

# File lib/lolsoap/wsdl.rb, line 73
def operation(name)
  @operations.fetch(name)
end
operations() click to toggle source

Hash of operations that are supported by the SOAP service

# File lib/lolsoap/wsdl.rb, line 68
def operations
  Hash[@operations.values.map { |o| [o.name, o] }]
end
prefix(namespace) click to toggle source

Get the prefix for a namespace

# File lib/lolsoap/wsdl.rb, line 78
def prefix(namespace)
  prefixes.fetch namespace
end
type(namespace, name) click to toggle source

Get a single type, or a NullType if the type doesn't exist

# File lib/lolsoap/wsdl.rb, line 54
def type(namespace, name)
  if @allow_abstract_types
    @types.fetch([namespace, name]) { abstract_type(namespace, name) }
  else
    @types.fetch([namespace, name]) { NullType.new }
  end
end
types() click to toggle source

Hash of types declared by the service

# File lib/lolsoap/wsdl.rb, line 44
def types
  Hash[@types.values.map { |t| [t.name, t] }]
end

Private Instance Methods

build_element(params) click to toggle source

@private

# File lib/lolsoap/wsdl.rb, line 150
def build_element(params)
  Element.new(
    self,
    params[:name],
    params[:namespace] && prefix(params[:namespace]),
    type_reference(params[:type]),
    params[:singular]
  )
end
build_elements(elements) click to toggle source

@private

# File lib/lolsoap/wsdl.rb, line 141
def build_elements(elements)
  Hash[
    elements.map do |name, el|
      [name, build_element(el)]
    end
  ]
end
build_io(io, parser) click to toggle source

@private

# File lib/lolsoap/wsdl.rb, line 170
def build_io(io, parser)
  OperationIO.new(
    build_io_part('Header', io[:header], parser),
    build_io_part('Body', io[:body], parser)
  )
end
build_io_part(name, elements, parser) click to toggle source

@private

# File lib/lolsoap/wsdl.rb, line 178
def build_io_part(name, elements, parser)
  OperationIOPart.new(
    self,
    name,
    type_reference(io_part_type(name, elements, parser))
  )
end
build_type(params) click to toggle source

@private

# File lib/lolsoap/wsdl.rb, line 131
def build_type(params)
  Type.new(
    params[:name],
    params[:prefix] || prefix(params.fetch(:namespace)),
    build_elements(params.fetch(:elements)),
    params.fetch(:attributes)
  )
end
generate_prefixes(parser) click to toggle source

@private

# File lib/lolsoap/wsdl.rb, line 116
def generate_prefixes(parser)
  prefixes = {}
  index    = 0

  parser.types.merge(parser.elements).values.each do |el|
    unless prefixes[el[:namespace]]
      prefixes[el[:namespace]] = "ns#{index}"
      index += 1
    end
  end

  prefixes
end
io_part_type(name, elements, parser) click to toggle source

@private

# File lib/lolsoap/wsdl.rb, line 187
def io_part_type(name, elements, parser)
  return unless elements.any?

  {
    :name       => name,
    :prefix     => 'soap',
    :elements   => Hash[
      elements.map { |el|
        element = parser.elements.fetch(el)
        [element[:name], element]
      }
    ],
    :attributes => []
  }
end
load_operations(parser) click to toggle source

@private

# File lib/lolsoap/wsdl.rb, line 101
def load_operations(parser)
  Hash[
    parser.operations.map do |k, op|
      [k, Operation.new(
        self,
        k,
        op[:action],
        build_io(op[:input], parser),
        build_io(op[:output], parser)
      )]
    end
  ]
end
load_types(types) click to toggle source

@private

# File lib/lolsoap/wsdl.rb, line 92
def load_types(types)
  Hash[
    types.map do |id, type|
      [id, build_type(type)]
    end
  ]
end
type_reference(type) click to toggle source

@private

# File lib/lolsoap/wsdl.rb, line 161
def type_reference(type)
  if type.is_a?(Array)
    NamedTypeReference.new(*type, self)
  else
    ImmediateTypeReference.new(type ? build_type(type) : NullType.new)
  end
end