savon 0.7.9 → 0.8.0.beta.1
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/.gitignore +9 -0
- data/.rspec +1 -0
- data/.yardopts +2 -0
- data/CHANGELOG.md +332 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +37 -0
- data/Rakefile +28 -39
- data/autotest/discover.rb +1 -0
- data/lib/savon.rb +10 -31
- data/lib/savon/client.rb +116 -98
- data/lib/savon/core_ext/array.rb +36 -22
- data/lib/savon/core_ext/datetime.rb +15 -6
- data/lib/savon/core_ext/hash.rb +122 -94
- data/lib/savon/core_ext/object.rb +19 -11
- data/lib/savon/core_ext/string.rb +62 -57
- data/lib/savon/core_ext/symbol.rb +13 -5
- data/lib/savon/error.rb +6 -0
- data/lib/savon/global.rb +75 -0
- data/lib/savon/http/error.rb +42 -0
- data/lib/savon/soap.rb +8 -283
- data/lib/savon/soap/fault.rb +48 -0
- data/lib/savon/soap/request.rb +61 -0
- data/lib/savon/soap/response.rb +65 -0
- data/lib/savon/soap/xml.rb +132 -0
- data/lib/savon/version.rb +2 -2
- data/lib/savon/wsdl/document.rb +107 -0
- data/lib/savon/wsdl/parser.rb +90 -0
- data/lib/savon/wsdl/request.rb +35 -0
- data/lib/savon/wsse.rb +42 -104
- data/savon.gemspec +26 -0
- data/spec/fixtures/response/response_fixture.rb +26 -26
- data/spec/fixtures/response/xml/list.xml +18 -0
- data/spec/fixtures/wsdl/wsdl_fixture.rb +6 -0
- data/spec/fixtures/wsdl/wsdl_fixture.yml +4 -4
- data/spec/savon/client_spec.rb +274 -51
- data/spec/savon/core_ext/datetime_spec.rb +1 -1
- data/spec/savon/core_ext/hash_spec.rb +40 -4
- data/spec/savon/core_ext/object_spec.rb +1 -1
- data/spec/savon/core_ext/string_spec.rb +0 -12
- data/spec/savon/http/error_spec.rb +52 -0
- data/spec/savon/savon_spec.rb +90 -0
- data/spec/savon/soap/fault_spec.rb +80 -0
- data/spec/savon/soap/request_spec.rb +45 -0
- data/spec/savon/soap/response_spec.rb +153 -0
- data/spec/savon/soap/xml_spec.rb +249 -0
- data/spec/savon/soap_spec.rb +4 -177
- data/spec/savon/{wsdl_spec.rb → wsdl/document_spec.rb} +54 -17
- data/spec/savon/wsdl/request_spec.rb +15 -0
- data/spec/savon/wsse_spec.rb +123 -92
- data/spec/spec_helper.rb +19 -4
- data/spec/support/endpoint.rb +25 -0
- metadata +97 -97
- data/.autotest +0 -5
- data/CHANGELOG +0 -176
- data/README.rdoc +0 -64
- data/lib/savon/core_ext.rb +0 -8
- data/lib/savon/core_ext/net_http.rb +0 -19
- data/lib/savon/core_ext/uri.rb +0 -10
- data/lib/savon/logger.rb +0 -56
- data/lib/savon/request.rb +0 -138
- data/lib/savon/response.rb +0 -174
- data/lib/savon/wsdl.rb +0 -137
- data/lib/savon/wsdl_stream.rb +0 -85
- data/spec/basic_spec_helper.rb +0 -11
- data/spec/endpoint_helper.rb +0 -23
- data/spec/http_stubs.rb +0 -26
- data/spec/integration/http_basic_auth_spec.rb +0 -16
- data/spec/integration/server.rb +0 -51
- data/spec/savon/core_ext/net_http_spec.rb +0 -38
- data/spec/savon/core_ext/uri_spec.rb +0 -19
- data/spec/savon/request_spec.rb +0 -117
- data/spec/savon/response_spec.rb +0 -179
- data/spec/spec.opts +0 -4
@@ -1,16 +1,24 @@
|
|
1
|
-
|
1
|
+
require "savon/core_ext/datetime"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end unless defined? blank?
|
3
|
+
module Savon
|
4
|
+
module CoreExt
|
5
|
+
module Object
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
# Returns +true+ if the Object is nil, false or empty. Implementation from ActiveSupport.
|
8
|
+
def blank?
|
9
|
+
respond_to?(:empty?) ? empty? : !self
|
10
|
+
end unless defined? blank?
|
11
|
+
|
12
|
+
# Returns the Object as a SOAP request compliant value.
|
13
|
+
def to_soap_value
|
14
|
+
return to_s unless respond_to? :to_datetime
|
15
|
+
to_datetime.to_soap_value
|
16
|
+
end
|
13
17
|
|
14
|
-
|
18
|
+
alias_method :to_soap_value!, :to_soap_value
|
15
19
|
|
20
|
+
end
|
21
|
+
end
|
16
22
|
end
|
23
|
+
|
24
|
+
Object.send :include, Savon::CoreExt::Object
|
@@ -1,69 +1,74 @@
|
|
1
|
-
|
1
|
+
require "cgi"
|
2
2
|
|
3
|
-
|
4
|
-
def self.random(length = 100)
|
5
|
-
(0...length).map { ("a".."z").to_a[rand(26)] }.join
|
6
|
-
end
|
3
|
+
require "savon/soap"
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
str.gsub! /::/, '/'
|
12
|
-
str.gsub! /([A-Z]+)([A-Z][a-z])/, '\1_\2'
|
13
|
-
str.gsub! /([a-z\d])([A-Z])/, '\1_\2'
|
14
|
-
str.tr! ".", "_"
|
15
|
-
str.tr! "-", "_"
|
16
|
-
str.downcase!
|
17
|
-
str
|
18
|
-
end
|
5
|
+
module Savon
|
6
|
+
module CoreExt
|
7
|
+
module String
|
19
8
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
9
|
+
# Returns the String in snake_case.
|
10
|
+
def snakecase
|
11
|
+
str = dup
|
12
|
+
str.gsub! /::/, '/'
|
13
|
+
str.gsub! /([A-Z]+)([A-Z][a-z])/, '\1_\2'
|
14
|
+
str.gsub! /([a-z\d])([A-Z])/, '\1_\2'
|
15
|
+
str.tr! ".", "_"
|
16
|
+
str.tr! "-", "_"
|
17
|
+
str.downcase!
|
18
|
+
str
|
19
|
+
end
|
28
20
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
21
|
+
# Returns the String in lowerCamelCase.
|
22
|
+
def lower_camelcase
|
23
|
+
str = dup
|
24
|
+
str.gsub!(/\/(.?)/) { "::#{$1.upcase}" }
|
25
|
+
str.gsub!(/(?:_+|-+)([a-z])/) { $1.upcase }
|
26
|
+
str.gsub!(/(\A|\s)([A-Z])/) { $1 + $2.downcase }
|
27
|
+
str
|
28
|
+
end
|
34
29
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
30
|
+
# Returns whether the String starts with a given +prefix+.
|
31
|
+
def starts_with?(prefix)
|
32
|
+
prefix = prefix.to_s
|
33
|
+
self[0, prefix.length] == prefix
|
34
|
+
end unless defined? starts_with?
|
40
35
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
36
|
+
# Returns whether the String ends with a given +suffix+.
|
37
|
+
def ends_with?(suffix)
|
38
|
+
suffix = suffix.to_s
|
39
|
+
self[-suffix.length, suffix.length] == suffix
|
40
|
+
end unless defined? ends_with?
|
45
41
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
return false if self.strip.downcase == "false"
|
51
|
-
self
|
52
|
-
end
|
42
|
+
# Returns the String without namespace.
|
43
|
+
def strip_namespace
|
44
|
+
split(":").last
|
45
|
+
end
|
53
46
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
47
|
+
# Translates SOAP response values to Ruby Objects.
|
48
|
+
def map_soap_response
|
49
|
+
return ::DateTime.parse(self) if Savon::SOAP::DateTimeRegexp === self
|
50
|
+
return true if self.strip.downcase == "true"
|
51
|
+
return false if self.strip.downcase == "false"
|
52
|
+
self
|
53
|
+
end
|
58
54
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
55
|
+
# Returns the Object as a SOAP request compliant key.
|
56
|
+
def to_soap_key
|
57
|
+
self[-1, 1] == "!" ? chop : self
|
58
|
+
end
|
63
59
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
60
|
+
# Returns the String as a SOAP value. Escapes special characters for XML.
|
61
|
+
def to_soap_value
|
62
|
+
CGI.escapeHTML self
|
63
|
+
end
|
64
|
+
|
65
|
+
# Convert the String into a SOAP value without escaping special characters.
|
66
|
+
def to_soap_value!
|
67
|
+
self
|
68
|
+
end
|
68
69
|
|
70
|
+
end
|
71
|
+
end
|
69
72
|
end
|
73
|
+
|
74
|
+
String.send :include, Savon::CoreExt::String
|
@@ -1,8 +1,16 @@
|
|
1
|
-
|
1
|
+
require "savon/core_ext/string"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
3
|
+
module Savon
|
4
|
+
module CoreExt
|
5
|
+
module Symbol
|
6
|
+
|
7
|
+
# Returns the Symbol as a lowerCamelCase String.
|
8
|
+
def to_soap_key
|
9
|
+
to_s.to_soap_key.lower_camelcase
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
6
13
|
end
|
14
|
+
end
|
7
15
|
|
8
|
-
|
16
|
+
Symbol.send :include, Savon::CoreExt::Symbol
|
data/lib/savon/error.rb
ADDED
data/lib/savon/global.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require "logger"
|
2
|
+
require "savon/soap"
|
3
|
+
|
4
|
+
module Savon
|
5
|
+
module Global
|
6
|
+
|
7
|
+
# Sets whether to log HTTP requests.
|
8
|
+
attr_writer :log
|
9
|
+
|
10
|
+
# Returns whether to log HTTP requests. Defaults to +true+.
|
11
|
+
def log?
|
12
|
+
@log != false
|
13
|
+
end
|
14
|
+
|
15
|
+
# Sets the logger to use.
|
16
|
+
attr_writer :logger
|
17
|
+
|
18
|
+
# Returns the logger. Defaults to an instance of +Logger+ writing to STDOUT.
|
19
|
+
def logger
|
20
|
+
@logger ||= ::Logger.new STDOUT
|
21
|
+
end
|
22
|
+
|
23
|
+
# Sets the log level.
|
24
|
+
attr_writer :log_level
|
25
|
+
|
26
|
+
# Returns the log level. Defaults to :debug.
|
27
|
+
def log_level
|
28
|
+
@log_level ||= :debug
|
29
|
+
end
|
30
|
+
|
31
|
+
# Logs a given +message+.
|
32
|
+
def log(message)
|
33
|
+
logger.send log_level, message if log?
|
34
|
+
end
|
35
|
+
|
36
|
+
# Sets whether to raise HTTP errors and SOAP faults.
|
37
|
+
attr_writer :raise_errors
|
38
|
+
|
39
|
+
# Returns whether to raise errors. Defaults to +true+.
|
40
|
+
def raise_errors?
|
41
|
+
@raise_errors != false
|
42
|
+
end
|
43
|
+
|
44
|
+
# Sets the global SOAP version.
|
45
|
+
def soap_version=(version)
|
46
|
+
raise ArgumentError, "Invalid SOAP version: #{version}" unless SOAP::Versions.include? version
|
47
|
+
@version = version
|
48
|
+
end
|
49
|
+
|
50
|
+
# Returns SOAP version. Defaults to +DefaultVersion+.
|
51
|
+
def soap_version
|
52
|
+
@version ||= SOAP::DefaultVersion
|
53
|
+
end
|
54
|
+
|
55
|
+
# Returns whether to strip namespaces in a SOAP response Hash.
|
56
|
+
# Defaults to +true+.
|
57
|
+
def strip_namespaces?
|
58
|
+
@strip_namespaces != false
|
59
|
+
end
|
60
|
+
|
61
|
+
# Sets whether to strip namespaces in a SOAP response Hash.
|
62
|
+
attr_writer :strip_namespaces
|
63
|
+
|
64
|
+
# Reset to default configuration.
|
65
|
+
def reset_config!
|
66
|
+
self.log = true
|
67
|
+
self.logger = ::Logger.new STDOUT
|
68
|
+
self.log_level = :debug
|
69
|
+
self.raise_errors = true
|
70
|
+
self.soap_version = SOAP::DefaultVersion
|
71
|
+
self.strip_namespaces = true
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require "savon/error"
|
2
|
+
require "savon/soap/xml"
|
3
|
+
|
4
|
+
module Savon
|
5
|
+
module HTTP
|
6
|
+
|
7
|
+
# = Savon::HTTP::Error
|
8
|
+
#
|
9
|
+
# Represents an HTTP error. Contains the original <tt>HTTPI::Response</tt>.
|
10
|
+
class Error < Error
|
11
|
+
|
12
|
+
# Expects an <tt>HTTPI::Response</tt>.
|
13
|
+
def initialize(http)
|
14
|
+
self.http = http
|
15
|
+
end
|
16
|
+
|
17
|
+
# Accessor for the <tt>HTTPI::Response</tt>.
|
18
|
+
attr_accessor :http
|
19
|
+
|
20
|
+
# Returns whether an HTTP error is present.
|
21
|
+
def present?
|
22
|
+
http.error?
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns the HTTP error message.
|
26
|
+
def to_s
|
27
|
+
return "" unless present?
|
28
|
+
|
29
|
+
@message ||= begin
|
30
|
+
message = "HTTP error (#{http.code})"
|
31
|
+
message << ": #{http.body}" unless http.body.empty?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns the HTTP response as a Hash.
|
36
|
+
def to_hash
|
37
|
+
@hash = { :code => http.code, :headers => http.headers, :body => http.body }
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/savon/soap.rb
CHANGED
@@ -2,121 +2,14 @@ module Savon
|
|
2
2
|
|
3
3
|
# = Savon::SOAP
|
4
4
|
#
|
5
|
-
#
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
#
|
11
|
-
# The body method lets you specify parameters to be received by the SOAP action.
|
12
|
-
#
|
13
|
-
# You can either pass in a hash (which will be translated to XML via Hash.to_soap_xml):
|
14
|
-
#
|
15
|
-
# response = client.get_user_by_id do |soap|
|
16
|
-
# soap.body = { :id => 123 }
|
17
|
-
# end
|
18
|
-
#
|
19
|
-
# Or a string containing the raw XML:
|
20
|
-
#
|
21
|
-
# response = client.get_user_by_id do |soap|
|
22
|
-
# soap.body = "<id>123</id>"
|
23
|
-
# end
|
24
|
-
#
|
25
|
-
# Request output:
|
26
|
-
#
|
27
|
-
# <env:Envelope
|
28
|
-
# xmlns:wsdl="http://example.com/user/1.0/UserService"
|
29
|
-
# xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
|
30
|
-
# <env:Body>
|
31
|
-
# <wsdl:getUserById><id>123</id></wsdl:getUserById>
|
32
|
-
# </env:Body>
|
33
|
-
# </env:Envelope>
|
34
|
-
#
|
35
|
-
# Please look at the documentation of Hash.to_soap_xml for some more information.
|
36
|
-
#
|
37
|
-
# == Version
|
38
|
-
#
|
39
|
-
# Savon defaults to SOAP 1.1. In case your service uses SOAP 1.2, you can use the version method
|
40
|
-
# to change the default per request.
|
41
|
-
#
|
42
|
-
# response = client.get_all_users do |soap|
|
43
|
-
# soap.version = 2
|
44
|
-
# end
|
45
|
-
#
|
46
|
-
# You can also change the default to SOAP 1.2 for all request:
|
47
|
-
#
|
48
|
-
# Savon::SOAP.version = 2
|
49
|
-
#
|
50
|
-
# == Header
|
51
|
-
#
|
52
|
-
# If you need to add custom XML into the SOAP header, you can use the header method.
|
53
|
-
#
|
54
|
-
# The value is expected to be a hash (which will be translated to XML via Hash.to_soap_xml):
|
55
|
-
#
|
56
|
-
# response = client.get_all_users do |soap|
|
57
|
-
# soap.header["specialApiKey"] = "secret"
|
58
|
-
# end
|
59
|
-
#
|
60
|
-
# Or a string containing the raw XML:
|
61
|
-
#
|
62
|
-
# response = client.get_all_users do |soap|
|
63
|
-
# soap.header = "<specialApiKey>secret</specialApiKey>"
|
64
|
-
# end
|
65
|
-
#
|
66
|
-
# Request output:
|
67
|
-
#
|
68
|
-
# <env:Envelope
|
69
|
-
# xmlns:wsdl="http://example.com/user/1.0/UserService"
|
70
|
-
# xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
|
71
|
-
# <env:Header>
|
72
|
-
# <specialApiKey>secret</specialApiKey>
|
73
|
-
# </env:Header>
|
74
|
-
# <env:Body>
|
75
|
-
# <wsdl:getAllUsers></wsdl:getAllUsers>
|
76
|
-
# </env:Body>
|
77
|
-
# </env:Envelope>
|
78
|
-
#
|
79
|
-
# == Namespaces
|
80
|
-
#
|
81
|
-
# The namespaces method contains a hash of attributes for the SOAP envelope. You can overwrite it
|
82
|
-
# or add additional attributes.
|
83
|
-
#
|
84
|
-
# response = client.get_all_users do |soap|
|
85
|
-
# soap.namespaces["xmlns:domains"] = "http://domains.example.com"
|
86
|
-
# end
|
87
|
-
#
|
88
|
-
# Request output:
|
89
|
-
#
|
90
|
-
# <env:Envelope
|
91
|
-
# xmlns:wsdl="http://example.com/user/1.0/UserService"
|
92
|
-
# xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
|
93
|
-
# xmlns:domains="http://domains.example.com">
|
94
|
-
# <env:Body>
|
95
|
-
# <wsdl:getAllUsers></wsdl:getAllUsers>
|
96
|
-
# </env:Body>
|
97
|
-
# </env:Envelope>
|
98
|
-
#
|
99
|
-
# == Input
|
100
|
-
#
|
101
|
-
# You can change the name of the SOAP input tag in case you need to.
|
102
|
-
#
|
103
|
-
# response = client.get_all_users do |soap|
|
104
|
-
# soap.input = "GetAllUsersRequest"
|
105
|
-
# end
|
106
|
-
#
|
107
|
-
# Request output:
|
108
|
-
#
|
109
|
-
# <env:Envelope
|
110
|
-
# xmlns:wsdl="http://example.com/user/1.0/UserService"
|
111
|
-
# xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
|
112
|
-
# <env:Body>
|
113
|
-
# <wsdl:GetAllUsersRequest></wsdl:GetAllUsersRequest>
|
114
|
-
# </env:Body>
|
115
|
-
# </env:Envelope>
|
116
|
-
class SOAP
|
5
|
+
# Contains various SOAP details.
|
6
|
+
module SOAP
|
7
|
+
|
8
|
+
# Default SOAP version.
|
9
|
+
DefaultVersion = 1
|
117
10
|
|
118
11
|
# Supported SOAP versions.
|
119
|
-
Versions =
|
12
|
+
Versions = 1..2
|
120
13
|
|
121
14
|
# SOAP namespaces by SOAP version.
|
122
15
|
Namespace = {
|
@@ -124,179 +17,11 @@ module Savon
|
|
124
17
|
2 => "http://www.w3.org/2003/05/soap-envelope"
|
125
18
|
}
|
126
19
|
|
127
|
-
# Content-Types by SOAP version.
|
128
|
-
ContentType = { 1 => "text/xml", 2 => "application/soap+xml" }
|
129
|
-
|
130
20
|
# SOAP xs:dateTime format.
|
131
21
|
DateTimeFormat = "%Y-%m-%dT%H:%M:%S%Z"
|
132
22
|
|
133
23
|
# SOAP xs:dateTime Regexp.
|
134
|
-
DateTimeRegexp =
|
135
|
-
|
136
|
-
# The global SOAP version.
|
137
|
-
@@version = 1
|
138
|
-
|
139
|
-
# Returns the global SOAP version.
|
140
|
-
def self.version
|
141
|
-
@@version
|
142
|
-
end
|
143
|
-
|
144
|
-
# Sets the global SOAP version.
|
145
|
-
def self.version=(version)
|
146
|
-
@@version = version if Versions.include? version
|
147
|
-
end
|
148
|
-
|
149
|
-
# Sets the global SOAP header. Expected to be a Hash that can be translated to XML via
|
150
|
-
# Hash.to_soap_xml or any other Object responding to to_s.
|
151
|
-
def self.header=(header)
|
152
|
-
@@header = header
|
153
|
-
end
|
154
|
-
|
155
|
-
# Returns the global SOAP header. Defaults to an empty Hash.
|
156
|
-
def self.header
|
157
|
-
@@header ||= {}
|
158
|
-
end
|
159
|
-
|
160
|
-
# Sets the global namespaces. Expected to be a Hash containing the namespaces (keys) and the
|
161
|
-
# corresponding URI's (values).
|
162
|
-
def self.namespaces=(namespaces)
|
163
|
-
@@namespaces = namespaces if namespaces.kind_of? Hash
|
164
|
-
end
|
165
|
-
|
166
|
-
# Returns the global namespaces. A Hash containing the namespaces (keys) and the corresponding
|
167
|
-
# URI's (values).
|
168
|
-
def self.namespaces
|
169
|
-
@@namespaces ||= {}
|
170
|
-
end
|
171
|
-
|
172
|
-
# Initialzes the SOAP object. Expects a SOAP +operation+ Hash along with an +endpoint+.
|
173
|
-
def initialize(action, input, endpoint)
|
174
|
-
@action, @input = action, input
|
175
|
-
@endpoint = endpoint.kind_of?(URI) ? endpoint : URI(endpoint)
|
176
|
-
@builder = Builder::XmlMarkup.new
|
177
|
-
end
|
178
|
-
|
179
|
-
# Sets the WSSE options.
|
180
|
-
attr_writer :wsse
|
181
|
-
|
182
|
-
# Sets the SOAP action.
|
183
|
-
attr_writer :action
|
184
|
-
|
185
|
-
# Returns the SOAP action.
|
186
|
-
def action
|
187
|
-
@action ||= ""
|
188
|
-
end
|
189
|
-
|
190
|
-
# Sets the SOAP input.
|
191
|
-
attr_writer :input
|
192
|
-
|
193
|
-
# Returns the SOAP input.
|
194
|
-
def input
|
195
|
-
@input ||= ""
|
196
|
-
end
|
197
|
-
|
198
|
-
# Accessor for the SOAP endpoint.
|
199
|
-
attr_accessor :endpoint
|
200
|
-
|
201
|
-
# Sets the SOAP header. Expected to be a Hash that can be translated to XML via Hash.to_soap_xml
|
202
|
-
# or any other Object responding to to_s.
|
203
|
-
attr_writer :header
|
204
|
-
|
205
|
-
# Returns the SOAP header. Defaults to an empty Hash.
|
206
|
-
def header
|
207
|
-
@header ||= {}
|
208
|
-
end
|
209
|
-
|
210
|
-
# Accessor for the SOAP body. Expected to be a Hash that can be translated to XML via Hash.to_soap_xml
|
211
|
-
# or any other Object responding to to_s.
|
212
|
-
attr_accessor :body
|
213
|
-
|
214
|
-
# Accessor for overwriting the default SOAP request. Let's you specify completely custom XML.
|
215
|
-
attr_accessor :xml
|
216
|
-
|
217
|
-
# Sets the namespaces. Expected to be a Hash containing the namespaces (keys) and the
|
218
|
-
# corresponding URI's (values).
|
219
|
-
attr_writer :namespaces
|
220
|
-
|
221
|
-
# Returns the namespaces. A Hash containing the namespaces (keys) and the corresponding URI's
|
222
|
-
# (values). Defaults to a Hash containing an +xmlns:env+ key and the namespace for the current
|
223
|
-
# SOAP version.
|
224
|
-
def namespaces
|
225
|
-
@namespaces ||= { "xmlns:env" => Namespace[version] }
|
226
|
-
end
|
227
|
-
|
228
|
-
# Convenience method for setting the +xmlns:wsdl+ namespace.
|
229
|
-
def namespace=(namespace)
|
230
|
-
namespaces["xmlns:wsdl"] = namespace
|
231
|
-
end
|
232
|
-
|
233
|
-
# Sets the SOAP version.
|
234
|
-
def version=(version)
|
235
|
-
@version = version if Versions.include? version
|
236
|
-
end
|
237
|
-
|
238
|
-
# Returns the SOAP version. Defaults to the global default.
|
239
|
-
def version
|
240
|
-
@version ||= self.class.version
|
241
|
-
end
|
242
|
-
|
243
|
-
# Returns the SOAP envelope XML.
|
244
|
-
def to_xml
|
245
|
-
unless @xml
|
246
|
-
@builder.instruct!
|
247
|
-
@xml = @builder.env :Envelope, merged_namespaces do |xml|
|
248
|
-
xml.env(:Header) { xml << merged_header } unless merged_header.empty?
|
249
|
-
xml_body xml
|
250
|
-
end
|
251
|
-
end
|
252
|
-
@xml
|
253
|
-
end
|
254
|
-
|
255
|
-
private
|
256
|
-
|
257
|
-
# Returns a String containing the global and per request header.
|
258
|
-
def merged_header
|
259
|
-
if self.class.header.kind_of?(Hash) && header.kind_of?(Hash)
|
260
|
-
merged_header = self.class.header.merge(header).to_soap_xml
|
261
|
-
else
|
262
|
-
global_header = self.class.header.to_soap_xml rescue self.class.header.to_s
|
263
|
-
request_header = header.to_soap_xml rescue header.to_s
|
264
|
-
merged_header = global_header + request_header
|
265
|
-
end
|
266
|
-
merged_header + wsse_header
|
267
|
-
end
|
268
|
-
|
269
|
-
# Returns the WSSE header or an empty String in case WSSE was not set.
|
270
|
-
def wsse_header
|
271
|
-
@wsse.respond_to?(:header) ? @wsse.header : ""
|
272
|
-
end
|
273
|
-
|
274
|
-
# Adds a SOAP XML body to a given +xml+ Object.
|
275
|
-
def xml_body(xml)
|
276
|
-
xml.env(:Body) do
|
277
|
-
xml.tag!(:wsdl, *input_array) { xml << (@body.to_soap_xml rescue @body.to_s) }
|
278
|
-
end
|
279
|
-
end
|
280
|
-
|
281
|
-
# Returns a Hash containing the global and per request namespaces.
|
282
|
-
def merged_namespaces
|
283
|
-
self.class.namespaces.merge namespaces
|
284
|
-
end
|
285
|
-
|
286
|
-
# Returns an Array of SOAP input names to append to the wsdl namespace. Defaults to use the
|
287
|
-
# name of the SOAP action. May return an empty Array in case the specified SOAP input seems
|
288
|
-
# to be invalid.
|
289
|
-
def input_array
|
290
|
-
if input.kind_of?(Array) && !input.blank?
|
291
|
-
[input[0].to_sym, input[1]]
|
292
|
-
elsif !input.blank?
|
293
|
-
[input.to_sym]
|
294
|
-
elsif !action.blank?
|
295
|
-
[action.to_sym]
|
296
|
-
else
|
297
|
-
[]
|
298
|
-
end
|
299
|
-
end
|
24
|
+
DateTimeRegexp = /\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/
|
300
25
|
|
301
26
|
end
|
302
|
-
end
|
27
|
+
end
|