savon 0.7.9 → 0.8.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/.rspec +1 -0
- data/.yardopts +2 -0
- data/CHANGELOG.md +332 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +37 -0
- data/Rakefile +28 -39
- data/autotest/discover.rb +1 -0
- data/lib/savon.rb +10 -31
- data/lib/savon/client.rb +116 -98
- data/lib/savon/core_ext/array.rb +36 -22
- data/lib/savon/core_ext/datetime.rb +15 -6
- data/lib/savon/core_ext/hash.rb +122 -94
- data/lib/savon/core_ext/object.rb +19 -11
- data/lib/savon/core_ext/string.rb +62 -57
- data/lib/savon/core_ext/symbol.rb +13 -5
- data/lib/savon/error.rb +6 -0
- data/lib/savon/global.rb +75 -0
- data/lib/savon/http/error.rb +42 -0
- data/lib/savon/soap.rb +8 -283
- data/lib/savon/soap/fault.rb +48 -0
- data/lib/savon/soap/request.rb +61 -0
- data/lib/savon/soap/response.rb +65 -0
- data/lib/savon/soap/xml.rb +132 -0
- data/lib/savon/version.rb +2 -2
- data/lib/savon/wsdl/document.rb +107 -0
- data/lib/savon/wsdl/parser.rb +90 -0
- data/lib/savon/wsdl/request.rb +35 -0
- data/lib/savon/wsse.rb +42 -104
- data/savon.gemspec +26 -0
- data/spec/fixtures/response/response_fixture.rb +26 -26
- data/spec/fixtures/response/xml/list.xml +18 -0
- data/spec/fixtures/wsdl/wsdl_fixture.rb +6 -0
- data/spec/fixtures/wsdl/wsdl_fixture.yml +4 -4
- data/spec/savon/client_spec.rb +274 -51
- data/spec/savon/core_ext/datetime_spec.rb +1 -1
- data/spec/savon/core_ext/hash_spec.rb +40 -4
- data/spec/savon/core_ext/object_spec.rb +1 -1
- data/spec/savon/core_ext/string_spec.rb +0 -12
- data/spec/savon/http/error_spec.rb +52 -0
- data/spec/savon/savon_spec.rb +90 -0
- data/spec/savon/soap/fault_spec.rb +80 -0
- data/spec/savon/soap/request_spec.rb +45 -0
- data/spec/savon/soap/response_spec.rb +153 -0
- data/spec/savon/soap/xml_spec.rb +249 -0
- data/spec/savon/soap_spec.rb +4 -177
- data/spec/savon/{wsdl_spec.rb → wsdl/document_spec.rb} +54 -17
- data/spec/savon/wsdl/request_spec.rb +15 -0
- data/spec/savon/wsse_spec.rb +123 -92
- data/spec/spec_helper.rb +19 -4
- data/spec/support/endpoint.rb +25 -0
- metadata +97 -97
- data/.autotest +0 -5
- data/CHANGELOG +0 -176
- data/README.rdoc +0 -64
- data/lib/savon/core_ext.rb +0 -8
- data/lib/savon/core_ext/net_http.rb +0 -19
- data/lib/savon/core_ext/uri.rb +0 -10
- data/lib/savon/logger.rb +0 -56
- data/lib/savon/request.rb +0 -138
- data/lib/savon/response.rb +0 -174
- data/lib/savon/wsdl.rb +0 -137
- data/lib/savon/wsdl_stream.rb +0 -85
- data/spec/basic_spec_helper.rb +0 -11
- data/spec/endpoint_helper.rb +0 -23
- data/spec/http_stubs.rb +0 -26
- data/spec/integration/http_basic_auth_spec.rb +0 -16
- data/spec/integration/server.rb +0 -51
- data/spec/savon/core_ext/net_http_spec.rb +0 -38
- data/spec/savon/core_ext/uri_spec.rb +0 -19
- data/spec/savon/request_spec.rb +0 -117
- data/spec/savon/response_spec.rb +0 -179
- data/spec/spec.opts +0 -4
data/.autotest
DELETED
data/CHANGELOG
DELETED
@@ -1,176 +0,0 @@
|
|
1
|
-
== 0.7.9 (2010-06-14)
|
2
|
-
* Fix for issue #53 (DateTime.to_soap_value assumes UTC).
|
3
|
-
|
4
|
-
== 0.7.8 (2010-05-09)
|
5
|
-
* Fixed gemspec to include missing files (*.yml, *.gz, .autotest and spec/spec.opts) in the gem.
|
6
|
-
|
7
|
-
== 0.7.7 (2010-05-09)
|
8
|
-
* SOAP requests now start with a proper XML declaration.
|
9
|
-
* Added support for gzipped requests and responses (http://github.com/lucascs). While gzipped SOAP
|
10
|
-
responses are decoded automatically, you have to manually instruct Savon to gzip SOAP requests:
|
11
|
-
|
12
|
-
client = Savon::Client.new "http://example.com/UserService?wsdl", :gzip => true
|
13
|
-
|
14
|
-
* Fix for issue #51. Added the :soap_endpoint option to Savon::Client.new which let's you specify a SOAP
|
15
|
-
endpoint per client instance:
|
16
|
-
|
17
|
-
client = Savon::Client.new "http://example.com/UserService?wsdl",
|
18
|
-
:soap_endpoint => "http://localhost/UserService"
|
19
|
-
|
20
|
-
* Fix for issue #50. Savon still escapes special characters in SOAP request Hash values, but you can now
|
21
|
-
append an exclamation mark to Hash keys specifying that it's value should not be escaped.
|
22
|
-
|
23
|
-
== 0.7.6 (2010-03-21)
|
24
|
-
* Moved documentation from the Github Wiki to the actual class files and established a much nicer
|
25
|
-
documentation combining examples and implementation (using Hanna) at: http://savon.rubiii.com
|
26
|
-
* Added Savon::Client#call as a workaround for dispatching calls to SOAP actions named after
|
27
|
-
existing methods. Fix for issue #48.
|
28
|
-
* Add support for specifying attributes for duplicate tags (via Hash values as Arrays). Fix for issue #45.
|
29
|
-
* Fix for issue #41 (Escape special characters (e.g. &) for XML requests).
|
30
|
-
* Fix for issue #39 and #49. Added Savon::SOAP#xml which let's you specify completely custom SOAP request XML.
|
31
|
-
|
32
|
-
== 0.7.5 (2010-02-19)
|
33
|
-
* Fix for issue #34 (soap_actions returns empty for wsdl12).
|
34
|
-
* Fix for issue #36 (Custom WSDL actions broken).
|
35
|
-
* Added feature requested in issue #35 (Setting an attribute on an element?).
|
36
|
-
* Changed the key for specifying the order of tags from :@inorder to :order!
|
37
|
-
|
38
|
-
== 0.7.4 (2010-02-02)
|
39
|
-
* Fix for issue #33 (undefined method 'start_with?').
|
40
|
-
|
41
|
-
== 0.7.3 (2010-01-31)
|
42
|
-
* Added support for Geotrust-style WSDL documents (Julian Kornberger <github.corny@digineo.de>).
|
43
|
-
* Make HTTP requests include path and query only. This was breaking requests via proxy as scheme and host
|
44
|
-
were repeated (Adrian Mugnolo <adrian@mugnolo.com>)
|
45
|
-
* Avoid warning on 1.8.7 and 1.9.1 (Adrian Mugnolo <adrian@mugnolo.com>).
|
46
|
-
* Fix for issue #29 (WSSE Created Bug?). Default to UTC to xs:dateTime value for WSSE authentication.
|
47
|
-
* Fix for issue #28 (Undefined Method ssl? on URI::Generic).
|
48
|
-
* Fix for issue #27 (http content-type defaults to utf-8). The Content-Type now defaults to UTF-8.
|
49
|
-
* Modification to allow assignment of an Array with an input name and an optional Hash of values to soap.input.
|
50
|
-
Patches issue #30 (stanleydrew <andrewmbenton@gmail.com>).
|
51
|
-
* Fix for issue #25 (header-tag should not be sent if not set).
|
52
|
-
|
53
|
-
== 0.7.2 (2010-01-17)
|
54
|
-
* Exposed the Net::HTTP response (added by Kevin Ingolfsland). Use the "http" accessor (response.http) on your
|
55
|
-
Savon::Response to access the Net::HTTP response object.
|
56
|
-
* Fix for issue #21 (savon is stripping ?SOAP off the end of WSDL locations).
|
57
|
-
* Fix for issue #22 (REXML::ParseException parsing 401 Unauthorized response body).
|
58
|
-
* Fix for issue #19 (Unable to set attribute in name-spaced WSSE password element).
|
59
|
-
* Added support for global header and namespaces. See issue #9 (Setting headers and namespaces).
|
60
|
-
|
61
|
-
== 0.7.1 (2010-01-10)
|
62
|
-
* The Hash of HTTP headers for SOAP calls is now public via Savon::Request#headers.
|
63
|
-
Patch for: http://github.com/rubiii/savon/issues/#issue/8
|
64
|
-
|
65
|
-
== 0.7.0 (2010-01-09)
|
66
|
-
This version comes with several changes to the public API!
|
67
|
-
Pay attention to the following list and read the updated Wiki: http://wiki.github.com/rubiii/savon
|
68
|
-
|
69
|
-
* Changed how Savon::WSDL can be disabled. Instead of disabling the WSDL globally/per request via two
|
70
|
-
different methods, you now simply append an exclamation mark (!) to your SOAP call: client.get_all_users!
|
71
|
-
Make sure you know what you're doing because when the WSDL is disabled, Savon does not know about which
|
72
|
-
SOAP actions are valid and just dispatches everything.
|
73
|
-
* The Net::HTTP object used by Savon::Request to retrieve WSDL documents and execute SOAP calls is now public.
|
74
|
-
While this makes the library even more flexible, it also comes with two major changes:
|
75
|
-
* SSL client authentication needs to be defined directly on the Net::HTTP object:
|
76
|
-
client.request.http.client_cert = ...
|
77
|
-
I added a shortcut method for setting all options through a Hash similar to the previous implementation:
|
78
|
-
client.request.http.ssl_client_auth :client_cert => ...
|
79
|
-
* Open and read timeouts also need to be set on the Net::HTTP object:
|
80
|
-
client.request.http.open_timeout = 30
|
81
|
-
client.request.http.read_timeout = 30
|
82
|
-
* Please refer to the Net::HTTP documentation for more details:
|
83
|
-
http://www.ruby-doc.org/stdlib/libdoc/net/http/rdoc/index.html
|
84
|
-
* Thanks to JulianMorrison, Savon now supports HTTP basic authentication:
|
85
|
-
client.request.http.basic_auth "username", "password"
|
86
|
-
* Julian also added a way to explicitly specify the order of Hash keys and values, so you should now be able
|
87
|
-
to work with services requiring a specific order of input parameters while still using Hash input.
|
88
|
-
For example: client.find_user { |soap| soap.body = { :name => "Lucy", :id => 666, :@inorder => [:id, :name] } }
|
89
|
-
* Savon::Response#to_hash now returns the content inside of "soap:Body" instead of trying to go one level
|
90
|
-
deeper and return it's content. The previous implementation only worked when the "soap:Body" element
|
91
|
-
contained a single child. See: http://github.com/rubiii/savon/issues#issue/17
|
92
|
-
* Added Savon::SOAP#namespace as a shortcut for setting the "xmlns:wsdl" namespace.
|
93
|
-
Usage example: soap.namespace = "http://example.com"
|
94
|
-
|
95
|
-
== 0.6.8 (2010-01-01)
|
96
|
-
* Improved specifications for various kinds of WSDL documents.
|
97
|
-
* Added support for SOAP endpoints which are different than the WSDL endpoint of a service.
|
98
|
-
* Changed how SOAP actions and inputs are retrieved from the WSDL documents. This might break a few existing
|
99
|
-
implementations, but makes Savon work well with even more services. If this change breaks your implementation,
|
100
|
-
please take a look at the +action+ and +input+ methods of the Savon::SOAP object.
|
101
|
-
One specific problem I know of is working with the createsend WSDL and its namespaced actions.
|
102
|
-
To make it work, call the SOAP action without namespace and specify the input manually:
|
103
|
-
client.get_api_key { |soap| soap.input = "User.GetApiKey" }
|
104
|
-
|
105
|
-
== 0.6.7 (2009-12-18)
|
106
|
-
* Implemented support for a proxy server. The proxy URI can be set through an optional Hash of options passed
|
107
|
-
to instantiating Savon::Client (Dave Woodward <dave@futuremint.com>)
|
108
|
-
* Implemented support for SSL client authentication. Settings can be set through an optional Hash of arguments
|
109
|
-
passed to instantiating Savon::Client (colonhyphenp)
|
110
|
-
* Patch for issue #10 (Problem with operation tags without a namespace).
|
111
|
-
|
112
|
-
== 0.6.6 (2009-12-14)
|
113
|
-
* Default to use the name of the SOAP action (the method called in a client) in lowerCamelCase for SOAP action
|
114
|
-
and input when Savon::WSDL is disabled. You still need to specify soap.action and maybe soap.input in case
|
115
|
-
your SOAP actions are named any different.
|
116
|
-
|
117
|
-
== 0.6.5 (2009-12-13)
|
118
|
-
* Added an open_timeout method to Savon::Request.
|
119
|
-
|
120
|
-
== 0.6.4 (2009-12-13)
|
121
|
-
* Refactored specs to be less unit-like.
|
122
|
-
* Added a getter for the Savon::Request to Savon::Client and a read_timeout setter for HTTP requests.
|
123
|
-
* wsdl.soap_actions now returns an Array of SOAP actions. For the previous "mapping" please use wsdl.operations.
|
124
|
-
* Replaced WSDL document with stream parsing.
|
125
|
-
|
126
|
-
Benchmarks (1000 SOAP calls):
|
127
|
-
|
128
|
-
user system total real
|
129
|
-
0.6.4 72.180000 8.280000 80.460000 (750.799011)
|
130
|
-
0.6.3 192.900000 19.630000 212.530000 (914.031865)
|
131
|
-
|
132
|
-
== 0.6.3 (2009-12-11)
|
133
|
-
* Removing 2 ruby deprecation warnings for parenthesized arguments. (Dave Woodward <dave@futuremint.com>)
|
134
|
-
* Added global and per request options for disabling Savon::WSDL.
|
135
|
-
|
136
|
-
Benchmarks (1000 SOAP calls):
|
137
|
-
|
138
|
-
user system total real
|
139
|
-
WSDL 192.900000 19.630000 212.530000 (914.031865)
|
140
|
-
disabled WSDL 5.680000 1.340000 7.020000 (298.265318)
|
141
|
-
|
142
|
-
* Improved XPath expressions for parsing the WSDL document.
|
143
|
-
|
144
|
-
Benchmarks (1000 SOAP calls):
|
145
|
-
|
146
|
-
user system total real
|
147
|
-
0.6.3 192.900000 19.630000 212.530000 (914.031865)
|
148
|
-
0.6.2 574.720000 78.380000 653.100000 (1387.778539)
|
149
|
-
|
150
|
-
== 0.6.2 (2009-12-06)
|
151
|
-
* Added support for changing the name of the SOAP input node.
|
152
|
-
* Added a CHANGELOG.
|
153
|
-
|
154
|
-
== 0.6.1 (2009-12-06)
|
155
|
-
* Fixed a problem with WSSE credentials, where every request contained a WSSE authentication header.
|
156
|
-
|
157
|
-
== 0.6.0 (2009-12-06)
|
158
|
-
* method_missing now yields the SOAP and WSSE objects to a given block.
|
159
|
-
* The response_process (which previously was a block passed to method_missing) was replaced by Savon::Response.
|
160
|
-
* Improved SOAP action handling (another problem that came up with issue #1).
|
161
|
-
|
162
|
-
== 0.5.3 (2009-11-30)
|
163
|
-
* Patch for issue #2 (NoMethodError: undefined method `invalid!' for Savon::WSDL)
|
164
|
-
|
165
|
-
== 0.5.2 (2009-11-30)
|
166
|
-
* Patch for issue #1 (Calls fail if api methods have periods in them)
|
167
|
-
|
168
|
-
== 0.5.1 (2009-11-29)
|
169
|
-
* Optimized default response process.
|
170
|
-
* Added WSSE settings via defaults.
|
171
|
-
* Added SOAP fault and HTTP error handling.
|
172
|
-
* Improved documentation
|
173
|
-
* Added specs
|
174
|
-
|
175
|
-
== 0.5.0 (2009-11-29)
|
176
|
-
* Complete rewrite.
|
data/README.rdoc
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
= Savon
|
2
|
-
|
3
|
-
==== Heavy metal Ruby SOAP client library
|
4
|
-
|
5
|
-
{Documentation}[http://savon.rubiii.com] | {Metrics}[http://getcaliper.com/caliper/project?repo=git://github.com/rubiii/savon.git]
|
6
|
-
|
7
|
-
== Installation
|
8
|
-
|
9
|
-
$ gem install savon
|
10
|
-
|
11
|
-
Savon expects you to be familiar with SOAP, WSDL and tools like soapUI.
|
12
|
-
|
13
|
-
== Instantiate a client
|
14
|
-
|
15
|
-
Instantiate Savon::Client, passing in the WSDL of your service.
|
16
|
-
|
17
|
-
client = Savon::Client.new "http://example.com/UserService?wsdl"
|
18
|
-
|
19
|
-
For production, it is highly recommended to not use Savon::WSDL. Information on {how to disable the WSDL}[http://savon.rubiii.com/docs/latest/classes/Savon/WSDL.html].
|
20
|
-
|
21
|
-
== Calling a SOAP action
|
22
|
-
|
23
|
-
Assuming your service applies to the defaults, you can now call any available SOAP action.
|
24
|
-
|
25
|
-
response = client.get_all_users
|
26
|
-
|
27
|
-
Savon lets you call SOAP actions using snake_case, because even though they will propably be written in lowerCamelCase or CamelCase, it just feels much more natural.
|
28
|
-
|
29
|
-
== The WSDL object
|
30
|
-
|
31
|
-
Savon::WSDL represents the WSDL of your service, including information like the namespace URI and available SOAP actions.
|
32
|
-
|
33
|
-
client.wsdl.soap_actions
|
34
|
-
=> [:get_all_users, :get_user_by_id, :user_magic]
|
35
|
-
|
36
|
-
== The SOAP object
|
37
|
-
|
38
|
-
Savon::SOAP represents the SOAP request. Pass a block to your SOAP call and the SOAP object is passed to it as the first argument. The object allows setting the SOAP version, header, body and namespaces per request.
|
39
|
-
|
40
|
-
response = client.get_user_by_id { |soap| soap.body = { :id => 666 } }
|
41
|
-
|
42
|
-
== The WSSE object
|
43
|
-
|
44
|
-
Savon::WSSE represents WSSE authentication. Pass a block to your SOAP call and the WSSE object is passed to it as the second argument. The object allows setting the WSSE username, password and whether to use digest authentication.
|
45
|
-
|
46
|
-
response = client.get_user_by_id do |soap, wsse|
|
47
|
-
wsse.username = "gorilla"
|
48
|
-
wsse.password = "secret"
|
49
|
-
soap.body = { :id => 666 }
|
50
|
-
end
|
51
|
-
|
52
|
-
== The Response object
|
53
|
-
|
54
|
-
Savon::Response represents the HTTP and SOAP response. It contains and raises errors in case of an HTTP error or SOAP fault (unless disabled). Also you can get the response as XML (for parsing it with an XML library) or translated into a Hash.
|
55
|
-
|
56
|
-
== HTTP errors and SOAP faults
|
57
|
-
|
58
|
-
Savon raises a Savon::SOAPFault in case of a SOAP fault and a Savon::HTTPError in case of an HTTP error.
|
59
|
-
More information: {Errors}[http://savon.rubiii.com/docs/latest/classes/Savon/Response.html]
|
60
|
-
|
61
|
-
== Logging
|
62
|
-
|
63
|
-
Savon logs each request and response to STDOUT. But there are a couple of options to change the default behavior.
|
64
|
-
More information: {Logging}[http://savon.rubiii.com/docs/latest/classes/Savon/Request.html]
|
data/lib/savon/core_ext.rb
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
require "savon/core_ext/object"
|
2
|
-
require "savon/core_ext/string"
|
3
|
-
require "savon/core_ext/symbol"
|
4
|
-
require "savon/core_ext/datetime"
|
5
|
-
require "savon/core_ext/array"
|
6
|
-
require "savon/core_ext/hash"
|
7
|
-
require "savon/core_ext/uri"
|
8
|
-
require "savon/core_ext/net_http"
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Net
|
2
|
-
class HTTP
|
3
|
-
|
4
|
-
# Sets the endpoint +address+ and +port+.
|
5
|
-
def endpoint(address, port)
|
6
|
-
@address, @port = address, port
|
7
|
-
end
|
8
|
-
|
9
|
-
# Convenience method for setting SSL client authentication through a Hash of +options+.
|
10
|
-
def ssl_client_auth(options)
|
11
|
-
self.use_ssl = true
|
12
|
-
self.cert = options[:cert] if options[:cert]
|
13
|
-
self.key = options[:key] if options[:key]
|
14
|
-
self.ca_file = options[:ca_file] if options[:ca_file]
|
15
|
-
self.verify_mode = options[:verify_mode] if options[:verify_mode]
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
data/lib/savon/core_ext/uri.rb
DELETED
data/lib/savon/logger.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
module Savon
|
2
|
-
|
3
|
-
# = Savon::Logger
|
4
|
-
#
|
5
|
-
# Savon::Logger can be mixed into classes to provide logging behavior.
|
6
|
-
#
|
7
|
-
# By default, the Logger mixin uses {Ruby's Logger}[http://ruby-doc.org/stdlib/libdoc/logger/rdoc/]
|
8
|
-
# from the standard library, a log level of :debug and is pointing to STDOUT.
|
9
|
-
module Logger
|
10
|
-
|
11
|
-
module ClassMethods
|
12
|
-
|
13
|
-
# Sets whether to log.
|
14
|
-
def log=(log)
|
15
|
-
@log = log
|
16
|
-
end
|
17
|
-
|
18
|
-
# Returns whether to log. Defaults to +true+.
|
19
|
-
def log?
|
20
|
-
@log != false
|
21
|
-
end
|
22
|
-
|
23
|
-
# Sets the logger.
|
24
|
-
def logger=(logger)
|
25
|
-
@logger = logger
|
26
|
-
end
|
27
|
-
|
28
|
-
# Returns the logger. Defaults to an instance of +Logger+ writing to STDOUT.
|
29
|
-
def logger
|
30
|
-
@logger ||= ::Logger.new STDOUT
|
31
|
-
end
|
32
|
-
|
33
|
-
# Sets the log level.
|
34
|
-
def log_level=(log_level)
|
35
|
-
@log_level = log_level
|
36
|
-
end
|
37
|
-
|
38
|
-
# Returns the log level. Defaults to +debug+.
|
39
|
-
def log_level
|
40
|
-
@log_level ||= :debug
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
# Extends the class including this module with its ClassMethods.
|
46
|
-
def self.included(base)
|
47
|
-
base.extend ClassMethods
|
48
|
-
end
|
49
|
-
|
50
|
-
# Logs a given +message+.
|
51
|
-
def log(message)
|
52
|
-
self.class.logger.send self.class.log_level, message if self.class.log?
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
end
|
data/lib/savon/request.rb
DELETED
@@ -1,138 +0,0 @@
|
|
1
|
-
module Savon
|
2
|
-
|
3
|
-
# = Savon::Request
|
4
|
-
#
|
5
|
-
# Savon::Request handles both WSDL and SOAP requests.
|
6
|
-
#
|
7
|
-
# == The Net::HTTP object
|
8
|
-
#
|
9
|
-
# You can access the Net::HTTP object used for both WSDL and SOAP requests via:
|
10
|
-
#
|
11
|
-
# client.request.http
|
12
|
-
#
|
13
|
-
# Here's an example of how to set open and read timeouts on the Net::HTTP object.
|
14
|
-
#
|
15
|
-
# client.request.http.open_timeout = 30
|
16
|
-
# client.request.http.read_timeout = 30
|
17
|
-
#
|
18
|
-
# Please refer to the {Net::HTTP documentation}[http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/]
|
19
|
-
# for more information.
|
20
|
-
#
|
21
|
-
# == HTTP basic authentication
|
22
|
-
#
|
23
|
-
# Setting credentials for HTTP basic authentication:
|
24
|
-
#
|
25
|
-
# client.request.basic_auth "username", "password"
|
26
|
-
#
|
27
|
-
# == SSL client authentication
|
28
|
-
#
|
29
|
-
# You can use the methods provided by Net::HTTP to set SSL client authentication or use a shortcut:
|
30
|
-
#
|
31
|
-
# client.request.http.ssl_client_auth(
|
32
|
-
# :cert => OpenSSL::X509::Certificate.new(File.read("client_cert.pem")),
|
33
|
-
# :key => OpenSSL::PKey::RSA.new(File.read("client_key.pem"), "password if one exists"),
|
34
|
-
# :ca_file => "cacert.pem",
|
35
|
-
# :verify_mode => OpenSSL::SSL::VERIFY_PEER
|
36
|
-
# )
|
37
|
-
#
|
38
|
-
# == HTTP headers
|
39
|
-
#
|
40
|
-
# There's an accessor for the Hash of HTTP headers sent with any SOAP call:
|
41
|
-
#
|
42
|
-
# client.request.headers["custom"] = "header"
|
43
|
-
class Request
|
44
|
-
include Logger
|
45
|
-
|
46
|
-
# Content-Types by SOAP version.
|
47
|
-
ContentType = { 1 => "text/xml;charset=UTF-8", 2 => "application/soap+xml;charset=UTF-8" }
|
48
|
-
|
49
|
-
# Expects a WSDL or SOAP +endpoint+ and accepts a custom +proxy+ address.
|
50
|
-
def initialize(endpoint, options = {})
|
51
|
-
@endpoint = URI endpoint
|
52
|
-
@proxy = URI options[:proxy] || ""
|
53
|
-
headers["Accept-encoding"] = "gzip,deflate" if options[:gzip]
|
54
|
-
end
|
55
|
-
|
56
|
-
# Returns the endpoint URI.
|
57
|
-
attr_reader :endpoint
|
58
|
-
|
59
|
-
# Returns the proxy URI.
|
60
|
-
attr_reader :proxy
|
61
|
-
|
62
|
-
# Returns the HTTP headers for a SOAP request.
|
63
|
-
def headers
|
64
|
-
@headers ||= {}
|
65
|
-
end
|
66
|
-
|
67
|
-
# Sets the HTTP headers for a SOAP request.
|
68
|
-
def headers=(headers)
|
69
|
-
@headers = headers if headers.kind_of? Hash
|
70
|
-
end
|
71
|
-
|
72
|
-
# Sets the +username+ and +password+ for HTTP basic authentication.
|
73
|
-
def basic_auth(username, password)
|
74
|
-
@basic_auth = [username, password]
|
75
|
-
end
|
76
|
-
|
77
|
-
# Retrieves WSDL document and returns the Net::HTTP response.
|
78
|
-
def wsdl
|
79
|
-
log "Retrieving WSDL from: #{@endpoint}"
|
80
|
-
http.endpoint @endpoint.host, @endpoint.port
|
81
|
-
http.use_ssl = @endpoint.ssl?
|
82
|
-
http.start { |h| h.request request(:wsdl) }
|
83
|
-
end
|
84
|
-
|
85
|
-
# Executes a SOAP request using a given Savon::SOAP instance and returns the Net::HTTP response.
|
86
|
-
def soap(soap)
|
87
|
-
@soap = soap
|
88
|
-
http.endpoint @soap.endpoint.host, @soap.endpoint.port
|
89
|
-
http.use_ssl = @soap.endpoint.ssl?
|
90
|
-
|
91
|
-
log_request
|
92
|
-
@response = http.start do |h|
|
93
|
-
h.request request(:soap) { |request| request.body = @soap.to_xml }
|
94
|
-
end
|
95
|
-
log_response
|
96
|
-
@response
|
97
|
-
end
|
98
|
-
|
99
|
-
# Returns the Net::HTTP object.
|
100
|
-
def http
|
101
|
-
@http ||= Net::HTTP::Proxy(@proxy.host, @proxy.port).new @endpoint.host, @endpoint.port
|
102
|
-
end
|
103
|
-
|
104
|
-
private
|
105
|
-
|
106
|
-
# Logs the SOAP request.
|
107
|
-
def log_request
|
108
|
-
log "SOAP request: #{@soap.endpoint}"
|
109
|
-
log soap_headers.merge(headers).map { |key, value| "#{key}: #{value}" }.join(", ")
|
110
|
-
log @soap.to_xml
|
111
|
-
end
|
112
|
-
|
113
|
-
# Logs the SOAP response.
|
114
|
-
def log_response
|
115
|
-
log "SOAP response (status #{@response.code}):"
|
116
|
-
log @response.body
|
117
|
-
end
|
118
|
-
|
119
|
-
# Returns a Net::HTTP request for a given +type+. Yields the request to an optional block.
|
120
|
-
def request(type)
|
121
|
-
request = case type
|
122
|
-
when :wsdl then Net::HTTP::Get.new @endpoint.request_uri
|
123
|
-
when :soap then Net::HTTP::Post.new @soap.endpoint.request_uri, soap_headers.merge(headers)
|
124
|
-
end
|
125
|
-
|
126
|
-
request.basic_auth(*@basic_auth) if @basic_auth
|
127
|
-
yield request if block_given?
|
128
|
-
request
|
129
|
-
end
|
130
|
-
|
131
|
-
# Returns a Hash containing the SOAP headers for an HTTP request.
|
132
|
-
def soap_headers
|
133
|
-
{ "Content-Type" => ContentType[@soap.version], "SOAPAction" => @soap.action }
|
134
|
-
end
|
135
|
-
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|