Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@joerichsen
Created October 31, 2010 21:06
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joerichsen/657153 to your computer and use it in GitHub Desktop.
Save joerichsen/657153 to your computer and use it in GitHub Desktop.
Querying the e-conomic.dk API using Savon and Ruby
# In Gemfile
gem 'savon', :git => 'http://github.com/rubiii/savon.git', :branch => 'eight'
gem 'httpclient'
# Run this in the console to fetch the name and address of the first debtor
client = Savon::Client.new do
wsdl.document = "https://www.e-conomic.com/secure/api1/EconomicWebservice.asmx?WSDL"
end
# Authenticate
response = client.request :n1, :connect do
soap.body = {
'n1:agreementNumber' => 123456,
'n1:userName' => 'api',
'n1:password' => 'verysecret',
:order! => ['n1:agreementNumber', 'n1:userName', 'n1:password']
}
end
# Save the session cookie
client.http.headers["Cookie"] = response.http.headers["Set-Cookie"]
# Get the list of debtors
response = client.request :debtor_get_all
# Get the name and the address of the first debtor
first_debtor_number = response.to_hash[:debtor_get_all_response][:debtor_get_all_result][:debtor_handle].first[:number]
response = client.request :n1, :debtor_get_data do
soap.body = {
'n1:entityHandle' => {
'n1:Number' => first_debtor_number
}
}
end
# Convert the result to a struct for easier access
k,v = response.to_hash[:debtor_get_data_response][:debtor_get_data_result].to_a.transpose
s = Struct.new(*k).new(*v)
# And print it
puts s.name
puts s.address
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment