Ruby SOAP client library to enjoy.
Communicating with a SOAP webservice can be done in two lines of code. Instantiate a new Savon::Service passing in the URI to the WSDL of the service you would like to use. Then call the SOAP service method on your Savon::Service instance (catched via method_missing) and pass in a Hash of options for the service method to receive.
$ gem install smacks-savon -s http://gems.github.com
hpricot 0.6.164 (also available for JRuby) smacks-apricoteatsgorilla >= 0.4.1
Instantiate a new Savon::Service instance passing in the WSDL of your service.
proxy = Savon::Service.new "http://example.com/ExampleService?wsdl"
Call the SOAP service method of your choice on your Savon::Service instance passing in a Hash of options for the service method to receive.
response = proxy.findExampleById(:id => 123)
You can use the service_methods method of the WSDL in your Savon::Service instance to get a list of available SOAP service methods.
proxy.wsdl.service_methods # => [ "findExampleById", "findExampleByName" ]
Check if the SOAP request was successful.
response.success? response.error?
Access error message and code in case a request was not successful.
response.error_message response.error_code
To work with the response of the service you need to convert the response object using one of the following methods.
# SOAP response XML: response.to_s # response as a Hash response.to_hash # response as a Mash response.to_mash
The to_hash and to_mash methods accept an XPath expression (Hpricot search) as second parameter to define a custom root node to start translating the response XML at.
# response as a Hash starting at a custom root node response.to_hash("//item") # response as a Mash starting at a custom root node response.to_mash("//user/email")
You should specify the logger to use before working with any services.
# example for Ruby on Rails Savon::Service.logger = RAILS_DEFAULT_LOGGER