soap-object 0.6.3 → 0.6.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,22 +1,22 @@
1
-
2
- module SoapObject
3
- module Factory
4
-
5
- def using(cls, &block)
6
- @the_service = find_service(cls)
7
- block.call @the_service if block
8
- @the_service
9
- end
10
-
11
- private
12
-
13
- def find_service(cls)
14
- services[cls] = cls.new unless services[cls]
15
- services[cls]
16
- end
17
-
18
- def services
19
- @services ||= {}
20
- end
21
- end
22
- end
1
+
2
+ module SoapObject
3
+ module Factory
4
+
5
+ def using(cls, &block)
6
+ @the_service = find_service(cls)
7
+ block.call @the_service if block
8
+ @the_service
9
+ end
10
+
11
+ private
12
+
13
+ def find_service(cls)
14
+ services[cls] = cls.new(Savon) unless services[cls]
15
+ services[cls]
16
+ end
17
+
18
+ def services
19
+ @services ||= {}
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,39 @@
1
+ module SoapObject
2
+ module Response
3
+
4
+ #
5
+ # Return the xml response
6
+ #
7
+ def to_xml
8
+ response.to_xml
9
+ end
10
+
11
+ #
12
+ # Return value at xpath
13
+ #
14
+ def xpath(path)
15
+ response.xpath(path)
16
+ end
17
+
18
+ #
19
+ # Return the response as a Hash
20
+ #
21
+ def to_hash
22
+ response.hash
23
+ end
24
+
25
+ #
26
+ # Return the body of the message as a Hash
27
+ #
28
+ def body
29
+ response.body
30
+ end
31
+
32
+ #
33
+ # Return the response as a Nokogiri document
34
+ #
35
+ def doc
36
+ response.doc
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,22 @@
1
+ module SoapObject
2
+ class SslOptions
3
+ attr_accessor :verify_mode, :version
4
+
5
+ def initialize
6
+ yield self if block_given?
7
+ end
8
+
9
+ def options
10
+ build_options
11
+ end
12
+
13
+ private
14
+
15
+ def build_options
16
+ options = {}
17
+ options[:ssl_verify_mode] = verify_mode if verify_mode
18
+ options[:ssl_version] = version if version
19
+ options
20
+ end
21
+ end
22
+ end
@@ -1,5 +1,3 @@
1
- module Soap
2
- module Object
3
- VERSION = "0.6.3"
4
- end
5
- end
1
+ module SoapObject
2
+ VERSION = "0.6.8"
3
+ end
@@ -1,24 +1,24 @@
1
- # -*- encoding: utf-8 -*-
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'soap-object/version'
5
-
6
- Gem::Specification.new do |gem|
7
- gem.name = "soap-object"
8
- gem.version = Soap::Object::VERSION
9
- gem.authors = ["Jeffrey S. Morgan", "Doug Morgan"]
10
- gem.email = ["jeff.morgan@leandog.com", "douglas.morgan3405@gmail.com"]
11
- gem.description = %q{Wrapper around SOAP service calls to make it easy to test}
12
- gem.summary = %q{Wrapper around SOAP service calls to make it easy to test}
13
- gem.homepage = "http://github.com/cheezy/soap-object"
14
-
15
- gem.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
19
-
20
- gem.add_dependency 'savon', '>= 2.2.0'
21
-
22
- gem.add_development_dependency 'rspec', '>= 2.12.0'
23
- gem.add_development_dependency 'cucumber', '>= 1.2.0'
24
- end
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'soap-object/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "soap-object"
8
+ gem.version = SoapObject::VERSION
9
+ gem.authors = ["Jeffrey S. Morgan", "Doug Morgan"]
10
+ gem.email = ["jeff.morgan@leandog.com", "douglas.morgan3405@gmail.com"]
11
+ gem.description = %q{Wrapper around SOAP service calls to make it easy to test}
12
+ gem.summary = %q{Wrapper around SOAP service calls to make it easy to test}
13
+ gem.homepage = "http://github.com/cheezy/soap-object"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency 'savon', '>= 2.2.0'
21
+
22
+ gem.add_development_dependency 'rspec', '>= 2.12.0'
23
+ gem.add_development_dependency 'cucumber', '>= 1.2.0'
24
+ end
@@ -0,0 +1,119 @@
1
+ require 'spec_helper'
2
+
3
+ describe SoapObject do
4
+ let(:client) { double('client') }
5
+ let(:platform) {double('savon')}
6
+
7
+ before do
8
+ allow(platform).to receive(:client).and_return(client)
9
+ end
10
+
11
+ context 'when creating new instances' do
12
+
13
+ it 'should know when it is connected to service' do
14
+ subject = TestSoapObjectWithProperties.new(platform)
15
+
16
+ expect(subject).to be_connected
17
+ end
18
+
19
+ it 'should initialize the client using the wsdl' do
20
+ expect(platform).to receive(:client).with(hash_including(wsdl: 'http://blah.com'))
21
+
22
+ TestSoapObjectWithProperties.new(platform)
23
+ end
24
+
25
+ it 'should allow one to override the endpoint' do
26
+ expect(platform).to receive(:client).with(hash_including(endpoint: 'https://blah.com'))
27
+
28
+ TestSoapObjectWithProperties.new(platform)
29
+ end
30
+
31
+ it 'should allow one to setup a proxy' do
32
+ expect(platform).to receive(:client).with(hash_including(proxy: 'http://proxy.com:8080'))
33
+
34
+ TestSoapObjectWithProperties.new(platform)
35
+ end
36
+
37
+ it 'should allow one to set an open timeout' do
38
+ expect(platform).to receive(:client).with(hash_including(open_timeout: 10))
39
+
40
+ TestSoapObjectWithProperties.new(platform)
41
+ end
42
+
43
+ it 'should allow one to set a read timeout' do
44
+ expect(platform).to receive(:client).with(hash_including(read_timeout: 20))
45
+
46
+ TestSoapObjectWithProperties.new(platform)
47
+ end
48
+
49
+ it 'should allow one to set a soap header' do
50
+ expect(platform).to receive(:client).with(hash_including(soap_header: {'Token' => 'secret'}))
51
+
52
+ TestSoapObjectWithProperties.new(platform)
53
+ end
54
+
55
+ it 'should allow one to set the encoding' do
56
+ expect(platform).to receive(:client).with(hash_including(encoding: 'UTF-16'))
57
+
58
+ TestSoapObjectWithProperties.new(platform)
59
+ end
60
+
61
+ it 'should allow one to use basic authentication' do
62
+ expect(platform).to receive(:client).with(hash_including(basic_auth: ['steve', 'secret']))
63
+
64
+ TestSoapObjectWithProperties.new(platform)
65
+ end
66
+
67
+ it 'should allow one to use digest authentication' do
68
+ expect(platform).to receive(:client).with(hash_including(digest_auth: ['digest', 'auth']))
69
+
70
+ TestSoapObjectWithProperties.new(platform)
71
+ end
72
+
73
+ it 'should enable logging when logging level set' do
74
+ expect(platform).to receive(:client).with(hash_including(log: true))
75
+
76
+ TestSoapObjectWithProperties.new(platform)
77
+ end
78
+
79
+ it 'should allow one to set the log level' do
80
+ expect(platform).to receive(:client).with(hash_including(log_level: :error))
81
+
82
+ TestSoapObjectWithProperties.new(platform)
83
+ end
84
+
85
+ it 'should use pretty format for xml when logging' do
86
+ expect(platform).to receive(:client).with(hash_including(pretty_print_xml: true))
87
+
88
+ TestSoapObjectWithProperties.new(platform)
89
+ end
90
+
91
+ it 'should allow one to set the soap version' do
92
+ expect(platform).to receive(:client).with(hash_including(soap_version: 2))
93
+
94
+ TestSoapObjectWithProperties.new(platform)
95
+ end
96
+
97
+ end
98
+
99
+ context 'when creating new instances with out client property overrides' do
100
+
101
+ it 'should set SSL version to 3 by default' do
102
+ expect(platform).to receive(:client).with(hash_including(ssl_version: :SSLv3))
103
+
104
+ WithoutClientProperties.new(platform)
105
+ end
106
+
107
+ it 'should disable SSL verification by default' do
108
+ expect(platform).to receive(:client).with(hash_including(ssl_verify_mode: :none))
109
+
110
+ WithoutClientProperties.new(platform)
111
+ end
112
+
113
+ it 'should disable logging by default' do
114
+ expect(platform).to receive(:client).with(hash_including(log: false))
115
+
116
+ WithoutClientProperties.new(platform)
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe SoapObject::Factory do
4
+ context "when using the factory to create to service" do
5
+ let(:world) { TestWorld.new }
6
+
7
+ it "should create a valid service object" do
8
+ service = world.using(TestSoapObject)
9
+ expect(service).to be_instance_of TestSoapObject
10
+ end
11
+
12
+ it "should create a valid service and invoke a block" do
13
+ world.using(TestSoapObject) do |service|
14
+ expect(service).to be_instance_of TestSoapObject
15
+ end
16
+ end
17
+
18
+ it "should create the service the first time we use it" do
19
+ obj = TestSoapObject
20
+ expect(TestSoapObject).to receive(:new).with(Savon).once.and_return(obj)
21
+ world.using(TestSoapObject)
22
+ world.using(TestSoapObject)
23
+ end
24
+ end
25
+ end
@@ -1,143 +1,37 @@
1
- require 'spec_helper'
2
-
3
- class TestServiceWithWsdl
4
- include SoapObject
5
-
6
- wsdl 'http://blah.com'
7
- proxy 'http://proxy.com:8080'
8
- open_timeout 10
9
- read_timeout 20
10
- soap_header 'Token' => 'secret'
11
- encoding 'UTF-16'
12
- basic_auth 'steve', 'secret'
13
- digest_auth 'digest', 'auth'
14
- log_level :error
15
- ssl_verification false
16
- end
17
-
18
- class TestSoapObjectWithoutClientProperties
19
- include SoapObject
20
- end
21
-
22
- class TestSoapObjectWithExplicitSslVerification
23
- include SoapObject
24
- ssl_verification true
25
- end
26
-
27
- class TestWorld
28
- include SoapObject::Factory
29
- end
30
-
31
- describe SoapObject do
32
- let(:client) { double('client') }
33
- let(:subject) { TestServiceWithWsdl.new }
34
-
35
- context "when creating new instances" do
36
- before do
37
- allow(Savon).to receive(:client).and_return(client)
38
- end
39
-
40
- it "should initialize the client using the wsdl" do
41
- expect(subject.send(:client_properties)[:wsdl]).to eq('http://blah.com')
42
- end
43
-
44
- it "should know when it is connected to service" do
45
- expect(subject).to be_connected
46
- end
47
-
48
- it "should allow one to setup a proxy" do
49
- expect(subject.send(:client_properties)[:proxy]).to eq('http://proxy.com:8080')
50
- end
51
-
52
- it "should allow one to set an open timeout" do
53
- expect(subject.send(:client_properties)[:open_timeout]).to eq(10)
54
- end
55
-
56
- it "should allow one to set a read timeout" do
57
- expect(subject.send(:client_properties)[:read_timeout]).to eq(20)
58
- end
59
-
60
- it "should allow one to set a soap header" do
61
- expect(subject.send(:client_properties)[:soap_header]).to eq({'Token' => 'secret'})
62
- end
63
-
64
- it "should allow one to set the encoding" do
65
- expect(subject.send(:client_properties)[:encoding]).to eq('UTF-16')
66
- end
67
-
68
- it "should allow one to use basic authentication" do
69
- expect(subject.send(:client_properties)[:basic_auth]).to eq(['steve', 'secret'])
70
- end
71
-
72
- it "should allow one to use digest authentication" do
73
- expect(subject.send(:client_properties)[:digest_auth]).to eq(['digest', 'auth'])
74
- end
75
-
76
- it "should disable logging when no logging level set" do
77
- expect(TestSoapObjectWithoutClientProperties.new.send(:client_properties)[:log]).to eq(false)
78
- end
79
-
80
- it "should enable logging when logging level set" do
81
- expect(subject.send(:client_properties)[:log]).to eq(true)
82
- end
83
-
84
- it "should allow one to set the log level" do
85
- expect(subject.send(:client_properties)[:log_level]).to eq(:error)
86
- end
87
-
88
- it "should enable SSL verification by default" do
89
- expect(TestSoapObjectWithoutClientProperties.new.send(:client_properties)[:ssl_verify_mode]).to be_nil
90
- end
91
-
92
- it "should allow one to disable SSL verification" do
93
- expect(subject.send(:client_properties)[:ssl_verify_mode]).to eq(:none)
94
- end
95
-
96
- it "should allow one to explicitly enable SSL verification" do
97
- expect(TestSoapObjectWithExplicitSslVerification.new.send(:client_properties)[:ssl_verify_mode]).to be_nil
98
- end
99
-
100
- end
101
-
102
- context "when using the factory to create to service" do
103
- let(:world) { TestWorld.new }
104
-
105
- it "should create a valid service object" do
106
- service = world.using(TestServiceWithWsdl)
107
- expect(service).to be_instance_of TestServiceWithWsdl
108
- end
109
-
110
- it "should create a valid service and invoke a block" do
111
- world.using(TestServiceWithWsdl) do |service|
112
- expect(service).to be_instance_of TestServiceWithWsdl
113
- end
114
- end
115
-
116
- it "should create the service the first time we use it" do
117
- obj = TestServiceWithWsdl.new
118
- expect(TestServiceWithWsdl).to receive(:new).once.and_return(obj)
119
- world.using(TestServiceWithWsdl)
120
- world.using(TestServiceWithWsdl)
121
- end
122
- end
123
-
124
- context "when calling methods on the service" do
125
- let(:response) { double('response') }
126
-
127
- before do
128
- expect(Savon).to receive(:client).and_return(client)
129
- expect(response).to receive(:to_xml)
130
- end
131
-
132
- it "should make a valid request" do
133
- expect(client).to receive(:call).with(:fake_call, message: {data_key: 'some_value'}).and_return(response)
134
- subject.fake_call data_key: 'some_value'
135
- end
136
-
137
- it "should make a valid request with custom xml" do
138
- expected_xml = "<xml><envelope/><data></data></envelope></xml>"
139
- expect(client).to receive(:call).with(anything, xml: expected_xml).and_return(response)
140
- subject.fake_call expected_xml
141
- end
142
- end
143
- end
1
+ require 'spec_helper'
2
+
3
+ describe SoapObject do
4
+
5
+ context 'when calling methods on the service' do
6
+ let(:response) { double('response') }
7
+ let(:client) { double('client') }
8
+ let(:platform) {double('savon')}
9
+ let(:subject) { WithoutClientProperties.new(platform) }
10
+
11
+ before do
12
+ allow(platform).to receive(:client).and_return(client)
13
+ allow(client).to receive(:call).with(anything, anything).and_return(response)
14
+ allow(response).to receive(:to_xml)
15
+ end
16
+
17
+ it 'should make a valid request' do
18
+ expect(client).to receive(:call).with(:fake_call, message: {data_key: 'some_value'}).and_return(response)
19
+ subject.fake_call data_key: 'some_value'
20
+ end
21
+
22
+ it 'should return the repsonse as xml' do
23
+ expected_xml = '<xml><envelope/><data></data></envelope></xml>'
24
+ expect(response).to receive(:to_xml).and_return(expected_xml)
25
+ response = subject.fake_call data_key: 'some_value'
26
+ expect(response).to eq(expected_xml)
27
+ end
28
+
29
+ it 'should make a valid request with custom xml' do
30
+ expected_xml = '<xml><envelope/><data></data></envelope></xml>'
31
+ expect(client).to receive(:call).with(:fake_call, xml: expected_xml).and_return(response)
32
+ subject.fake_call expected_xml
33
+ end
34
+
35
+
36
+ end
37
+ end