savon 0.8.0.beta.3 → 0.8.0.beta.4
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.md +18 -0
- data/lib/savon/global.rb +0 -9
- data/lib/savon/soap/fault.rb +1 -1
- data/lib/savon/soap/response.rb +10 -26
- data/lib/savon/soap/xml.rb +1 -1
- data/lib/savon/version.rb +1 -1
- data/savon.gemspec +1 -1
- data/spec/fixtures/response/response_fixture.rb +4 -0
- data/spec/fixtures/response/xml/another_soap_fault.xml +14 -0
- data/spec/savon/savon_spec.rb +0 -13
- data/spec/savon/soap/fault_spec.rb +9 -0
- data/spec/savon/soap/response_spec.rb +12 -49
- data/spec/savon/soap/xml_spec.rb +11 -0
- metadata +9 -8
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,21 @@
|
|
1
|
+
## 0.8.0.beta.4 (2010-11-20)
|
2
|
+
|
3
|
+
* Fix for issue #107 (Soap Fault regex not working for API I connect).
|
4
|
+
|
5
|
+
* Fix for issue #108 (Fixing an issue with :attributes! getting overriden by a double call).
|
6
|
+
|
7
|
+
* Replaced Savon.response_pattern with a slightly different implementation of the
|
8
|
+
Savon::SOAP::Response#to_array method. The method now accepts multiple arguments
|
9
|
+
representing the response Hash keys to traverse and returns the result as an Array
|
10
|
+
or an empty Array in case the key is nil or does not exist.
|
11
|
+
|
12
|
+
response.to_array :get_user_response, :return
|
13
|
+
# => [{ :id => 1, :name => "foo"}, { :id => 2, :name => "bar"}]
|
14
|
+
|
15
|
+
## 0.8.0.beta.3 (2010-11-06)
|
16
|
+
|
17
|
+
* Fix for [savon_spec](http://rubygems.org/gems/savon_spec) to not send nil to Savon::SOAP::XML#body.
|
18
|
+
|
1
19
|
## 0.8.0.beta.2 (2010-11-05)
|
2
20
|
|
3
21
|
* Added Savon.response_pattern to automatically walk deeper into the SOAP response Hash when a
|
data/lib/savon/global.rb
CHANGED
@@ -61,14 +61,6 @@ module Savon
|
|
61
61
|
# Sets whether to strip namespaces in a SOAP response Hash.
|
62
62
|
attr_writer :strip_namespaces
|
63
63
|
|
64
|
-
# Returns the response pattern to apply.
|
65
|
-
def response_pattern
|
66
|
-
@response_pattern ||= []
|
67
|
-
end
|
68
|
-
|
69
|
-
# Sets the response pattern (an Array of Regexps or Symbols).
|
70
|
-
attr_writer :response_pattern
|
71
|
-
|
72
64
|
# Reset to default configuration.
|
73
65
|
def reset_config!
|
74
66
|
self.log = true
|
@@ -77,7 +69,6 @@ module Savon
|
|
77
69
|
self.raise_errors = true
|
78
70
|
self.soap_version = SOAP::DefaultVersion
|
79
71
|
self.strip_namespaces = true
|
80
|
-
self.response_pattern = []
|
81
72
|
end
|
82
73
|
|
83
74
|
end
|
data/lib/savon/soap/fault.rb
CHANGED
data/lib/savon/soap/response.rb
CHANGED
@@ -44,22 +44,20 @@ module Savon
|
|
44
44
|
end
|
45
45
|
|
46
46
|
# Returns the SOAP response body as a Hash.
|
47
|
-
def original_hash
|
48
|
-
@original_hash ||= Savon::SOAP::XML.to_hash to_xml
|
49
|
-
end
|
50
|
-
|
51
|
-
# Returns the SOAP response body as a Hash and applies
|
52
|
-
# the <tt>Savon.response_pattern</tt> if defined.
|
53
47
|
def to_hash
|
54
|
-
@hash ||=
|
48
|
+
@hash ||= Savon::SOAP::XML.to_hash to_xml
|
55
49
|
end
|
56
50
|
|
57
|
-
#
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
51
|
+
# Traverses the SOAP response Hash for a given +path+ of Hash keys
|
52
|
+
# and returns the value as an Array. Defaults to return an empty Array
|
53
|
+
# in case the path does not exist or returns nil.
|
54
|
+
def to_array(*path)
|
55
|
+
value = path.inject to_hash do |memo, key|
|
56
|
+
return [] unless memo[key]
|
57
|
+
memo[key]
|
62
58
|
end
|
59
|
+
|
60
|
+
value.kind_of?(Array) ? value.compact : [value].compact
|
63
61
|
end
|
64
62
|
|
65
63
|
# Returns the SOAP response XML.
|
@@ -74,20 +72,6 @@ module Savon
|
|
74
72
|
raise http_error if http_error?
|
75
73
|
end
|
76
74
|
|
77
|
-
def apply_response_pattern(hash)
|
78
|
-
return hash if Savon.response_pattern.blank?
|
79
|
-
|
80
|
-
Savon.response_pattern.inject(hash) do |memo, pattern|
|
81
|
-
key = case pattern
|
82
|
-
when Regexp then memo.keys.find { |key| key.to_s =~ pattern }
|
83
|
-
else memo.keys.find { |key| key.to_s == pattern.to_s }
|
84
|
-
end
|
85
|
-
|
86
|
-
return hash unless key
|
87
|
-
memo[key]
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
75
|
end
|
92
76
|
end
|
93
77
|
end
|
data/lib/savon/soap/xml.rb
CHANGED
@@ -114,7 +114,7 @@ module Savon
|
|
114
114
|
|
115
115
|
# Returns the SOAP header as an XML String.
|
116
116
|
def header_for_xml
|
117
|
-
header.to_soap_xml + wsse_header
|
117
|
+
@header_for_xml ||= header.to_soap_xml + wsse_header
|
118
118
|
end
|
119
119
|
|
120
120
|
# Returns the WSSE header or an empty String in case WSSE was not set.
|
data/lib/savon/version.rb
CHANGED
data/savon.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
|
17
17
|
s.add_dependency "builder", "~> 2.1.2"
|
18
18
|
s.add_dependency "crack", "~> 0.1.8"
|
19
|
-
s.add_dependency "httpi", ">= 0.
|
19
|
+
s.add_dependency "httpi", ">= 0.7.1"
|
20
20
|
|
21
21
|
s.add_development_dependency "rspec", "~> 2.0.0"
|
22
22
|
s.add_development_dependency "mocha", "~> 0.9.7"
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
|
2
|
+
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
|
3
|
+
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
|
4
|
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
5
|
+
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
6
|
+
<SOAP-ENV:Body>
|
7
|
+
<SOAP-ENV:Fault>
|
8
|
+
<faultcode>ERR_NO_SESSION</faultcode>
|
9
|
+
<faultfactor>doGetItemsInfo - Wrong session</faultfactor>
|
10
|
+
<faultstring>Wrong session message</faultstring>
|
11
|
+
<detail><soapVal><ERRNO xsi:type="xsd:string">80:1289245853:55</ERRNO></soapVal></detail>
|
12
|
+
</SOAP-ENV:Fault>
|
13
|
+
</SOAP-ENV:Body>
|
14
|
+
</SOAP-ENV:Envelope>
|
data/spec/savon/savon_spec.rb
CHANGED
@@ -80,19 +80,6 @@ describe Savon do
|
|
80
80
|
Savon.strip_namespaces?.should == false
|
81
81
|
end
|
82
82
|
end
|
83
|
-
|
84
|
-
describe "response_pattern" do
|
85
|
-
it "should default to an empty Array" do
|
86
|
-
Savon.response_pattern.should == []
|
87
|
-
end
|
88
|
-
|
89
|
-
it "should return the response pattern to apply" do
|
90
|
-
pattern = [/.+_response/, :return]
|
91
|
-
Savon.configure { |config| config.response_pattern = pattern }
|
92
|
-
|
93
|
-
Savon.response_pattern.should == pattern
|
94
|
-
end
|
95
|
-
end
|
96
83
|
end
|
97
84
|
|
98
85
|
end
|
@@ -3,6 +3,7 @@ require "spec_helper"
|
|
3
3
|
describe Savon::SOAP::Fault do
|
4
4
|
let(:soap_fault) { Savon::SOAP::Fault.new new_response(:body => ResponseFixture.soap_fault) }
|
5
5
|
let(:soap_fault2) { Savon::SOAP::Fault.new new_response(:body => ResponseFixture.soap_fault12) }
|
6
|
+
let(:another_soap_fault) { Savon::SOAP::Fault.new new_response(:body => ResponseFixture.another_soap_fault) }
|
6
7
|
let(:no_fault) { Savon::SOAP::Fault.new new_response }
|
7
8
|
|
8
9
|
it "should be a Savon::Error" do
|
@@ -24,6 +25,10 @@ describe Savon::SOAP::Fault do
|
|
24
25
|
soap_fault2.should be_present
|
25
26
|
end
|
26
27
|
|
28
|
+
it "should return true if the HTTP response contains a SOAP fault with different namespaces" do
|
29
|
+
another_soap_fault.should be_present
|
30
|
+
end
|
31
|
+
|
27
32
|
it "should return false unless the HTTP response contains a SOAP fault" do
|
28
33
|
no_fault.should_not be_present
|
29
34
|
end
|
@@ -42,6 +47,10 @@ describe Savon::SOAP::Fault do
|
|
42
47
|
it "should return a SOAP 1.2 fault message" do
|
43
48
|
soap_fault2.send(method).should == "(soap:Sender) Sender Timeout"
|
44
49
|
end
|
50
|
+
|
51
|
+
it "should return a SOAP fault message (with different namespaces)" do
|
52
|
+
another_soap_fault.send(method).should == "(ERR_NO_SESSION) Wrong session message"
|
53
|
+
end
|
45
54
|
end
|
46
55
|
end
|
47
56
|
|
@@ -116,72 +116,35 @@ describe Savon::SOAP::Response do
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
-
describe "#
|
119
|
+
describe "#to_hash" do
|
120
120
|
it "should return the SOAP response body as a Hash" do
|
121
|
-
soap_response.
|
121
|
+
soap_response.to_hash[:authenticate_response][:return].should ==
|
122
122
|
ResponseFixture.authentication(:to_hash)
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
-
describe "#
|
126
|
+
describe "#to_array" do
|
127
127
|
let(:response) { soap_response }
|
128
128
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
context "without response pattern" do
|
134
|
-
it "should return the original Hash" do
|
135
|
-
response.to_hash[:authenticate_response].should be_a(Hash)
|
129
|
+
context "when the given path exists" do
|
130
|
+
it "should return an Array containing the path value" do
|
131
|
+
response.to_array(:authenticate_response, :return).should == [ResponseFixture.authentication(:to_hash)]
|
136
132
|
end
|
137
133
|
end
|
138
134
|
|
139
|
-
context "
|
140
|
-
it "should
|
141
|
-
|
142
|
-
response.to_hash[:success].should be_true
|
143
|
-
|
144
|
-
Savon.response_pattern = nil # reset to default
|
135
|
+
context "when the given path returns nil" do
|
136
|
+
it "should return an empty Array" do
|
137
|
+
response.to_array(:authenticate_response, :undefined).should == []
|
145
138
|
end
|
146
139
|
end
|
147
140
|
|
148
|
-
context "
|
149
|
-
it "should return
|
150
|
-
|
151
|
-
response.to_hash.should == response.original_hash
|
152
|
-
|
153
|
-
Savon.response_pattern = nil # reset to default
|
141
|
+
context "when the given path does not exist at all" do
|
142
|
+
it "should return an empty Array" do
|
143
|
+
response.to_array(:authenticate_response, :some, :wrong, :path).should == []
|
154
144
|
end
|
155
145
|
end
|
156
146
|
end
|
157
147
|
|
158
|
-
describe "#to_array" do
|
159
|
-
let(:response) { soap_response }
|
160
|
-
|
161
|
-
around do |example|
|
162
|
-
Savon.response_pattern = [/.+_response/, :return]
|
163
|
-
example.run
|
164
|
-
Savon.response_pattern = nil # reset to default
|
165
|
-
end
|
166
|
-
|
167
|
-
it "should memoize the result" do
|
168
|
-
response.to_array.should equal(response.to_array)
|
169
|
-
end
|
170
|
-
|
171
|
-
it "should return an Array for a single response element" do
|
172
|
-
response.to_array.should be_an(Array)
|
173
|
-
response.to_array.first[:success].should be_true
|
174
|
-
end
|
175
|
-
|
176
|
-
it "should return an Array for multiple response element" do
|
177
|
-
Savon.response_pattern = [/.+_response/, :history, :case]
|
178
|
-
list_response = soap_response :body => ResponseFixture.list
|
179
|
-
|
180
|
-
list_response.to_array.should be_an(Array)
|
181
|
-
list_response.to_array.should have(2).items
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
148
|
describe "#to_xml" do
|
186
149
|
it "should return the raw SOAP response body" do
|
187
150
|
soap_response.to_xml.should == ResponseFixture.authentication
|
data/spec/savon/soap/xml_spec.rb
CHANGED
@@ -166,6 +166,17 @@ describe Savon::SOAP::XML do
|
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
169
|
+
context "with a SOAP header" do
|
170
|
+
it "should contain the given header" do
|
171
|
+
xml.header = {
|
172
|
+
:token => "secret",
|
173
|
+
:attributes! => { :token => { :xmlns => "http://example.com" } }
|
174
|
+
}
|
175
|
+
|
176
|
+
xml.to_xml.should include('<env:Header><token xmlns="http://example.com">secret</token></env:Header>')
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
169
180
|
context "with the global SOAP version set to 1.2" do
|
170
181
|
it "should contain the namespace for SOAP 1.2" do
|
171
182
|
Savon.soap_version = 2
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: savon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 62196267
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 8
|
9
9
|
- 0
|
10
10
|
- beta
|
11
|
-
-
|
12
|
-
version: 0.8.0.beta.
|
11
|
+
- 4
|
12
|
+
version: 0.8.0.beta.4
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Daniel Harrington
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-11-
|
20
|
+
date: 2010-11-26 00:00:00 +01:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -60,12 +60,12 @@ dependencies:
|
|
60
60
|
requirements:
|
61
61
|
- - ">="
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
hash:
|
63
|
+
hash: 1
|
64
64
|
segments:
|
65
65
|
- 0
|
66
|
-
-
|
67
|
-
-
|
68
|
-
version: 0.
|
66
|
+
- 7
|
67
|
+
- 1
|
68
|
+
version: 0.7.1
|
69
69
|
type: :runtime
|
70
70
|
version_requirements: *id003
|
71
71
|
- !ruby/object:Gem::Dependency
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- spec/fixtures/gzip/gzip_response_fixture.rb
|
144
144
|
- spec/fixtures/gzip/message.gz
|
145
145
|
- spec/fixtures/response/response_fixture.rb
|
146
|
+
- spec/fixtures/response/xml/another_soap_fault.xml
|
146
147
|
- spec/fixtures/response/xml/authentication.xml
|
147
148
|
- spec/fixtures/response/xml/list.xml
|
148
149
|
- spec/fixtures/response/xml/multi_ref.xml
|