savon_model 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,11 @@
1
+ # https://github.com/travis-ci/travis-ci/wiki/.travis.yml-options
2
+ bundler_args: --without developer_happiness
3
+ script: "bundle exec rake"
4
+ rvm:
5
+ - 1.8.7
6
+ - 1.9.2
7
+ - 1.9.3
8
+ - ree
9
+ - rbx
10
+ - rbx-2.0
11
+ - jruby
@@ -0,0 +1,8 @@
1
+ == 1.1.0 (2011-09-26)
2
+
3
+ * Feature: Added a .wsse_auth class method to set WSSE credentials.
4
+ * Refactoring: Removed several client-related instance methods.
5
+
6
+ == 1.0.0 (2011-06-24)
7
+
8
+ * Switched to Semantic Versioning.
data/Gemfile CHANGED
@@ -1,2 +1,7 @@
1
1
  source :rubygems
2
2
  gemspec
3
+
4
+ # excluded from travis
5
+ group :developer_happiness do
6
+ gem "autotest"
7
+ end
data/README.md CHANGED
@@ -1,71 +1,153 @@
1
- Savon::Model [![Build Status](http://travis-ci.org/rubiii/savon_model.png)](http://travis-ci.org/rubiii/savon_model)
1
+ Savon::Model [![Build Status](https://secure.travis-ci.org/rubiii/savon_model.png)](http://travis-ci.org/rubiii/savon_model)
2
2
  ============
3
3
 
4
4
  Model for SOAP service oriented applications.
5
5
 
6
- [Bugs](http://github.com/rubiii/savon_model/issues) | [Docs](http://rubydoc.info/gems/savon_model/frames)
7
-
8
6
 
9
7
  Installation
10
8
  ------------
11
9
 
12
- The gem is available through [Rubygems](http://rubygems.org/gems/savon_model) and can be installed via:
10
+ Savon::Model is available through [Rubygems](http://rubygems.org/gems/savon_model) and can be installed via:
13
11
 
14
- $ gem install savon_model
12
+ ``` bash
13
+ $ gem install savon_model
14
+ ```
15
15
 
16
16
 
17
- Getting started
18
- ---------------
17
+ Include
18
+ -------
19
19
 
20
- class User
21
- include Savon::Model
20
+ Savon::Model comes with quite a few handy class and instance methods for using [Savon](https://github.com/rubiii/savon) inside your SOAP model classes.
21
+ Simply include the module in any of your classes to get started.
22
22
 
23
- client do [1]
24
- http.headers["Pragma"] = "no-cache"
25
- end
23
+ ``` ruby
24
+ require "savon_model"
26
25
 
27
- document "http://example.com/users?wsdl" [2]
26
+ class User
27
+ include Savon::Model
28
+ end
29
+ ```
28
30
 
29
- endpoint "http://example.com/users" [3]
30
- namespace "http://v1.example.com/users" [4]
31
31
 
32
- basic_auth "login", "password" [5]
32
+ Service
33
+ -------
33
34
 
34
- actions :get_user, :get_all_users [6]
35
+ You can configure Savon to work with or without a WSDL document with the `.document`, `.endpoint` and `.namespace` class methods.
36
+ Point Savon to the WSDL of your service:
35
37
 
36
- def self.all
37
- get_all_users.to_array [7]
38
- end
38
+ ``` ruby
39
+ class User
40
+ include Savon::Model
39
41
 
40
- def self.find(id)
41
- get_user(:id => id).to_hash [8]
42
- end
42
+ document "http://service.example.com?wsdl"
43
+ end
44
+ ```
43
45
 
44
- def self.delete(id)
45
- client.request(:delete_user) do [9]
46
- soap.body = { :id => 1 }
47
- end.to_hash
48
- end
49
- end
46
+ or set the SOAP endpoint and target namespace to bypass the WSDL:
47
+
48
+ ``` ruby
49
+ class User
50
+ include Savon::Model
51
+
52
+ endpoint "http://service.example.com"
53
+ namespace "http://v1.service.example.com"
54
+ end
55
+ ```
56
+
57
+
58
+ Authentication
59
+ --------------
60
+
61
+ Set your HTTP basic authentication username and password via the `.basic_auth` method:
62
+
63
+ ``` ruby
64
+ class User
65
+ include Savon::Model
66
+
67
+ basic_auth "login", "password"
68
+ end
69
+ ```
70
+
71
+ or use the `.wsse_auth` method to set your WSSE username, password and (optional) whether or not to use digest authentication.
72
+
73
+ ``` ruby
74
+ class User
75
+ include Savon::Model
76
+
77
+ wsse_auth "login", "password", :digest
78
+ end
79
+ ```
80
+
81
+
82
+ Actions
83
+ -------
84
+
85
+ Define the service methods you're working with via the `.actions` class method. Savon::Model creates both class and instance
86
+ methods for every action. These methods accept a SOAP body Hash and return a `Savon::SOAP::Response` for you to use.
87
+ You can wrap those methods in other methods:
50
88
 
51
- 1. You can call the `client` method with a block of settings to be passed to `Savon::Client.new`.
52
- The `client` method memoizes a `Savon::Client` instance, so you need to call this method before
53
- it gets called by any other method.
89
+ ``` ruby
90
+ class User
91
+ include Savon::Model
54
92
 
55
- 2. Sets the WSDL document.
93
+ actions :get_user, :get_all_users
56
94
 
57
- 3. Sets the SOAP endpoint.
58
- 4. Sets the target namespace.
95
+ def self.all
96
+ get_all_users.to_array
97
+ end
59
98
 
60
- 5. Sets basic auth credentials.
99
+ end
100
+ ```
61
101
 
62
- 6. Specifies the SOAP actions provided by the service. This method dynamically creates both class
63
- and instance methods named after the arguments. These methods accept an optional SOAP body Hash
64
- or XML String to be passed to the `Savon::Client` instance.
102
+ or extend them by delegating to `super`:
65
103
 
66
- 7. `User.all` calls the `get_all_users` SOAP action and returns a `Savon::Response`.
104
+ ``` ruby
105
+ class User
106
+ include Savon::Model
107
+
108
+ actions :get_user, :get_all_users
109
+
110
+ def get_user(id)
111
+ super(:user_id => id).to_hash[:get_user_response][:return]
112
+ end
113
+
114
+ end
115
+ ```
116
+
117
+
118
+ Else
119
+ ----
120
+
121
+ The `Savon::Client` instance used in your model lives at `.client` inside your class. It gets initialized lazily whenever you call
122
+ any other class or instance method that tries to access the client. In case you need to control how the client gets initialized,
123
+ you can pass a block to `.client` before it's memoized:
124
+
125
+ ``` ruby
126
+ class User
127
+ include Savon::Model
128
+
129
+ client do
130
+ http.headers["Pragma"] = "no-cache"
131
+ end
132
+
133
+ end
134
+ ```
135
+
136
+ You can also bypass Savon::Model and directly use the client:
137
+
138
+ ``` ruby
139
+ class User
140
+ include Savon::Model
141
+
142
+ document "http://service.example.com?wsdl"
143
+
144
+ def find_by_id(id)
145
+ response = client.request(:find_user) do
146
+ soap.body = { :id => id }
147
+ end
67
148
 
68
- 8. `User.find` calls the `get_user` SOAP action with a SOAP body Hash and returns a `Savon::Response`.
149
+ response.body[:find_user_response][:return]
150
+ end
69
151
 
70
- 9. This is an example of what happens "behind the scenes" on [6]. You can always use the `client`
71
- method to directly access and use the `Savon::Client` instance.
152
+ end
153
+ ```
data/Rakefile CHANGED
@@ -1,11 +1,7 @@
1
- require "bundler"
2
- Bundler::GemHelper.install_tasks
3
-
1
+ require "bundler/gem_tasks"
4
2
  require "rspec/core/rake_task"
5
3
 
6
- RSpec::Core::RakeTask.new do |t|
7
- t.rspec_opts = %w(-c)
8
- end
4
+ RSpec::Core::RakeTask.new
9
5
 
10
6
  task :default => :spec
11
7
  task :test => :spec
@@ -40,20 +40,20 @@ module Savon
40
40
  private
41
41
 
42
42
  def define_class_action(action)
43
- class_action_module.module_eval <<-CODE
43
+ class_action_module.module_eval %{
44
44
  def #{action.to_s.snakecase}(body = nil, &block)
45
45
  response = client.request :wsdl, #{action.inspect}, :body => body, &block
46
46
  Savon::Model.handle_response ? Savon::Model.handle_response.call(response) : response
47
47
  end
48
- CODE
48
+ }
49
49
  end
50
50
 
51
51
  def define_instance_action(action)
52
- instance_action_module.module_eval <<-CODE
52
+ instance_action_module.module_eval %{
53
53
  def #{action.to_s.snakecase}(body = nil, &block)
54
54
  self.class.#{action.to_s.snakecase} body, &block
55
55
  end
56
- CODE
56
+ }
57
57
  end
58
58
 
59
59
  def class_action_module
@@ -66,15 +66,19 @@ module Savon
66
66
  def endpoint(uri)
67
67
  client.wsdl.endpoint = uri
68
68
  end
69
-
69
+
70
70
  def document(uri)
71
71
  client.wsdl.document = uri
72
72
  end
73
-
73
+
74
74
  def basic_auth(login, password)
75
75
  client.http.auth.basic login, password
76
76
  end
77
77
 
78
+ def wsse_auth(*args)
79
+ client.wsse.credentials(*args)
80
+ end
81
+
78
82
  def namespace(uri)
79
83
  client.wsdl.namespace = uri
80
84
  end
@@ -89,22 +93,6 @@ module Savon
89
93
  self.class.client &block
90
94
  end
91
95
 
92
- def endpoint(uri)
93
- self.class.endpoint uri
94
- end
95
-
96
- def document(uri)
97
- self.class.document uri
98
- end
99
-
100
- def basic_auth(login, password)
101
- self.class.basic_auth login, password
102
- end
103
-
104
- def namespace(uri)
105
- self.class.namespace uri
106
- end
107
-
108
96
  end.tap { |mod| include mod }
109
97
  end
110
98
 
@@ -1,7 +1,7 @@
1
1
  module Savon
2
2
  module Model
3
3
 
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
 
6
6
  end
7
7
  end
@@ -1,6 +1,5 @@
1
- lib = File.expand_path("../lib/", __FILE__)
2
- $:.unshift lib unless $:.include?(lib)
3
-
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
4
3
  require "savon/model_version"
5
4
 
6
5
  Gem::Specification.new do |s|
@@ -9,18 +8,20 @@ Gem::Specification.new do |s|
9
8
  s.authors = "Daniel Harrington"
10
9
  s.email = "me@rubiii.com"
11
10
  s.homepage = "http://github.com/rubiii/#{s.name}"
12
- s.summary = "SOAP model"
13
- s.description = "Model for SOAP service oriented applications."
11
+ s.summary = "Model for SOAP service oriented applications"
12
+ s.description = s.summary
14
13
 
15
14
  s.rubyforge_project = s.name
16
15
 
17
16
  s.add_dependency "httpi", ">= 0.7.8"
18
17
  s.add_dependency "savon", ">= 0.8.2"
19
18
 
20
- s.add_development_dependency "rspec", "~> 2.4.0"
21
- s.add_development_dependency "mocha", "~> 0.9.8"
22
- s.add_development_dependency "autotest"
19
+ s.add_development_dependency "rake", "~> 0.8.7"
20
+ s.add_development_dependency "rspec", "~> 2.6.0"
21
+ s.add_development_dependency "mocha", "~> 0.10.0"
23
22
 
24
- s.files = `git ls-files`.split("\n")
25
- s.require_path = "lib"
23
+ s.files = `git ls-files`.split("\n")
24
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
26
+ s.require_paths = ["lib"]
26
27
  end
@@ -2,109 +2,135 @@ require "spec_helper"
2
2
  require "savon/model"
3
3
 
4
4
  describe Savon::Model do
5
- let(:model) { Class.new { include Savon::Model } }
5
+
6
+ let(:model) do
7
+ Class.new { include Savon::Model }
8
+ end
6
9
 
7
10
  describe ".handle_response" do
8
- before(:all) { model.actions :get_user, "GetAllUsers" }
9
11
 
10
- it "should be used for pre-processing SOAP responses" do
12
+ before(:all) do
13
+ model.actions :get_user, "GetAllUsers"
14
+ end
15
+
16
+ it "can be used for pre-processing SOAP responses" do
11
17
  Savon::Model.handle_response = lambda { |response| response }
12
18
 
13
19
  model.client.stubs(:request).returns("response")
14
20
  model.get_user.should == "response"
15
21
  end
22
+
16
23
  end
17
24
 
18
25
  describe ".client" do
19
- it "should should pass a given block to a new Savon::Client"
20
26
 
21
- it "should memoize the Savon::Client" do
27
+ it "passes a given block to a new Savon::Client"
28
+
29
+ it "memoizes the Savon::Client" do
22
30
  model.client.should equal(model.client)
23
31
  end
32
+
24
33
  end
25
34
 
26
35
  describe ".endpoint" do
27
- it "should set the SOAP endpoint" do
36
+
37
+ it "sets the SOAP endpoint" do
28
38
  model.endpoint "http://example.com"
29
39
  model.client.wsdl.endpoint.should == "http://example.com"
30
40
  end
41
+
31
42
  end
32
43
 
33
44
  describe ".document" do
34
- it "should set WSDL document" do
45
+
46
+ it "sets WSDL document" do
35
47
  model.document "http://example.com/?wsdl"
36
48
  model.client.wsdl.document.should == "http://example.com/?wsdl"
37
49
  end
50
+
38
51
  end
39
52
 
40
53
  describe ".basic_auth" do
41
- it "should set HTTP Basic auth credentials" do
54
+
55
+ it "sets HTTP Basic auth credentials" do
42
56
  model.basic_auth "login", "password"
43
- puts model.client.http.auth.basic.should == ["login", "password"]
57
+ model.client.http.auth.basic.should == ["login", "password"]
58
+ end
59
+
60
+ end
61
+
62
+ describe ".wsse_auth" do
63
+
64
+ it "sets WSSE auth credentials" do
65
+ model.wsse_auth "login", "password", :digest
66
+
67
+ model.client.wsse.username.should == "login"
68
+ model.client.wsse.password.should == "password"
69
+ model.client.wsse.should be_digest
44
70
  end
71
+
45
72
  end
46
73
 
47
74
  describe ".namespace" do
48
- it "should set the target namespace" do
75
+
76
+ it "sets the target namespace" do
49
77
  model.namespace "http://v1.example.com"
50
78
  model.client.wsdl.namespace.should == "http://v1.example.com"
51
79
  end
80
+
52
81
  end
53
82
 
54
83
  describe ".actions" do
55
- before(:all) { model.actions :get_user, "GetAllUsers" }
56
84
 
57
- it "should define class methods each action" do
85
+ before(:all) do
86
+ model.actions :get_user, "GetAllUsers"
87
+ end
88
+
89
+ it "defines class methods each action" do
58
90
  model.should respond_to(:get_user, :get_all_users)
59
91
  end
60
92
 
61
- it "should define instance methods each action" do
93
+ it "defines instance methods each action" do
62
94
  model.new.should respond_to(:get_user, :get_all_users)
63
95
  end
64
96
 
65
97
  context "(class-level)" do
66
- it "should execute SOAP requests with a given body" do
98
+
99
+ it "executes SOAP requests with a given body" do
67
100
  model.client.expects(:request).with(:wsdl, :get_user, :body => { :id => 1 })
68
101
  model.get_user :id => 1
69
102
  end
70
103
 
71
- it "should accept and pass Strings for action names" do
104
+ it "accepts and passes Strings for action names" do
72
105
  model.client.expects(:request).with(:wsdl, "GetAllUsers", :body => { :id => 1 })
73
106
  model.get_all_users :id => 1
74
107
  end
75
108
  end
76
109
 
77
110
  context "(instance-level)" do
78
- it "should delegate to the corresponding class method" do
111
+
112
+ it "delegates to the corresponding class method" do
79
113
  model.expects(:get_all_users).with(:active => true)
80
114
  model.new.get_all_users :active => true
81
115
  end
116
+
82
117
  end
118
+
83
119
  end
84
120
 
85
121
  describe "#client" do
86
- it "should return the class-level Savon::Client" do
87
- model.new.client.should == model.client
88
- end
89
- end
90
122
 
91
- describe "#endpoint" do
92
- it "should delegate to .endpoint" do
93
- model.expects(:endpoint).with("http://example.com")
94
- model.new.endpoint "http://example.com"
123
+ it "returns the class-level Savon::Client" do
124
+ model.new.client.should == model.client
95
125
  end
96
- end
97
126
 
98
- describe "#namespace" do
99
- it "should delegate to .namespace" do
100
- model.expects(:namespace).with("http://v1.example.com")
101
- model.new.namespace "http://v1.example.com"
102
- end
103
127
  end
104
128
 
105
129
  describe "overwriting action methods" do
130
+
106
131
  context "(class-level)" do
107
- let :supermodel do
132
+
133
+ let(:supermodel) do
108
134
  supermodel = model.dup
109
135
  supermodel.actions :get_user
110
136
 
@@ -116,16 +142,18 @@ describe Savon::Model do
116
142
  supermodel
117
143
  end
118
144
 
119
- it "should be possible" do
145
+ it "works" do
120
146
  supermodel.client.expects(:request).with(:wsdl, :get_user, :body => { :id => 1 })
121
147
  supermodel.expects(:p).with("super") # stupid, but works
122
148
 
123
149
  supermodel.get_user :id => 1
124
150
  end
151
+
125
152
  end
126
153
 
127
154
  context "(instance-level)" do
128
- let :supermodel do
155
+
156
+ let(:supermodel) do
129
157
  supermodel = model.dup
130
158
  supermodel.actions :get_user
131
159
  supermodel = supermodel.new
@@ -138,13 +166,15 @@ describe Savon::Model do
138
166
  supermodel
139
167
  end
140
168
 
141
- it "should be possible" do
169
+ it "works" do
142
170
  supermodel.client.expects(:request).with(:wsdl, :get_user, :body => { :id => 1 })
143
171
  supermodel.expects(:p).with("super") # stupid, but works
144
172
 
145
173
  supermodel.get_user :id => 1
146
174
  end
175
+
147
176
  end
177
+
148
178
  end
149
179
 
150
180
  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: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 1.0.0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel Harrington
@@ -15,12 +15,10 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-24 00:00:00 Z
18
+ date: 2011-09-26 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: httpi
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
22
  none: false
25
23
  requirements:
26
24
  - - ">="
@@ -31,12 +29,12 @@ dependencies:
31
29
  - 7
32
30
  - 8
33
31
  version: 0.7.8
32
+ name: httpi
34
33
  type: :runtime
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: savon
38
34
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
35
+ requirement: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
40
38
  none: false
41
39
  requirements:
42
40
  - - ">="
@@ -47,55 +45,59 @@ dependencies:
47
45
  - 8
48
46
  - 2
49
47
  version: 0.8.2
48
+ name: savon
50
49
  type: :runtime
51
- version_requirements: *id002
52
- - !ruby/object:Gem::Dependency
53
- name: rspec
54
50
  prerelease: false
55
- requirement: &id003 !ruby/object:Gem::Requirement
51
+ requirement: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
56
54
  none: false
57
55
  requirements:
58
56
  - - ~>
59
57
  - !ruby/object:Gem::Version
60
- hash: 31
58
+ hash: 49
61
59
  segments:
62
- - 2
63
- - 4
64
60
  - 0
65
- version: 2.4.0
61
+ - 8
62
+ - 7
63
+ version: 0.8.7
64
+ name: rake
66
65
  type: :development
67
- version_requirements: *id003
68
- - !ruby/object:Gem::Dependency
69
- name: mocha
70
66
  prerelease: false
71
- requirement: &id004 !ruby/object:Gem::Requirement
67
+ requirement: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ version_requirements: &id004 !ruby/object:Gem::Requirement
72
70
  none: false
73
71
  requirements:
74
72
  - - ~>
75
73
  - !ruby/object:Gem::Version
76
- hash: 43
74
+ hash: 23
77
75
  segments:
76
+ - 2
77
+ - 6
78
78
  - 0
79
- - 9
80
- - 8
81
- version: 0.9.8
79
+ version: 2.6.0
80
+ name: rspec
82
81
  type: :development
83
- version_requirements: *id004
84
- - !ruby/object:Gem::Dependency
85
- name: autotest
86
82
  prerelease: false
87
- requirement: &id005 !ruby/object:Gem::Requirement
83
+ requirement: *id004
84
+ - !ruby/object:Gem::Dependency
85
+ version_requirements: &id005 !ruby/object:Gem::Requirement
88
86
  none: false
89
87
  requirements:
90
- - - ">="
88
+ - - ~>
91
89
  - !ruby/object:Gem::Version
92
- hash: 3
90
+ hash: 55
93
91
  segments:
94
92
  - 0
95
- version: "0"
93
+ - 10
94
+ - 0
95
+ version: 0.10.0
96
+ name: mocha
96
97
  type: :development
97
- version_requirements: *id005
98
- description: Model for SOAP service oriented applications.
98
+ prerelease: false
99
+ requirement: *id005
100
+ description: Model for SOAP service oriented applications
99
101
  email: me@rubiii.com
100
102
  executables: []
101
103
 
@@ -106,6 +108,8 @@ extra_rdoc_files: []
106
108
  files:
107
109
  - .gitignore
108
110
  - .rspec
111
+ - .travis.yml
112
+ - CHANGELOG.md
109
113
  - Gemfile
110
114
  - LICENSE
111
115
  - README.md
@@ -145,9 +149,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
149
  requirements: []
146
150
 
147
151
  rubyforge_project: savon_model
148
- rubygems_version: 1.8.5
152
+ rubygems_version: 1.8.6
149
153
  signing_key:
150
154
  specification_version: 3
151
- summary: SOAP model
152
- test_files: []
153
-
155
+ summary: Model for SOAP service oriented applications
156
+ test_files:
157
+ - spec/savon/model_spec.rb
158
+ - spec/spec_helper.rb