tictoc-savon 0.7.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/.autotest +5 -0
  2. data/CHANGELOG +176 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +64 -0
  5. data/Rakefile +50 -0
  6. data/lib/savon.rb +35 -0
  7. data/lib/savon/client.rb +131 -0
  8. data/lib/savon/core_ext.rb +8 -0
  9. data/lib/savon/core_ext/array.rb +31 -0
  10. data/lib/savon/core_ext/datetime.rb +10 -0
  11. data/lib/savon/core_ext/hash.rb +107 -0
  12. data/lib/savon/core_ext/net_http.rb +19 -0
  13. data/lib/savon/core_ext/object.rb +16 -0
  14. data/lib/savon/core_ext/string.rb +69 -0
  15. data/lib/savon/core_ext/symbol.rb +8 -0
  16. data/lib/savon/core_ext/uri.rb +10 -0
  17. data/lib/savon/logger.rb +56 -0
  18. data/lib/savon/request.rb +138 -0
  19. data/lib/savon/response.rb +174 -0
  20. data/lib/savon/soap.rb +302 -0
  21. data/lib/savon/version.rb +5 -0
  22. data/lib/savon/wsdl.rb +137 -0
  23. data/lib/savon/wsdl_stream.rb +85 -0
  24. data/lib/savon/wsse.rb +163 -0
  25. data/spec/basic_spec_helper.rb +11 -0
  26. data/spec/endpoint_helper.rb +23 -0
  27. data/spec/fixtures/gzip/gzip_response_fixture.rb +7 -0
  28. data/spec/fixtures/gzip/message.gz +0 -0
  29. data/spec/fixtures/response/response_fixture.rb +36 -0
  30. data/spec/fixtures/response/xml/authentication.xml +14 -0
  31. data/spec/fixtures/response/xml/multi_ref.xml +39 -0
  32. data/spec/fixtures/response/xml/soap_fault.xml +8 -0
  33. data/spec/fixtures/response/xml/soap_fault12.xml +18 -0
  34. data/spec/fixtures/wsdl/wsdl_fixture.rb +37 -0
  35. data/spec/fixtures/wsdl/wsdl_fixture.yml +42 -0
  36. data/spec/fixtures/wsdl/xml/authentication.xml +63 -0
  37. data/spec/fixtures/wsdl/xml/geotrust.xml +156 -0
  38. data/spec/fixtures/wsdl/xml/namespaced_actions.xml +307 -0
  39. data/spec/fixtures/wsdl/xml/no_namespace.xml +115 -0
  40. data/spec/http_stubs.rb +26 -0
  41. data/spec/integration/http_basic_auth_spec.rb +16 -0
  42. data/spec/integration/server.rb +51 -0
  43. data/spec/savon/client_spec.rb +86 -0
  44. data/spec/savon/core_ext/array_spec.rb +49 -0
  45. data/spec/savon/core_ext/datetime_spec.rb +21 -0
  46. data/spec/savon/core_ext/hash_spec.rb +190 -0
  47. data/spec/savon/core_ext/net_http_spec.rb +38 -0
  48. data/spec/savon/core_ext/object_spec.rb +34 -0
  49. data/spec/savon/core_ext/string_spec.rb +99 -0
  50. data/spec/savon/core_ext/symbol_spec.rb +12 -0
  51. data/spec/savon/core_ext/uri_spec.rb +19 -0
  52. data/spec/savon/request_spec.rb +117 -0
  53. data/spec/savon/response_spec.rb +179 -0
  54. data/spec/savon/soap_spec.rb +202 -0
  55. data/spec/savon/wsdl_spec.rb +107 -0
  56. data/spec/savon/wsse_spec.rb +132 -0
  57. data/spec/spec.opts +4 -0
  58. data/spec/spec_helper.rb +5 -0
  59. metadata +229 -0
