savon_model 0.3.1 → 0.4.0
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/lib/savon/model.rb +61 -27
- data/savon_model.gemspec +3 -2
- data/spec/savon/model_spec.rb +70 -2
- metadata +29 -18
- data/autotest/discover.rb +0 -1
data/lib/savon/model.rb
CHANGED
@@ -7,52 +7,91 @@ module Savon
|
|
7
7
|
# Model for SOAP service oriented applications.
|
8
8
|
module Model
|
9
9
|
|
10
|
-
VERSION = "0.
|
10
|
+
VERSION = "0.4.0"
|
11
11
|
|
12
|
-
|
12
|
+
def self.handle_response=(recipe)
|
13
|
+
@handle_response = recipe
|
14
|
+
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
@client ||= Savon::Client.new &block
|
18
|
-
end
|
16
|
+
def self.handle_response
|
17
|
+
@handle_response
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
module ClassMethods
|
21
|
+
|
22
|
+
def self.extend_object(base)
|
23
|
+
super
|
24
|
+
base.init_savon_model
|
23
25
|
end
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
def init_savon_model
|
28
|
+
class_action_module
|
29
|
+
instance_action_module
|
28
30
|
end
|
29
31
|
|
30
32
|
# Accepts one or more SOAP actions and generates both class and instance methods named
|
31
33
|
# after the given actions. Each generated method accepts an optional SOAP body Hash and
|
32
34
|
# a block to be passed to <tt>Savon::Client#request</tt> and executes a SOAP request.
|
33
|
-
def actions(*
|
34
|
-
|
35
|
-
define_class_action
|
36
|
-
define_instance_action
|
35
|
+
def actions(*actions)
|
36
|
+
actions.each do |action|
|
37
|
+
define_class_action action
|
38
|
+
define_instance_action action
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
40
42
|
private
|
41
43
|
|
42
44
|
def define_class_action(action)
|
43
|
-
|
45
|
+
class_action_module.module_eval <<-CODE
|
44
46
|
def #{action.to_s.snakecase}(body = nil, &block)
|
45
|
-
client.request :wsdl, #{action.inspect}, :body => body, &block
|
47
|
+
response = client.request :wsdl, #{action.inspect}, :body => body, &block
|
48
|
+
Savon::Model.handle_response ? Savon::Model.handle_response.call(response) : response
|
46
49
|
end
|
47
|
-
|
50
|
+
CODE
|
48
51
|
end
|
49
52
|
|
50
53
|
def define_instance_action(action)
|
51
|
-
|
54
|
+
instance_action_module.module_eval <<-CODE
|
52
55
|
def #{action.to_s.snakecase}(body = nil, &block)
|
53
56
|
self.class.#{action.to_s.snakecase} body, &block
|
54
57
|
end
|
55
|
-
|
58
|
+
CODE
|
59
|
+
end
|
60
|
+
|
61
|
+
def class_action_module
|
62
|
+
@class_action_module ||= Module.new do
|
63
|
+
|
64
|
+
def client(&block)
|
65
|
+
@client ||= Savon::Client.new &block
|
66
|
+
end
|
67
|
+
|
68
|
+
def endpoint(uri)
|
69
|
+
client.wsdl.endpoint = uri
|
70
|
+
end
|
71
|
+
|
72
|
+
def namespace(uri)
|
73
|
+
client.wsdl.namespace = uri
|
74
|
+
end
|
75
|
+
|
76
|
+
end.tap { |mod| extend mod }
|
77
|
+
end
|
78
|
+
|
79
|
+
def instance_action_module
|
80
|
+
@instance_action_module ||= Module.new do
|
81
|
+
|
82
|
+
def client(&block)
|
83
|
+
self.class.client &block
|
84
|
+
end
|
85
|
+
|
86
|
+
def endpoint(uri)
|
87
|
+
self.class.endpoint uri
|
88
|
+
end
|
89
|
+
|
90
|
+
def namespace(uri)
|
91
|
+
self.class.namespace uri
|
92
|
+
end
|
93
|
+
|
94
|
+
end.tap { |mod| include mod }
|
56
95
|
end
|
57
96
|
|
58
97
|
end
|
@@ -61,10 +100,5 @@ module Savon
|
|
61
100
|
base.extend ClassMethods
|
62
101
|
end
|
63
102
|
|
64
|
-
# Returns a memoized <tt>Savon::Client</tt> instance.
|
65
|
-
def client
|
66
|
-
self.class.client
|
67
|
-
end
|
68
|
-
|
69
103
|
end
|
70
104
|
end
|
data/savon_model.gemspec
CHANGED
@@ -14,9 +14,10 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.rubyforge_project = s.name
|
16
16
|
|
17
|
-
s.add_dependency "savon", "~> 0.8.
|
17
|
+
s.add_dependency "savon", "~> 0.8.2"
|
18
18
|
|
19
|
-
s.add_development_dependency "rspec", "~> 2.
|
19
|
+
s.add_development_dependency "rspec", "~> 2.4.0"
|
20
|
+
s.add_development_dependency "autotest"
|
20
21
|
s.add_development_dependency "mocha", "~> 0.9.8"
|
21
22
|
|
22
23
|
s.files = `git ls-files`.split("\n")
|
data/spec/savon/model_spec.rb
CHANGED
@@ -2,8 +2,17 @@ require "spec_helper"
|
|
2
2
|
require "savon/model"
|
3
3
|
|
4
4
|
describe Savon::Model do
|
5
|
-
let
|
6
|
-
|
5
|
+
let(:model) { Class.new { include Savon::Model } }
|
6
|
+
|
7
|
+
describe ".handle_response" do
|
8
|
+
before(:all) { model.actions :get_user, "GetAllUsers" }
|
9
|
+
|
10
|
+
it "should be used for pre-processing SOAP responses" do
|
11
|
+
Savon::Model.handle_response = lambda { |response| response }
|
12
|
+
|
13
|
+
model.client.stubs(:request).returns("response")
|
14
|
+
model.get_user.should == "response"
|
15
|
+
end
|
7
16
|
end
|
8
17
|
|
9
18
|
describe ".client" do
|
@@ -65,4 +74,63 @@ describe Savon::Model do
|
|
65
74
|
end
|
66
75
|
end
|
67
76
|
|
77
|
+
describe "#endpoint" do
|
78
|
+
it "should delegate to .endpoint" do
|
79
|
+
model.expects(:endpoint).with("http://example.com")
|
80
|
+
model.new.endpoint "http://example.com"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe "#namespace" do
|
85
|
+
it "should delegate to .namespace" do
|
86
|
+
model.expects(:namespace).with("http://v1.example.com")
|
87
|
+
model.new.namespace "http://v1.example.com"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "overwriting action methods" do
|
92
|
+
context "(class-level)" do
|
93
|
+
let :supermodel do
|
94
|
+
supermodel = model.dup
|
95
|
+
supermodel.actions :get_user
|
96
|
+
|
97
|
+
def supermodel.get_user(body = nil, &block)
|
98
|
+
p "super"
|
99
|
+
super
|
100
|
+
end
|
101
|
+
|
102
|
+
supermodel
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should be possible" do
|
106
|
+
supermodel.client.expects(:request).with(:wsdl, :get_user, :body => { :id => 1 })
|
107
|
+
supermodel.expects(:p).with("super") # stupid, but works
|
108
|
+
|
109
|
+
supermodel.get_user :id => 1
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "(instance-level)" do
|
114
|
+
let :supermodel do
|
115
|
+
supermodel = model.dup
|
116
|
+
supermodel.actions :get_user
|
117
|
+
supermodel = supermodel.new
|
118
|
+
|
119
|
+
def supermodel.get_user(body = nil, &block)
|
120
|
+
p "super"
|
121
|
+
super
|
122
|
+
end
|
123
|
+
|
124
|
+
supermodel
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should be possible" do
|
128
|
+
supermodel.client.expects(:request).with(:wsdl, :get_user, :body => { :id => 1 })
|
129
|
+
supermodel.expects(:p).with("super") # stupid, but works
|
130
|
+
|
131
|
+
supermodel.get_user :id => 1
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
68
136
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: savon_model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 15
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel Harrington
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2011-02-17 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -26,14 +26,12 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 59
|
30
30
|
segments:
|
31
31
|
- 0
|
32
32
|
- 8
|
33
|
-
-
|
34
|
-
|
35
|
-
- 3
|
36
|
-
version: 0.8.0.beta.3
|
33
|
+
- 2
|
34
|
+
version: 0.8.2
|
37
35
|
type: :runtime
|
38
36
|
version_requirements: *id001
|
39
37
|
- !ruby/object:Gem::Dependency
|
@@ -44,18 +42,32 @@ dependencies:
|
|
44
42
|
requirements:
|
45
43
|
- - ~>
|
46
44
|
- !ruby/object:Gem::Version
|
47
|
-
hash:
|
45
|
+
hash: 31
|
48
46
|
segments:
|
49
47
|
- 2
|
48
|
+
- 4
|
50
49
|
- 0
|
51
|
-
|
52
|
-
version: 2.0.0
|
50
|
+
version: 2.4.0
|
53
51
|
type: :development
|
54
52
|
version_requirements: *id002
|
55
53
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
54
|
+
name: autotest
|
57
55
|
prerelease: false
|
58
56
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 3
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
version: "0"
|
65
|
+
type: :development
|
66
|
+
version_requirements: *id003
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: mocha
|
69
|
+
prerelease: false
|
70
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
59
71
|
none: false
|
60
72
|
requirements:
|
61
73
|
- - ~>
|
@@ -67,7 +79,7 @@ dependencies:
|
|
67
79
|
- 8
|
68
80
|
version: 0.9.8
|
69
81
|
type: :development
|
70
|
-
version_requirements: *
|
82
|
+
version_requirements: *id004
|
71
83
|
description: Model for SOAP service oriented applications.
|
72
84
|
email: me@rubiii.com
|
73
85
|
executables: []
|
@@ -83,7 +95,6 @@ files:
|
|
83
95
|
- LICENSE
|
84
96
|
- README.md
|
85
97
|
- Rakefile
|
86
|
-
- autotest/discover.rb
|
87
98
|
- lib/savon/model.rb
|
88
99
|
- lib/savon_model.rb
|
89
100
|
- savon_model.gemspec
|
@@ -119,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
130
|
requirements: []
|
120
131
|
|
121
132
|
rubyforge_project: savon_model
|
122
|
-
rubygems_version: 1.
|
133
|
+
rubygems_version: 1.4.1
|
123
134
|
signing_key:
|
124
135
|
specification_version: 3
|
125
136
|
summary: SOAP model
|
data/autotest/discover.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Autotest.add_discovery { "rspec2" }
|