public
Last active

  • Download Gist
savon_getting_started.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
# 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.