Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

into 1.1.7

  • Loading branch information...
commit 78a294447edf140c0f1e970526109988062eac69 2 parents e8127f4 + 99e021a
Tiago Fernandes authored
View
2  .gitignore
@@ -7,3 +7,5 @@
log/*
pkg/*
tests/rails_root/*
+*.swp
+*.orig
View
2  DEPLOY.markdown
@@ -7,4 +7,4 @@ To make a release, do:
rake build
gem push pkg/handsoap-*.gem
-You need `jeweleer` and `gemcutter`, as well as login credentials for gemcutter.
+You need `jeweler` and `gemcutter`, as well as login credentials for gemcutter.
View
9 README.markdown
@@ -93,6 +93,15 @@ For parsing XML, Handsoap defaults to use [Nokogiri](http://github.com/tenderlov
Finally, there is a library for generating XML, which you'll use when mapping from Ruby to SOAP. It's quite similar to [Builder](http://builder.rubyforge.org/), but is tailored towards being used for writing SOAP-messages. The name of this library is `XmlMason` and it is included/part of Handsoap.
+Maintainers & Contributors
+---
+
+Handsoap is maintained by [Unwire A/S](http://www.unwire.dk), namely [Troels Knak-Nielsen](http://github.com/troelskn) and [Jimmi Westerberg](http://github.com/jimmiw), with the help of many other contributors.
+
+Use the git command below to see a list of them all. (GIT command was found at formtastic)
+
+ git shortlog -n -s --no-merges
+
License
---
View
2  VERSION.yml
@@ -1,5 +1,5 @@
---
+:patch: 7
:major: 1
:minor: 1
-:patch: 4
:build:
View
4 handsoap.gemspec
@@ -5,11 +5,11 @@
Gem::Specification.new do |s|
s.name = %q{handsoap}
- s.version = "1.1.4"
+ s.version = "1.1.7"
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{2009-11-04}
+ s.date = %q{2010-02-11}
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 = [
View
16 lib/handsoap/http/drivers/curb_driver.rb
@@ -19,12 +19,18 @@ def get_curl(url)
if @curl
@curl.url = url
else
- @curl = ::Curl::Easy.new(url)
- @curl.timeout = Handsoap.timeout
- @curl.enable_cookies = @enable_cookies
+ @curl = ::Curl::Easy.new(url)
+ @curl.timeout = Handsoap.timeout
+ @curl.enable_cookies = @enable_cookies
+
+ if Handsoap.follow_redirects?
+ @curl.follow_location = true
+ @curl.max_redirects = Handsoap.max_redirects
+ end
end
@curl
end
+
private :get_curl
def send_http_request(request)
@@ -33,6 +39,10 @@ def send_http_request(request)
if request.username && request.password
http_client.userpwd = [request.username, ":", request.password].join
end
+ http_client.cacert = request.trust_ca_file if request.trust_ca_file
+ http_client.cert = request.client_cert_file if request.client_cert_file
+ # I have submitted a patch for this to curb, but it's not yet supported. If you get errors, try upgrading curb.
+ http_client.cert_key = request.client_cert_key_file if request.client_cert_key_file
# pack headers
headers = request.headers.inject([]) do |arr, (k,v)|
arr + v.map {|x| "#{k}: #{x}" }
View
1  lib/handsoap/http/drivers/net_http_driver.rb
@@ -32,6 +32,7 @@ def send_http_request(request)
http_client = Net::HTTP.new(url.host, url.port)
#http_client.read_timeout = 120
+ http_client.open_timeout = Handsoap.timeout
http_client.read_timeout = Handsoap.timeout
http_client.use_ssl = true if url.scheme == 'https'
View
66 lib/handsoap/service.rb
@@ -35,6 +35,27 @@ def self.timeout=(timeout)
def self.timeout
@timeout || (self.timeout = 60)
end
+
+ # Tell Handsoap to follow redirects
+ def self.follow_redirects!
+ @follow_redirects = true
+ end
+
+ # Check whether Handsoap should follow redirects
+ def self.follow_redirects?
+ @follow_redirects || false
+ end
+
+ # Sets the max number of redirects
+ def self.max_redirects=(max_redirects)
+ @max_redirects = max_redirects
+ end
+
+ # Fetches the max number of redirects
+ # The default is 1
+ def self.max_redirects
+ @max_redirects || (self.max_redirects = 1)
+ end
# Wraps SOAP errors in a standard class.
class Fault < StandardError
@@ -193,7 +214,7 @@ def http_driver_instance
# +String+ sends a SOAPAction http header.
#
# +nil+ sends no SOAPAction http header.
- def invoke(action, options = { :soap_action => :auto }, &block) # :yields: Handsoap::XmlMason::Element
+ def invoke(action, options = { :soap_action => :auto, :http_options => nil }, &block) # :yields: Handsoap::XmlMason::Element
if action
if options.kind_of? String
options = { :soap_action => options }
@@ -204,11 +225,16 @@ def invoke(action, options = { :soap_action => :auto }, &block) # :yields: Hands
options[:soap_action] = nil
end
doc = make_envelope do |body,header|
- options[:soap_header].each_pair do |k,v|
- header.add k,v
+ if options[:soap_header]
+ 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)
@@ -219,12 +245,14 @@ def invoke(action, options = { :soap_action => :auto }, &block) # :yields: Hands
}
headers["SOAPAction"] = options[:soap_action] unless options[:soap_action].nil?
on_before_dispatch
- request = make_http_request(self.uri, doc.to_s, headers,options[:http_options])
+ 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.
@@ -296,6 +324,26 @@ 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)
+ element.add(name) do |subelement|
+ value.each do |item|
+ iterate_hash_array(subelement, item) if item.is_a?(Hash)
+ end
+ end
+ else
+ 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).
@@ -351,12 +399,14 @@ def debug(message = nil) #:nodoc:
end
end
- def make_http_request(uri, post_body, headers,http_options=nil)
+ def make_http_request(uri, post_body, headers, http_options=nil)
request = Handsoap::Http::Request.new(uri, :post)
# SSL CA AND CLIENT CERTIFICATES
- request.set_trust_ca_file(http_options[:trust_ca_file])
- request.set_client_cert_files(http_options[:client_cert_file],http_options[:client_cert_key_file])
+ if http_options
+ request.set_trust_ca_file(http_options[:trust_ca_file]) if http_options[:trust_ca_file]
+ request.set_client_cert_files(http_options[:client_cert_file], http_options[:client_cert_key_file]) if http_options[:client_cert_file] && http_options[:client_cert_key_file]
+ end
headers.each do |key, value|
request.add_header(key, value)
View
17 lib/handsoap/xml_mason.rb
@@ -15,9 +15,9 @@ class Node
def initialize
@namespaces = {}
end
- def add(node_name, value = nil, *flags) # :yields: Handsoap::XmlMason::Element
+ def add(node_name, value = nil, options = {}) # :yields: Handsoap::XmlMason::Element
prefix, name = parse_ns(node_name)
- node = append_child Element.new(self, prefix, name, value, flags)
+ node = append_child Element.new(self, prefix, name, value, options)
if block_given?
yield node
end
@@ -105,7 +105,7 @@ def to_s(indentation = '')
end
class Element < Node
- def initialize(parent, prefix, node_name, value = nil, flags = []) # :yields: Handsoap::XmlMason::Element
+ def initialize(parent, prefix, node_name, value = nil, options = {}) # :yields: Handsoap::XmlMason::Element
super()
# if prefix.to_s == ""
# raise "missing prefix"
@@ -115,8 +115,11 @@ def initialize(parent, prefix, node_name, value = nil, flags = []) # :yields: Ha
@node_name = node_name
@children = []
@attributes = {}
+ if options[:attributes]
+ @attributes = options[:attributes]
+ end
if not value.nil?
- set_value value.to_s, *flags
+ set_value value.to_s, options
end
if block_given?
yield self
@@ -142,14 +145,14 @@ def append_child(node)
end
# Sets the inner text of this element.
#
- # By default the string is escaped, but you can pass the flag :raw to inject XML.
+ # By default the string is escaped, but you can pass the option flag :raw to inject XML.
#
# You usually won't need to call this method, but will rather use +add+
- def set_value(value, *flags)
+ def set_value(value, options = {})
if @children.length > 0
raise "Element already has children. Can't set value"
end
- if flags && flags.include?(:raw)
+ if options && options.include?(:raw)
@children = [RawContent.new(value)]
else
@children = [TextNode.new(value)]
View
25 lib/handsoap/xml_query_front.rb
@@ -92,6 +92,9 @@ def to_s
def node_name
self.first.node_name if self.any?
end
+ def node_namespace
+ self.first.node_namespace if self.any?
+ end
def xpath(expression, ns = nil)
self.first.xpath(expression, ns)
end
@@ -172,6 +175,11 @@ def native_element
def node_name
raise NotImplementedError.new
end
+ # Returns the node namespace uri of the current element if any, +nil+ otherwise.
+ # Result returned for attribute nodes varies for different drivers, currently.
+ def node_namespace
+ raise NotImplementedError.new
+ end
# Queries the document with XPath, relative to the current element.
#
# +ns+ Should be a Hash of prefix => namespace
@@ -216,6 +224,13 @@ class LibXMLDriver
def node_name
@element.name
end
+ def node_namespace
+ if @element.respond_to? :namespaces
+ if namespace = @element.namespaces.namespace
+ namespace.href
+ end
+ end
+ end
def xpath(expression, ns = nil)
ns = {} if ns.nil?
ns = @namespaces.merge(ns)
@@ -256,6 +271,13 @@ def node_name
@element.class.name.gsub(/.*::([^:]+)$/, "\\1").downcase
end
end
+ def node_namespace
+ if @element.respond_to? :namespace
+ namespace = @element.namespace
+ return if namespace == ''
+ end
+ namespace
+ end
def xpath(expression, ns = nil)
ns = {} if ns.nil?
ns = @namespaces.merge(ns)
@@ -297,6 +319,9 @@ class NokogiriDriver
def node_name
@element.name
end
+ def node_namespace
+ @element.namespace.href if @element.namespace
+ end
def xpath(expression, ns = nil)
ns = {} if ns.nil?
ns = @namespaces.merge(ns)
View
19 tests/service_test.rb
@@ -0,0 +1,19 @@
+require 'rubygems'
+require 'test/unit'
+
+$LOAD_PATH << "#{File.dirname(__FILE__)}/../lib/"
+require "handsoap"
+
+class TestFollowRedirects < Test::Unit::TestCase
+ def test_follow_redirects
+ assert !Handsoap.follow_redirects?
+ Handsoap.follow_redirects!
+ assert Handsoap.follow_redirects?
+ end
+
+ def test_max_redirects
+ assert_equal Handsoap.max_redirects, 1
+ Handsoap.max_redirects = 10
+ assert_equal Handsoap.max_redirects, 10
+ end
+end
View
8 tests/xml_query_front_test.rb
@@ -87,6 +87,14 @@ def test_get_node_name
doc = create_default_document
assert_equal "Thumbnail", doc.xpath("//aws:Response/aws:ThumbnailResult/*").first.node_name
end
+ def test_get_node_namespace
+ doc = create_default_document
+ assert_equal "http://ast.amazonaws.com/doc/2006-05-15/", doc.xpath("//aws:Response/aws:ThumbnailResult/*").first.node_namespace
+ end
+ def test_get_nil_node_namespace
+ doc = create_default_document
+ assert_equal nil, doc.xpath("//entity-test").first.node_namespace
+ end
def test_get_attribute_name
doc = create_default_document
assert_equal "Exists", doc.xpath("//aws:Thumbnail/@Exists").first.node_name
Please sign in to comment.
Something went wrong with that request. Please try again.