wash_out 0.2.0 → 0.2.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/Gemfile.lock +2 -1
- data/README.md +25 -8
- data/lib/wash_out/dispatcher.rb +23 -12
- data/lib/wash_out/version.rb +1 -1
- data/spec/wash_out_spec.rb +25 -0
- data/wash_out.gemspec +1 -0
- metadata +21 -10
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -6,7 +6,9 @@ Wash Out is a gem that greatly simplifies creation of SOAP service providers.
|
|
|
6
6
|
Installation
|
|
7
7
|
------------
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
In your Gemfile, add this line:
|
|
10
|
+
|
|
11
|
+
gem 'wash_out'
|
|
10
12
|
|
|
11
13
|
Usage
|
|
12
14
|
-----
|
|
@@ -16,7 +18,7 @@ action corresponds to a certain controller method; this mapping, as well as the
|
|
|
16
18
|
by [soap_action][] method. Check the method documentation for complete info; here,
|
|
17
19
|
only a few examples will be demonstrated.
|
|
18
20
|
|
|
19
|
-
[soap_action]: #
|
|
21
|
+
[soap_action]: http://rubydoc.info/gems/wash_out/0.2.1/WashOut/SOAP/ClassMethods#soap_action-instance_method
|
|
20
22
|
|
|
21
23
|
```ruby
|
|
22
24
|
# app/controllers/api_controller.rb
|
|
@@ -26,15 +28,15 @@ class ApiController < ApplicationController
|
|
|
26
28
|
soap_action "integer_to_string",
|
|
27
29
|
:args => :integer,
|
|
28
30
|
:return => :string
|
|
29
|
-
def integer_to_string
|
|
30
|
-
render :soap => value.to_s
|
|
31
|
+
def integer_to_string
|
|
32
|
+
render :soap => params[:value].to_s
|
|
31
33
|
end
|
|
32
34
|
|
|
33
35
|
soap_action "concat",
|
|
34
|
-
:args => { :a => :string, :b => :string }
|
|
36
|
+
:args => { :a => :string, :b => :string },
|
|
35
37
|
:return => :string
|
|
36
|
-
def concat
|
|
37
|
-
render :soap => (a + b)
|
|
38
|
+
def concat
|
|
39
|
+
render :soap => (params[:a] + params[:b])
|
|
38
40
|
end
|
|
39
41
|
|
|
40
42
|
soap_action "AddCircle",
|
|
@@ -43,7 +45,9 @@ class ApiController < ApplicationController
|
|
|
43
45
|
:radius => :float } },
|
|
44
46
|
:return => [],
|
|
45
47
|
:to => :add_circle
|
|
46
|
-
def add_circle
|
|
48
|
+
def add_circle
|
|
49
|
+
circle = params[:circle]
|
|
50
|
+
|
|
47
51
|
raise SOAPError, "radius is too small" if circle[:radius] < 3.0
|
|
48
52
|
|
|
49
53
|
Circle.new(circle[:center][:x], circle[:center][:y], circle[:radius])
|
|
@@ -60,6 +64,19 @@ HelloWorld::Application.routes.draw do
|
|
|
60
64
|
end
|
|
61
65
|
```
|
|
62
66
|
|
|
67
|
+
In such a setup, the generated WSDL may be queried at path `/api/wsdl`. So, with a
|
|
68
|
+
gem like Savon, a request can be done using this path:
|
|
69
|
+
|
|
70
|
+
```ruby
|
|
71
|
+
require 'savon'
|
|
72
|
+
|
|
73
|
+
client = Savon::Client.new("http://localhost:3000/api/wsdl")
|
|
74
|
+
client.wsdl.soap_actions # => [:integer_to_string, :concat]
|
|
75
|
+
client.request(:concat) do
|
|
76
|
+
soap.body = { :a => "123", :b => "abc" }
|
|
77
|
+
end[:value] # => "123abc"
|
|
78
|
+
```
|
|
79
|
+
|
|
63
80
|
License
|
|
64
81
|
-------
|
|
65
82
|
|
data/lib/wash_out/dispatcher.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'nori'
|
|
2
|
+
|
|
1
3
|
module WashOut
|
|
2
4
|
# The WashOut::Dispatcher module should be included in a controller acting
|
|
3
5
|
# as a SOAP endpoint. It includes actions for generating WSDL and handling
|
|
@@ -21,19 +23,20 @@ module WashOut
|
|
|
21
23
|
def _action
|
|
22
24
|
map = self.class.soap_actions
|
|
23
25
|
method = request.env['HTTP_SOAPACTION'].gsub(/^\"(.*)\"$/, '\1')
|
|
24
|
-
@_current = map[method]
|
|
26
|
+
@_current = map[method.force_encoding('UTF-8')]
|
|
25
27
|
|
|
26
|
-
raise
|
|
28
|
+
raise SOAPError, "Method #{method} does not exists" unless @_current
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
params = Nori.parse(request.body)
|
|
31
|
+
xml_data = params[:envelope][:body][method.downcase.to_sym]
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
param = @_current[:in].find { |param| param.name == opt }
|
|
33
|
+
@_params = HashWithIndifferentAccess.new
|
|
34
|
+
(xml_data || {}).map do |opt, value|
|
|
35
|
+
param = @_current[:in].find { |param| param.name.underscore.to_sym == opt }
|
|
33
36
|
raise SOAPError, "unknown parameter #{opt}" unless param
|
|
34
|
-
|
|
37
|
+
|
|
38
|
+
@_params[param.name] = param.load(value)
|
|
35
39
|
end
|
|
36
|
-
@_params.merge!(Hash[*params.flatten])
|
|
37
40
|
|
|
38
41
|
send(@_current[:to])
|
|
39
42
|
end
|
|
@@ -49,15 +52,23 @@ module WashOut
|
|
|
49
52
|
:locals => { :result => result }
|
|
50
53
|
end
|
|
51
54
|
|
|
55
|
+
# Render a SOAP error response.
|
|
56
|
+
#
|
|
57
|
+
# Rails do not support sequental rescue_from handling, that is, rescuing an
|
|
58
|
+
# exception from a rescue_from handler. Hence this function is a public API.
|
|
59
|
+
def render_soap_error(message)
|
|
60
|
+
render :template => 'wash_with_soap/error', :status => 500,
|
|
61
|
+
:locals => { :error_message => message }
|
|
62
|
+
end
|
|
63
|
+
|
|
52
64
|
private
|
|
53
65
|
|
|
54
66
|
def self.included(controller)
|
|
55
|
-
controller.send :rescue_from, SOAPError, :with => :
|
|
67
|
+
controller.send :rescue_from, SOAPError, :with => :_render_soap_exception
|
|
56
68
|
end
|
|
57
69
|
|
|
58
|
-
def
|
|
59
|
-
|
|
60
|
-
:locals => { :error_message => error.message }
|
|
70
|
+
def _render_soap_exception(error)
|
|
71
|
+
render_soap_error(error.message)
|
|
61
72
|
end
|
|
62
73
|
end
|
|
63
74
|
end
|
data/lib/wash_out/version.rb
CHANGED
data/spec/wash_out_spec.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
#encoding:utf-8
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
|
|
3
5
|
describe WashOut do
|
|
@@ -95,4 +97,27 @@ describe WashOut do
|
|
|
95
97
|
end
|
|
96
98
|
}.should raise_exception(Savon::SOAP::Fault)
|
|
97
99
|
end
|
|
100
|
+
|
|
101
|
+
it "should report a SOAP error if method does not exists" do
|
|
102
|
+
mock_controller{}.use!
|
|
103
|
+
|
|
104
|
+
client = savon_instance
|
|
105
|
+
lambda {
|
|
106
|
+
client.request(:nonexistent)
|
|
107
|
+
}.should raise_exception(Savon::SOAP::Fault)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it "should be possible to explicitly render a SOAP error" do
|
|
111
|
+
mock_controller do
|
|
112
|
+
soap_action "error", :args => [], :return => []
|
|
113
|
+
def error
|
|
114
|
+
render_soap_error "a message"
|
|
115
|
+
end
|
|
116
|
+
end.use!
|
|
117
|
+
|
|
118
|
+
client = savon_instance
|
|
119
|
+
lambda {
|
|
120
|
+
client.request(:error)
|
|
121
|
+
}.should raise_exception(Savon::SOAP::Fault)
|
|
122
|
+
end
|
|
98
123
|
end
|
data/wash_out.gemspec
CHANGED
|
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
|
|
|
13
13
|
s.files = `git ls-files`.split("\n")
|
|
14
14
|
s.require_paths = ["lib"]
|
|
15
15
|
|
|
16
|
+
s.add_dependency("nori")
|
|
16
17
|
s.add_development_dependency("rspec-rails")
|
|
17
18
|
s.add_development_dependency("appraisal")
|
|
18
19
|
s.add_development_dependency("tzinfo")
|
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.1
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -10,11 +10,22 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2011-
|
|
13
|
+
date: 2011-12-09 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: nori
|
|
17
|
+
requirement: &70328753506960 !ruby/object:Gem::Requirement
|
|
18
|
+
none: false
|
|
19
|
+
requirements:
|
|
20
|
+
- - ! '>='
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: '0'
|
|
23
|
+
type: :runtime
|
|
24
|
+
prerelease: false
|
|
25
|
+
version_requirements: *70328753506960
|
|
15
26
|
- !ruby/object:Gem::Dependency
|
|
16
27
|
name: rspec-rails
|
|
17
|
-
requirement: &
|
|
28
|
+
requirement: &70328753506480 !ruby/object:Gem::Requirement
|
|
18
29
|
none: false
|
|
19
30
|
requirements:
|
|
20
31
|
- - ! '>='
|
|
@@ -22,10 +33,10 @@ dependencies:
|
|
|
22
33
|
version: '0'
|
|
23
34
|
type: :development
|
|
24
35
|
prerelease: false
|
|
25
|
-
version_requirements: *
|
|
36
|
+
version_requirements: *70328753506480
|
|
26
37
|
- !ruby/object:Gem::Dependency
|
|
27
38
|
name: appraisal
|
|
28
|
-
requirement: &
|
|
39
|
+
requirement: &70328753506040 !ruby/object:Gem::Requirement
|
|
29
40
|
none: false
|
|
30
41
|
requirements:
|
|
31
42
|
- - ! '>='
|
|
@@ -33,10 +44,10 @@ dependencies:
|
|
|
33
44
|
version: '0'
|
|
34
45
|
type: :development
|
|
35
46
|
prerelease: false
|
|
36
|
-
version_requirements: *
|
|
47
|
+
version_requirements: *70328753506040
|
|
37
48
|
- !ruby/object:Gem::Dependency
|
|
38
49
|
name: tzinfo
|
|
39
|
-
requirement: &
|
|
50
|
+
requirement: &70328753505480 !ruby/object:Gem::Requirement
|
|
40
51
|
none: false
|
|
41
52
|
requirements:
|
|
42
53
|
- - ! '>='
|
|
@@ -44,10 +55,10 @@ dependencies:
|
|
|
44
55
|
version: '0'
|
|
45
56
|
type: :development
|
|
46
57
|
prerelease: false
|
|
47
|
-
version_requirements: *
|
|
58
|
+
version_requirements: *70328753505480
|
|
48
59
|
- !ruby/object:Gem::Dependency
|
|
49
60
|
name: savon
|
|
50
|
-
requirement: &
|
|
61
|
+
requirement: &70328753504960 !ruby/object:Gem::Requirement
|
|
51
62
|
none: false
|
|
52
63
|
requirements:
|
|
53
64
|
- - ! '>='
|
|
@@ -55,7 +66,7 @@ dependencies:
|
|
|
55
66
|
version: '0'
|
|
56
67
|
type: :development
|
|
57
68
|
prerelease: false
|
|
58
|
-
version_requirements: *
|
|
69
|
+
version_requirements: *70328753504960
|
|
59
70
|
description: Dead simple Rails 3 SOAP server library
|
|
60
71
|
email: boris@roundlake.ru
|
|
61
72
|
executables: []
|