savon 0.8.0.beta.1 → 0.8.0.beta.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/savon/global.rb +9 -0
- data/lib/savon/soap/response.rb +29 -1
- data/lib/savon/version.rb +1 -1
- data/spec/savon/savon_spec.rb +14 -6
- data/spec/savon/soap/response_spec.rb +61 -2
- data/spec/savon/wsdl/document_spec.rb +56 -89
- data/spec/savon/wsdl/parser_spec.rb +78 -0
- metadata +5 -4
data/lib/savon/global.rb
CHANGED
@@ -61,6 +61,14 @@ 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
|
+
|
64
72
|
# Reset to default configuration.
|
65
73
|
def reset_config!
|
66
74
|
self.log = true
|
@@ -69,6 +77,7 @@ module Savon
|
|
69
77
|
self.raise_errors = true
|
70
78
|
self.soap_version = SOAP::DefaultVersion
|
71
79
|
self.strip_namespaces = true
|
80
|
+
self.response_pattern = []
|
72
81
|
end
|
73
82
|
|
74
83
|
end
|
data/lib/savon/soap/response.rb
CHANGED
@@ -44,8 +44,22 @@ 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.
|
47
53
|
def to_hash
|
48
|
-
@hash ||=
|
54
|
+
@hash ||= apply_response_pattern original_hash
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns the SOAP response Hash as an Array.
|
58
|
+
def to_array
|
59
|
+
@array ||= begin
|
60
|
+
array = to_hash.kind_of?(Array) ? to_hash : [to_hash]
|
61
|
+
array.compact
|
62
|
+
end
|
49
63
|
end
|
50
64
|
|
51
65
|
# Returns the SOAP response XML.
|
@@ -60,6 +74,20 @@ module Savon
|
|
60
74
|
raise http_error if http_error?
|
61
75
|
end
|
62
76
|
|
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
|
+
|
63
91
|
end
|
64
92
|
end
|
65
93
|
end
|
data/lib/savon/version.rb
CHANGED
data/spec/savon/savon_spec.rb
CHANGED
@@ -7,6 +7,7 @@ describe Savon do
|
|
7
7
|
Savon.reset_config!
|
8
8
|
example.run
|
9
9
|
Savon.reset_config!
|
10
|
+
Savon.log = false # disable logging
|
10
11
|
end
|
11
12
|
|
12
13
|
describe "log" do
|
@@ -51,8 +52,6 @@ describe Savon do
|
|
51
52
|
it "should not raise errors when disabled" do
|
52
53
|
Savon.raise_errors = false
|
53
54
|
Savon.raise_errors?.should be_false
|
54
|
-
|
55
|
-
Savon.raise_errors = true # reset to default
|
56
55
|
end
|
57
56
|
end
|
58
57
|
|
@@ -64,8 +63,6 @@ describe Savon do
|
|
64
63
|
it "should return 2 if set to SOAP 1.2" do
|
65
64
|
Savon.soap_version = 2
|
66
65
|
Savon.soap_version.should == 2
|
67
|
-
|
68
|
-
Savon.soap_version = 1 # reset to default
|
69
66
|
end
|
70
67
|
|
71
68
|
it "should raise an ArgumentError in case of an invalid version" do
|
@@ -81,10 +78,21 @@ describe Savon do
|
|
81
78
|
it "should not strip namespaces when set to false" do
|
82
79
|
Savon.strip_namespaces = false
|
83
80
|
Savon.strip_namespaces?.should == false
|
84
|
-
|
85
|
-
Savon.strip_namespaces = true # reset to default
|
86
81
|
end
|
87
82
|
end
|
88
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
|
89
96
|
end
|
97
|
+
|
90
98
|
end
|
@@ -116,13 +116,72 @@ describe Savon::SOAP::Response do
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
-
describe "#
|
119
|
+
describe "#original_hash" do
|
120
120
|
it "should return the SOAP response body as a Hash" do
|
121
|
-
soap_response.
|
121
|
+
soap_response.original_hash[:authenticate_response][:return].should ==
|
122
122
|
ResponseFixture.authentication(:to_hash)
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
+
describe "#to_hash" do
|
127
|
+
let(:response) { soap_response }
|
128
|
+
|
129
|
+
it "should memoize the result" do
|
130
|
+
response.to_hash.should equal(response.to_hash)
|
131
|
+
end
|
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)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context "with response pattern" do
|
140
|
+
it "should apply the response pattern" do
|
141
|
+
Savon.response_pattern = [/.+_response/, :return]
|
142
|
+
response.to_hash[:success].should be_true
|
143
|
+
|
144
|
+
Savon.response_pattern = nil # reset to default
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context "with unmatched response pattern" do
|
149
|
+
it "should return the original Hash" do
|
150
|
+
Savon.response_pattern = [:unmatched, :pattern]
|
151
|
+
response.to_hash.should == response.original_hash
|
152
|
+
|
153
|
+
Savon.response_pattern = nil # reset to default
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
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
|
+
|
126
185
|
describe "#to_xml" do
|
127
186
|
it "should return the raw SOAP response body" do
|
128
187
|
soap_response.to_xml.should == ResponseFixture.authentication
|
@@ -2,143 +2,110 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Savon::WSDL::Document do
|
4
4
|
|
5
|
-
|
6
|
-
let(:wsdl) { Savon::WSDL::Document.new HTTPI::Request.new, Endpoint.wsdl }
|
7
|
-
before { HTTPI.stubs(:get).returns(new_response) }
|
8
|
-
|
5
|
+
shared_examples_for "a WSDL document" do
|
9
6
|
it "should be present" do
|
10
7
|
wsdl.should be_present
|
11
8
|
end
|
12
9
|
|
13
10
|
describe "#namespace" do
|
14
11
|
it "should return the namespace URI" do
|
15
|
-
wsdl.namespace.should ==
|
12
|
+
wsdl.namespace.should == "http://v1_0.ws.auth.order.example.com/"
|
16
13
|
end
|
17
14
|
end
|
18
15
|
|
19
16
|
describe "#soap_actions" do
|
20
17
|
it "should return an Array of available SOAP actions" do
|
21
|
-
wsdl.soap_actions.should
|
18
|
+
wsdl.soap_actions.should == [:authenticate]
|
22
19
|
end
|
23
20
|
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context "with a local document" do
|
27
|
-
let(:wsdl) do
|
28
|
-
wsdl = "spec/fixtures/wsdl/xml/authentication.xml"
|
29
|
-
Savon::WSDL::Document.new HTTPI::Request.new, wsdl
|
30
|
-
end
|
31
21
|
|
32
|
-
|
22
|
+
describe "#soap_action" do
|
23
|
+
it "should return the SOAP action for a given key" do
|
24
|
+
wsdl.soap_action(:authenticate).should == "authenticate"
|
25
|
+
end
|
33
26
|
|
34
|
-
|
35
|
-
|
27
|
+
it "should return nil if no SOAP action could be found" do
|
28
|
+
wsdl.soap_action(:unknown).should be_nil
|
29
|
+
end
|
36
30
|
end
|
37
31
|
|
38
|
-
describe "#
|
39
|
-
it "should return the
|
40
|
-
wsdl.
|
32
|
+
describe "#soap_input" do
|
33
|
+
it "should return the SOAP input tag for a given key" do
|
34
|
+
wsdl.soap_input(:authenticate).should == :authenticate
|
41
35
|
end
|
42
|
-
end
|
43
36
|
|
44
|
-
|
45
|
-
|
46
|
-
wsdl.soap_actions.should include(*WSDLFixture.authentication(:operations).keys)
|
37
|
+
it "should return nil if no SOAP input tag could be found" do
|
38
|
+
wsdl.soap_input(:unknown).should be_nil
|
47
39
|
end
|
48
40
|
end
|
49
|
-
end
|
50
41
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
59
|
-
__END__
|
60
|
-
|
61
|
-
it "has a getter for the namespace URI" do
|
62
|
-
@wsdl.namespace.should == WSDLFixture.authentication(:namespace_uri)
|
42
|
+
describe "#operations" do
|
43
|
+
it "should return a Hash of SOAP operations" do
|
44
|
+
wsdl.operations.should == {
|
45
|
+
:authenticate => {
|
46
|
+
:input => "authenticate", :action => "authenticate"
|
47
|
+
}
|
48
|
+
}
|
49
|
+
end
|
63
50
|
end
|
64
51
|
|
65
|
-
|
66
|
-
|
67
|
-
|
52
|
+
describe "#document" do
|
53
|
+
it "should return the raw WSDL document" do
|
54
|
+
wsdl.document.should == WSDLFixture.load
|
68
55
|
end
|
69
|
-
end
|
70
56
|
|
71
|
-
|
72
|
-
|
57
|
+
it "should be memoized" do
|
58
|
+
wsdl.document.should equal(wsdl.document)
|
59
|
+
end
|
73
60
|
end
|
61
|
+
end
|
74
62
|
|
75
|
-
|
76
|
-
|
77
|
-
@wsdl.respond_to?(soap_action).should be_true
|
78
|
-
end
|
63
|
+
context "with a remote document" do
|
64
|
+
let(:wsdl) { Savon::WSDL::Document.new HTTPI::Request.new, Endpoint.wsdl }
|
79
65
|
|
80
|
-
|
81
|
-
|
66
|
+
before do
|
67
|
+
response = HTTPI::Response.new(200, {}, WSDLFixture.load)
|
68
|
+
HTTPI.stubs(:get).returns(response)
|
82
69
|
end
|
83
70
|
|
84
|
-
|
85
|
-
@wsdl.to_xml.should == WSDLFixture.authentication
|
86
|
-
end
|
71
|
+
it_should_behave_like "a WSDL document"
|
87
72
|
end
|
88
73
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
@wsdl.namespace_uri.should == WSDLFixture.no_namespace(:namespace_uri)
|
74
|
+
context "with a local document" do
|
75
|
+
let(:wsdl) do
|
76
|
+
wsdl = "spec/fixtures/wsdl/xml/authentication.xml"
|
77
|
+
Savon::WSDL::Document.new HTTPI::Request.new, wsdl
|
94
78
|
end
|
95
79
|
|
96
|
-
|
97
|
-
WSDLFixture.no_namespace(:operations).keys.each do |soap_action|
|
98
|
-
@wsdl.soap_actions.should include(soap_action)
|
99
|
-
end
|
100
|
-
end
|
80
|
+
before { HTTPI.expects(:get).never }
|
101
81
|
|
102
|
-
|
103
|
-
@wsdl.operations.should == WSDLFixture.no_namespace(:operations)
|
104
|
-
end
|
82
|
+
it_should_behave_like "a WSDL document"
|
105
83
|
end
|
106
84
|
|
107
|
-
|
108
|
-
|
85
|
+
context "without a WSDL document" do
|
86
|
+
let(:wsdl) { Savon::WSDL::Document.new HTTPI::Request.new }
|
109
87
|
|
110
|
-
it "
|
111
|
-
|
88
|
+
it "should not be present" do
|
89
|
+
wsdl.should_not be_present
|
112
90
|
end
|
113
91
|
|
114
|
-
|
115
|
-
|
116
|
-
|
92
|
+
describe "#soap_action" do
|
93
|
+
it "should return nil" do
|
94
|
+
wsdl.soap_action(:authenticate).should be_nil
|
117
95
|
end
|
118
96
|
end
|
119
97
|
|
120
|
-
|
121
|
-
|
98
|
+
describe "#soap_input" do
|
99
|
+
it "should return nil" do
|
100
|
+
wsdl.soap_input(:authenticate).should be_nil
|
101
|
+
end
|
122
102
|
end
|
123
|
-
end
|
124
103
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
it "returns the namespace URI" do
|
129
|
-
@wsdl.namespace_uri.should == WSDLFixture.geotrust(:namespace_uri)
|
130
|
-
end
|
131
|
-
|
132
|
-
it "returns an Array of available SOAP actions" do
|
133
|
-
WSDLFixture.geotrust(:operations).keys.each do |soap_action|
|
134
|
-
@wsdl.soap_actions.should include(soap_action)
|
104
|
+
describe "#document" do
|
105
|
+
it "should raise an ArgumentError" do
|
106
|
+
lambda { wsdl.document }.should raise_error(ArgumentError)
|
135
107
|
end
|
136
108
|
end
|
137
|
-
|
138
|
-
it "returns a Hash of SOAP operations" do
|
139
|
-
@wsdl.operations.should == WSDLFixture.geotrust(:operations)
|
140
|
-
end
|
141
109
|
end
|
142
110
|
|
143
|
-
|
144
111
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Savon::WSDL::Parser do
|
4
|
+
|
5
|
+
context "with namespaced_actions.xml" do
|
6
|
+
let(:parser) { new_parser :namespaced_actions }
|
7
|
+
|
8
|
+
it "should know the target namespace" do
|
9
|
+
parser.namespace.should == "http://api.example.com/api/"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should know the SOAP endpoint" do
|
13
|
+
parser.endpoint.should == URI("https://api.example.com/api/api.asmx")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should know the available SOAP operations" do
|
17
|
+
parser.operations.should match_operations(
|
18
|
+
:get_api_key => { :input => "GetApiKey", :action => "http://api.example.com/api/User.GetApiKey" },
|
19
|
+
:delete_client => { :input => "DeleteClient", :action => "http://api.example.com/api/Client.Delete" },
|
20
|
+
:get_clients => { :input => "GetClients", :action => "http://api.example.com/api/User.GetClients" }
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "with no_namespace.xml" do
|
26
|
+
let(:parser) { new_parser :no_namespace }
|
27
|
+
|
28
|
+
it "should know the target namespace" do
|
29
|
+
parser.namespace.should == "urn:ActionWebService"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should know the SOAP endpoint" do
|
33
|
+
parser.endpoint.should == URI("http://example.com/api/api")
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should know the available SOAP operations" do
|
37
|
+
parser.operations.should match_operations(
|
38
|
+
:search_user => { :input => "SearchUser", :action => "/api/api/SearchUser" },
|
39
|
+
:get_user_login_by_id => { :input => "GetUserLoginById", :action => "/api/api/GetUserLoginById" },
|
40
|
+
:get_all_contacts => { :input => "GetAllContacts", :action => "/api/api/GetAllContacts" }
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "with geotrust.xml" do
|
46
|
+
let(:parser) { new_parser :geotrust }
|
47
|
+
|
48
|
+
it "should know the target namespace" do
|
49
|
+
parser.namespace.should == "http://api.geotrust.com/webtrust/query"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should know the SOAP endpoint" do
|
53
|
+
parser.endpoint.should == URI("https://test-api.geotrust.com/webtrust/query.jws")
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should know the available SOAP operations" do
|
57
|
+
parser.operations.should match_operations(
|
58
|
+
:get_quick_approver_list => { :input => "GetQuickApproverList", :action => "GetQuickApproverList" },
|
59
|
+
:hello => { :input => "hello", :action => "hello" }
|
60
|
+
)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
RSpec::Matchers.define :match_operations do |expected|
|
65
|
+
match do |actual|
|
66
|
+
actual.should have(expected.keys.size).items
|
67
|
+
actual.keys.should include(*expected.keys)
|
68
|
+
actual.each { |key, value| value.should == expected[key] }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def new_parser(fixture)
|
73
|
+
parser = Savon::WSDL::Parser.new
|
74
|
+
REXML::Document.parse_stream WSDLFixture.load(fixture), parser
|
75
|
+
parser
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
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: 62196263
|
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
|
+
- 2
|
12
|
+
version: 0.8.0.beta.2
|
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-
|
20
|
+
date: 2010-11-05 00:00:00 +01:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -169,6 +169,7 @@ files:
|
|
169
169
|
- spec/savon/soap/xml_spec.rb
|
170
170
|
- spec/savon/soap_spec.rb
|
171
171
|
- spec/savon/wsdl/document_spec.rb
|
172
|
+
- spec/savon/wsdl/parser_spec.rb
|
172
173
|
- spec/savon/wsdl/request_spec.rb
|
173
174
|
- spec/savon/wsse_spec.rb
|
174
175
|
- spec/spec_helper.rb
|