Skip to content

Instantly share code, notes, and snippets.

@joerichsen
Created December 9, 2010 20:35
Show Gist options
  • Select an option

  • Save joerichsen/735296 to your computer and use it in GitHub Desktop.

Select an option

Save joerichsen/735296 to your computer and use it in GitHub Desktop.

Revisions

  1. joerichsen created this gist Dec 9, 2010.
    45 changes: 45 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    # Old version is here
    # https://gist.github.com/657153

    # In Gemfile
    gem 'savon', :git => 'https://github.com/rubiii/savon.git', :branch => 'eight'
    gem 'httpclient'

    # Run this in the console to fetch the name and address of the first debtor
    HTTPI::Adapter.use = :net_http
    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"].first

    # 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