handsoap 1.1.6 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  ---
2
- :patch: 6
2
+ :patch: 7
3
3
  :major: 1
4
4
  :minor: 1
5
5
  :build:
@@ -226,12 +226,15 @@ module Handsoap
226
226
  end
227
227
  doc = make_envelope do |body,header|
228
228
  if options[:soap_header]
229
- options[:soap_header].each_pair do |k,v|
230
- header.add k,v
231
- end
229
+ iterate_hash_array(header, options[:soap_header])
232
230
  end
233
231
 
234
- body.add action
232
+ if options[:soap_body]
233
+ action_hash = { action => options[:soap_body] }
234
+ iterate_hash_array(body, action_hash)
235
+ else
236
+ body.add(action)
237
+ end
235
238
  end
236
239
  if block_given?
237
240
  yield doc.find(action)
@@ -248,6 +251,8 @@ module Handsoap
248
251
  end
249
252
  end
250
253
 
254
+
255
+
251
256
  # Async invocation
252
257
  #
253
258
  # Creates an XML document and sends it over HTTP.
@@ -319,6 +324,26 @@ module Handsoap
319
324
  return nil
320
325
  end
321
326
 
327
+
328
+
329
+ #Used to iterate over a Hash, that can include Hash, Array or String/Float/Integer etc and insert it in the correct element.
330
+ def iterate_hash_array(element, hash_array)
331
+ hash_array.each {|hash| iterate_hash_array(element, hash) } if hash_array.is_a?(Array)
332
+ hash_array.each do |name,value|
333
+ if value.is_a?(Hash)
334
+ element.add(name){|subelement| iterate_hash_array(subelement, value)}
335
+ elsif value.is_a?(Array)
336
+ element.add(name) do |subelement|
337
+ value.each do |item|
338
+ iterate_hash_array(subelement, item) if item.is_a?(Hash)
339
+ end
340
+ end
341
+ else
342
+ element.add name, value.to_s
343
+ end
344
+ end
345
+ end
346
+
322
347
  # Hook that is called when a new request document is created.
323
348
  #
324
349
  # You can override this to add namespaces and other elements that are common to all requests (Such as authentication).
@@ -15,9 +15,9 @@ module Handsoap
15
15
  def initialize
16
16
  @namespaces = {}
17
17
  end
18
- def add(node_name, value = nil, *flags) # :yields: Handsoap::XmlMason::Element
18
+ def add(node_name, value = nil, options = {}) # :yields: Handsoap::XmlMason::Element
19
19
  prefix, name = parse_ns(node_name)
20
- node = append_child Element.new(self, prefix, name, value, flags)
20
+ node = append_child Element.new(self, prefix, name, value, options)
21
21
  if block_given?
22
22
  yield node
23
23
  end
@@ -105,7 +105,7 @@ module Handsoap
105
105
  end
106
106
 
107
107
  class Element < Node
108
- def initialize(parent, prefix, node_name, value = nil, flags = []) # :yields: Handsoap::XmlMason::Element
108
+ def initialize(parent, prefix, node_name, value = nil, options = {}) # :yields: Handsoap::XmlMason::Element
109
109
  super()
110
110
  # if prefix.to_s == ""
111
111
  # raise "missing prefix"
@@ -115,8 +115,11 @@ module Handsoap
115
115
  @node_name = node_name
116
116
  @children = []
117
117
  @attributes = {}
118
+ if options[:attributes]
119
+ @attributes = options[:attributes]
120
+ end
118
121
  if not value.nil?
119
- set_value value.to_s, *flags
122
+ set_value value.to_s, options
120
123
  end
121
124
  if block_given?
122
125
  yield self
@@ -142,14 +145,14 @@ module Handsoap
142
145
  end
143
146
  # Sets the inner text of this element.
144
147
  #
145
- # By default the string is escaped, but you can pass the flag :raw to inject XML.
148
+ # By default the string is escaped, but you can pass the option flag :raw to inject XML.
146
149
  #
147
150
  # You usually won't need to call this method, but will rather use +add+
148
- def set_value(value, *flags)
151
+ def set_value(value, options = {})
149
152
  if @children.length > 0
150
153
  raise "Element already has children. Can't set value"
151
154
  end
152
- if flags && flags.include?(:raw)
155
+ if options && options.include?(:raw)
153
156
  @children = [RawContent.new(value)]
154
157
  else
155
158
  @children = [TextNode.new(value)]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: handsoap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Troels Knak-Nielsen
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-01-16 00:00:00 +01:00
13
+ date: 2010-02-11 00:00:00 +01:00
14
14
  default_executable:
15
15
  dependencies: []
16
16