wash_out 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +2 -2
- data/lib/wash_out/param.rb +34 -14
- data/lib/wash_out/router.rb +4 -1
- data/lib/wash_out/version.rb +1 -1
- data/spec/wash_out_spec.rb +22 -0
- metadata +18 -12
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -18,7 +18,7 @@ action corresponds to a certain controller method; this mapping, as well as the
|
|
18
18
|
by [soap_action][] method. Check the method documentation for complete info; here, only a few examples will be
|
19
19
|
demonstrated.
|
20
20
|
|
21
|
-
[soap_action]: http://rubydoc.info/gems/wash_out/
|
21
|
+
[soap_action]: http://rubydoc.info/gems/wash_out/WashOut/SOAP/ClassMethods#soap_action-instance_method
|
22
22
|
|
23
23
|
```ruby
|
24
24
|
# app/controllers/api_controller.rb
|
@@ -42,7 +42,7 @@ class ApiController < ApplicationController
|
|
42
42
|
soap_action "AddCircle",
|
43
43
|
:args => { :circle => { :center => { :x => :integer,
|
44
44
|
:y => :integer },
|
45
|
-
:radius => :
|
45
|
+
:radius => :double } },
|
46
46
|
:return => [],
|
47
47
|
:to => :add_circle
|
48
48
|
def add_circle
|
data/lib/wash_out/param.rb
CHANGED
@@ -25,11 +25,10 @@ module WashOut
|
|
25
25
|
# Converts a generic externally derived Ruby value, such as String or
|
26
26
|
# Hash, to a native Ruby object according to the definition of this type.
|
27
27
|
def load(data)
|
28
|
+
check_if_missing(data)
|
29
|
+
|
28
30
|
if struct?
|
29
|
-
data
|
30
|
-
@map.map do |param|
|
31
|
-
param.load(data[param.name])
|
32
|
-
end
|
31
|
+
map_struct(data) { |param, elem| param.load(elem) }
|
33
32
|
else
|
34
33
|
case type
|
35
34
|
when 'string'; data.to_s
|
@@ -43,11 +42,10 @@ module WashOut
|
|
43
42
|
|
44
43
|
# The opposite of #load.
|
45
44
|
def store(data)
|
45
|
+
check_if_missing(data)
|
46
|
+
|
46
47
|
if struct?
|
47
|
-
data
|
48
|
-
@map.map do |param|
|
49
|
-
param.store(data[param.name])
|
50
|
-
end
|
48
|
+
map_struct(data) { |param, elem| param.store(elem) }
|
51
49
|
else
|
52
50
|
data.to_s
|
53
51
|
end
|
@@ -66,12 +64,12 @@ module WashOut
|
|
66
64
|
# Parses a +definition+. The format of the definition is best described
|
67
65
|
# by the following BNF-like grammar.
|
68
66
|
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
67
|
+
# simple_type := :string | :integer | :double | :boolean
|
68
|
+
# nested_type := type_hash | simple_type | WashOut::Param instance
|
69
|
+
# type_hash := { :parameter_name => nested_type, ... }
|
70
|
+
# definition := [ WashOut::Param, ... ] |
|
71
|
+
# type_hash |
|
72
|
+
# simple_type
|
75
73
|
#
|
76
74
|
# If a simple type is passed as the +definition+, a single Param is returned
|
77
75
|
# with the +name+ set to "value".
|
@@ -94,5 +92,27 @@ module WashOut
|
|
94
92
|
definition.to_a
|
95
93
|
end
|
96
94
|
end
|
95
|
+
|
96
|
+
private
|
97
|
+
|
98
|
+
# Used to load or store an entire structure.
|
99
|
+
def map_struct(data)
|
100
|
+
data = data.with_indifferent_access
|
101
|
+
struct = {}.with_indifferent_access
|
102
|
+
|
103
|
+
# RUBY18 Enumerable#each_with_object is better, but 1.9 only.
|
104
|
+
@map.map do |param|
|
105
|
+
struct[param.name] = yield param, data[param.name]
|
106
|
+
end
|
107
|
+
|
108
|
+
struct
|
109
|
+
end
|
110
|
+
|
111
|
+
# Raise an appropriate exception if a required datum is missing.
|
112
|
+
def check_if_missing(data)
|
113
|
+
if data.nil?
|
114
|
+
raise WashOut::Dispatcher::SOAPError, "Required SOAP parameter #{@name} is missing"
|
115
|
+
end
|
116
|
+
end
|
97
117
|
end
|
98
118
|
end
|
data/lib/wash_out/router.rb
CHANGED
@@ -10,7 +10,10 @@ module WashOut
|
|
10
10
|
controller = @controller_name.constantize
|
11
11
|
|
12
12
|
soap_action = env['HTTP_SOAPACTION']
|
13
|
-
|
13
|
+
|
14
|
+
# RUBY18 1.8 does not have force_encoding.
|
15
|
+
soap_action.force_encoding('UTF-8') if soap_action.respond_to? :force_encoding
|
16
|
+
|
14
17
|
soap_action.gsub!(/^\"(.*)\"$/, '\1')
|
15
18
|
|
16
19
|
env['wash_out.soap_action'] = soap_action
|
data/lib/wash_out/version.rb
CHANGED
data/spec/wash_out_spec.rb
CHANGED
@@ -66,6 +66,28 @@ describe WashOut do
|
|
66
66
|
end.to_hash[:value].should == '420k'
|
67
67
|
end
|
68
68
|
|
69
|
+
it "should understand nested parameter specifications" do
|
70
|
+
mock_controller do
|
71
|
+
soap_action "getArea", :args => { :circle => { :center => { :x => :integer,
|
72
|
+
:y => :integer },
|
73
|
+
:radius => :double } },
|
74
|
+
:return => { :area => :double,
|
75
|
+
:distance_from_o => :double },
|
76
|
+
:to => :get_area
|
77
|
+
def get_area
|
78
|
+
circle = params[:circle]
|
79
|
+
render :soap => { :area => Math::PI * circle[:radius] ** 2,
|
80
|
+
:distance_from_o => Math.sqrt(circle[:center][:x] ** 2 + circle[:center][:y] ** 2) }
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
client = savon_instance
|
85
|
+
client.request(:get_area) do
|
86
|
+
soap.body = { :circle => { :center => { :x => 3, :y => 4 },
|
87
|
+
:radius => 5 } }
|
88
|
+
end.to_hash.should == ({ :area => (Math::PI * 25).to_s, :distance_from_o => (5.0).to_s })
|
89
|
+
end
|
90
|
+
|
69
91
|
it "should allow arbitrary action names" do
|
70
92
|
mock_controller do
|
71
93
|
soap_action "AnswerToTheUltimateQuestionOfLifeTheUniverseAndEverything",
|
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.2.
|
4
|
+
version: 0.2.3
|
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: 2011-12-
|
13
|
+
date: 2011-12-20 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: nori
|
17
|
-
requirement: &
|
17
|
+
requirement: &73419490 !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: *73419490
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rspec-rails
|
28
|
-
requirement: &
|
28
|
+
requirement: &73418980 !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: *73418980
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: appraisal
|
39
|
-
requirement: &
|
39
|
+
requirement: &73418630 !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: *73418630
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: tzinfo
|
50
|
-
requirement: &
|
50
|
+
requirement: &73417730 !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: *73417730
|
59
59
|
- !ruby/object:Gem::Dependency
|
60
60
|
name: savon
|
61
|
-
requirement: &
|
61
|
+
requirement: &73415050 !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: *73415050
|
70
70
|
description: Dead simple Rails 3 SOAP server library
|
71
71
|
email: boris@roundlake.ru
|
72
72
|
executables: []
|
@@ -134,12 +134,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
134
134
|
- - ! '>='
|
135
135
|
- !ruby/object:Gem::Version
|
136
136
|
version: '0'
|
137
|
+
segments:
|
138
|
+
- 0
|
139
|
+
hash: -441958353
|
137
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
141
|
none: false
|
139
142
|
requirements:
|
140
143
|
- - ! '>='
|
141
144
|
- !ruby/object:Gem::Version
|
142
145
|
version: '0'
|
146
|
+
segments:
|
147
|
+
- 0
|
148
|
+
hash: -441958353
|
143
149
|
requirements: []
|
144
150
|
rubyforge_project:
|
145
151
|
rubygems_version: 1.8.10
|