2024-12-12 05:22:00 +00:00
// aviation.js
// Namhyeon Go <abuse@catswords.net>
// https://github.com/gnh1201/welsonjs
//
// ***SECURITY NOTICE***
// Aviation Data Integration requires an internet connection, and data may be transmitted externally. Users must adhere to the terms of use and privacy policy.
// - AviationStack website: https://aviationstack.com/?utm_source=FirstPromoter&utm_medium=Affiliate&fpr=namhyeon71
2024-12-27 06:04:08 +00:00
// - SearchApi website: https://www.searchapi.io/?via=namhyeon
2024-12-12 05:22:00 +00:00
//
var HTTP = require ( "lib/http" ) ;
2025-01-13 05:46:48 +00:00
var CRED = require ( "lib/credentials" ) ;
2024-12-12 05:22:00 +00:00
function getData ( type , params , limit , offset ) {
var params = params || { } ;
var limit = ( function ( n ) {
return n > 0 ? n : 100 ;
} ( parseInt ( limit ) ) ;
var offset = ( function ( n ) {
return n > - 1 ? n : 0 ;
} ( parseInt ( limit ) ) ;
params [ "limit" ] = limit ;
params [ "offset" ] = offset ;
2025-01-13 05:46:48 +00:00
params [ "access_key" ] = CRED . get ( "apikey" , "aviationstack" ) ;
2024-12-12 05:22:00 +00:00
var response = HTTP . create ( )
. setParameters ( params )
2024-12-27 06:04:08 +00:00
. open ( "GET" , "https://api.aviationstack.com/v1/" + type )
2024-12-12 05:22:00 +00:00
. send ( ) ;
return response . responseBody ;
}
function getFlights ( params , limit , offset ) {
return getData ( "flights" , params , limit , offset ) ;
}
function getRoutes ( params , limit , offset ) {
return getData ( "routes" , params , limit , offset ) ;
}
function getAirports ( params , limit , offset ) {
return getData ( "airports" , params , limit , offset ) ;
}
function getAirlines ( params , limit , offset ) {
return getData ( "airlines" , params , limit , offset ) ;
}
function getAircraftTypes ( params , limit , offset ) {
return getData ( "aircraft_types" , params , limit , offset ) ;
}
function getCities ( params , limit , offset ) {
return getData ( "cities" , params , limit , offset ) ;
}
function getCountries ( params , limit , offset ) {
return getData ( "countries" , params , limit , offset ) ;
}
function getFlightSchedules ( params , limit , offset ) {
return getData ( "timetable" , params , limit , offset ) ;
}
function getFlightsFuture ( params , limit , offset ) {
return getData ( "flightsFuture" , params , limit , offset ) ;
}
2024-12-27 06:04:08 +00:00
function getRoundTrip ( arrival _id , departure _id , outbound _date , return _date ) {
var response = HTTP . create ( )
. setParameters ( {
2025-01-13 05:46:48 +00:00
"api_key" : CRED . get ( "apikey" , "searchapi" ) ,
2024-12-27 06:04:08 +00:00
"arrival_id" : arrival _id ,
"departure_id" : departure _id ,
"engine" : "google_flights" ,
"flight_type" : "round_trip" ,
"outbound_date" : outbound _date ,
"return_date" : return _date
} )
. open ( "GET" , "https://www.searchapi.io/api/v1/search" )
. send ( ) ;
return response . responseBody ;
}
function getOneWay ( arrival _id , departure _id , outbound _date ) {
var response = HTTP . create ( )
. setParameters ( {
2025-01-13 05:46:48 +00:00
"api_key" : CRED . get ( "apikey" , "searchapi" ) ,
2024-12-27 06:04:08 +00:00
"arrival_id" : arrival _id ,
"departure_id" : departure _id ,
"engine" : "google_flights" ,
"flight_type" : "one_way" ,
"outbound_date" : outbound _date
} )
. open ( "GET" , "https://www.searchapi.io/api/v1/search" )
. send ( ) ;
return response . responseBody ;
}
2024-12-12 05:22:00 +00:00
exports . getData = getData ;
exports . getFlights = getFlights ;
exports . getRoutes = getRoutes ;
exports . getAirports = getAirports ;
exports . getAirlines = getAirlines ;
exports . getAircraftTypes = getAircraftTypes ;
exports . getCities = getCities ;
exports . getCountries = getCountries ;
exports . getFlightSchedules = getFlightSchedules ;
exports . getFlightsFuture = getFlightsFuture ;
2024-12-27 06:04:08 +00:00
exports . getRoundTrip = getRoundTrip ;
exports . getOneWay = getOneWay ;
2024-12-12 05:22:00 +00:00
2025-01-13 05:46:48 +00:00
exports . VERSIONINFO = "Aviation Data Integration (aviation.js) version 0.1.3" ;
2024-12-12 05:22:00 +00:00
exports . AUTHOR = "abuse@catswords.net" ;
exports . global = global ;
exports . require = global . require ;