Skip to content

dduugg/savon

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Savon

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.

Install

$ gem install smacks-savon -s http://gems.github.com

Dependencies

hpricot 0.6.164 (also available for JRuby)
smacks-apricoteatsgorilla >= 0.4.1

How to use

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)

Check for available SOAP service methods

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" ]

Handle HTTP and SOAP errors

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

Different response formats

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")

Logging request and response

You should specify the logger to use before working with any services.

# example for Ruby on Rails
Savon::Service.logger = RAILS_DEFAULT_LOGGER

About

Heavy metal SOAP client

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%