atix-internetmarke
Version:
A node wrapper for the Internetmarke web service of the Deutsche Post.
64 lines (53 loc) • 1.3 kB
JavaScript
/**
* internetmarke
* Copyright (c) 2018 Manuel Schächinger
* MIT Lisenced
*/
;
const soap = require('soap');
class SoapService {
/**
* Creates a new soap service instance.
*
* @constructor
* @param {Object} config
* @param {string} config.wsdl - The wsdl url that desclares the service.
* @param {User} config.user - The user object to retrieve the session token.
*/
constructor({ wsdl, user }) {
/** @type {string} */
this._wsdl = wsdl;
/** @type{(User|null)} */
this._user = user;
this._soapClient = null;
}
/**
* Helper method to retrieve the soap client for every api call.
*
* @returns {Promise.<Client>}
*/
_getSoapClient() {
let promise = null;
if (this._soapClient) {
promise = Promise.resolve(this._soapClient);
}
else {
promise = soap.createClientAsync(this._wsdl, {
disableCache: true
})
.then(client => {
this._soapClient = client;
this._initClient(client);
return client;
});
}
return promise;
}
/**
* Retrieve the client object in every case.
*
* @param {Client} client - The client object that links to the web serice.
*/
_initClient(client) {}
}
module.exports = SoapService;