Hi, I’m using both Savon and FlightXML for the first time and started with the test script. Unfortunately I get the following. Any ideas how to troubleshoot? Would anything have changed in the Savon API from when FlightAware’s test.xml was developed?
...>ruby test.rb
c:/ruby193/lib/ruby/gems/1.9.1/gems/savon-2.11.0/lib/savon/options.rb:107:in `ws
dl': wrong number of arguments (0 for 1) (ArgumentError)
from c:/ruby193/lib/ruby/gems/1.9.1/gems/savon-2.11.0/lib/savon/block_in
terface.rb:20:in `method_missing'
from test.rb:11:in `block in <main>'
from c:/ruby193/lib/ruby/gems/1.9.1/gems/savon-2.11.0/lib/savon/block_in
terface.rb:13:in `instance_eval'
from c:/ruby193/lib/ruby/gems/1.9.1/gems/savon-2.11.0/lib/savon/block_in
terface.rb:13:in `evaluate'
from c:/ruby193/lib/ruby/gems/1.9.1/gems/savon-2.11.0/lib/savon/client.r
b:52:in `set_globals'
from c:/ruby193/lib/ruby/gems/1.9.1/gems/savon-2.11.0/lib/savon/client.r
b:15:in `initialize'
from test.rb:10:in `new'
from test.rb:10:in `<main>'
Versions of Ruby and Windows follow.
...>ruby --version
ruby 1.9.3p545 (2014-02-24) [i386-mingw32]
...>systeminfo
...
OS Name: Microsoft Windows 8.1
OS Version: 6.3.9600 N/A Build 9600
Just to clarify, I’m using the sample code from flightaware.com/commercial/fligh … ation2.rvt for savon:
#!/usr/bin/env ruby
require 'rubygems'
require 'savon'
SOAP_URL = 'http://flightxml.flightaware.com/soap/FlightXML2/wsdl'
USERNAME = 'sampleuser'
API_KEY = 'abc123abc123abc123abc123abc123abc123'
client = Savon::Client.new do
wsdl.document = SOAP_URL
http.auth.basic USERNAME, API_KEY
end
result = client.request(:enroute) do
soap.body = {
:airport => 'KSMO',
:how_many => 10,
:filter => '',
:offset => 0
}
end
flights = result.to_hash:enroute_results]:enroute_result]:enroute]
print "Aircraft en route to KSMO:
"
flights.each { |flight|
print "#{flight:ident]} (#{flight:aircrafttype]}) #{flight:origin_name]} (#{flight:origin]})
"
}
Well, I solved it with a couple of modifications.
- First, the latest Savon doesn’t play nice with the latest rubyntlm, so I did the following to downgrade versions:
> gem uninstall rubyntlm
> gem install rubyntlm -v "~>0.3.2"
-
Second, the sample FlightXML Savon code used a lot of the block interface. I dumbed this down to the more straightforward non-block interface.
-
I think some of the API options in the sample code may be broken, but at any rate, I redid them from the Savon documentation.
Here’s my working code:
#!/usr/bin/env ruby
# require 'rubygems'
require 'savon'
require 'YAML'
#test_config.yml contents should be formatted as follows:
=begin
---
:username: 'sampleuser'
:api_key: 'abc123abc123abc123abc123abc123abc123'
=end
CONFIG=YAML::load_file("test_config.yml")
USERNAME=CONFIG]
API_KEY=CONFIG:api_key]
SOAP_URL = 'http://flightxml.flightaware.com/soap/FlightXML2/wsdl'
client = Savon.client(wsdl: SOAP_URL, basic_auth: [USERNAME, API_KEY])
puts "We have client #{client}"
test_body = {
:airport => 'KSMO',
:how_many => 10,
:filter => '',
:offset => 0
}
response = client.call(:enroute, message: test_body)
puts "We have response #{response}"
flights = response.to_hash:enroute_results]:enroute_result]:enroute]
print "Aircraft en route to KSMO:
"
flights.each { |flight|
print "#{flight:ident]} (#{flight:aircrafttype]}) #{flight:origin_name]} (#{flight:origin]})
"
}
Hope this helps! Feel free to update the sample with my code.
Ok great. We’ll try to update our sample code with your new proposed changes.