Skip to content

Instantly share code, notes, and snippets.

@rubiii
Created June 6, 2010 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rubiii/427900 to your computer and use it in GitHub Desktop.
Save rubiii/427900 to your computer and use it in GitHub Desktop.
# rubygems.org/gems/savon by examples
# overview of examples at: http://gist.github.com/gists/427837
require "savon"
# = Instantiation
#
# Savon is based on the Savon::Client object. So the first thing you want to do, is to create a new
# Savon::Client instance. A few examples on using the Savon::Client with or without a WSDL are at:
# http://gist.github.com/427832
client = Savon::Client.new do
wsdl.location = "http://users.example.com?wsdl"
end
# = SOAP actions
#
# When using Savon with a WSDL, you can ask Savon::WSDL about available SOAP actions.
client.wsdl.soap_actions # => [:get_user_by_id, :get_all_users]
# = Executing a SOAP request
#
# To execute a SOAP request, you just call the name of the SOAP action on the Savon::Client instance.
#
# When using Savon with a WSDL, you can name the method in snake_case without a problem. When you don't,
# Savon don't knows anything about your service, so it uses the convention of converting the method into
# lowerCamelCase. In case that doesn't work for you, please have a look at: http://gist.github.com/427897
#
# To specify the payload for the SOAP action to receive, you can pass a Hash to Savon::SOAP#body.
# The Hash will be converted into XML via Hash#to_soap_xml. More information: http://gist.github.com/427915
#
# You can also pass the raw XML as a String in case Hash#to_soap_xml does not work for you.
client.get_user_by_id do
soap.body = { :id => 12 }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment