savon 0.7.5 → 0.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +11 -0
- data/README.rdoc +5 -3
- data/Rakefile +2 -0
- data/lib/savon.rb +1 -0
- data/lib/savon/client.rb +54 -13
- data/lib/savon/core_ext.rb +0 -0
- data/lib/savon/core_ext/array.rb +20 -6
- data/lib/savon/core_ext/datetime.rb +0 -0
- data/lib/savon/core_ext/hash.rb +36 -15
- data/lib/savon/core_ext/net_http.rb +1 -2
- data/lib/savon/core_ext/object.rb +1 -3
- data/lib/savon/core_ext/string.rb +9 -2
- data/lib/savon/core_ext/symbol.rb +0 -0
- data/lib/savon/core_ext/uri.rb +1 -1
- data/lib/savon/logger.rb +56 -0
- data/lib/savon/request.rb +42 -50
- data/lib/savon/response.rb +62 -9
- data/lib/savon/soap.rb +157 -42
- data/lib/savon/wsdl.rb +71 -6
- data/lib/savon/wsdl_stream.rb +2 -2
- data/lib/savon/wsse.rb +36 -5
- data/spec/basic_spec_helper.rb +0 -0
- data/spec/endpoint_helper.rb +0 -0
- data/spec/fixtures/response/response_fixture.rb +0 -0
- data/spec/fixtures/response/xml/authentication.xml +0 -0
- data/spec/fixtures/response/xml/multi_ref.xml +0 -0
- data/spec/fixtures/response/xml/soap_fault.xml +0 -0
- data/spec/fixtures/response/xml/soap_fault12.xml +0 -0
- data/spec/fixtures/wsdl/wsdl_fixture.rb +0 -0
- data/spec/fixtures/wsdl/xml/authentication.xml +0 -0
- data/spec/fixtures/wsdl/xml/geotrust.xml +0 -0
- data/spec/fixtures/wsdl/xml/namespaced_actions.xml +0 -0
- data/spec/fixtures/wsdl/xml/no_namespace.xml +0 -0
- data/spec/http_stubs.rb +0 -0
- data/spec/integration/http_basic_auth_spec.rb +0 -0
- data/spec/integration/server.rb +0 -0
- data/spec/savon/client_spec.rb +5 -1
- data/spec/savon/core_ext/array_spec.rb +0 -0
- data/spec/savon/core_ext/datetime_spec.rb +0 -0
- data/spec/savon/core_ext/hash_spec.rb +10 -1
- data/spec/savon/core_ext/net_http_spec.rb +0 -0
- data/spec/savon/core_ext/object_spec.rb +0 -0
- data/spec/savon/core_ext/string_spec.rb +6 -2
- data/spec/savon/core_ext/symbol_spec.rb +0 -0
- data/spec/savon/core_ext/uri_spec.rb +4 -0
- data/spec/savon/request_spec.rb +5 -4
- data/spec/savon/response_spec.rb +0 -0
- data/spec/savon/soap_spec.rb +124 -130
- data/spec/savon/wsdl_spec.rb +0 -0
- data/spec/savon/wsse_spec.rb +0 -0
- data/spec/spec_helper.rb +0 -0
- metadata +55 -37
- data/readme/client.rdoc +0 -18
- data/readme/errors.rdoc +0 -11
- data/readme/logging.rdoc +0 -11
- data/readme/participate.rdoc +0 -21
- data/readme/request.rdoc +0 -37
- data/readme/response.rdoc +0 -46
- data/readme/soap.rdoc +0 -71
- data/readme/value_mapping.rdoc +0 -49
- data/readme/wsdl.rdoc +0 -39
- data/readme/wsse.rdoc +0 -28
data/CHANGELOG
CHANGED
@@ -1,7 +1,18 @@
|
|
1
|
+
== 0.7.6 (2010-03-21)
|
2
|
+
* Renamed
|
3
|
+
* Moved documentation from the Github Wiki to the actual class files and established a much nicer
|
4
|
+
documentation combining examples and implementation (using Hanna) at: http://savon.rubiii.com
|
5
|
+
* Added Savon::Client#call as a workaround for dispatching calls to SOAP actions named after
|
6
|
+
existing methods. Fix for issue #48.
|
7
|
+
* Add support for specifying attributes for duplicate tags (via Hash values as Arrays). Fix for issue #45.
|
8
|
+
* Fix for issue #41 (Escape special characters (e.g. &) for XML requests).
|
9
|
+
* Fix for issue #39 and #49. Added Savon::SOAP#xml which let's you specify completely custom SOAP request XML.
|
10
|
+
|
1
11
|
== 0.7.5 (2010-02-19)
|
2
12
|
* Fix for issue #34 (soap_actions returns empty for wsdl12).
|
3
13
|
* Fix for issue #36 (Custom WSDL actions broken).
|
4
14
|
* Added feature requested in issue #35 (Setting an attribute on an element?).
|
15
|
+
* Changed the key for specifying the order of tags from :@inorder to :order!
|
5
16
|
|
6
17
|
== 0.7.4 (2010-02-02)
|
7
18
|
* Fix for issue #33 (undefined method 'start_with?').
|
data/README.rdoc
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
==== Heavy metal Ruby SOAP client library
|
4
4
|
|
5
|
-
{
|
5
|
+
{Documentation}[http://savon.rubiii.com] | {Metrics}[http://getcaliper.com/caliper/project?repo=git://github.com/rubiii/savon.git]
|
6
6
|
|
7
7
|
== Installation
|
8
8
|
|
@@ -16,6 +16,8 @@ Instantiate Savon::Client, passing in the WSDL of your service.
|
|
16
16
|
|
17
17
|
client = Savon::Client.new "http://example.com/UserService?wsdl"
|
18
18
|
|
19
|
+
For production, it is highly recommended to not use Savon::WSDL. Information on {how to disable the WSDL}[http://savon.rubiii.com/docs/latest/classes/Savon/WSDL.html].
|
20
|
+
|
19
21
|
== Calling a SOAP action
|
20
22
|
|
21
23
|
Assuming your service applies to the defaults, you can now call any available SOAP action.
|
@@ -54,9 +56,9 @@ Savon::Response represents the HTTP and SOAP response. It contains and raises er
|
|
54
56
|
== HTTP errors and SOAP faults
|
55
57
|
|
56
58
|
Savon raises a Savon::SOAPFault in case of a SOAP fault and a Savon::HTTPError in case of an HTTP error.
|
57
|
-
More information: {Errors}[http://
|
59
|
+
More information: {Errors}[http://savon.rubiii.com/docs/latest/classes/Savon/Response.html]
|
58
60
|
|
59
61
|
== Logging
|
60
62
|
|
61
63
|
Savon logs each request and response to STDOUT. But there are a couple of options to change the default behavior.
|
62
|
-
More information: {Logging}[http://
|
64
|
+
More information: {Logging}[http://savon.rubiii.com/docs/latest/classes/Savon/Request.html]
|
data/Rakefile
CHANGED
@@ -36,6 +36,7 @@ Spec::Rake::SpecTask.new(:run_integration_spec) do |spec|
|
|
36
36
|
end
|
37
37
|
|
38
38
|
begin
|
39
|
+
$:.unshift File.join(File.dirname(__FILE__), "..", "hanna", "lib")
|
39
40
|
require "hanna/rdoctask"
|
40
41
|
|
41
42
|
Rake::RDocTask.new do |rdoc|
|
@@ -43,6 +44,7 @@ begin
|
|
43
44
|
rdoc.rdoc_dir = "doc"
|
44
45
|
rdoc.rdoc_files.include("**/*.rdoc").include("lib/**/*.rb")
|
45
46
|
rdoc.options << "--line-numbers"
|
47
|
+
rdoc.options << "--webcvs=http://github.com/rubiii/savon/tree/master/"
|
46
48
|
end
|
47
49
|
rescue LoadError
|
48
50
|
puts "'gem install hanna' for documentation"
|
data/lib/savon.rb
CHANGED
data/lib/savon/client.rb
CHANGED
@@ -1,13 +1,47 @@
|
|
1
1
|
module Savon
|
2
2
|
|
3
|
-
#
|
3
|
+
# = Savon::Client
|
4
4
|
#
|
5
|
-
#
|
6
|
-
#
|
5
|
+
# Savon::Client is the main object for connecting to a SOAP service. It includes methods to access
|
6
|
+
# both the Savon::WSDL and Savon::Request object.
|
7
|
+
#
|
8
|
+
# == Instantiation
|
9
|
+
#
|
10
|
+
# Depending on whether you aim to use Savon with or without Savon::WSDL, you need to instantiate
|
11
|
+
# Savon::Client by passing in the WSDL or SOAP endpoint.
|
12
|
+
#
|
13
|
+
# Client instance with a WSDL endpoint:
|
14
|
+
#
|
15
|
+
# client = Savon::Client.new "http://example.com/UserService?wsdl"
|
16
|
+
#
|
17
|
+
# Client instance with a SOAP endpoint (for using Savon without a WSDL):
|
18
|
+
#
|
19
|
+
# client = Savon::Client.new "http://example.com/UserService"
|
20
|
+
#
|
21
|
+
# It is recommended to not use Savon::WSDL for production. Please take a look at the Documentation
|
22
|
+
# for Savon::WSDL for more information about how to disable it.
|
23
|
+
#
|
24
|
+
# == Using a proxy server
|
25
|
+
#
|
26
|
+
# You can specify the URI to a proxy server via optional hash arguments.
|
27
|
+
#
|
28
|
+
# client = Savon::Client.new "http://example.com/UserService?wsdl", :proxy => "http://proxy.example.com"
|
29
|
+
#
|
30
|
+
# == Savon::WSDL
|
31
|
+
#
|
32
|
+
# You can access Savon::WSDL via:
|
33
|
+
#
|
34
|
+
# client.wsdl
|
35
|
+
#
|
36
|
+
# == Savon::Request
|
37
|
+
#
|
38
|
+
# You can also access Savon::Request via:
|
39
|
+
#
|
40
|
+
# client.request
|
7
41
|
class Client
|
8
42
|
|
9
|
-
# Expects a SOAP +endpoint+
|
10
|
-
#
|
43
|
+
# Expects a SOAP +endpoint+ string. Also accepts an optional hash of +options+ for specifying
|
44
|
+
# a +:proxy+ server to use.
|
11
45
|
def initialize(endpoint, options = {})
|
12
46
|
@request = Request.new endpoint, options
|
13
47
|
@wsdl = WSDL.new @request
|
@@ -25,6 +59,12 @@ module Savon
|
|
25
59
|
super
|
26
60
|
end
|
27
61
|
|
62
|
+
# Same as method_missing. Workaround for SOAP actions that method_missing does not catch
|
63
|
+
# because the method does exist.
|
64
|
+
def call(method, *args, &block)
|
65
|
+
method_missing method, *args, &block
|
66
|
+
end
|
67
|
+
|
28
68
|
private
|
29
69
|
|
30
70
|
# Dispatches requests to SOAP actions matching a given +method+ name.
|
@@ -32,12 +72,12 @@ module Savon
|
|
32
72
|
soap_action = soap_action_from method.to_s
|
33
73
|
super unless @wsdl.respond_to? soap_action
|
34
74
|
|
35
|
-
setup_objects
|
75
|
+
setup_objects *@wsdl.operation_from(soap_action), &block
|
36
76
|
Response.new @request.soap(@soap)
|
37
77
|
end
|
38
78
|
|
39
|
-
# Sets whether to use Savon::WSDL by a given +method+ name and
|
40
|
-
#
|
79
|
+
# Sets whether to use Savon::WSDL by a given +method+ name and returns the original method name
|
80
|
+
# without exclamation marks.
|
41
81
|
def soap_action_from(method)
|
42
82
|
@wsdl.enabled = !method.ends_with?("!")
|
43
83
|
|
@@ -50,16 +90,17 @@ module Savon
|
|
50
90
|
@wsdl.enabled? ? @wsdl.soap_endpoint : @request.endpoint
|
51
91
|
end
|
52
92
|
|
53
|
-
# Expects a SOAP operation Hash and sets up Savon::SOAP and Savon::WSSE.
|
54
|
-
#
|
55
|
-
def setup_objects(
|
56
|
-
@soap, @wsse = SOAP.new(
|
93
|
+
# Expects a SOAP operation Hash and sets up Savon::SOAP and Savon::WSSE. Yields them to a given
|
94
|
+
# +block+ in case one was given.
|
95
|
+
def setup_objects(action, input, &block)
|
96
|
+
@soap, @wsse = SOAP.new(action, input, soap_endpoint), WSSE.new
|
57
97
|
yield_objects &block if block
|
58
98
|
@soap.namespaces["xmlns:wsdl"] ||= @wsdl.namespace_uri if @wsdl.enabled?
|
59
99
|
@soap.wsse = @wsse
|
60
100
|
end
|
61
101
|
|
62
|
-
# Yields Savon::SOAP and Savon::WSSE to a given +block
|
102
|
+
# Yields either Savon::SOAP or Savon::SOAP and Savon::WSSE to a given +block+, depending on
|
103
|
+
# the number of arguments expected by the block.
|
63
104
|
def yield_objects(&block)
|
64
105
|
case block.arity
|
65
106
|
when 1 then yield @soap
|
data/lib/savon/core_ext.rb
CHANGED
File without changes
|
data/lib/savon/core_ext/array.rb
CHANGED
@@ -1,17 +1,31 @@
|
|
1
1
|
class Array
|
2
2
|
|
3
|
-
# Translates the Array into SOAP
|
4
|
-
def to_soap_xml(key)
|
3
|
+
# Translates the Array into SOAP compatible XML. See: Hash.to_soap_xml.
|
4
|
+
def to_soap_xml(key, attributes = {})
|
5
5
|
xml = Builder::XmlMarkup.new
|
6
6
|
|
7
|
-
|
7
|
+
each_with_index do |item, index|
|
8
|
+
attrs = tag_attributes attributes, index
|
8
9
|
case item
|
9
|
-
when
|
10
|
-
else
|
10
|
+
when Hash then xml.tag!(key, attrs) { xml << item.to_soap_xml }
|
11
|
+
else xml.tag!(key, attrs) { xml << item.to_soap_value }
|
11
12
|
end
|
12
13
|
end
|
13
14
|
|
14
15
|
xml.target!
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
|
+
private
|
19
|
+
|
20
|
+
# Takes a Hash of +attributes+ and the +index+ for which to return attributes
|
21
|
+
# for duplicate tags.
|
22
|
+
def tag_attributes(attributes, index)
|
23
|
+
return {} if attributes.empty?
|
24
|
+
|
25
|
+
attributes.inject({}) do |hash, (key, value)|
|
26
|
+
value = value[index] if value.kind_of? Array
|
27
|
+
hash.merge key => value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
File without changes
|
data/lib/savon/core_ext/hash.rb
CHANGED
@@ -10,26 +10,47 @@ class Hash
|
|
10
10
|
|
11
11
|
# Translates the Hash into SOAP request compatible XML.
|
12
12
|
#
|
13
|
-
# === Example:
|
14
|
-
#
|
15
13
|
# { :find_user => { :id => 123, "wsdl:Key" => "api" } }.to_soap_xml
|
16
14
|
# # => "<findUser><id>123</id><wsdl:Key>api</wsdl:Key></findUser>"
|
17
15
|
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
16
|
+
# ==== Mapping
|
17
|
+
#
|
18
|
+
# * Hash keys specified as Symbols are converted to lowerCamelCase Strings
|
19
|
+
# * Hash keys specified as Strings are not converted and may contain namespaces
|
20
|
+
# * DateTime values are converted to xs:dateTime Strings
|
21
|
+
# * Objects responding to to_datetime (except Strings) are converted to xs:dateTime Strings
|
22
|
+
# * TrueClass and FalseClass objects are converted to "true" and "false" Strings
|
23
|
+
# * All other objects are expected to be converted to Strings using to_s
|
24
|
+
#
|
25
|
+
# An example:
|
26
|
+
#
|
27
|
+
# { :magic_request => {
|
28
|
+
# :perform_move => true,
|
29
|
+
# "perform_at" => DateTime.new(2010, 11, 22, 11, 22, 33)
|
30
|
+
# }
|
31
|
+
# }.to_soap_xml
|
32
|
+
#
|
33
|
+
# <magicRequest>
|
34
|
+
# <performMove>true</performMove>
|
35
|
+
# <perform_at>2012-06-11T10:42:21</perform_at>
|
36
|
+
# </magicRequest>
|
37
|
+
#
|
38
|
+
# ==== :order!
|
21
39
|
#
|
22
|
-
#
|
40
|
+
# In case your service requires the tags to be in a specific order (parameterOrder), you have two
|
41
|
+
# options. The first is to specify your body as an XML string. The second is to specify the order
|
42
|
+
# through an additional array stored under the +:order!+ key.
|
23
43
|
#
|
24
|
-
# { :
|
25
|
-
# # => "<
|
44
|
+
# { :name => "Eve", :id => 123, :order! => [:id, :name] }.to_soap_xml
|
45
|
+
# # => "<id>123</id><name>Eve</name>"
|
26
46
|
#
|
27
|
-
#
|
47
|
+
# ==== :attributes!
|
28
48
|
#
|
29
|
-
#
|
49
|
+
# If you need attributes, you could either go with an XML string or add another hash under the
|
50
|
+
# +:attributes!+ key.
|
30
51
|
#
|
31
|
-
# { :
|
32
|
-
# # =>
|
52
|
+
# { :person => "Eve", :attributes! => { :person => { :id => 666 } } }.to_soap_xml
|
53
|
+
# # => '<person id="666">Eve</person>'
|
33
54
|
def to_soap_xml
|
34
55
|
xml = Builder::XmlMarkup.new
|
35
56
|
attributes = delete(:attributes!) || {}
|
@@ -40,7 +61,7 @@ class Hash
|
|
40
61
|
key = key.to_soap_key
|
41
62
|
|
42
63
|
case value
|
43
|
-
when Array then xml << value.to_soap_xml(key)
|
64
|
+
when Array then xml << value.to_soap_xml(key, attrs)
|
44
65
|
when Hash then xml.tag!(key, attrs) { xml << value.to_soap_xml }
|
45
66
|
else xml.tag!(key, attrs) { xml << value.to_soap_value }
|
46
67
|
end
|
@@ -54,7 +75,7 @@ class Hash
|
|
54
75
|
inject({}) do |hash, (key, value)|
|
55
76
|
value = case value
|
56
77
|
when Hash then value["xsi:nil"] ? nil : value.map_soap_response
|
57
|
-
when Array then value.map { |
|
78
|
+
when Array then value.map { |val| val.map_soap_response rescue val }
|
58
79
|
when String then value.map_soap_response
|
59
80
|
end
|
60
81
|
|
@@ -78,4 +99,4 @@ private
|
|
78
99
|
order
|
79
100
|
end
|
80
101
|
|
81
|
-
end
|
102
|
+
end
|
@@ -6,8 +6,7 @@ module Net
|
|
6
6
|
@address, @port = address, port
|
7
7
|
end
|
8
8
|
|
9
|
-
# Convenience method for setting SSL client authentication
|
10
|
-
# through a Hash of +options+.
|
9
|
+
# Convenience method for setting SSL client authentication through a Hash of +options+.
|
11
10
|
def ssl_client_auth(options)
|
12
11
|
self.use_ssl = true
|
13
12
|
self.cert = options[:cert] if options[:cert]
|
@@ -1,8 +1,6 @@
|
|
1
1
|
class Object
|
2
2
|
|
3
|
-
# Returns +true+ if the Object is
|
4
|
-
# For example, "", false, nil, [], and {} are blank.
|
5
|
-
# Implementation from ActiveSupport.
|
3
|
+
# Returns +true+ if the Object is nil, false or empty. Implementation from ActiveSupport.
|
6
4
|
def blank?
|
7
5
|
respond_to?(:empty?) ? empty? : !self
|
8
6
|
end unless defined? blank?
|
@@ -35,7 +35,7 @@ class String
|
|
35
35
|
# Returns whether the String ends with a given +suffix+.
|
36
36
|
def ends_with?(suffix)
|
37
37
|
suffix = suffix.to_s
|
38
|
-
self[-suffix.length, suffix.length] == suffix
|
38
|
+
self[-suffix.length, suffix.length] == suffix
|
39
39
|
end unless defined? ends_with?
|
40
40
|
|
41
41
|
# Returns the String without namespace.
|
@@ -52,8 +52,15 @@ class String
|
|
52
52
|
end
|
53
53
|
|
54
54
|
# Returns the String as a SOAP request compliant value.
|
55
|
+
# Escapes special characters for XML.
|
55
56
|
def to_soap_value
|
56
|
-
|
57
|
+
str = dup
|
58
|
+
str.gsub! "&", "&"
|
59
|
+
str.gsub! '"', """
|
60
|
+
str.gsub! "'", "'"
|
61
|
+
str.gsub! "<", "<"
|
62
|
+
str.gsub! ">", ">"
|
63
|
+
str
|
57
64
|
end
|
58
65
|
|
59
66
|
end
|
File without changes
|
data/lib/savon/core_ext/uri.rb
CHANGED
data/lib/savon/logger.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
module Savon
|
2
|
+
|
3
|
+
# = Savon::Logger
|
4
|
+
#
|
5
|
+
# Savon::Logger can be mixed into classes to provide logging behavior.
|
6
|
+
#
|
7
|
+
# By default, the Logger mixin uses {Ruby's Logger}[http://ruby-doc.org/stdlib/libdoc/logger/rdoc/]
|
8
|
+
# from the standard library, a log level of :debug and is pointing to STDOUT.
|
9
|
+
module Logger
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
|
13
|
+
# Sets whether to log.
|
14
|
+
def log=(log)
|
15
|
+
@log = log
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns whether to log. Defaults to +true+.
|
19
|
+
def log?
|
20
|
+
@log != false
|
21
|
+
end
|
22
|
+
|
23
|
+
# Sets the logger.
|
24
|
+
def logger=(logger)
|
25
|
+
@logger = logger
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns the logger. Defaults to an instance of +Logger+ writing to STDOUT.
|
29
|
+
def logger
|
30
|
+
@logger ||= ::Logger.new STDOUT
|
31
|
+
end
|
32
|
+
|
33
|
+
# Sets the log level.
|
34
|
+
def log_level=(log_level)
|
35
|
+
@log_level = log_level
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns the log level. Defaults to +debug+.
|
39
|
+
def log_level
|
40
|
+
@log_level ||= :debug
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
# Extends the class including this module with its ClassMethods.
|
46
|
+
def self.included(base)
|
47
|
+
base.extend ClassMethods
|
48
|
+
end
|
49
|
+
|
50
|
+
# Logs a given +message+.
|
51
|
+
def log(message)
|
52
|
+
self.class.logger.send self.class.log_level, message if self.class.log?
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
data/lib/savon/request.rb
CHANGED
@@ -1,52 +1,51 @@
|
|
1
1
|
module Savon
|
2
2
|
|
3
|
-
#
|
3
|
+
# = Savon::Request
|
4
4
|
#
|
5
|
-
#
|
5
|
+
# Savon::Request handles both WSDL and SOAP requests.
|
6
|
+
#
|
7
|
+
# == The Net::HTTP object
|
8
|
+
#
|
9
|
+
# You can access the Net::HTTP object used for both WSDL and SOAP requests via:
|
10
|
+
#
|
11
|
+
# client.request.http
|
12
|
+
#
|
13
|
+
# Here's an example of how to set open and read timeouts on the Net::HTTP object.
|
14
|
+
#
|
15
|
+
# client.request.http.open_timeout = 30
|
16
|
+
# client.request.http.read_timeout = 30
|
17
|
+
#
|
18
|
+
# Please refer to the {Net::HTTP documentation}[http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/]
|
19
|
+
# for more information.
|
20
|
+
#
|
21
|
+
# == HTTP basic authentication
|
22
|
+
#
|
23
|
+
# Setting credentials for HTTP basic authentication:
|
24
|
+
#
|
25
|
+
# client.request.basic_auth "username", "password"
|
26
|
+
#
|
27
|
+
# == SSL client authentication
|
28
|
+
#
|
29
|
+
# You can use the methods provided by Net::HTTP to set SSL client authentication or use a shortcut:
|
30
|
+
#
|
31
|
+
# client.request.http.ssl_client_auth(
|
32
|
+
# :cert => OpenSSL::X509::Certificate.new(File.read("client_cert.pem")),
|
33
|
+
# :key => OpenSSL::PKey::RSA.new(File.read("client_key.pem"), "password if one exists"),
|
34
|
+
# :ca_file => "cacert.pem",
|
35
|
+
# :verify_mode => OpenSSL::SSL::VERIFY_PEER
|
36
|
+
# )
|
37
|
+
#
|
38
|
+
# == HTTP headers
|
39
|
+
#
|
40
|
+
# There's an accessor for the Hash of HTTP headers sent with any SOAP call:
|
41
|
+
#
|
42
|
+
# client.request.headers["custom"] = "header"
|
6
43
|
class Request
|
44
|
+
include Logger
|
7
45
|
|
8
46
|
# Content-Types by SOAP version.
|
9
47
|
ContentType = { 1 => "text/xml;charset=UTF-8", 2 => "application/soap+xml;charset=UTF-8" }
|
10
48
|
|
11
|
-
# Whether to log HTTP requests.
|
12
|
-
@@log = true
|
13
|
-
|
14
|
-
# The default logger.
|
15
|
-
@@logger = Logger.new STDOUT
|
16
|
-
|
17
|
-
# The default log level.
|
18
|
-
@@log_level = :debug
|
19
|
-
|
20
|
-
# Sets whether to log HTTP requests.
|
21
|
-
def self.log=(log)
|
22
|
-
@@log = log
|
23
|
-
end
|
24
|
-
|
25
|
-
# Returns whether to log HTTP requests.
|
26
|
-
def self.log?
|
27
|
-
@@log
|
28
|
-
end
|
29
|
-
|
30
|
-
# Sets the logger.
|
31
|
-
def self.logger=(logger)
|
32
|
-
@@logger = logger
|
33
|
-
end
|
34
|
-
|
35
|
-
# Returns the logger.
|
36
|
-
def self.logger
|
37
|
-
@@logger
|
38
|
-
end
|
39
|
-
|
40
|
-
# Sets the log level.
|
41
|
-
def self.log_level=(log_level)
|
42
|
-
@@log_level = log_level
|
43
|
-
end
|
44
|
-
|
45
|
-
# Returns the log level.
|
46
|
-
def self.log_level
|
47
|
-
@@log_level
|
48
|
-
end
|
49
|
-
|
50
49
|
# Expects a SOAP +endpoint+ String. Also accepts an optional Hash
|
51
50
|
# of +options+ for specifying a proxy server.
|
52
51
|
def initialize(endpoint, options = {})
|
@@ -83,8 +82,7 @@ module Savon
|
|
83
82
|
http.start { |h| h.request request(:wsdl) }
|
84
83
|
end
|
85
84
|
|
86
|
-
# Executes a SOAP request using a given Savon::SOAP instance and
|
87
|
-
# returns the Net::HTTP response.
|
85
|
+
# Executes a SOAP request using a given Savon::SOAP instance and returns the Net::HTTP response.
|
88
86
|
def soap(soap)
|
89
87
|
@soap = soap
|
90
88
|
http.endpoint @soap.endpoint.host, @soap.endpoint.port
|
@@ -118,8 +116,7 @@ module Savon
|
|
118
116
|
log @response.body
|
119
117
|
end
|
120
118
|
|
121
|
-
# Returns a Net::HTTP request for a given +type+. Yields the request
|
122
|
-
# to an optional block.
|
119
|
+
# Returns a Net::HTTP request for a given +type+. Yields the request to an optional block.
|
123
120
|
def request(type)
|
124
121
|
request = case type
|
125
122
|
when :wsdl then Net::HTTP::Get.new @endpoint.request_uri
|
@@ -136,10 +133,5 @@ module Savon
|
|
136
133
|
{ "Content-Type" => ContentType[@soap.version], "SOAPAction" => @soap.action }
|
137
134
|
end
|
138
135
|
|
139
|
-
# Logs a given +message+.
|
140
|
-
def log(message)
|
141
|
-
self.class.logger.send self.class.log_level, message if self.class.log?
|
142
|
-
end
|
143
|
-
|
144
136
|
end
|
145
137
|
end
|