Skip to content

Instantly share code, notes, and snippets.

@joewils
Created October 10, 2013 19:04
Show Gist options
  • Save joewils/6923694 to your computer and use it in GitHub Desktop.
Save joewils/6923694 to your computer and use it in GitHub Desktop.
Login to BarraOne SOAP service using Ruby and Savon
#https://www.barraone.com
#http://savonrb.com
require 'savon'
def barra_xml_to_hash (dirty_xml)
# Clean up the response, not sure why the payload from BarraOne is so dirty
xml = dirty_xml.gsub(/--.*<\?/m,'<?')
xml = xml.gsub(/--.*--/,'')
# Convert to Hash via Nori
# Hack. If we didn't need to clean up the xml, we could use Savon's response.hash method
nori_options = { strip_namespaces: true, convert_tags_to: lambda { |tag| tag.snakecase.to_sym } }
non_nil_nori_options = nori_options.reject { |_, value| value.nil? }
parser = Nori.new(non_nil_nori_options)
hash = parser.parse(xml)
end
client = Savon.client(wsdl: "bdti.wsdl", ssl_verify_mode: :none, convert_request_keys_to: :none, raise_errors: false, log: true)
#puts(client.operations)
#Login
message = {User: "username", Client: "clientid", Password: "password"}
login = client.call(:login, message: message)
login_cookies = login.http.cookies
#GetModels
models_response = client.call(:get_models, message: {Filter: 'SYSTEM'}, cookies: login_cookies)
models = barra_xml_to_hash models_response.to_xml()
models[:envelope][:body][:get_models_response][:model].each do |model|
puts model[:@name]
end
@joewils
Copy link
Author

joewils commented Oct 10, 2013

Need to have a BarraOne account and access to the BTDInteractive WSDL file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment