Module: Vindicia::XMLBuilder

Included in:
SoapClient, SoapObject
Defined in:
lib/vindicia.rb

Instance Method Summary collapse

Instance Method Details

#build_array_xml(xml, name, type, value) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/vindicia.rb', line 141

def build_array_xml(xml, name, type, value)
  attrs = {
    "xmlns:enc" => "http://schemas.xmlsoap.org/soap/encoding/",
    "xsi:type" => "enc:Array",
    "enc:arrayType" => "vin:#{name}[#{value.size}]"
  }
  xml.tag!(name, attrs) do |x|
    value.each do |val|
      build_tag_xml(x, 'item', type, val)
    end
  end
end

#build_tag_xml(xml, name, type, value) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/vindicia.rb', line 154

def build_tag_xml(xml, name, type, value)
  case value
  when Hash
    Vindicia.class(type).new(value).build(xml, name)
  when SoapObject
    value.build(xml, name)
  when NilClass
    xml.tag!(name, value, {"xsi:nil" => true})
  else
    type = type.sub(/^tns/,'vin')
    # format dates/times with full timestamp
    value = value.strftime('%Y-%m-%dT%H:%M:%S%z') if value.respond_to?(:strftime) && type == 'xsd:dateTime'
    xml.tag!(name, value, {"xsi:type" => type})
  end
end

#build_xml(xml, name, type, value) ⇒ Object



133
134
135
136
137
138
139
# File 'lib/vindicia.rb', line 133

def build_xml(xml, name, type, value)
  if value.kind_of? Array
    build_array_xml(xml, name, type, value)
  else
    build_tag_xml(xml, name, type, value)
  end
end