Class: Savon::Service
- Inherits:
-
Object
- Object
- Savon::Service
- Defined in:
- lib/savon/service.rb
Overview
Savon::Service
Savon::Service is a SOAP client library to enjoy. The goal is to minimize the overhead of working with SOAP services and provide a lightweight alternative to other libraries.
Example
proxy = Savon::Service.new("http://example.com/ExampleService?wsdl")
response = proxy.find_user_by_id(:id => 123)
Constant Summary collapse
- SOAPVersions =
Supported SOAP versions.
[1, 2]
- ContentType =
Content-Types by SOAP version.
{ 1 => "text/xml", 2 => "application/soap+xml" }
Instance Method Summary collapse
-
#initialize(endpoint, version = 1) ⇒ Service
constructor
Initializer expects an
endpoint
URI and takes an optional SOAPversion
. -
#wsdl ⇒ Object
Returns an instance of Savon::WSDL.
Constructor Details
#initialize(endpoint, version = 1) ⇒ Service
Initializer expects an endpoint
URI and takes an optional SOAP version
.
22 23 24 25 26 27 |
# File 'lib/savon/service.rb', line 22 def initialize(endpoint, version = 1) raise ArgumentError, "Invalid endpoint: #{endpoint}" unless /^http.+/ === endpoint raise ArgumentError, "Invalid version: #{version}" unless SOAPVersions.include? version @endpoint = URI(endpoint) @version = version end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object (private)
Catches calls to SOAP actions, checks if the method called was found in the WSDL and dispatches the SOAP action if it’s valid. Takes an optional Hash of options to be passed to the SOAP action and an optional XPath- Expression to define a custom XML root node to start parsing the SOAP response at.
96 97 98 99 100 101 102 |
# File 'lib/savon/service.rb', line 96 def method_missing(method, *args) soap_action = camelize(method) super unless wsdl.soap_actions.include? soap_action soap_body = args[0] || {} response_xpath = args[1] || "//return" dispatch(soap_action, soap_body, response_xpath) end |