Created
October 31, 2010 21:06
-
-
Save joerichsen/657153 to your computer and use it in GitHub Desktop.
Querying the e-conomic.dk API using Savon and Ruby
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 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