Created
May 23, 2014 13:19
-
-
Save snreid/f365f06a3ed30c74ea29 to your computer and use it in GitHub Desktop.
Savon Gem Configuration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#In your gemfile add: | |
gem 'savon', '~>2.0' | |
#In your model (or service; whatever is appropriate for your app): | |
def self.get_response(method, message) | |
client = Savon.client( | |
wsdl: 'https://Your-WSDL-URL.com/service.wsdl', | |
#This is optional. I needed it to send credentials with custom xml. Custom XML will be nested in the <header></header> tags. | |
soap_header: '<custom-xml-header></custom-xml-header>', | |
#you can change the namespace to be more specific. | |
namespace_identifier: :my_namespace, | |
#element_for_default: adds or removes the namespace from the body of your message. :unqualified removes the namespace, :qualified adds the namespace. | |
#This was the tricky part for me. Savon tries to guess what your WSDL requires. If the body was qualified, and it shouldn't be, I would get an error. | |
element_form_default: :unqualified, | |
#Turns out, the WSDL your using can be picky about the environment namespace (typically :env). | |
env_namespace: :my_env, | |
# I wanted to suppress logging to keep the credentials I am sending in plain text secure. | |
log: false | |
) | |
# You an use these to log xml in a readable format. | |
# client.globals.pretty_print_xml true | |
# client.globals.log true | |
#"method.to_sym", savon accepts the WSDL method you are using as a symbol underscored. It defaults to converting it to camelcasing. | |
#":message => message". The message variable contains a message formed as a hash {"XML_TAG_NAME" => "Text Content"} | |
response = client.call(method.to_sym, :message => message) | |
return response | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment