Ruby/Rails + airportInfo = unknown airport INVALID

Hello,

I’m trying to figure out why this Ruby code is not working for me:

@airportinfo = FA.airportInfo(AirportInfoRequest.new(‘KLAX’))

FA is my FlightAware authentication object, I’m able to use allAirports (e.g. @airports = FA.allAirports(AllAirportsRequest.new)), so the problem is not with my FlightAware config/init, but the error message I’m getting is:

SOAP::FaultError: unknown airport INVALID
from #SOAP::Mapping::Object:0x007ff56a37e080

I get this error message no matter what ICAO airport code I use as a parameter. Any clue what is going on here? Looking at the Ruby driver (github.com/flightaware/flightxm … ghtXML2.rb) it looks like this should work?

I do the following in our Ruby test cases:



$testairports = {
  'KHOU' => 'KHOU',
  'KIAH' => 'KIAH',
  'KAUS' => 'KAUS',
  'BUR' => 'KBUR',
  'sfo' => 'KSFO'
}

  $testairports.each { |airport,airportc|
   result = $fxml.AirportInfo(airport)
    it 'should succeed' do
      result.should.not.be.nil
      result.should.not == ''
      result.should.be.kind_of? AirportInfoStruct
    end

    it 'should have the expected members' do
      validate_nonempty_string(result.timezone)
      validate_nonempty_string(result.location)
      validate_nonempty_string(result.name)
      validate_latlon(result.latitude, result.longitude)
    end

  }


Hmmmm… The camel case vs. title case is a little confusing to me.

Why wouldn’t the following work in the console then?

FA.AirportInfo(‘KHOU’)

this yields:

NoMethodError: undefined method `AirportInfo’ for #FlightXML2Soap:0x007ff568dae958

and:

FA.airportInfo(‘KHOU’)

yields:

SOAP::FaultError: unknown airport INVALID
from #SOAP::Mapping::Object:0x007ff56bdac600

Why would “AirportInfo” be a valid method for you and not me, and since it is clear that a string like “KHOU” should work, what’s up with the invalid airport error? Puzzling…

Thanks for your help, it is greatly appreciated!

bovineone, if you could kindly post a complete example that includes the declaration of your $fxml, that would be tremendously helpful. I’m still having problems tracing down the source of my problem here. If your $fxml is equivalent to:

$fxml = FlightXML2Soap.new(FAAPI_USERNAME, FAAPI_KEY)

I would really like to understand why the following:

result = $fxml.AirportInfo(‘KHOU’)

is producing the following error:

NoMethodError: undefined method `AirportInfo’ for #FlightXML2Soap:0x007fa7450d8e98

Thanks in advance for your help here, I sense that there is just something basic here that isn’t clicking for me just yet!

I actually find the savon library easier to use than the github package (which uses soap4r):


#!/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("AirportInfo") do
  soap.body = {
    :airport => 'KSMO',
  }
end

airportResult = result.to_hash:airport_info_results]:airport_info_result]

print "Latitude: #{airportResult]}
"
print "Longitude: #{airportResult:longitude]}
"



Cool, I will try the Savon library then. Were you able to reproduce the problems I had with the soap4r library?

I tried it but I didn’t get that far because the soap4r people have seemingly renamed/moved some functionality since that flightxml2-client-ruby github package was written and it no longer runs for me on my dev machine. soap4r was originally lacking some internal plumbing needed for HTTP Basic-Auth support and it was rather suboptimal to begin with. That github package probably needs to be rewritten to be compatible with modern soap4r versions. Maybe they support Basic-Auth natively now? Maybe those Client+Driver files just need to be regenerated? You’re welcome to try to revamp it and submit a pull-request to our github project if you figure out the soap4r method.

Hmmm… Or, maybe instead of Gemfiles pulling from the soap4r Github head, they should pull an older certain tagged release until this stuff can be sorted out?

Up until this point my Gemfile included the following:

gem ‘soap4r’, :git => ‘git://github.com/felipec/soap4r.git’

Maybe instead I should have made a Soap4r Git submodule, checked out an older version, and linked against that? I’m going to try the Savon library now, but if I have time I might circle back and experiment with this a little bit. If there are no problems with the Savon library perhaps you’d decide it would be easier to abandon the soap4r driver altogether, but I’d expect that figuring out what version caused things to break would be the lower hanging fruit for your existing developers using the soap4r library who aren’t ready to jump ship?

For my sanity and curiosity though, was it:

FA.airportInfo(AirportInfoRequest.new(airport))

or:

FA.AirportInfo(AirportInfoRequest.new(airport))

that should have worked? :slight_smile:

Thanks again for your help here!

As I said, the first example I pasted was from our test harness, though for FlightXML1 rather than FlightXML2:

github.com/flightaware/flightxml-client-ruby



require 'DirectFlightDriver.rb'

endpoint_url = 'http://flightxml.flightaware.com:80/soap/DirectFlight/go'

$fxml = DirectFlightSoap.new('username', 'apikey', endpoint_url)


Thanks for your help, I’m having much greater success with the Savon driver and not running into these problems. So far, so good!

I will add though, for those struggling like me, that I had to use an older version of Savon to make this work:

gem ‘savon’, “~> 1.2.0”