wash_out 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -0
- data/lib/wash_out/dispatcher.rb +10 -4
- data/lib/wash_out/param.rb +12 -6
- data/lib/wash_out/version.rb +1 -1
- data/spec/wash_out_spec.rb +44 -15
- metadata +12 -12
data/README.md
CHANGED
@@ -41,6 +41,7 @@ demonstrated.
|
|
41
41
|
class RumbasController < ApplicationController
|
42
42
|
include WashOut::SOAP
|
43
43
|
|
44
|
+
# Simple case
|
44
45
|
soap_action "integer_to_string",
|
45
46
|
:args => :integer,
|
46
47
|
:return => :string
|
@@ -55,6 +56,7 @@ class RumbasController < ApplicationController
|
|
55
56
|
render :soap => (params[:a] + params[:b])
|
56
57
|
end
|
57
58
|
|
59
|
+
# Complex structures
|
58
60
|
soap_action "AddCircle",
|
59
61
|
:args => { :circle => { :center => { :x => :integer,
|
60
62
|
:y => :integer },
|
@@ -71,6 +73,14 @@ class RumbasController < ApplicationController
|
|
71
73
|
render :soap => nil
|
72
74
|
end
|
73
75
|
|
76
|
+
# Arrays
|
77
|
+
soap_action "integers_to_boolean",
|
78
|
+
:args => { :data => [:integer] },
|
79
|
+
:return => [:boolean]
|
80
|
+
def integers_to_boolean
|
81
|
+
render :soap => params[:data].map{|x| x ? 1 : 0}
|
82
|
+
end
|
83
|
+
|
74
84
|
# You can use all Rails features like filtering, too. A SOAP controller
|
75
85
|
# is just like a normal controller with a special routing.
|
76
86
|
before_filter :dump_parameters
|
data/lib/wash_out/dispatcher.rb
CHANGED
@@ -7,7 +7,7 @@ module WashOut
|
|
7
7
|
module Dispatcher
|
8
8
|
# Default Type namespace
|
9
9
|
NAMESPACE = 'urn:WashOut'
|
10
|
-
|
10
|
+
|
11
11
|
# A SOAPError exception can be raised to return a correct SOAP error
|
12
12
|
# response.
|
13
13
|
class SOAPError < Exception; end
|
@@ -17,12 +17,18 @@ module WashOut
|
|
17
17
|
soap_action = request.env['wash_out.soap_action']
|
18
18
|
action_spec = self.class.soap_actions[soap_action]
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
# Do not interfere with project-space Nori setup
|
21
|
+
strip = Nori.strip_namespaces?
|
22
|
+
convert = Nori.convert_tags?
|
22
23
|
Nori.strip_namespaces = true
|
24
|
+
Nori.convert_tags_to { |tag| tag.snakecase.to_sym }
|
25
|
+
|
23
26
|
params = Nori.parse(request.body)
|
24
27
|
xml_data = params[:envelope][:body][soap_action.underscore.to_sym]
|
28
|
+
|
29
|
+
# Reset Nori setup to project-space
|
25
30
|
Nori.strip_namespaces = strip
|
31
|
+
Nori.convert_tags_to convert
|
26
32
|
|
27
33
|
@_params = HashWithIndifferentAccess.new
|
28
34
|
(xml_data || {}).map do |opt, value|
|
@@ -52,7 +58,7 @@ module WashOut
|
|
52
58
|
|
53
59
|
result = { 'value' => result } unless result.is_a? Hash
|
54
60
|
result = HashWithIndifferentAccess.new(result)
|
55
|
-
|
61
|
+
|
56
62
|
inject = lambda {|data, spec|
|
57
63
|
spec.each do |param|
|
58
64
|
if param.struct?
|
data/lib/wash_out/param.rb
CHANGED
@@ -31,7 +31,13 @@ module WashOut
|
|
31
31
|
data = Array(data) if @multiplied
|
32
32
|
|
33
33
|
if struct?
|
34
|
-
|
34
|
+
if @multiplied
|
35
|
+
data.map do |x|
|
36
|
+
map_struct(x) { |param, elem| param.load(elem) }
|
37
|
+
end
|
38
|
+
else
|
39
|
+
map_struct(data) { |param, elem| param.load(elem) }
|
40
|
+
end
|
35
41
|
else
|
36
42
|
operation = case type
|
37
43
|
when 'string'; :to_s
|
@@ -40,10 +46,10 @@ module WashOut
|
|
40
46
|
when 'boolean'; nil # Nori handles that for us
|
41
47
|
else raise RuntimeError, "Invalid WashOut simple type: #{type}"
|
42
48
|
end
|
43
|
-
|
49
|
+
|
44
50
|
if operation.nil?
|
45
51
|
data
|
46
|
-
elsif
|
52
|
+
elsif @multiplied
|
47
53
|
data.map{|x| x.send(operation)}
|
48
54
|
else
|
49
55
|
data.send(operation)
|
@@ -80,7 +86,7 @@ module WashOut
|
|
80
86
|
def self.parse_def(definition)
|
81
87
|
raise RuntimeError, "[] should not be used in your params. Use nil if you want to mark empty set." if definition == []
|
82
88
|
return [] if definition == nil
|
83
|
-
|
89
|
+
|
84
90
|
if [Array, Symbol].include?(definition.class)
|
85
91
|
definition = { :value => definition }
|
86
92
|
end
|
@@ -99,7 +105,7 @@ module WashOut
|
|
99
105
|
raise RuntimeError, "Wrong definition: #{type.inspect}"
|
100
106
|
end
|
101
107
|
end
|
102
|
-
|
108
|
+
|
103
109
|
def clone
|
104
110
|
copy = self.class.new(@name, @type.to_sym, @multiplied)
|
105
111
|
copy.map = @map.map{|x| x.clone}
|
@@ -124,7 +130,7 @@ module WashOut
|
|
124
130
|
# Raise an appropriate exception if a required datum is missing.
|
125
131
|
def check_if_missing(data)
|
126
132
|
if data.nil?
|
127
|
-
raise WashOut::Dispatcher::SOAPError, "Required SOAP parameter #{@name} is missing"
|
133
|
+
raise WashOut::Dispatcher::SOAPError, "Required SOAP parameter '#{@name}' is missing"
|
128
134
|
end
|
129
135
|
end
|
130
136
|
end
|
data/lib/wash_out/version.rb
CHANGED
data/spec/wash_out_spec.rb
CHANGED
@@ -34,7 +34,7 @@ describe WashOut do
|
|
34
34
|
:distance_from_o => Math.sqrt(circle[:center][:x] ** 2 + circle[:center][:y] ** 2) }
|
35
35
|
end
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
client = savon_instance
|
39
39
|
xml = Nori.parse client.wsdl.xml
|
40
40
|
|
@@ -124,7 +124,7 @@ describe WashOut do
|
|
124
124
|
|
125
125
|
it "should allow arbitrary action names" do
|
126
126
|
name = 'AnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything'
|
127
|
-
|
127
|
+
|
128
128
|
mock_controller do
|
129
129
|
soap_action name,
|
130
130
|
:args => nil, :return => :integer, :to => :answer
|
@@ -182,7 +182,7 @@ describe WashOut do
|
|
182
182
|
client.request(:error)
|
183
183
|
}.should raise_exception(Savon::SOAP::Fault)
|
184
184
|
end
|
185
|
-
|
185
|
+
|
186
186
|
it "should handle nested returns" do
|
187
187
|
mock_controller do
|
188
188
|
soap_action "gogogo",
|
@@ -204,10 +204,10 @@ describe WashOut do
|
|
204
204
|
}
|
205
205
|
end
|
206
206
|
end
|
207
|
-
|
207
|
+
|
208
208
|
savon_instance.request(:gogogo)[:gogogo_response].should == {:zoo=>"zoo", :boo=>{:moo=>"moo", :doo=>"doo", :"@xsi:type"=>"tns:boo"}}
|
209
209
|
end
|
210
|
-
|
210
|
+
|
211
211
|
it "should handle arrays" do
|
212
212
|
mock_controller do
|
213
213
|
soap_action "rumba",
|
@@ -220,29 +220,58 @@ describe WashOut do
|
|
220
220
|
render :soap => nil
|
221
221
|
end
|
222
222
|
end
|
223
|
-
|
223
|
+
|
224
224
|
savon_instance.request(:rumba) do
|
225
225
|
soap.body = {
|
226
226
|
:rumbas => [1, 2, 3]
|
227
227
|
}
|
228
228
|
end
|
229
229
|
end
|
230
|
-
|
230
|
+
|
231
|
+
it "should handle complex structures inside arrays" do
|
232
|
+
mock_controller do
|
233
|
+
soap_action "rumba",
|
234
|
+
:args => {
|
235
|
+
:rumbas => [ {
|
236
|
+
:zombies => :string,
|
237
|
+
:puppies => :string
|
238
|
+
} ]
|
239
|
+
},
|
240
|
+
:return => nil
|
241
|
+
def rumba
|
242
|
+
params.should == {
|
243
|
+
"rumbas" => [
|
244
|
+
{"zombies" => 'suck', "puppies" => 'rock'},
|
245
|
+
{"zombies" => 'slow', "puppies" => 'fast'}
|
246
|
+
]
|
247
|
+
}
|
248
|
+
render :soap => nil
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
savon_instance.request(:rumba) do
|
253
|
+
soap.body = {
|
254
|
+
:rumbas => [
|
255
|
+
{:zombies => 'suck', :puppies => 'rock'},
|
256
|
+
{:zombies => 'slow', :puppies => 'fast'}
|
257
|
+
]
|
258
|
+
}
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
231
262
|
it "should be able to return arrays" do
|
232
263
|
mock_controller do
|
233
264
|
soap_action "rumba",
|
234
265
|
:args => nil,
|
235
|
-
:return =>
|
236
|
-
:rumbas => [:integer]
|
237
|
-
}
|
266
|
+
:return => [:integer]
|
238
267
|
def rumba
|
239
|
-
render :soap =>
|
268
|
+
render :soap => [1, 2, 3]
|
240
269
|
end
|
241
270
|
end
|
242
|
-
|
243
|
-
savon_instance.request(:rumba).to_hash[:rumba_response].should == {:
|
271
|
+
|
272
|
+
savon_instance.request(:rumba).to_hash[:rumba_response].should == {:value => ["1", "2", "3"]}
|
244
273
|
end
|
245
|
-
|
274
|
+
|
246
275
|
it "should deprecate old syntax" do
|
247
276
|
# save rspec context check
|
248
277
|
raise_runtime_exception = raise_exception(RuntimeError)
|
@@ -258,5 +287,5 @@ describe WashOut do
|
|
258
287
|
end
|
259
288
|
end
|
260
289
|
end
|
261
|
-
|
290
|
+
|
262
291
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wash_out
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-02-02 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: nori
|
17
|
-
requirement: &
|
17
|
+
requirement: &70307076083660 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70307076083660
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rspec-rails
|
28
|
-
requirement: &
|
28
|
+
requirement: &70307076083140 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70307076083140
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: appraisal
|
39
|
-
requirement: &
|
39
|
+
requirement: &70307076082660 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *70307076082660
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: tzinfo
|
50
|
-
requirement: &
|
50
|
+
requirement: &70307076081960 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,10 +55,10 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *70307076081960
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: savon
|
61
|
-
requirement: &
|
61
|
+
requirement: &70307076081100 !ruby/object:Gem::Requirement
|
62
62
|
none: false
|
63
63
|
requirements:
|
64
64
|
- - ! '>='
|
@@ -66,7 +66,7 @@ dependencies:
|
|
66
66
|
version: '0'
|
67
67
|
type: :development
|
68
68
|
prerelease: false
|
69
|
-
version_requirements: *
|
69
|
+
version_requirements: *70307076081100
|
70
70
|
description: Dead simple Rails 3 SOAP server library
|
71
71
|
email: boris@roundlake.ru
|
72
72
|
executables: []
|