Module: Uddi4r::SoapBuilder

Included in:
Connection
Defined in:
lib/soap_builder.rb

Overview

Helper module to be mixed into Uddi4r::Connection

Instance Method Summary collapse

Instance Method Details

#create_bodyObject

Create an empty DOM element for SOAP Body



39
40
41
# File 'lib/soap_builder.rb', line 39

def create_body
  body = REXML::Element.new("Body")
end

#create_element(name, value = nil, attributes = {}) ⇒ Object

Create a DOM element for given name



56
57
58
59
60
61
# File 'lib/soap_builder.rb', line 56

def create_element(name, value=nil, attributes={})
  elm = REXML::Element.new(name)
  elm.text = value if value
  attributes.each { |k,v| elm.add_attribute(k, v) }
  return elm
end

#create_elements(name, *values) ⇒ Object

Create element array



30
31
32
33
34
35
36
# File 'lib/soap_builder.rb', line 30

def create_elements(name, *values)
  elems = []
  values.each do |value|
    elems << create_element(name, value)
  end
  return elems
end

#create_operation(name, attribs = {}, *elements) ⇒ Object

Create the operation for the SOAP body

name

Name of the element

attribs

Attributes for the element

elements

Sub elements varargs (items can be nil, Hash,

Array of Hashes and REXML:Element)



68
69
70
71
72
73
74
# File 'lib/soap_builder.rb', line 68

def create_operation(name, attribs={}, *elements)
  operation = create_uddi_operation(name, attribs)
  elements.each do |elem|
    add_element(operation, elem)
  end
  return operation
end

#create_payload(body) ⇒ Object

Create payload for given body (DOM element)



8
9
10
11
12
13
14
15
16
# File 'lib/soap_builder.rb', line 8

def create_payload(body)
  content = REXML::Document.new()
  content << REXML::XMLDecl.new("1.0", "utf-8")
  envelope = REXML::Element.new("Envelope")
  envelope.add_attribute("xmlns", "http://schemas.xmlsoap.org/soap/envelope/")
  envelope << body
  content << envelope
  return content
end

#create_t_model_bag(keys) ⇒ Object

Creates tModelBag with key



19
20
21
22
23
24
25
26
27
# File 'lib/soap_builder.rb', line 19

def create_t_model_bag(keys)
  bags = []
  keys.each do |key|
    t_model_bag = REXML::Element.new("tModelBag")
    t_model_bag.add_element(create_element("tModelKey", key))
    bags << t_model_bag
  end
  return bags
end

#create_uddi_operation(name, attribs = {}) ⇒ Object

Create a template operation element for given name



44
45
46
47
48
49
50
51
52
53
# File 'lib/soap_builder.rb', line 44

def create_uddi_operation(name, attribs={})
  operation = REXML::Element.new(name)
  # set UDDI attributes
  operation.add_attribute("generic",@version)
  operation.add_attribute("xmlns",@uddi_namespace)
  operation.add_attribute("maxRows",@max_rows) if @max_rows      
  # add passed attributes
  attribs.each {|k,v| operation.add_attribute(k,v)}
  return operation
end