Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added support to load Array or Hash in body or header for the invoke …

…method, just by giving it a Array or Hash in the options[:soap_body/header]
  • Loading branch information...
commit 183eadc9b373cd96eff2e253c3c56d9daa715e55 1 parent 5ca55b0
Peter Glerup Ericson pgericson authored
Showing with 31 additions and 6 deletions.
  1. +2 −2 handsoap.gemspec
  2. +29 −4 lib/handsoap/service.rb
4 handsoap.gemspec
View
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{handsoap}
- s.version = "1.1.5"
+ s.version = "1.1.6"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Troels Knak-Nielsen", "Jimmi Westerberg"]
- s.date = %q{2010-01-12}
+ s.date = %q{2010-01-18}
s.description = %q{Handsoap is a library for creating SOAP clients in Ruby}
s.email = ["troelskn@gmail.com", "frontend@unwire.dk"]
s.extra_rdoc_files = [
33 lib/handsoap/service.rb
View
@@ -226,12 +226,15 @@ def invoke(action, options = { :soap_action => :auto }, &block) # :yields: Hands
end
doc = make_envelope do |body,header|
if options[:soap_header]
- options[:soap_header].each_pair do |k,v|
- header.add k,v
- end
+ iterate_hash_array(header, options[:soap_header])
end
- body.add action
+ if options[:soap_body]
+ action_hash = { action => options[:soap_body] }
+ iterate_hash_array(body, action_hash)
+ else
+ body.add(action)
+ end
end
if block_given?
yield doc.find(action)
@@ -242,12 +245,15 @@ def invoke(action, options = { :soap_action => :auto }, &block) # :yields: Hands
}
headers["SOAPAction"] = options[:soap_action] unless options[:soap_action].nil?
on_before_dispatch
+ puts doc.to_s
request = make_http_request(self.uri, doc.to_s, headers,options[:http_options])
response = http_driver_instance.send_http_request(request)
parse_http_response(response)
end
end
+
+
# Async invocation
#
# Creates an XML document and sends it over HTTP.
@@ -319,6 +325,25 @@ def async(user_block, &block) # :yields: Handsoap::AsyncDispatch
return nil
end
+
+
+ #Used to iterate over a Hash, that can include Hash, Array or String/Float/Integer etc and insert it in the correct element.
+ def iterate_hash_array(element, hash_array)
+ hash_array.each {|hash| iterate_hash_array(element, hash)} if hash_array.is_a?(Array)
+ hash_array.each do |name,value|
+ if value.is_a?(Hash)
+ element.add(name){|subelement| iterate_hash_array(subelement, value)}
+ elsif value.is_a?(Array)
+ value.each do |item|
+ element.add(name, iterate_hash_array(element,item)) if item.is_a?(Hash)
+ end
+ else
+ puts "#{name.to_s}: #{name.class.to_s} - #{value.to_s}:#{value.class.to_s}"
+ element.add name, value.to_s
+ end
+ end
+ end
+
# Hook that is called when a new request document is created.
#
# You can override this to add namespaces and other elements that are common to all requests (Such as authentication).
Please sign in to comment.
Something went wrong with that request. Please try again.