fshub-api 2.0.1 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mocharc.json +4 -0
- package/.vscode/launch.json +15 -0
- package/dist/api/airline/Airline_get.d.ts +1 -1
- package/dist/api/airline/Airline_get.d.ts.map +1 -1
- package/dist/api/airline/Airline_getAll.d.ts +1 -1
- package/dist/api/airline/Airline_getAll.d.ts.map +1 -1
- package/dist/api/airline/Airline_getAllFlightDeparturesAndArrivals.d.ts +1 -1
- package/dist/api/airline/Airline_getAllFlightDeparturesAndArrivals.d.ts.map +1 -1
- package/dist/api/airline/Airline_getAllFlightsArrivals.d.ts +1 -1
- package/dist/api/airline/Airline_getAllFlightsArrivals.d.ts.map +1 -1
- package/dist/api/airline/Airline_getAllFlightsDepartures.d.ts +1 -1
- package/dist/api/airline/Airline_getAllFlightsDepartures.d.ts.map +1 -1
- package/dist/api/airline/Airline_getAllScreenshots.d.ts +1 -1
- package/dist/api/airline/Airline_getAllScreenshots.d.ts.map +1 -1
- package/dist/api/airline/Airline_getFlights.d.ts +1 -1
- package/dist/api/airline/Airline_getFlights.d.ts.map +1 -1
- package/dist/api/airline/Airline_getPilotStats.d.ts +1 -1
- package/dist/api/airline/Airline_getPilotStats.d.ts.map +1 -1
- package/dist/api/airline/Airline_getPilots.d.ts +1 -1
- package/dist/api/airline/Airline_getPilots.d.ts.map +1 -1
- package/dist/api/airline/Airline_getStats.d.ts +1 -1
- package/dist/api/airline/Airline_getStats.d.ts.map +1 -1
- package/dist/api/flight/Flight_getFlightById.d.ts +1 -1
- package/dist/api/flight/Flight_getFlightById.d.ts.map +1 -1
- package/dist/api/flight/Flight_getFlightScreenshotsById.d.ts +1 -1
- package/dist/api/flight/Flight_getFlightScreenshotsById.d.ts.map +1 -1
- package/dist/api/flight/Flight_getFlightScreenshotsById.js +12 -3
- package/dist/api/flight/Flight_getFlightScreenshotsById.js.map +1 -1
- package/dist/api/pilot/Pilot_get.d.ts +1 -1
- package/dist/api/pilot/Pilot_get.d.ts.map +1 -1
- package/dist/api/pilot/Pilot_getAll.d.ts +1 -1
- package/dist/api/pilot/Pilot_getAll.d.ts.map +1 -1
- package/dist/api/pilot/Pilot_getAllAirlines.d.ts +1 -1
- package/dist/api/pilot/Pilot_getAllAirlines.d.ts.map +1 -1
- package/dist/api/pilot/Pilot_getAllFlightDeparturesAndArrivals.d.ts +1 -1
- package/dist/api/pilot/Pilot_getAllFlightDeparturesAndArrivals.d.ts.map +1 -1
- package/dist/api/pilot/Pilot_getAllFlights.d.ts +1 -1
- package/dist/api/pilot/Pilot_getAllFlights.d.ts.map +1 -1
- package/dist/api/pilot/Pilot_getAllFlightsArrivals.d.ts +1 -1
- package/dist/api/pilot/Pilot_getAllFlightsArrivals.d.ts.map +1 -1
- package/dist/api/pilot/Pilot_getAllFlightsDepartures.d.ts +1 -1
- package/dist/api/pilot/Pilot_getAllFlightsDepartures.d.ts.map +1 -1
- package/dist/api/pilot/Pilot_getAllScreenshots.d.ts +1 -1
- package/dist/api/pilot/Pilot_getAllScreenshots.d.ts.map +1 -1
- package/dist/api/pilot/Pilot_getLatestFlight.d.ts +1 -1
- package/dist/api/pilot/Pilot_getLatestFlight.d.ts.map +1 -1
- package/dist/api/pilot/Pilot_getStats.d.ts +1 -1
- package/dist/api/pilot/Pilot_getStats.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +17 -10
- package/src/api/FSHubApiRequest.ts +16 -0
- package/src/api/airline/Airline_get.ts +8 -0
- package/src/api/airline/Airline_getAll.ts +8 -0
- package/src/api/airline/Airline_getAllFlightDeparturesAndArrivals.ts +8 -0
- package/src/api/airline/Airline_getAllFlightsArrivals.ts +8 -0
- package/src/api/airline/Airline_getAllFlightsDepartures.ts +8 -0
- package/src/api/airline/Airline_getAllScreenshots.ts +16 -0
- package/src/api/airline/Airline_getFlights.ts +8 -0
- package/src/api/airline/Airline_getPilotStats.ts +8 -0
- package/src/api/airline/Airline_getPilots.ts +8 -0
- package/src/api/airline/Airline_getStats.ts +8 -0
- package/src/api/airline/index.ts +23 -0
- package/src/api/flight/Flight_getFlightById.ts +9 -0
- package/src/api/flight/Flight_getFlightScreenshotsById.ts +18 -0
- package/src/api/flight/index.ts +7 -0
- package/src/api/index.ts +9 -0
- package/src/api/pilot/Pilot_get.ts +8 -0
- package/src/api/pilot/Pilot_getAll.ts +8 -0
- package/src/api/pilot/Pilot_getAllAirlines.ts +8 -0
- package/src/api/pilot/Pilot_getAllFlightDeparturesAndArrivals.ts +8 -0
- package/src/api/pilot/Pilot_getAllFlights.ts +8 -0
- package/src/api/pilot/Pilot_getAllFlightsArrivals.ts +8 -0
- package/src/api/pilot/Pilot_getAllFlightsDepartures.ts +8 -0
- package/src/api/pilot/Pilot_getAllScreenshots.ts +16 -0
- package/src/api/pilot/Pilot_getCurrent.ts +8 -0
- package/src/api/pilot/Pilot_getLatestFlight.ts +8 -0
- package/src/api/pilot/Pilot_getStats.ts +8 -0
- package/src/api/pilot/index.ts +25 -0
- package/src/index.spec.ts +216 -0
- package/src/index.ts +1 -1
- package/src/types/index.ts +237 -0
- package/tsconfig.json +41 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Airline, FSHubApi, FSHubResponse } from "../../types";
|
|
2
|
+
import FSHubApiRequest from "../FSHubApiRequest";
|
|
3
|
+
|
|
4
|
+
export default async function Pilot_getAllAirlines(id: number, api: FSHubApi): Promise<Airline[]> {
|
|
5
|
+
const response: FSHubResponse<Airline[]> = await FSHubApiRequest(`pilot/${id}/airline`, api);
|
|
6
|
+
|
|
7
|
+
return response.data;
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Flight, FSHubApi, FSHubResponse } from "../../types";
|
|
2
|
+
import FSHubApiRequest from "../FSHubApiRequest";
|
|
3
|
+
|
|
4
|
+
export default async function Pilot_getAllFlightDeparturesAndArrivals(id: number, departureAirportCode: string, arrivalAirportCode: string, api: FSHubApi): Promise<Flight[]> {
|
|
5
|
+
const response: FSHubResponse<Flight[]> = await FSHubApiRequest(`pilot/${id}/flight/departure/${departureAirportCode}/arrival/${arrivalAirportCode}`, api);
|
|
6
|
+
|
|
7
|
+
return response.data;
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FSHubApi, FSHubResponse, Flight } from "../../types";
|
|
2
|
+
import FSHubApiRequest from "../FSHubApiRequest";
|
|
3
|
+
|
|
4
|
+
export default async function Pilot_getAllFlights(id: number, api: FSHubApi): Promise<Flight[]> {
|
|
5
|
+
const response: FSHubResponse<Flight[]> = await FSHubApiRequest(`pilot/${id}/flight`, api);
|
|
6
|
+
|
|
7
|
+
return response.data;
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FSHubApi, FSHubResponse, Flight } from "../../types";
|
|
2
|
+
import FSHubApiRequest from "../FSHubApiRequest";
|
|
3
|
+
|
|
4
|
+
export default async function Pilot_getAllFlightsArrivals(id: number, airportCode: string, api: FSHubApi): Promise<Flight[]> {
|
|
5
|
+
const response: FSHubResponse<Flight[]> = await FSHubApiRequest(`pilot/${id}/flight/arrival/${airportCode}`, api);
|
|
6
|
+
|
|
7
|
+
return response.data;
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Flight, FSHubApi, FSHubResponse } from "../../types";
|
|
2
|
+
import FSHubApiRequest from "../FSHubApiRequest";
|
|
3
|
+
|
|
4
|
+
export default async function Pilot_getAllFlightsDepartures(id: number, airportCode: string, api: FSHubApi): Promise<Flight[]> {
|
|
5
|
+
const response: FSHubResponse<Flight[]> = await FSHubApiRequest(`pilot/${id}/flight/departure/${airportCode}`, api);
|
|
6
|
+
|
|
7
|
+
return response.data;
|
|
8
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FSHubApi, FSHubResponse, Screenshot } from "../../types";
|
|
2
|
+
import FSHubApiRequest from "../FSHubApiRequest";
|
|
3
|
+
|
|
4
|
+
export default async function Pilot_getAllScreenshots(id: number, api: FSHubApi): Promise<Screenshot[]> {
|
|
5
|
+
try {
|
|
6
|
+
const response: FSHubResponse<Screenshot[]> = await FSHubApiRequest(`pilot/${id}/screenshot`, api);
|
|
7
|
+
|
|
8
|
+
return response.data;
|
|
9
|
+
} catch (error) {
|
|
10
|
+
if (error instanceof Error && error.message === 'No records found') {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CurrentPilot, FSHubApi, FSHubResponse } from "../../types";
|
|
2
|
+
import FSHubApiRequest from "../FSHubApiRequest";
|
|
3
|
+
|
|
4
|
+
export default async function Pilot_getCurrent(api: FSHubApi): Promise<CurrentPilot> {
|
|
5
|
+
const response: FSHubResponse<CurrentPilot> = await FSHubApiRequest('user', api);
|
|
6
|
+
|
|
7
|
+
return response.data;
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FSHubApi, FSHubResponse, Flight } from "../../types";
|
|
2
|
+
import FSHubApiRequest from "../FSHubApiRequest";
|
|
3
|
+
|
|
4
|
+
export default async function Pilot_getLatestFlight(id: number, api: FSHubApi): Promise<Flight> {
|
|
5
|
+
const response: FSHubResponse<Flight> = await FSHubApiRequest(`pilot/${id}/flight/latest`, api);
|
|
6
|
+
|
|
7
|
+
return response.data;
|
|
8
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FSHubApi, FSHubResponse, PilotStats } from "../../types";
|
|
2
|
+
import FSHubApiRequest from "../FSHubApiRequest";
|
|
3
|
+
|
|
4
|
+
export default async function Pilot_getStats(id: number, api: FSHubApi): Promise<PilotStats> {
|
|
5
|
+
const response: FSHubResponse<PilotStats> = await FSHubApiRequest(`pilot/${id}/stats`, api);
|
|
6
|
+
|
|
7
|
+
return response.data;
|
|
8
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import Pilot_getAll from './Pilot_getAll';
|
|
2
|
+
import Pilot_getCurrent from './Pilot_getCurrent';
|
|
3
|
+
import Pilot_get from './Pilot_get';
|
|
4
|
+
import Pilot_getLatestFlight from './Pilot_getLatestFlight';
|
|
5
|
+
import Pilot_getAllFlights from './Pilot_getAllFlights';
|
|
6
|
+
import Pilot_getAllAirlines from './Pilot_getAllAirlines';
|
|
7
|
+
import Pilot_getStats from './Pilot_getStats';
|
|
8
|
+
import Pilot_getAllFlightsDepartures from './Pilot_getAllFlightsDepartures';
|
|
9
|
+
import Pilot_getAllFlightsArrivals from './Pilot_getAllFlightsArrivals';
|
|
10
|
+
import Pilot_getAllFlightDeparturesAndArrivals from './Pilot_getAllFlightDeparturesAndArrivals';
|
|
11
|
+
import Pilot_getAllScreenshots from './Pilot_getAllScreenshots';
|
|
12
|
+
|
|
13
|
+
export const Pilot = {
|
|
14
|
+
getCurrent: Pilot_getCurrent,
|
|
15
|
+
getAll: Pilot_getAll,
|
|
16
|
+
get: Pilot_get,
|
|
17
|
+
getLatestFlight: Pilot_getLatestFlight,
|
|
18
|
+
getAllFlights: Pilot_getAllFlights,
|
|
19
|
+
getAllAirlines: Pilot_getAllAirlines,
|
|
20
|
+
getStats: Pilot_getStats,
|
|
21
|
+
getAllFlightsDepartures: Pilot_getAllFlightsDepartures,
|
|
22
|
+
getAllFlightsArrivals: Pilot_getAllFlightsArrivals,
|
|
23
|
+
getAllFlightDeparturesAndArrivals: Pilot_getAllFlightDeparturesAndArrivals,
|
|
24
|
+
getAllScreenshots: Pilot_getAllScreenshots,
|
|
25
|
+
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { describe, before } from 'mocha';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
import FSHubApiClass from './index';
|
|
4
|
+
import dotenv from 'dotenv';
|
|
5
|
+
import { CurrentPilot, Flight, Pilot, FSHubApi, Airline, PilotStats, Screenshot } from './types';
|
|
6
|
+
|
|
7
|
+
dotenv.config();
|
|
8
|
+
let api: FSHubApi;
|
|
9
|
+
|
|
10
|
+
describe('FSHubApi()', function() {
|
|
11
|
+
let apiKey: string;
|
|
12
|
+
|
|
13
|
+
before(function() {
|
|
14
|
+
if (!process.env.FSHUB_API_KEY) {
|
|
15
|
+
throw new Error('FSHUB_API_KEY is not set in .env file');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apiKey = process.env.FSHUB_API_KEY;
|
|
19
|
+
api = new FSHubApiClass({ apiKey });
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('when instantiated with valid data, it should return an FSHubApi object with the expected class methods', async function() {
|
|
23
|
+
expect(api.Pilot_getCurrent).to.be.a('function');
|
|
24
|
+
expect(api.Pilot_getAll).to.be.a('function');
|
|
25
|
+
expect(api.Pilot_get).to.be.a('function');
|
|
26
|
+
expect(api.Pilot_getLatestFlight).to.be.a('function');
|
|
27
|
+
expect(api.Pilot_getAllFlights).to.be.a('function');
|
|
28
|
+
expect(api.Pilot_getAllAirlines).to.be.a('function');
|
|
29
|
+
expect(api.Pilot_getStats).to.be.a('function');
|
|
30
|
+
expect(api.Pilot_getAllFlightsDepartures).to.be.a('function');
|
|
31
|
+
expect(api.Pilot_getAllFlightsArrivals).to.be.a('function');
|
|
32
|
+
expect(api.Pilot_getAllFlightDeparturesAndArrivals).to.be.a('function');
|
|
33
|
+
expect(api.Pilot_getAllScreenshots).to.be.a('function');
|
|
34
|
+
expect(api.Airline_getAll).to.be.a('function');
|
|
35
|
+
expect(api.Airline_get).to.be.a('function');
|
|
36
|
+
expect(api.Airline_getPilots).to.be.a('function');
|
|
37
|
+
expect(api.Airline_getPilotStats).to.be.a('function');
|
|
38
|
+
expect(api.Airline_getFlights).to.be.a('function');
|
|
39
|
+
expect(api.Airline_getAllFlightsDepartures).to.be.a('function');
|
|
40
|
+
expect(api.Airline_getAllFlightsArrivals).to.be.a('function');
|
|
41
|
+
expect(api.Airline_getAllFlightDeparturesAndArrivals).to.be.a('function');
|
|
42
|
+
expect(api.Airline_getAllScreenshots).to.be.a('function');
|
|
43
|
+
expect(api.Airline_getStats).to.be.a('function');
|
|
44
|
+
expect(api.Flight_getFlightById).to.be.a('function');
|
|
45
|
+
expect(api.Flight_getFlightScreenshotsById).to.be.a('function');
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe('Pilot', function() {
|
|
49
|
+
it('Pilot_getCurrent() is called, it should return a valid CurrentPilot object', async function() {
|
|
50
|
+
const pilot: CurrentPilot = await api.Pilot_getCurrent();
|
|
51
|
+
|
|
52
|
+
expect(pilot).to.be.an('Object');
|
|
53
|
+
expect(pilot.id).to.be.a('number');
|
|
54
|
+
expect(pilot.name).to.be.a('string');
|
|
55
|
+
expect(pilot.base).to.be.a('string');
|
|
56
|
+
expect(pilot.locale).to.be.an('string');
|
|
57
|
+
expect(pilot.gps).to.be.an('Object');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('Pilot_getAll() is called, it should return an array of valid Pilot objects', async function() {
|
|
61
|
+
const pilots: Pilot[] = await api.Pilot_getAll();
|
|
62
|
+
|
|
63
|
+
expect(pilots).to.be.an('Array');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('Pilot_get(id) is called, it should return a valid Pilot object', async function() {
|
|
67
|
+
const pilot: Pilot = await api.Pilot_get(1);
|
|
68
|
+
|
|
69
|
+
expect(pilot).to.be.an('Object');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('Pilot_getLatestFlight(id) is called, it should return a valid Flight object', async function() {
|
|
73
|
+
const pilot: Pilot = await api.Pilot_getCurrent();
|
|
74
|
+
const flight: Flight = await api.Pilot_getLatestFlight(pilot.id);
|
|
75
|
+
|
|
76
|
+
expect(flight).to.be.an('Object');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('Pilot_getAllFlights(id) is called, it should return an array of valid Flight objects', async function() {
|
|
80
|
+
const pilot: Pilot = await api.Pilot_getCurrent();
|
|
81
|
+
const flights: Flight[] = await api.Pilot_getAllFlights(pilot.id);
|
|
82
|
+
|
|
83
|
+
expect(flights).to.be.an('Array');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('Pilot_getAllAirlines(id) is called, it should return an array of valid Airline objects', async function() {
|
|
87
|
+
const pilot: Pilot = await api.Pilot_getCurrent();
|
|
88
|
+
const airlines: Airline[] = await api.Pilot_getAllAirlines(pilot.id);
|
|
89
|
+
|
|
90
|
+
expect(airlines).to.be.an('Array');
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('Pilot_getStats(id) is called, it should return a valid PilotStats object', async function() {
|
|
94
|
+
const pilot: Pilot = await api.Pilot_getCurrent();
|
|
95
|
+
const stats: PilotStats = await api.Pilot_getStats(pilot.id);
|
|
96
|
+
|
|
97
|
+
expect(stats).to.be.an('Object');
|
|
98
|
+
expect(stats.id).to.be.a('number');
|
|
99
|
+
expect(stats.all_time).to.be.an('Object');
|
|
100
|
+
expect(stats.month).to.be.an('Object');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('Pilot_getAllFlightsDepartures(id, airportCode) is called, it should return an array of valid Flight objects', async function() {
|
|
104
|
+
const pilot: Pilot = await api.Pilot_getCurrent();
|
|
105
|
+
const flights: Flight[] = await api.Pilot_getAllFlightsDepartures(pilot.id, 'KPHX');
|
|
106
|
+
|
|
107
|
+
expect(flights).to.be.an('Array');
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('Pilot_getAllFlightsArrivals(id, airportCode) is called, it should return an array of valid Flight objects', async function() {
|
|
111
|
+
const pilot: Pilot = await api.Pilot_getCurrent();
|
|
112
|
+
const flights: Flight[] = await api.Pilot_getAllFlightsArrivals(pilot.id, 'KPHX');
|
|
113
|
+
|
|
114
|
+
expect(flights).to.be.an('Array');
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('Pilot_getAllFlightDeparturesAndArrivals(id, departureAirportCode, arrivalAirportCode) is called, it should return an array of valid Flight objects', async function() {
|
|
118
|
+
const pilot: Pilot = await api.Pilot_getCurrent();
|
|
119
|
+
const flights: Flight[] = await api.Pilot_getAllFlightDeparturesAndArrivals(pilot.id, 'KPHX', 'KJAC');
|
|
120
|
+
|
|
121
|
+
expect(flights).to.be.an('Array');
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('Pilot_getAllScreenshots(id) is called, it should return an array of valid Screenshot objects', async function() {
|
|
125
|
+
const pilot: Pilot = await api.Pilot_getCurrent();
|
|
126
|
+
const screenshots: Screenshot[] = await api.Pilot_getAllScreenshots(pilot.id);
|
|
127
|
+
|
|
128
|
+
expect(screenshots).to.be.an('Array');
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe('Airline', function() {
|
|
133
|
+
it('Airline_getAll() is called, it should return an array of valid Airline objects', async function() {
|
|
134
|
+
const airlines: Airline[] = await api.Airline_getAll();
|
|
135
|
+
|
|
136
|
+
expect(airlines).to.be.an('Array');
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('Airline_get(id) is called, it should return a valid Airline object', async function() {
|
|
140
|
+
const airline: Airline = await api.Airline_get(6082);
|
|
141
|
+
|
|
142
|
+
expect(airline).to.be.an('Object');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('Airline_getPilots(id) is called, it should return an array of valid Pilot objects', async function() {
|
|
146
|
+
const airline: Airline = await api.Airline_get(6082);
|
|
147
|
+
const pilots: Pilot[] = await api.Airline_getPilots(airline.id);
|
|
148
|
+
|
|
149
|
+
expect(pilots).to.be.an('Array');
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('Airline_getPilotStats(id, pilotId) is called, it should return a valid PilotStats object', async function() {
|
|
153
|
+
const airline: Airline = await api.Airline_get(6082);
|
|
154
|
+
const pilot: Pilot = await api.Pilot_getCurrent();
|
|
155
|
+
const stats: PilotStats = await api.Airline_getPilotStats(airline.id, pilot.id);
|
|
156
|
+
|
|
157
|
+
expect(stats).to.be.an('Object');
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('Airline_getFlights(id) is called, it should return an array of valid Flight objects', async function() {
|
|
161
|
+
const airline: Airline = await api.Airline_get(6082);
|
|
162
|
+
const flights: Flight[] = await api.Airline_getFlights(airline.id);
|
|
163
|
+
|
|
164
|
+
expect(flights).to.be.an('Array');
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('Airline_getAllFlightsDepartures(id, airportCode) is called, it should return an array of valid Flight objects', async function() {
|
|
168
|
+
const airline: Airline = await api.Airline_get(6082);
|
|
169
|
+
const flights: Flight[] = await api.Airline_getAllFlightsDepartures(airline.id, 'KPHX');
|
|
170
|
+
|
|
171
|
+
expect(flights).to.be.an('Array');
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('Airline_getAllFlightsArrivals(id, airportCode) is called, it should return an array of valid Flight objects', async function() {
|
|
175
|
+
const airline: Airline = await api.Airline_get(6082);
|
|
176
|
+
const flights: Flight[] = await api.Airline_getAllFlightsArrivals(airline.id, 'KPHX');
|
|
177
|
+
|
|
178
|
+
expect(flights).to.be.an('Array');
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('Airline_getAllFlightDeparturesAndArrivals(id, departureAirportCode, arrivalAirportCode) is called, it should return an array of valid Flight objects', async function() {
|
|
182
|
+
const airline: Airline = await api.Airline_get(6082);
|
|
183
|
+
const flights: Flight[] = await api.Airline_getAllFlightDeparturesAndArrivals(airline.id, 'KPHX', 'KJAC');
|
|
184
|
+
|
|
185
|
+
expect(flights).to.be.an('Array');
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('Airline_getAllScreenshots(id) is called, it should return an array of valid Screenshot objects', async function() {
|
|
189
|
+
const airline: Airline = await api.Airline_get(6082);
|
|
190
|
+
const screenshots: Screenshot[] = await api.Airline_getAllScreenshots(airline.id);
|
|
191
|
+
|
|
192
|
+
expect(screenshots).to.be.an('Array');
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('Airline_getStats(id) is called, it should return a valid object with airline statistics', async function() {
|
|
196
|
+
const airline: Airline = await api.Airline_get(6082);
|
|
197
|
+
const stats = await api.Airline_getStats(airline.id);
|
|
198
|
+
|
|
199
|
+
expect(stats).to.be.an('Object');
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
describe('Flight', function() {
|
|
204
|
+
it('Flight_getFlightById(id) is called, it should return a valid Flight object', async function() {
|
|
205
|
+
const flight: Flight = await api.Flight_getFlightById(4009359);
|
|
206
|
+
|
|
207
|
+
expect(flight).to.be.an('Object');
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('Flight_getFlightScreenshotsById(id) is called, it should return an array of valid Screenshot objects', async function() {
|
|
211
|
+
const flight: Screenshot[] = await api.Flight_getFlightScreenshotsById(4009359);
|
|
212
|
+
|
|
213
|
+
expect(flight).to.be.an('Array');
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* FSHub API Types and type= s
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export type Config = {
|
|
8
|
+
baseURL?: string;
|
|
9
|
+
apiKey?: string;
|
|
10
|
+
timeout?: number;
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type CurrentPilot = Pilot & {
|
|
15
|
+
discord_id?: number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type Pilot = {
|
|
19
|
+
id: number
|
|
20
|
+
name: string
|
|
21
|
+
base: string
|
|
22
|
+
locale: string
|
|
23
|
+
gps: Gps
|
|
24
|
+
is_online: boolean
|
|
25
|
+
online_at: string
|
|
26
|
+
bio?: string
|
|
27
|
+
handles?: Handles
|
|
28
|
+
timezone?: string
|
|
29
|
+
country?: string
|
|
30
|
+
created_at?: string
|
|
31
|
+
links?: Link[]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type Handles = {
|
|
35
|
+
facebook: any
|
|
36
|
+
twitter: string
|
|
37
|
+
website: any
|
|
38
|
+
vatsim: string
|
|
39
|
+
ivao: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type Link = {
|
|
43
|
+
rel: string
|
|
44
|
+
uri: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export type Gps = {
|
|
48
|
+
lat: number
|
|
49
|
+
lng: number
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type FSHubResponse<T> = {
|
|
53
|
+
data: T
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type FSHubError = {
|
|
57
|
+
message: string
|
|
58
|
+
code: number
|
|
59
|
+
error?: boolean
|
|
60
|
+
details?: {
|
|
61
|
+
pilot: number
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type Flight = {
|
|
66
|
+
id: number
|
|
67
|
+
user: User
|
|
68
|
+
airline: Airline
|
|
69
|
+
schedule_status: any
|
|
70
|
+
aircraft: Aircraft
|
|
71
|
+
plan: any
|
|
72
|
+
fuel_used: number
|
|
73
|
+
landing_rate: number
|
|
74
|
+
distance: Distance
|
|
75
|
+
average: Average
|
|
76
|
+
max: Max
|
|
77
|
+
time: number
|
|
78
|
+
tags: any[]
|
|
79
|
+
flags: any[]
|
|
80
|
+
points: number
|
|
81
|
+
departure: Airport
|
|
82
|
+
arrival: Airport
|
|
83
|
+
links: Link[]
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export type Airline = {
|
|
87
|
+
id: number
|
|
88
|
+
name: string
|
|
89
|
+
abbr: string
|
|
90
|
+
owner: Owner
|
|
91
|
+
handles: Handles
|
|
92
|
+
links: Link[]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type Owner = {
|
|
96
|
+
id: number
|
|
97
|
+
name: string
|
|
98
|
+
bio: any
|
|
99
|
+
handles: Handles
|
|
100
|
+
base: string
|
|
101
|
+
locale: string
|
|
102
|
+
gps: Gps
|
|
103
|
+
timezone: string
|
|
104
|
+
country: string
|
|
105
|
+
is_online: boolean
|
|
106
|
+
online_at: string
|
|
107
|
+
created_at: string
|
|
108
|
+
links: Link[]
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export type User = {
|
|
112
|
+
id: number
|
|
113
|
+
name: string
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export type Aircraft = {
|
|
117
|
+
icao: string
|
|
118
|
+
icao_name: string
|
|
119
|
+
name: string
|
|
120
|
+
type: string
|
|
121
|
+
user_conf: UserConf
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export type UserConf = {
|
|
125
|
+
tail: string
|
|
126
|
+
icao: string
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export type Distance = {
|
|
130
|
+
nm: number
|
|
131
|
+
km: number
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export type Average = {
|
|
135
|
+
spd: number
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export type Max = {
|
|
139
|
+
alt: number
|
|
140
|
+
spd: number
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export type Geo = {
|
|
144
|
+
lat: number
|
|
145
|
+
lng: number
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export type Hdg = {
|
|
149
|
+
mag: number
|
|
150
|
+
true: number
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export type Spd = {
|
|
154
|
+
tas: number
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export type Wind = {
|
|
158
|
+
spd: number
|
|
159
|
+
dir: number
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export type Airport = {
|
|
163
|
+
icao: string
|
|
164
|
+
iata: string
|
|
165
|
+
name: string
|
|
166
|
+
time: string
|
|
167
|
+
geo: Geo
|
|
168
|
+
hdg: Hdg
|
|
169
|
+
spd: Spd
|
|
170
|
+
fuel: number
|
|
171
|
+
pitch: number
|
|
172
|
+
bank: number
|
|
173
|
+
wind: Wind
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export type PilotStats = {
|
|
177
|
+
id: number
|
|
178
|
+
all_time: PilotStat
|
|
179
|
+
month: PilotStat
|
|
180
|
+
links: Link[]
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export type AirlineStats = {
|
|
184
|
+
id: number
|
|
185
|
+
total_pilots: number
|
|
186
|
+
all_time: PilotStat
|
|
187
|
+
month: PilotStat
|
|
188
|
+
links: Link[]
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export type PilotStat = {
|
|
192
|
+
total_flights: number
|
|
193
|
+
total_hours: number
|
|
194
|
+
total_distance: number
|
|
195
|
+
average_landing: number
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export type Screenshot = {
|
|
199
|
+
id: number
|
|
200
|
+
name: string
|
|
201
|
+
desc: any
|
|
202
|
+
urls: Urls
|
|
203
|
+
created_at: string
|
|
204
|
+
links: Link[]
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export type Urls = {
|
|
208
|
+
fullsize: string
|
|
209
|
+
thumbnail: string
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export type FSHubApi = {
|
|
213
|
+
axios: AxiosInstance
|
|
214
|
+
Pilot_getCurrent: () => Promise<CurrentPilot>
|
|
215
|
+
Pilot_getAll: () => Promise<Pilot[]>
|
|
216
|
+
Pilot_get: (id: number) => Promise<Pilot>
|
|
217
|
+
Pilot_getLatestFlight: (id: number) => Promise<Flight>
|
|
218
|
+
Pilot_getAllFlights: (id: number) => Promise<Flight[]>
|
|
219
|
+
Pilot_getAllAirlines: (id: number) => Promise<Airline[]>
|
|
220
|
+
Pilot_getStats: (id: number) => Promise<PilotStats>
|
|
221
|
+
Pilot_getAllFlightsDepartures:(id:number, airportCode:string) => Promise<Flight[]>
|
|
222
|
+
Pilot_getAllFlightsArrivals:(id:number, airportCode:string) => Promise<Flight[]>
|
|
223
|
+
Pilot_getAllFlightDeparturesAndArrivals:(id:number, departureAirportCode:string, arrivalAirportCode:string) => Promise<Flight[]>
|
|
224
|
+
Pilot_getAllScreenshots: (id: number) => Promise<Screenshot[]>
|
|
225
|
+
Airline_getAll: () => Promise<Airline[]>
|
|
226
|
+
Airline_get: (id: number) => Promise<Airline>
|
|
227
|
+
Airline_getPilots: (id: number) => Promise<Pilot[]>
|
|
228
|
+
Airline_getPilotStats: (id: number, pilotId: number) => Promise<PilotStats>
|
|
229
|
+
Airline_getFlights: (id: number) => Promise<Flight[]>
|
|
230
|
+
Airline_getAllFlightsDepartures:(id:number, airportCode:string) => Promise<Flight[]>
|
|
231
|
+
Airline_getAllFlightsArrivals:(id:number, airportCode:string) => Promise<Flight[]>
|
|
232
|
+
Airline_getAllFlightDeparturesAndArrivals:(id:number, departureAirportCode:string, arrivalAirportCode:string) => Promise<Flight[]>
|
|
233
|
+
Airline_getAllScreenshots: (id: number) => Promise<Screenshot[]>
|
|
234
|
+
Airline_getStats: (id: number) => Promise<AirlineStats>
|
|
235
|
+
Flight_getFlightById: (id: number) => Promise<Flight>
|
|
236
|
+
Flight_getFlightScreenshotsById: (id: number) => Promise<Screenshot[]>
|
|
237
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es5",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"lib": ["ESNext"],
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"rootDir": "./src",
|
|
9
|
+
"baseUrl": "./src",
|
|
10
|
+
"strict": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"allowSyntheticDefaultImports": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"declaration": true,
|
|
16
|
+
"declarationMap": true,
|
|
17
|
+
"sourceMap": true,
|
|
18
|
+
"removeComments": false,
|
|
19
|
+
"noImplicitAny": true,
|
|
20
|
+
"noImplicitReturns": true,
|
|
21
|
+
"noImplicitThis": true,
|
|
22
|
+
"noUnusedLocals": true,
|
|
23
|
+
"noUnusedParameters": true,
|
|
24
|
+
"exactOptionalPropertyTypes": true,
|
|
25
|
+
"noImplicitOverride": true,
|
|
26
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
27
|
+
"noUncheckedIndexedAccess": true,
|
|
28
|
+
"paths": {
|
|
29
|
+
"@/*": ["./*"]
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"include": [
|
|
33
|
+
"src"
|
|
34
|
+
],
|
|
35
|
+
"exclude": [
|
|
36
|
+
"node_modules",
|
|
37
|
+
"dist",
|
|
38
|
+
"**/*.test.ts",
|
|
39
|
+
"**/*.spec.ts"
|
|
40
|
+
]
|
|
41
|
+
}
|