Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/* eslint camelcase: "off" */
import { DateTime } from 'luxon'
import { createClientAsync } from 'soap'
const WSDL_URL = 'http://rtpi.dublinbus.ie/DublinBusRTPIService.asmx?WSDL'
const clientPromise = createClientAsync(WSDL_URL)
interface GetRealTimeStopDataOptions {
readonly stopId: number
readonly forceRefresh: boolean
}
interface GetRealTimeStopDataResponse {
readonly GetRealTimeStopDataResult: {
readonly diffgram: {
readonly DocumentElement: {
readonly StopData: Array<{
ServiceDelivery_ResponseTimestamp: string
MonitoredVehicleJourney_PublishedLineName: string
MonitoredVehicleJourney_DestinationName: string
MonitoredCall_ExpectedArrivalTime: string
MonitoredCall_VehicleAtStop: string
export const getClientInternal = async (
opts: ClientOptions
): Promise => {
const authOptions = opts.credentials ? makeAuthOptions(opts.credentials) : {}
const defaultOptions = { rejectUnauthorized: false, strictSSL: false }
const endpoint = getEndpoint(opts)
const options: IOptions = {
endpoint,
...defaultOptions,
...authOptions,
}
const client: T = await createClientAsync(opts.wsdlPath, options)
// note: the options endpoint and setEndpoint seem to set different values
// within the client. Setting both seems to work best :-B
client.setEndpoint(endpoint)
opts.credentials && setSecurity(client, opts.credentials)
return client
}
private getSoapClient(serviceName: WsServicesNames): any {
const urls = this.urls[this.getAfipEnvironment()];
const type = serviceName === "login" ? "login" : "service";
const url = urls[type].replace("{name}", encodeURIComponent(serviceName));
return soap.createClientAsync(url, {
namespaceArrayElements: false,
});
}
async function main () {
const client = await soap.createClientAsync(WSDL_URL)
const stopId = Number(process.argv[2])
getRealTimeInfoForStop(client, stopId)
}
static create_client(wsdl, wss_security, app_id){
debug("create_client() started.");
return soap.createClientAsync(wsdl).then(
(client) => {
debug("Rightnow soap client created.");
client.setSecurity(wss_security);
client.addSoapHeader(
{
ClientInfoHeader: {
AppID : app_id
}
}, //soapHeader Object({rootName: {name: "value"}}) or strict xml-string
'', //name Unknown parameter (it could just a empty string)
'rnm_v1', //namespace prefix of xml namespace
'' //xmlns URI
);
return client;
}
)