savon_model 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/Gemfile.lock +2 -2
- data/lib/savon/ext/response.rb +2 -1
- data/lib/savon/model.rb +19 -5
- data/savon_model.gemspec +1 -1
- data/spec/savon/model_spec.rb +6 -1
- metadata +8 -7
data/.gitignore
ADDED
data/Gemfile.lock
CHANGED
@@ -24,7 +24,7 @@ GEM
|
|
24
24
|
rspec-mocks (2.0.1)
|
25
25
|
rspec-core (~> 2.0.1)
|
26
26
|
rspec-expectations (~> 2.0.1)
|
27
|
-
savon (0.8.0.
|
27
|
+
savon (0.8.0.beta.1)
|
28
28
|
builder (~> 2.1.2)
|
29
29
|
crack (~> 0.1.8)
|
30
30
|
httpi (>= 0.6.0)
|
@@ -35,5 +35,5 @@ PLATFORMS
|
|
35
35
|
DEPENDENCIES
|
36
36
|
mocha (~> 0.9.8)
|
37
37
|
rspec (~> 2.0.0)
|
38
|
-
savon (~> 0.8.0.
|
38
|
+
savon (~> 0.8.0.beta.1)
|
39
39
|
savon_model!
|
data/lib/savon/ext/response.rb
CHANGED
@@ -5,7 +5,7 @@ module Savon
|
|
5
5
|
module SOAP
|
6
6
|
class Response
|
7
7
|
|
8
|
-
# Returns the
|
8
|
+
# Returns the original result of <tt>Savon::SOAP::Response#to_hash</tt>.
|
9
9
|
def new_hash
|
10
10
|
@new_hash ||= response_pattern original_hash
|
11
11
|
end
|
@@ -13,6 +13,7 @@ module Savon
|
|
13
13
|
alias_method :original_hash, :to_hash
|
14
14
|
alias_method :to_hash, :new_hash
|
15
15
|
|
16
|
+
# Returns the response Hash as an Array.
|
16
17
|
def to_array
|
17
18
|
@array ||= begin
|
18
19
|
array = to_hash.kind_of?(Array) ? to_hash : [to_hash]
|
data/lib/savon/model.rb
CHANGED
@@ -2,34 +2,47 @@ require "savon"
|
|
2
2
|
require "savon/ext/response"
|
3
3
|
|
4
4
|
module Savon
|
5
|
+
|
6
|
+
# = Savon::Model
|
7
|
+
#
|
8
|
+
# Model for SOAP service oriented applications.
|
5
9
|
module Model
|
6
10
|
|
7
|
-
VERSION = "0.
|
11
|
+
VERSION = "0.2.0"
|
8
12
|
|
9
13
|
class << self
|
10
14
|
|
15
|
+
# Returns the response pattern to apply.
|
11
16
|
def response_pattern
|
12
17
|
@response_pattern ||= []
|
13
18
|
end
|
14
19
|
|
20
|
+
# Sets the response pattern. This is required to be an Array of Regexps or Symbols.
|
15
21
|
attr_writer :response_pattern
|
16
22
|
|
17
23
|
end
|
18
24
|
|
19
25
|
module ClassMethods
|
20
26
|
|
27
|
+
# Returns a memoized <tt>Savon::Client</tt> instance. Accepts a block and passes it
|
28
|
+
# to <tt>Savon::Client.new</tt> when called for the first time.
|
21
29
|
def client(&block)
|
22
30
|
@@client ||= Savon::Client.new &block
|
23
31
|
end
|
24
32
|
|
33
|
+
# Sets the SOAP endpoint.
|
25
34
|
def endpoint(uri)
|
26
35
|
client.wsdl.endpoint = uri
|
27
36
|
end
|
28
37
|
|
38
|
+
# Sets the target namespace.
|
29
39
|
def namespace(uri)
|
30
40
|
client.wsdl.namespace = uri
|
31
41
|
end
|
32
42
|
|
43
|
+
# Accepts one or more SOAP actions and generates both class and instance methods named
|
44
|
+
# after the given actions. Each generated method accepts an optional SOAP body Hash and
|
45
|
+
# a block to be passed to <tt>Savon::Client#request</tt> and executes a SOAP request.
|
33
46
|
def actions(*args)
|
34
47
|
args.each do |arg|
|
35
48
|
define_class_action arg
|
@@ -41,16 +54,16 @@ module Savon
|
|
41
54
|
|
42
55
|
def define_class_action(action)
|
43
56
|
instance_eval %Q{
|
44
|
-
def #{action}(body = nil, &block)
|
45
|
-
client.request :wsdl,
|
57
|
+
def #{action.to_s.snakecase}(body = nil, &block)
|
58
|
+
client.request :wsdl, #{action.inspect}, :body => body, &block
|
46
59
|
end
|
47
60
|
}
|
48
61
|
end
|
49
62
|
|
50
63
|
def define_instance_action(action)
|
51
64
|
class_eval %Q{
|
52
|
-
def #{action}(body = nil, &block)
|
53
|
-
self.class.#{action} body, &block
|
65
|
+
def #{action.to_s.snakecase}(body = nil, &block)
|
66
|
+
self.class.#{action.to_s.snakecase} body, &block
|
54
67
|
end
|
55
68
|
}
|
56
69
|
end
|
@@ -61,6 +74,7 @@ module Savon
|
|
61
74
|
base.extend ClassMethods
|
62
75
|
end
|
63
76
|
|
77
|
+
# Returns a memoized <tt>Savon::Client</tt> instance.
|
64
78
|
def client
|
65
79
|
self.class.client
|
66
80
|
end
|
data/savon_model.gemspec
CHANGED
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.rubyforge_project = s.name
|
16
16
|
|
17
|
-
s.add_development_dependency "savon", "~> 0.8.0.
|
17
|
+
s.add_development_dependency "savon", "~> 0.8.0.beta.1"
|
18
18
|
|
19
19
|
s.add_development_dependency "rspec", "~> 2.0.0"
|
20
20
|
s.add_development_dependency "mocha", "~> 0.9.8"
|
data/spec/savon/model_spec.rb
CHANGED
@@ -34,7 +34,7 @@ describe Savon::Model do
|
|
34
34
|
end
|
35
35
|
|
36
36
|
describe ".actions" do
|
37
|
-
before(:all) { model.actions :get_user,
|
37
|
+
before(:all) { model.actions :get_user, "GetAllUsers" }
|
38
38
|
|
39
39
|
it "should define class methods each action" do
|
40
40
|
model.should respond_to(:get_user, :get_all_users)
|
@@ -49,6 +49,11 @@ describe Savon::Model do
|
|
49
49
|
model.client.expects(:request).with(:wsdl, :get_user, :body => { :id => 1 })
|
50
50
|
model.get_user :id => 1
|
51
51
|
end
|
52
|
+
|
53
|
+
it "should accept and pass Strings for action names" do
|
54
|
+
model.client.expects(:request).with(:wsdl, "GetAllUsers", :body => { :id => 1 })
|
55
|
+
model.get_all_users :id => 1
|
56
|
+
end
|
52
57
|
end
|
53
58
|
|
54
59
|
context "(instance-level)" do
|
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:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
- 1
|
9
8
|
- 2
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.2.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: 2010-10-
|
18
|
+
date: 2010-10-30 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -26,14 +26,14 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash:
|
29
|
+
hash: 62196257
|
30
30
|
segments:
|
31
31
|
- 0
|
32
32
|
- 8
|
33
33
|
- 0
|
34
|
-
-
|
34
|
+
- beta
|
35
35
|
- 1
|
36
|
-
version: 0.8.0.
|
36
|
+
version: 0.8.0.beta.1
|
37
37
|
type: :development
|
38
38
|
version_requirements: *id001
|
39
39
|
- !ruby/object:Gem::Dependency
|
@@ -77,6 +77,7 @@ extensions: []
|
|
77
77
|
extra_rdoc_files: []
|
78
78
|
|
79
79
|
files:
|
80
|
+
- .gitignore
|
80
81
|
- .rspec
|
81
82
|
- Gemfile
|
82
83
|
- Gemfile.lock
|