bria
Version:
CounterPath Bria Desktop API for Node.js
50 lines • 1.87 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var sxml_1 = __importDefault(require("sxml"));
var BriaRequest = /** @class */ (function () {
/**
* instantiate a new BriaRequest
* @param endpoint Endpoint for request
* @param tag Root XML tag for body
*/
function BriaRequest(endpoint, tag) {
this.hasBody = false;
this.endpoint = endpoint;
if (tag) {
this.tag = tag;
this.hasBody = true;
this.xml = new sxml_1.default.XML();
//this.xml.setTag('status')
this.xml.setTag(this.tag);
}
}
BriaRequest.prototype.buildRequest = function (userAgent, transactionId) {
var contentLength = 0;
var bodyString = '';
if (this.xml) {
var xds = sxml_1.default.XML.head('utf-8');
var str = this.toXML().toString();
bodyString = "".concat(xds, "\r\n").concat(str);
contentLength = bodyString.length;
}
var req = "GET /".concat(this.endpoint, "\r\n");
req += "User-Agent: ".concat(userAgent, "\r\n");
req += "Transaction-ID: ".concat(transactionId, "\r\n");
req += "Content-Type: application/xml\r\n";
req += "Content-Length: ".concat(contentLength);
if (bodyString !== '') {
req += "\r\n".concat(bodyString);
}
return req;
};
BriaRequest.prototype.toXML = function () {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return this.xml;
};
return BriaRequest;
}());
exports.default = BriaRequest;
//# sourceMappingURL=BriaRequest.js.map