@flybywiresim/api-client
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -74,2 +74,5 @@ export declare class MetarResponse { | ||
} | ||
export declare class NXApi { | ||
static url: URL; | ||
} | ||
export declare class Metar { | ||
@@ -76,0 +79,0 @@ static get(icao: string, source?: string): Promise<MetarResponse>; |
@@ -16,3 +16,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Telex = exports.Taf = exports.Atis = exports.Metar = exports.TelexNotConnectedError = exports.HttpError = void 0; | ||
exports.Telex = exports.Taf = exports.Atis = exports.Metar = exports.NXApi = exports.TelexNotConnectedError = exports.HttpError = void 0; | ||
var HttpError = /** @class */ (function (_super) { | ||
@@ -39,5 +39,6 @@ __extends(HttpError, _super); | ||
} | ||
NXApi.url = "https://api.flybywiresim.com"; | ||
NXApi.url = new URL("https://api.flybywiresim.com"); | ||
return NXApi; | ||
}()); | ||
exports.NXApi = NXApi; | ||
var Metar = /** @class */ (function () { | ||
@@ -50,7 +51,7 @@ function Metar() { | ||
} | ||
var url = NXApi.url + "/metar/" + icao; | ||
var url = new URL("/metar/" + icao, NXApi.url); | ||
if (source) { | ||
url += "?source=" + source; | ||
url.searchParams.set("source", source); | ||
} | ||
return fetch(url) | ||
return fetch(url.href) | ||
.then(function (response) { | ||
@@ -73,7 +74,7 @@ if (!response.ok) { | ||
} | ||
var url = NXApi.url + "/atis/" + icao; | ||
var url = new URL("/atis/" + icao, NXApi.url); | ||
if (source) { | ||
url += "?source=" + source; | ||
url.searchParams.set("source", source); | ||
} | ||
return fetch(url) | ||
return fetch(url.href) | ||
.then(function (response) { | ||
@@ -96,7 +97,7 @@ if (!response.ok) { | ||
} | ||
var url = NXApi.url + "/taf/" + icao; | ||
var url = new URL("/taf/" + icao, NXApi.url); | ||
if (source) { | ||
url += "?source=" + source; | ||
url.searchParams.set("source", source); | ||
} | ||
return fetch(url) | ||
return fetch(url.href) | ||
.then(function (response) { | ||
@@ -120,3 +121,4 @@ if (!response.ok) { | ||
}; | ||
return fetch(NXApi.url + "/txcxn", { method: "POST", body: JSON.stringify(connectBody), headers: headers }) | ||
var url = new URL("/txcxn", NXApi.url); | ||
return fetch(url.href, { method: "POST", body: JSON.stringify(connectBody), headers: headers }) | ||
.then(function (response) { | ||
@@ -140,3 +142,4 @@ if (!response.ok) { | ||
}; | ||
return fetch(NXApi.url + "/txcxn", { method: "PUT", body: JSON.stringify(connectBody), headers: headers }) | ||
var url = new URL("/txcxn", NXApi.url); | ||
return fetch(url.href, { method: "PUT", body: JSON.stringify(connectBody), headers: headers }) | ||
.then(function (response) { | ||
@@ -154,3 +157,4 @@ if (!response.ok) { | ||
}; | ||
return fetch(NXApi.url + "/txcxn", { method: "DELETE", headers: headers }) | ||
var url = new URL("/txcxn", NXApi.url); | ||
return fetch(url.href, { method: "DELETE", headers: headers }) | ||
.then(function (response) { | ||
@@ -173,3 +177,4 @@ if (!response.ok) { | ||
}; | ||
return fetch(NXApi.url + "/txmsg", { method: "POST", body: JSON.stringify(body), headers: headers }) | ||
var url = new URL("/txmsg", NXApi.url); | ||
return fetch(url.href, { method: "POST", body: JSON.stringify(body), headers: headers }) | ||
.then(function (response) { | ||
@@ -187,3 +192,4 @@ if (!response.ok) { | ||
}; | ||
return fetch(NXApi.url + "/txmsg", { method: "GET", headers: headers }) | ||
var url = new URL("/txmsg", NXApi.url); | ||
return fetch(url.href, { method: "GET", headers: headers }) | ||
.then(function (response) { | ||
@@ -197,10 +203,10 @@ if (!response.ok) { | ||
Telex.fetchConnections = function (skip, take) { | ||
var url = NXApi.url + "/txcxn?"; | ||
var url = new URL("/txcxn", NXApi.url); | ||
if (skip) { | ||
url += "skip=" + skip + "&"; | ||
url.searchParams.set("skip", skip.toString()); | ||
} | ||
if (take) { | ||
url += "take=" + take; | ||
url.searchParams.append("take", take.toString()); | ||
} | ||
return fetch(url, { method: "GET" }) | ||
return fetch(url.href, { method: "GET" }) | ||
.then(function (response) { | ||
@@ -214,3 +220,4 @@ if (!response.ok) { | ||
Telex.fetchConnection = function (id) { | ||
return fetch(NXApi.url + "/txcxn/" + id, { method: "GET" }) | ||
var url = new URL("/txcxn/" + id, NXApi.url); | ||
return fetch(url.href, { method: "GET" }) | ||
.then(function (response) { | ||
@@ -224,3 +231,5 @@ if (!response.ok) { | ||
Telex.findConnection = function (flightNumber) { | ||
return fetch(NXApi.url + "/txcxn/_find?flight=" + flightNumber, { method: "GET" }) | ||
var url = new URL("/txcxn/_find", NXApi.url); | ||
url.searchParams.set("flight", flightNumber); | ||
return fetch(url.href, { method: "GET" }) | ||
.then(function (response) { | ||
@@ -227,0 +236,0 @@ if (!response.ok) { |
{ | ||
"name": "@flybywiresim/api-client", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Client library for the FlyByWire Simulations API", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
13133
355