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.
- checksums.yaml +5 -13
- data/.gitignore +21 -20
- data/.rspec +1 -1
- data/.ruby-gemset +1 -1
- data/.ruby-version +1 -1
- data/ChangeLog +66 -50
- data/Gemfile +11 -11
- data/Guardfile +17 -17
- data/LICENSE.txt +21 -21
- data/README.md +131 -42
- data/Rakefile +24 -21
- data/cucumber.yml +6 -6
- data/features/core_functionality.feature +24 -0
- data/features/response_functionality.feature +21 -0
- data/features/step_definitions/core_functionality_steps.rb +28 -0
- data/features/step_definitions/response_steps.rb +35 -0
- data/features/support/env.rb +7 -5
- data/features/support/services/define_service.rb +9 -0
- data/features/support/services/local_wsdl_service.rb +5 -0
- data/features/support/services/zip_code_service.rb +28 -0
- data/features/wsdl/uszip.asmx.wsdl.xml +394 -394
- data/lib/soap-object.rb +100 -128
- data/lib/soap-object/class_methods.rb +143 -125
- data/lib/soap-object/factory.rb +22 -22
- data/lib/soap-object/response.rb +39 -0
- data/lib/soap-object/ssl_options.rb +22 -0
- data/lib/soap-object/version.rb +3 -5
- data/soap-object.gemspec +24 -24
- data/spec/lib/client_options_spec.rb +119 -0
- data/spec/lib/factory_spec.rb +25 -0
- data/spec/lib/soap_object_spec.rb +37 -143
- data/spec/lib/ssl_options_spec.rb +27 -0
- data/spec/spec_helper.rb +45 -6
- metadata +41 -23
- data/features/basic_functionality.feature +0 -40
- data/features/step_definitions/basic_functionality_steps.rb +0 -89
data/lib/soap-object.rb
CHANGED
@@ -1,128 +1,100 @@
|
|
1
|
-
require 'savon'
|
2
|
-
require '
|
3
|
-
require 'soap-object/
|
4
|
-
require 'soap-object/
|
5
|
-
require 'soap-object/factory'
|
6
|
-
|
7
|
-
|
8
|
-
#
|
9
|
-
# to
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
#
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
#
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
response.
|
74
|
-
end
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
message = args.shift
|
102
|
-
type = message.is_a?(String) ? :xml : :message
|
103
|
-
call(operation, {type => message})
|
104
|
-
end
|
105
|
-
|
106
|
-
def call(operation, data)
|
107
|
-
@response = @client.call(operation, data)
|
108
|
-
response.to_xml
|
109
|
-
end
|
110
|
-
|
111
|
-
def client_properties
|
112
|
-
properties = { log: false }
|
113
|
-
[:with_wsdl,
|
114
|
-
:with_proxy,
|
115
|
-
:with_open_timeout,
|
116
|
-
:with_read_timeout,
|
117
|
-
:with_soap_header,
|
118
|
-
:with_encoding,
|
119
|
-
:with_basic_auth,
|
120
|
-
:with_digest_auth,
|
121
|
-
:with_log_level,
|
122
|
-
:with_ssl_verification].each do |sym|
|
123
|
-
properties = properties.merge(self.send sym) if self.respond_to? sym
|
124
|
-
end
|
125
|
-
properties
|
126
|
-
end
|
127
|
-
|
128
|
-
end
|
1
|
+
require 'savon'
|
2
|
+
require 'soap-object/version'
|
3
|
+
require 'soap-object/class_methods'
|
4
|
+
require 'soap-object/ssl_options'
|
5
|
+
require 'soap-object/factory'
|
6
|
+
require 'soap-object/response'
|
7
|
+
|
8
|
+
#
|
9
|
+
# module to make it simpler to tests SOAP web services. The goal is
|
10
|
+
# to abstract all information about how your call and parse results
|
11
|
+
# from the web service within the soap objects.
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
# class ZipCodeService
|
15
|
+
# include SoapObject
|
16
|
+
#
|
17
|
+
# wsdl 'http://www.webservicex.net/uszip.asmx?WSDL'
|
18
|
+
#
|
19
|
+
# def get_zipcode_info(zip_code)
|
20
|
+
# get_info_by_zip 'USZip' => zip_code
|
21
|
+
# end
|
22
|
+
#
|
23
|
+
# def state
|
24
|
+
# message[:state]
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# message
|
28
|
+
# response.body[:get_info_by_zip_response][:get_info_by_zip_result][:new_data_set][:table]
|
29
|
+
# end
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# There are many additional properties that can be set to configure
|
33
|
+
# the service calls. See the comments for SoapObject::ClassMethods to
|
34
|
+
# view all of the options.
|
35
|
+
#
|
36
|
+
module SoapObject
|
37
|
+
include Response
|
38
|
+
|
39
|
+
attr_reader :wsdl, :response
|
40
|
+
|
41
|
+
def initialize(platform)
|
42
|
+
@client = platform.client(client_properties)
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.included(cls)
|
46
|
+
cls.extend SoapObject::ClassMethods
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# Returns true if the service has established communication with the
|
51
|
+
# remote server.
|
52
|
+
#
|
53
|
+
def connected?
|
54
|
+
not @client.nil?
|
55
|
+
end
|
56
|
+
|
57
|
+
#
|
58
|
+
# Returns an array of operations that can be called on the remote
|
59
|
+
# service.
|
60
|
+
#
|
61
|
+
def operations
|
62
|
+
@client.operations
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
DEFAULT_PROPERTIES = {log: false,
|
67
|
+
ssl_verify_mode: :none,
|
68
|
+
ssl_version: :SSLv3}
|
69
|
+
|
70
|
+
def method_missing(operation, body)
|
71
|
+
request = build_request(body)
|
72
|
+
@response = @client.call(operation, request)
|
73
|
+
response.to_xml
|
74
|
+
end
|
75
|
+
|
76
|
+
def build_request(body)
|
77
|
+
type = body.is_a?(Hash) ? :message : :xml
|
78
|
+
{type => body}
|
79
|
+
end
|
80
|
+
|
81
|
+
def client_properties
|
82
|
+
properties = DEFAULT_PROPERTIES
|
83
|
+
[:with_wsdl,
|
84
|
+
:with_endpoint,
|
85
|
+
:with_proxy,
|
86
|
+
:with_open_timeout,
|
87
|
+
:with_read_timeout,
|
88
|
+
:with_soap_header,
|
89
|
+
:with_encoding,
|
90
|
+
:with_basic_auth,
|
91
|
+
:with_digest_auth,
|
92
|
+
:with_log_level,
|
93
|
+
:with_soap_version,
|
94
|
+
:with_ssl_options].each do |sym|
|
95
|
+
properties = properties.merge(self.send sym) if self.respond_to? sym
|
96
|
+
end
|
97
|
+
properties
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
@@ -1,125 +1,143 @@
|
|
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
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
#
|
32
|
-
#
|
33
|
-
# requests.
|
34
|
-
#
|
35
|
-
# @param [
|
36
|
-
#
|
37
|
-
def
|
38
|
-
define_method(:
|
39
|
-
{
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
#
|
44
|
-
# Sets the
|
45
|
-
#
|
46
|
-
#
|
47
|
-
# @param [Fixnum] the number of seconds for the timeout value
|
48
|
-
#
|
49
|
-
def
|
50
|
-
define_method(:
|
51
|
-
{
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
#
|
56
|
-
#
|
57
|
-
#
|
58
|
-
#
|
59
|
-
#
|
60
|
-
#
|
61
|
-
def
|
62
|
-
define_method(:
|
63
|
-
{
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
# @param [
|
71
|
-
#
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
#
|
91
|
-
#
|
92
|
-
#
|
93
|
-
#
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
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
|
-
|
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
|
+
# Override the endpoint binding in the WSDL
|
21
|
+
#
|
22
|
+
# @param [String] The target namespace is used to namespace the SOAP message.
|
23
|
+
#
|
24
|
+
def endpoint(url)
|
25
|
+
define_method(:with_endpoint) do
|
26
|
+
{endpoint: url}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
#
|
32
|
+
# Set a proxy server to be used. This will be used for retrieving
|
33
|
+
# the wsdl as well as making the remote requests.
|
34
|
+
#
|
35
|
+
# @param [String] the url for the proxy server
|
36
|
+
#
|
37
|
+
def proxy(url)
|
38
|
+
define_method(:with_proxy) do
|
39
|
+
{proxy: url}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
#
|
44
|
+
# Sets the open timeout for retrieving the wsdl and making remote
|
45
|
+
# requests.
|
46
|
+
#
|
47
|
+
# @param [Fixnum] the number of seconds for the timeout value
|
48
|
+
#
|
49
|
+
def open_timeout(timeout)
|
50
|
+
define_method(:with_open_timeout) do
|
51
|
+
{open_timeout: timeout}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
# Sets the read timeout for retrieving the wsdl and reading the
|
57
|
+
# results of remote requests.
|
58
|
+
#
|
59
|
+
# @param [Fixnum] the number of seconds for the timeout value
|
60
|
+
#
|
61
|
+
def read_timeout(timeout)
|
62
|
+
define_method(:with_read_timeout) do
|
63
|
+
{read_timeout: timeout}
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
#
|
68
|
+
# Add custom XML to the soap header.
|
69
|
+
#
|
70
|
+
# @param [Hash] will be converted into xml and placed in the soap
|
71
|
+
# header
|
72
|
+
#
|
73
|
+
def soap_header(hsh)
|
74
|
+
define_method(:with_soap_header) do
|
75
|
+
{soap_header: hsh}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
#
|
80
|
+
# Set the encoding for the message
|
81
|
+
#
|
82
|
+
# @param [String] the encoding to use
|
83
|
+
#
|
84
|
+
def encoding(enc)
|
85
|
+
define_method(:with_encoding) do
|
86
|
+
{encoding: enc}
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
#
|
91
|
+
# Use basic authentication for all requests
|
92
|
+
#
|
93
|
+
# @param [Array] username and password
|
94
|
+
#
|
95
|
+
def basic_auth(*name_password)
|
96
|
+
define_method(:with_basic_auth) do
|
97
|
+
{basic_auth: name_password}
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# Use digest authentiation for all requests
|
103
|
+
#
|
104
|
+
# @param [Array] username and password
|
105
|
+
#
|
106
|
+
def digest_auth(*name_password)
|
107
|
+
define_method(:with_digest_auth) do
|
108
|
+
{digest_auth: name_password}
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
#
|
113
|
+
# Set the log level used for logging
|
114
|
+
#
|
115
|
+
# [Symbol] valid values are :info, :debug, :warn, :error, and :fatal
|
116
|
+
#
|
117
|
+
def log_level(level)
|
118
|
+
define_method(:with_log_level) do
|
119
|
+
{log: true, log_level: level, pretty_print_xml: true}
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
#
|
124
|
+
# Set the ssl options
|
125
|
+
#
|
126
|
+
# @param [block] Available options in SslOptions class
|
127
|
+
#
|
128
|
+
def ssl_options(&block)
|
129
|
+
ssl = SslOptions.new(&block)
|
130
|
+
|
131
|
+
define_method(:with_ssl_options) do
|
132
|
+
ssl.options
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def soap_version(version)
|
137
|
+
define_method(:with_soap_version) do
|
138
|
+
{soap_version: version}
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
end
|