soap-object 0.1 → 0.2
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/ChangeLog +8 -0
- data/README.md +17 -4
- data/features/step_definitions/basic_functionality_steps.rb +8 -3
- data/lib/soap-object.rb +35 -9
- data/lib/soap-object/class_methods.rb +84 -6
- data/lib/soap-object/version.rb +1 -1
- data/spec/lib/soap_object_spec.rb +29 -4
- metadata +4 -4
data/ChangeLog
CHANGED
@@ -1,2 +1,10 @@
|
|
1
|
+
=== Version 0.2 / 2013-3-11
|
2
|
+
* Enhancements
|
3
|
+
* Added ability to add XML to the soap header
|
4
|
+
* Added ability to set the encoding for the messages
|
5
|
+
* Added ability to use basic authentication
|
6
|
+
* Added ability to use digest authentication
|
7
|
+
* Added ability to set the log level
|
8
|
+
|
1
9
|
=== Version 0.1 / 2013-3-4
|
2
10
|
Initial release
|
data/README.md
CHANGED
@@ -1,6 +1,22 @@
|
|
1
1
|
# Soap::Object
|
2
2
|
|
3
|
-
|
3
|
+
Module to make it simpler to tests SOAP web services. The goal is
|
4
|
+
to abstract all information about how your call and parse results
|
5
|
+
from the web service within the soap objects.
|
6
|
+
|
7
|
+
````ruby
|
8
|
+
class AirportService
|
9
|
+
include SoapObject
|
10
|
+
|
11
|
+
wsdl 'http://www.webservicex.net/airport.asmx?WSDL'
|
12
|
+
|
13
|
+
def get_airport_name_for(airport_code)
|
14
|
+
response = get_airport_information_by_airport_code airport_code: airport_code
|
15
|
+
doc = Nokogiri::XML(response)
|
16
|
+
doc.xpath('//Table/CityOrAirportName').first.content
|
17
|
+
end
|
18
|
+
end
|
19
|
+
````
|
4
20
|
|
5
21
|
## Installation
|
6
22
|
|
@@ -16,9 +32,6 @@ Or install it yourself as:
|
|
16
32
|
|
17
33
|
$ gem install soap-object
|
18
34
|
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
22
35
|
|
23
36
|
## Contributing
|
24
37
|
|
@@ -2,6 +2,13 @@ class TestServiceWithWsdl
|
|
2
2
|
include SoapObject
|
3
3
|
|
4
4
|
wsdl 'http://www.webservicex.net/airport.asmx?WSDL'
|
5
|
+
log_level :error
|
6
|
+
|
7
|
+
def get_airport_name_for(airport_code)
|
8
|
+
response = get_airport_information_by_airport_code airport_code: airport_code
|
9
|
+
doc = Nokogiri::XML(response)
|
10
|
+
doc.xpath('//Table/CityOrAirportName').first.content
|
11
|
+
end
|
5
12
|
end
|
6
13
|
|
7
14
|
class TestServiceWithLocalWsdl
|
@@ -33,7 +40,5 @@ Then /^I should be able to determine the operations$/ do
|
|
33
40
|
end
|
34
41
|
|
35
42
|
Then /^I should be able to make a call and receive the correct results$/ do
|
36
|
-
|
37
|
-
doc = Nokogiri::XML(response)
|
38
|
-
doc.xpath('//Table/AirportCode').first.content.should == 'SFO'
|
43
|
+
@so.get_airport_name_for('SFO').should == 'SAN FRANCISCO INTL'
|
39
44
|
end
|
data/lib/soap-object.rb
CHANGED
@@ -3,8 +3,26 @@ require 'soap-object/version'
|
|
3
3
|
require 'soap-object/class_methods'
|
4
4
|
|
5
5
|
#
|
6
|
-
# module to make it simpler to tests SOAP web services.
|
7
|
-
#
|
6
|
+
# module to make it simpler to tests SOAP web services. The goal is
|
7
|
+
# to abstract all information about how your call and parse results
|
8
|
+
# from the web service within the soap objects.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# class AirportService
|
12
|
+
# include SoapObject
|
13
|
+
#
|
14
|
+
# wsdl 'http://www.webservicex.net/airport.asmx?WSDL'
|
15
|
+
#
|
16
|
+
# def get_airport_name_for(airport_code)
|
17
|
+
# response = get_airport_information_by_airport_code airport_code: airport_code
|
18
|
+
# doc = Nokogiri::XML(response)
|
19
|
+
# doc.xpath('//Table/CityOrAirportName').first.content
|
20
|
+
# end
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# There are many additional properties that can be set to configure
|
24
|
+
# the service calls. See the comments for SoapObject::ClassMethods to
|
25
|
+
# view all of the options.
|
8
26
|
#
|
9
27
|
module SoapObject
|
10
28
|
attr_reader :wsdl
|
@@ -17,14 +35,24 @@ module SoapObject
|
|
17
35
|
cls.extend SoapObject::ClassMethods
|
18
36
|
end
|
19
37
|
|
38
|
+
#
|
39
|
+
# Returns true if the service has established communication with the
|
40
|
+
# remote server.
|
41
|
+
#
|
20
42
|
def connected?
|
21
43
|
not @client.nil?
|
22
44
|
end
|
23
45
|
|
46
|
+
#
|
47
|
+
# Returns an array of operations that can be called on the remote
|
48
|
+
# service.
|
49
|
+
#
|
24
50
|
def operations
|
25
51
|
@client.operations
|
26
52
|
end
|
27
53
|
|
54
|
+
private
|
55
|
+
|
28
56
|
def method_missing(*args)
|
29
57
|
method = args.shift
|
30
58
|
@response = @client.call(method, {message: args.first})
|
@@ -37,18 +65,16 @@ module SoapObject
|
|
37
65
|
:with_proxy,
|
38
66
|
:with_open_timeout,
|
39
67
|
:with_read_timeout,
|
40
|
-
:
|
68
|
+
:with_soap_header,
|
69
|
+
:with_encoding,
|
70
|
+
:with_basic_auth,
|
71
|
+
:with_digest_auth,
|
72
|
+
:with_log_level].each do |sym|
|
41
73
|
properties = properties.merge(self.send sym) if self.respond_to? sym
|
42
74
|
end
|
43
75
|
properties
|
44
76
|
end
|
45
77
|
|
46
|
-
def no_log
|
47
|
-
{log: false}
|
48
|
-
end
|
49
|
-
|
50
|
-
private
|
51
|
-
|
52
78
|
def body_for(method)
|
53
79
|
@response.body["#{method.to_s}_response".to_sym]["#{method.to_s}_result".to_sym]
|
54
80
|
end
|
@@ -2,6 +2,13 @@
|
|
2
2
|
module SoapObject
|
3
3
|
module ClassMethods
|
4
4
|
|
5
|
+
#
|
6
|
+
# Sets the url for the wsdl. It can be a path to a local file or
|
7
|
+
# a url to a remote server containing the file.
|
8
|
+
#
|
9
|
+
# @param [Stroing] either the local path to or the remote url to
|
10
|
+
# the wsdl to use for all requests.
|
11
|
+
#
|
5
12
|
def wsdl(url)
|
6
13
|
define_method(:with_wsdl) do
|
7
14
|
@wsdl ||= url
|
@@ -9,24 +16,95 @@ module SoapObject
|
|
9
16
|
end
|
10
17
|
end
|
11
18
|
|
19
|
+
#
|
20
|
+
# Set a proxy server to be used. This will be used for retrieving
|
21
|
+
# the wsdl as well as making the remote requests.
|
22
|
+
#
|
23
|
+
# @param [String] the url for the proxy server
|
24
|
+
#
|
12
25
|
def proxy(url)
|
13
26
|
define_method(:with_proxy) do
|
14
|
-
|
15
|
-
{proxy: @proxy}
|
27
|
+
{proxy: url}
|
16
28
|
end
|
17
29
|
end
|
18
30
|
|
31
|
+
#
|
32
|
+
# Sets the open timeout for retrieving the wsdl and making remote
|
33
|
+
# requests.
|
34
|
+
#
|
35
|
+
# @param [Fixnum] the number of seconds for the timeout value
|
36
|
+
#
|
19
37
|
def open_timeout(timeout)
|
20
38
|
define_method(:with_open_timeout) do
|
21
|
-
|
22
|
-
{open_timeout: @open_timeout}
|
39
|
+
{open_timeout: timeout}
|
23
40
|
end
|
24
41
|
end
|
25
42
|
|
43
|
+
#
|
44
|
+
# Sets the read timeout for retrieving the wsdl and reading the
|
45
|
+
# results of remote requests.
|
46
|
+
#
|
47
|
+
# @param [Fixnum] the number of seconds for the timeout value
|
48
|
+
#
|
26
49
|
def read_timeout(timeout)
|
27
50
|
define_method(:with_read_timeout) do
|
28
|
-
|
29
|
-
|
51
|
+
{read_timeout: timeout}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# Add custom XML to the soap header.
|
57
|
+
#
|
58
|
+
# @param [Hash] will be converted into xml and placed in the soap
|
59
|
+
# header
|
60
|
+
#
|
61
|
+
def soap_header(hsh)
|
62
|
+
define_method(:with_soap_header) do
|
63
|
+
{soap_header: hsh}
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# Set the encoding for the message
|
69
|
+
#
|
70
|
+
# @param [String] the encoding to use
|
71
|
+
#
|
72
|
+
def encoding(enc)
|
73
|
+
define_method(:with_encoding) do
|
74
|
+
{encoding: enc}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
#
|
79
|
+
# Use basic authentication for all requests
|
80
|
+
#
|
81
|
+
# @param [Array] username and password
|
82
|
+
#
|
83
|
+
def basic_auth(*name_password)
|
84
|
+
define_method(:with_basic_auth) do
|
85
|
+
{basic_auth: name_password}
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# Use digest authentiation for all requests
|
91
|
+
#
|
92
|
+
# @param [Array] username and password
|
93
|
+
#
|
94
|
+
def digest_auth(*name_password)
|
95
|
+
define_method(:with_digest_auth) do
|
96
|
+
{digest_auth: name_password}
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
#
|
101
|
+
# Set the log level used for logging
|
102
|
+
#
|
103
|
+
# [Symbol] valid values are :info, :debug, :warn, :error, and :fatal
|
104
|
+
#
|
105
|
+
def log_level(level)
|
106
|
+
define_method(:with_log_level) do
|
107
|
+
{log_level: level}
|
30
108
|
end
|
31
109
|
end
|
32
110
|
end
|
data/lib/soap-object/version.rb
CHANGED
@@ -7,6 +7,11 @@ class TestServiceWithWsdl
|
|
7
7
|
proxy 'http://proxy.com:8080'
|
8
8
|
open_timeout 10
|
9
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
|
10
15
|
end
|
11
16
|
|
12
17
|
|
@@ -21,7 +26,7 @@ describe SoapObject do
|
|
21
26
|
end
|
22
27
|
|
23
28
|
it "should initialize the client using the wsdl" do
|
24
|
-
subject.client_properties[:wsdl].should == 'http://blah.com'
|
29
|
+
subject.send(:client_properties)[:wsdl].should == 'http://blah.com'
|
25
30
|
end
|
26
31
|
|
27
32
|
it "should know when it is connected to service" do
|
@@ -29,15 +34,35 @@ describe SoapObject do
|
|
29
34
|
end
|
30
35
|
|
31
36
|
it "should allow one to setup a proxy" do
|
32
|
-
subject.client_properties[:proxy].should == 'http://proxy.com:8080'
|
37
|
+
subject.send(:client_properties)[:proxy].should == 'http://proxy.com:8080'
|
33
38
|
end
|
34
39
|
|
35
40
|
it "should allow one to set an open timeout" do
|
36
|
-
subject.client_properties[:open_timeout].should == 10
|
41
|
+
subject.send(:client_properties)[:open_timeout].should == 10
|
37
42
|
end
|
38
43
|
|
39
44
|
it "should allow one to set a read timeout" do
|
40
|
-
subject.client_properties[:read_timeout].should == 20
|
45
|
+
subject.send(:client_properties)[:read_timeout].should == 20
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should allow one to set a soap header" do
|
49
|
+
subject.send(:client_properties)[:soap_header].should == {'Token' => 'secret'}
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should allow one to set the encoding" do
|
53
|
+
subject.send(:client_properties)[:encoding].should == 'UTF-16'
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should allow one to use basic authentication" do
|
57
|
+
subject.send(:client_properties)[:basic_auth].should == ['steve', 'secret']
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should allow one to use digest authentication" do
|
61
|
+
subject.send(:client_properties)[:digest_auth].should == ['digest', 'auth']
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should allow one to set the log level" do
|
65
|
+
subject.send(:client_properties)[:log_level].should == :error
|
41
66
|
end
|
42
67
|
end
|
43
68
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soap-object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: savon
|
@@ -100,7 +100,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
100
|
version: '0'
|
101
101
|
segments:
|
102
102
|
- 0
|
103
|
-
hash: -
|
103
|
+
hash: -4037676578174017832
|
104
104
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
version: '0'
|
110
110
|
segments:
|
111
111
|
- 0
|
112
|
-
hash: -
|
112
|
+
hash: -4037676578174017832
|
113
113
|
requirements: []
|
114
114
|
rubyforge_project:
|
115
115
|
rubygems_version: 1.8.25
|