soap-object 0.6.3 → 0.6.4
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.
- checksums.yaml +8 -8
- data/.gitignore +20 -20
- data/.rspec +1 -1
- data/.ruby-gemset +1 -1
- data/.ruby-version +1 -1
- data/ChangeLog +50 -50
- data/Gemfile +11 -11
- data/Guardfile +17 -17
- data/LICENSE.txt +21 -21
- data/README.md +42 -42
- data/Rakefile +21 -21
- data/cucumber.yml +6 -6
- data/features/basic_functionality.feature +40 -40
- data/features/step_definitions/basic_functionality_steps.rb +89 -89
- data/features/support/env.rb +5 -5
- data/features/wsdl/uszip.asmx.wsdl.xml +394 -394
- data/lib/soap-object.rb +132 -128
- data/lib/soap-object/class_methods.rb +131 -125
- data/lib/soap-object/factory.rb +22 -22
- data/lib/soap-object/version.rb +5 -5
- data/soap-object.gemspec +24 -24
- data/spec/lib/factory_spec.rb +35 -0
- data/spec/lib/soap_object_spec.rb +145 -143
- data/spec/spec_helper.rb +6 -6
- metadata +6 -3
data/lib/soap-object.rb
CHANGED
@@ -1,128 +1,132 @@
|
|
1
|
-
require 'savon'
|
2
|
-
require 'cgi'
|
3
|
-
require 'soap-object/version'
|
4
|
-
require 'soap-object/class_methods'
|
5
|
-
require 'soap-object/factory'
|
6
|
-
|
7
|
-
#
|
8
|
-
# module to make it simpler to tests SOAP web services. The goal is
|
9
|
-
# to abstract all information about how your call and parse results
|
10
|
-
# from the web service within the soap objects.
|
11
|
-
#
|
12
|
-
# @example
|
13
|
-
# class ZipCodeService
|
14
|
-
# include SoapObject
|
15
|
-
#
|
16
|
-
# wsdl 'http://www.webservicex.net/uszip.asmx?WSDL'
|
17
|
-
#
|
18
|
-
# def get_zipcode_info(zip_code)
|
19
|
-
# get_info_by_zip 'USZip' => zip_code
|
20
|
-
# end
|
21
|
-
#
|
22
|
-
# def state
|
23
|
-
# message[:state]
|
24
|
-
# end
|
25
|
-
#
|
26
|
-
# message
|
27
|
-
# response.body[:get_info_by_zip_response][:get_info_by_zip_result][:new_data_set][:table]
|
28
|
-
# end
|
29
|
-
# end
|
30
|
-
#
|
31
|
-
# There are many additional properties that can be set to configure
|
32
|
-
# the service calls. See the comments for SoapObject::ClassMethods to
|
33
|
-
# view all of the options.
|
34
|
-
#
|
35
|
-
module SoapObject
|
36
|
-
attr_reader :wsdl, :response
|
37
|
-
|
38
|
-
def initialize
|
39
|
-
@client = Savon.client(client_properties)
|
40
|
-
end
|
41
|
-
|
42
|
-
def self.included(cls)
|
43
|
-
cls.extend SoapObject::ClassMethods
|
44
|
-
end
|
45
|
-
|
46
|
-
#
|
47
|
-
# Returns true if the service has established communication with the
|
48
|
-
# remote server.
|
49
|
-
#
|
50
|
-
def connected?
|
51
|
-
not @client.nil?
|
52
|
-
end
|
53
|
-
|
54
|
-
#
|
55
|
-
# Returns an array of operations that can be called on the remote
|
56
|
-
# service.
|
57
|
-
#
|
58
|
-
def operations
|
59
|
-
@client.operations
|
60
|
-
end
|
61
|
-
|
62
|
-
#
|
63
|
-
# Return the xml response
|
64
|
-
#
|
65
|
-
def to_xml
|
66
|
-
response.to_xml
|
67
|
-
end
|
68
|
-
|
69
|
-
#
|
70
|
-
# Return value at xpath
|
71
|
-
#
|
72
|
-
def xpath(path)
|
73
|
-
response.xpath(path)
|
74
|
-
end
|
75
|
-
|
76
|
-
#
|
77
|
-
# Return the response as a Hash
|
78
|
-
#
|
79
|
-
def to_hash
|
80
|
-
response.hash
|
81
|
-
end
|
82
|
-
|
83
|
-
#
|
84
|
-
# Return the body of the message as a Hash
|
85
|
-
#
|
86
|
-
def body
|
87
|
-
response.body
|
88
|
-
end
|
89
|
-
|
90
|
-
#
|
91
|
-
# Return the response as a Nokogiri document
|
92
|
-
#
|
93
|
-
def doc
|
94
|
-
response.doc
|
95
|
-
end
|
96
|
-
|
97
|
-
private
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
:
|
117
|
-
:
|
118
|
-
:
|
119
|
-
:
|
120
|
-
:
|
121
|
-
:
|
122
|
-
:
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
end
|
1
|
+
require 'savon'
|
2
|
+
require 'cgi'
|
3
|
+
require 'soap-object/version'
|
4
|
+
require 'soap-object/class_methods'
|
5
|
+
require 'soap-object/factory'
|
6
|
+
|
7
|
+
#
|
8
|
+
# module to make it simpler to tests SOAP web services. The goal is
|
9
|
+
# to abstract all information about how your call and parse results
|
10
|
+
# from the web service within the soap objects.
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
# class ZipCodeService
|
14
|
+
# include SoapObject
|
15
|
+
#
|
16
|
+
# wsdl 'http://www.webservicex.net/uszip.asmx?WSDL'
|
17
|
+
#
|
18
|
+
# def get_zipcode_info(zip_code)
|
19
|
+
# get_info_by_zip 'USZip' => zip_code
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
# def state
|
23
|
+
# message[:state]
|
24
|
+
# end
|
25
|
+
#
|
26
|
+
# message
|
27
|
+
# response.body[:get_info_by_zip_response][:get_info_by_zip_result][:new_data_set][:table]
|
28
|
+
# end
|
29
|
+
# end
|
30
|
+
#
|
31
|
+
# There are many additional properties that can be set to configure
|
32
|
+
# the service calls. See the comments for SoapObject::ClassMethods to
|
33
|
+
# view all of the options.
|
34
|
+
#
|
35
|
+
module SoapObject
|
36
|
+
attr_reader :wsdl, :response
|
37
|
+
|
38
|
+
def initialize
|
39
|
+
@client = Savon.client(client_properties)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.included(cls)
|
43
|
+
cls.extend SoapObject::ClassMethods
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Returns true if the service has established communication with the
|
48
|
+
# remote server.
|
49
|
+
#
|
50
|
+
def connected?
|
51
|
+
not @client.nil?
|
52
|
+
end
|
53
|
+
|
54
|
+
#
|
55
|
+
# Returns an array of operations that can be called on the remote
|
56
|
+
# service.
|
57
|
+
#
|
58
|
+
def operations
|
59
|
+
@client.operations
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# Return the xml response
|
64
|
+
#
|
65
|
+
def to_xml
|
66
|
+
response.to_xml
|
67
|
+
end
|
68
|
+
|
69
|
+
#
|
70
|
+
# Return value at xpath
|
71
|
+
#
|
72
|
+
def xpath(path)
|
73
|
+
response.xpath(path)
|
74
|
+
end
|
75
|
+
|
76
|
+
#
|
77
|
+
# Return the response as a Hash
|
78
|
+
#
|
79
|
+
def to_hash
|
80
|
+
response.hash
|
81
|
+
end
|
82
|
+
|
83
|
+
#
|
84
|
+
# Return the body of the message as a Hash
|
85
|
+
#
|
86
|
+
def body
|
87
|
+
response.body
|
88
|
+
end
|
89
|
+
|
90
|
+
#
|
91
|
+
# Return the response as a Nokogiri document
|
92
|
+
#
|
93
|
+
def doc
|
94
|
+
response.doc
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
DEFAULT_PROPERTIES = {log: false,
|
99
|
+
ssl_verify_mode: :none,
|
100
|
+
ssl_version: :SSLv3}
|
101
|
+
|
102
|
+
def method_missing(*args)
|
103
|
+
operation =args.shift
|
104
|
+
message = args.shift
|
105
|
+
type = message.is_a?(String) ? :xml : :message
|
106
|
+
call(operation, {type => message})
|
107
|
+
end
|
108
|
+
|
109
|
+
def call(operation, data)
|
110
|
+
@response = @client.call(operation, data)
|
111
|
+
response.to_xml
|
112
|
+
end
|
113
|
+
|
114
|
+
def client_properties
|
115
|
+
properties = DEFAULT_PROPERTIES
|
116
|
+
[:with_wsdl,
|
117
|
+
:with_proxy,
|
118
|
+
:with_open_timeout,
|
119
|
+
:with_read_timeout,
|
120
|
+
:with_soap_header,
|
121
|
+
:with_encoding,
|
122
|
+
:with_basic_auth,
|
123
|
+
:with_digest_auth,
|
124
|
+
:with_log_level,
|
125
|
+
:with_ssl_verification,
|
126
|
+
:with_ssl_version].each do |sym|
|
127
|
+
properties = properties.merge(self.send sym) if self.respond_to? sym
|
128
|
+
end
|
129
|
+
properties
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
@@ -1,125 +1,131 @@
|
|
1
|
-
|
2
|
-
module SoapObject
|
3
|
-
module ClassMethods
|
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 [String] either the local path to or the remote url to
|
10
|
-
# the wsdl to use for all requests.
|
11
|
-
#
|
12
|
-
def wsdl(url)
|
13
|
-
define_method(:with_wsdl) do
|
14
|
-
@wsdl ||= url
|
15
|
-
{wsdl: @wsdl}
|
16
|
-
end
|
17
|
-
end
|
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
|
-
#
|
25
|
-
def proxy(url)
|
26
|
-
define_method(:with_proxy) do
|
27
|
-
{proxy: url}
|
28
|
-
end
|
29
|
-
end
|
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
|
-
#
|
37
|
-
def open_timeout(timeout)
|
38
|
-
define_method(:with_open_timeout) do
|
39
|
-
{open_timeout: timeout}
|
40
|
-
end
|
41
|
-
end
|
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
|
-
#
|
49
|
-
def read_timeout(timeout)
|
50
|
-
define_method(:with_read_timeout) do
|
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: true, log_level: level}
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
#
|
112
|
-
# Enable/Disable SSL verification when calling services over HTTPS (Default is true)
|
113
|
-
#
|
114
|
-
# @param [Boolean] valid values are true, false
|
115
|
-
#
|
116
|
-
def ssl_verification(enable)
|
117
|
-
|
118
|
-
define_method(:with_ssl_verification) do
|
119
|
-
{ssl_verify_mode:
|
120
|
-
end
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
|
125
|
-
|
1
|
+
|
2
|
+
module SoapObject
|
3
|
+
module ClassMethods
|
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 [String] either the local path to or the remote url to
|
10
|
+
# the wsdl to use for all requests.
|
11
|
+
#
|
12
|
+
def wsdl(url)
|
13
|
+
define_method(:with_wsdl) do
|
14
|
+
@wsdl ||= url
|
15
|
+
{wsdl: @wsdl}
|
16
|
+
end
|
17
|
+
end
|
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
|
+
#
|
25
|
+
def proxy(url)
|
26
|
+
define_method(:with_proxy) do
|
27
|
+
{proxy: url}
|
28
|
+
end
|
29
|
+
end
|
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
|
+
#
|
37
|
+
def open_timeout(timeout)
|
38
|
+
define_method(:with_open_timeout) do
|
39
|
+
{open_timeout: timeout}
|
40
|
+
end
|
41
|
+
end
|
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
|
+
#
|
49
|
+
def read_timeout(timeout)
|
50
|
+
define_method(:with_read_timeout) do
|
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: true, log_level: level, pretty_print_xml: true}
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
#
|
112
|
+
# Enable/Disable SSL verification when calling services over HTTPS (Default is true)
|
113
|
+
#
|
114
|
+
# @param [Boolean] valid values are true, false
|
115
|
+
#
|
116
|
+
def ssl_verification(enable)
|
117
|
+
if enable
|
118
|
+
define_method(:with_ssl_verification) do
|
119
|
+
{ssl_verify_mode: nil}
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def ssl_version(version)
|
125
|
+
define_method(:with_ssl_version) do
|
126
|
+
{ssl_version: version}
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
end
|