data/.autotest ADDED
@@ -0,0 +1,5 @@
1
+ Autotest.add_hook(:initialize) do |at|
2
+ at.clear_mappings
3
+ at.add_mapping(%r%^spec/savon/.*_spec.rb$%) { |filename, _| filename }
4
+ at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m| ["spec/#{m[1]}_spec.rb"] }
5
+ end
data/CHANGELOG ADDED
@@ -0,0 +1,176 @@
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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Daniel Harrington
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,64 @@
1
+ = Savon
2
+
3
+ ==== Heavy metal Ruby SOAP client library
4
+
5
+ {Documentation}[http://savon.rubiii.com] | {Twitter}[http://twitter.com/savon_soap]
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/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ require "rake"
2
+ require "spec/rake/spectask"
3
+ require "spec/rake/verify_rcov"
4
+
5
+ task :default => :spec
6
+
7
+ Spec::Rake::SpecTask.new do |spec|
8
+ spec.spec_files = FileList["spec/{savon}/**/*_spec.rb"]
9
+ spec.spec_opts << "--color"
10
+ spec.libs += ["lib", "spec"]
11
+ spec.rcov = true
12
+ end
13
+
14
+ RCov::VerifyTask.new(:spec_verify => :spec) do |verify|
15
+ verify.threshold = 100.0
16
+ verify.index_html = "rcov/index.html"
17
+ end
18
+
19
+ desc "Run integration specs using WEBrick"
20
+ task :spec_integration do
21
+ pid = fork { exec "ruby spec/integration/server.rb" }
22
+ sleep 10 # wait until the server is actually ready
23
+ begin
24
+ task(:run_integration_spec).invoke
25
+ ensure
26
+ Process.kill "TERM", pid
27
+ Process.wait pid
28
+ end
29
+ end
30
+
31
+ desc "" # make this task invisible
32
+ Spec::Rake::SpecTask.new(:run_integration_spec) do |spec|
33
+ spec.spec_files = FileList["spec/{integration}/**/*_spec.rb"]
34
+ spec.spec_opts << "--color"
35
+ spec.libs += ["lib", "spec"]
36
+ end
37
+
38
+ begin
39
+ require "hanna/rdoctask"
40
+
41
+ Rake::RDocTask.new do |rdoc|
42
+ rdoc.title = "Savon - Heavy metal Ruby SOAP client library"
43
+ rdoc.rdoc_dir = "doc"
44
+ rdoc.rdoc_files.include("**/*.rdoc").include("lib/**/*.rb")
45
+ rdoc.options << "--line-numbers"
46
+ rdoc.options << "--webcvs=http://github.com/rubiii/savon/tree/master/"
47
+ end
48
+ rescue LoadError
49
+ puts "'gem install hanna' for documentation"
50
+ end
data/lib/savon.rb ADDED
@@ -0,0 +1,35 @@
1
+ module Savon
2
+
3
+ # Raised in case of an HTTP error.
4
+ class HTTPError < StandardError; end
5
+
6
+ # Raised in case of a SOAP fault.
7
+ class SOAPFault < StandardError; end
8
+
9
+ end
10
+
11
+ # standard libs
12
+ require "logger"
13
+ require "net/https"
14
+ require "base64"
15
+ require "digest/sha1"
16
+ require "rexml/document"
17
+ require "stringio"
18
+ require "zlib"
19
+ require "cgi"
20
+
21
+ # gem dependencies
22
+ require "builder"
23
+ require "crack/xml"
24
+
25
+ # core files
26
+ require "savon/core_ext"
27
+ require "savon/wsse"
28
+ require "savon/soap"
29
+ require "savon/logger"
30
+ require "savon/request"
31
+ require "savon/response"
32
+ require "savon/wsdl_stream"
33
+ require "savon/wsdl"
34
+ require "savon/client"
35
+ require "savon/version"
@@ -0,0 +1,131 @@
1
+ module Savon
2
+
3
+ # = Savon::Client
4
+ #
5
+ # Savon::Client is the main object for connecting to a SOAP service. It includes methods to access
6
+ # both the Savon::WSDL and Savon::Request object.
7
+ #
8
+ # == Instantiation
9
+ #
10
+ # Depending on whether you aim to use Savon with or without Savon::WSDL, you need to instantiate
11
+ # Savon::Client by passing in the WSDL or SOAP endpoint.
12
+ #
13
+ # Client instance with a WSDL endpoint:
14
+ #
15
+ # client = Savon::Client.new "http://example.com/UserService?wsdl"
16
+ #
17
+ # Client instance with a SOAP endpoint (for using Savon without a WSDL):
18
+ #
19
+ # client = Savon::Client.new "http://example.com/UserService"
20
+ #
21
+ # It is recommended to not use Savon::WSDL for production. Please take a look at the Documentation
22
+ # for Savon::WSDL for more information about how to disable it.
23
+ #
24
+ # == Using a proxy server
25
+ #
26
+ # You can specify the URI to a proxy server via optional hash arguments.
27
+ #
28
+ # client = Savon::Client.new "http://example.com/UserService?wsdl", :proxy => "http://proxy.example.com"
29
+ #
30
+ # == Forcing a particular SOAP endpoint
31
+ #
32
+ # In case you don't want to use the SOAP endpoint specified in the WSDL, you can tell Savon to use
33
+ # another SOAP endpoint.
34
+ #
35
+ # client = Savon::Client.new "http://example.com/UserService?wsdl", :soap_endpoint => "http://localhost/UserService"
36
+ #
37
+ # == Gzipped SOAP requests
38
+ #
39
+ # Sending gzipped SOAP requests can be specified per client instance.
40
+ #
41
+ # client = Savon::Client.new "http://example.com/UserService?wsdl", :gzip => true
42
+ #
43
+ # == Savon::WSDL
44
+ #
45
+ # You can access Savon::WSDL via:
46
+ #
47
+ # client.wsdl
48
+ #
49
+ # == Savon::Request
50
+ #
51
+ # You can also access Savon::Request via:
52
+ #
53
+ # client.request
54
+ class Client
55
+
56
+ # Expects a SOAP +endpoint+ string. Also accepts a Hash of +options+.
57
+ #
58
+ # ==== Options:
59
+ #
60
+ # [proxy] the proxy server to use
61
+ # [gzip] whether to gzip SOAP requests
62
+ # [soap_endpoint] force to use this SOAP endpoint
63
+ def initialize(endpoint, options = {})
64
+ soap_endpoint = options.delete(:soap_endpoint)
65
+ @request = Request.new endpoint, options
66
+ @wsdl = WSDL.new @request, soap_endpoint
67
+ end
68
+
69
+ # Returns the Savon::WSDL.
70
+ attr_reader :wsdl
71
+
72
+ # Returns the Savon::Request.
73
+ attr_reader :request
74
+
75
+ # Returns +true+ for available methods and SOAP actions.
76
+ def respond_to?(method)
77
+ return true if @wsdl.respond_to? method
78
+ super
79
+ end
80
+
81
+ # Same as method_missing. Workaround for SOAP actions that method_missing does not catch
82
+ # because the method does exist.
83
+ def call(method, *args, &block)
84
+ method_missing method, *args, &block
85
+ end
86
+
87
+ private
88
+
89
+ # Dispatches requests to SOAP actions matching a given +method+ name.
90
+ def method_missing(method, *args, &block) #:doc:
91
+ soap_action = soap_action_from method.to_s
92
+ super unless @wsdl.respond_to? soap_action
93
+
94
+ setup_objects *@wsdl.operation_from(soap_action), &block
95
+ Response.new @request.soap(@soap)
96
+ end
97
+
98
+ # Sets whether to use Savon::WSDL by a given +method+ name and returns the original method name
99
+ # without exclamation marks.
100
+ def soap_action_from(method)
101
+ @wsdl.enabled = !method.ends_with?("!")
102
+
103
+ method.chop! if method.ends_with?("!")
104
+ method.to_sym
105
+ end
106
+
107
+ # Returns the SOAP endpoint.
108
+ def soap_endpoint
109
+ @wsdl.enabled? ? @wsdl.soap_endpoint : @request.endpoint
110
+ end
111
+
112
+ # Expects a SOAP operation Hash and sets up Savon::SOAP and Savon::WSSE. Yields them to a given
113
+ # +block+ in case one was given.
114
+ def setup_objects(action, input, &block)
115
+ @soap, @wsse = SOAP.new(action, input, soap_endpoint), WSSE.new
116
+ yield_objects &block if block
117
+ @soap.namespaces["xmlns:wsdl"] ||= @wsdl.namespace_uri if @wsdl.enabled?
118
+ @soap.wsse = @wsse
119
+ end
120
+
121
+ # Yields either Savon::SOAP or Savon::SOAP and Savon::WSSE to a given +block+, depending on
122
+ # the number of arguments expected by the block.
123
+ def yield_objects(&block)
124
+ case block.arity
125
+ when 1 then yield @soap
126
+ when 2 then yield @soap, @wsse
127
+ end
128
+ end
129
+
130
+ end
131
+ end