lib/flightstats.js
function( options, callback ) {

    if( typeof options === 'function' ) {
      callback = options
      options = null
    }

    options = options != null ? options : {}

    var self = this
    var baseUrl = 'airports/rest/v1/json'
    var isCode = options.fs || options.iata || options.icao
    var isLocationCode = options.city || options.country
    var isLocation = options.latitude && options.longitude && options.radius
    var supportsDate = !options.all && isCode

    if( !options.all && !isCode ) {
      baseUrl += '/active'
    } else if( !isCode && !isLocationCode && !isLocation ) {
      baseUrl += '/all'
    }

    if( isCode || isLocationCode ) {
      if( options.fs ) {
        baseUrl += '/fs/' + options.fs
      } else if( options.iata ) {
        baseUrl += '/iata/' + options.iata
      } else if( options.icao ) {
        baseUrl += '/icao/' + options.icao
      } else if( options.city ) {
        baseUrl += '/cityCode/' + options.city
      } else if( options.country ) {
        baseUrl += '/countryCode/' + options.country
      }
    }

    if( options.date && supportsDate ) {

      var year = options.date.getFullYear()
      var month = options.date.getMonth() + 1
      var day = options.date.getDate()

      baseUrl += '/' + year + '/' + month + '/' + day

    }

    if( isLocation ) {
      baseUrl += '/' + options.longitude + '/' + options.latitude + '/' + options.radius
    }

    return this._clientRequest({
      url: baseUrl,
      extendedOptions: [
        'includeNewFields'
      ],
    }, function( error, data ) {

      if( error != null )
        return callback.call( self, error )

      var airports = [].concat( data.airports || data.airport || [] )
        .map( function( airport ) {

          airport.tzOffset = airport.utcOffsetHours
          airport.tzRegion = airport.timeZoneRegionName
          airport.elevation = airport.elevationFeet * 0.305

          airport.utcOffsetHours = undefined
          delete airport.utcOffsetHours

          airport.timeZoneRegionName = undefined
          delete airport.timeZoneRegionName

          return airport

        })

      callback.call( self, error, airports )

    })

  }
function( options, callback ) {

    if( typeof options === 'function' ) {
      callback = options
      options = null
    }

    options = options != null ? options : {}

    var self = this
    var baseUrl = 'airports/rest/v1/json'
    var isCode = options.fs || options.iata || options.icao
    var isLocationCode = options.city || options.country
    var isLocation = options.latitude && options.longitude && options.radius
    var supportsDate = !options.all && isCode

    if( !options.all && !isCode ) {
      baseUrl += '/active'
    } else if( !isCode && !isLocationCode && !isLocation ) {
      baseUrl += '/all'
    }

    if( isCode || isLocationCode ) {
      if( options.fs ) {
        baseUrl += '/fs/' + options.fs
      } else if( options.iata ) {
        baseUrl += '/iata/' + options.iata
      } else if( options.icao ) {
        baseUrl += '/icao/' + options.icao
      } else if( options.city ) {
        baseUrl += '/cityCode/' + options.city
      } else if( options.country ) {
        baseUrl += '/countryCode/' + options.country
      }
    }

    if( options.date && supportsDate ) {

      var year = options.date.getFullYear()
      var month = options.date.getMonth() + 1
      var day = options.date.getDate()

      baseUrl += '/' + year + '/' + month + '/' + day

    }

    if( isLocation ) {
      baseUrl += '/' + options.longitude + '/' + options.latitude + '/' + options.radius
    }

    return this._clientRequest({
      url: baseUrl,
      extendedOptions: [
        'includeNewFields'
      ],
    }, function( error, data ) {

      if( error != null )
        return callback.call( self, error )

      var airports = [].concat( data.airports || data.airport || [] )
        .map( function( airport ) {

          airport.tzOffset = airport.utcOffsetHours
          airport.tzRegion = airport.timeZoneRegionName
          airport.elevation = airport.elevationFeet * 0.305

          airport.utcOffsetHours = undefined
          delete airport.utcOffsetHours

          airport.timeZoneRegionName = undefined
          delete airport.timeZoneRegionName

          return airport

        })

      callback.call( self, error, airports )

    })

  }
function ( options , callback ) { if ( typeof options === 'function' ) { callback = options options = null } options = options != null ? options : { } var self = this var baseUrl = 'airports/rest/v1/json' var isCode = options . fs || options . iata || options . icao var isLocationCode = options . city || options . country var isLocation = options . latitude && options . longitude && options . radius var supportsDate = ! options . all && isCode if ( ! options . all && ! isCode ) { baseUrl += '/active' } else if ( ! isCode && ! isLocationCode && ! isLocation ) { baseUrl += '/all' } if ( isCode || isLocationCode ) { if ( options . fs ) { baseUrl += '/fs/' + options . fs } else if ( options . iata ) { baseUrl += '/iata/' + options . iata } else if ( options . icao ) { baseUrl += '/icao/' + options . icao } else if ( options . city ) { baseUrl += '/cityCode/' + options . city } else if ( options . country ) { baseUrl += '/countryCode/' + options . country } } if ( options . date && supportsDate ) { var year = options . date . getFullYear ( ) var month = options . date . getMonth ( ) + 1 var day = options . date . getDate ( ) baseUrl += '/' + year + '/' + month + '/' + day } if ( isLocation ) { baseUrl += '/' + options . longitude + '/' + options . latitude + '/' + options . radius } return this . _clientRequest ( { url : baseUrl , extendedOptions : [ 'includeNewFields' ] , } , function ( error , data ) { if ( error != null ) return callback . call ( self , error ) var airports = [ ] . concat ( data . airports || data . airport || [ ] ) . map ( function ( airport ) { airport . tzOffset = airport . utcOffsetHours airport . tzRegion = airport . timeZoneRegionName airport . elevation = airport . elevationFeet * 0.305 airport . utcOffsetHours = undefined delete airport . utcOffsetHours airport . timeZoneRegionName = undefined delete airport . timeZoneRegionName return airport } ) callback . call ( self , error , airports ) } ) }
Retrieve a list of airports
@param {Object} options
@param {?Boolean} [options.all=false] optional
@param {?Date} [options.date] optional
@param {?String} [options.iata] optional
@param {?String} [options.icao] optional
@param {?String} [options.fs] optional
@param {?String} [options.city] optional
@param {?String} [options.country] optional
@param {?Number} [options.latitude] optional
@param {?Number} [options.longitude] optional
@param {?Number} [options.radius] optional
@param {Function} callback
@return {Request}
Retrieve a list of airports