@apica-io/url-xi
Version:
URL Check for integrations and API monitoring
89 lines • 3.32 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ATSRest = void 0;
const log4js_1 = require("log4js");
class ATSRest {
constructor(api, url) {
this._api = api;
this._logger = (0, log4js_1.getLogger)('ATS-Rest');
this._url = url;
}
getUrl() {
return this._url;
}
getTableContent(table, columns) {
return __awaiter(this, void 0, void 0, function* () {
const data = [];
// eslint-disable-next-line no-constant-condition
while (true) {
const body = yield this.getTableRow(table, columns);
if (!body || Object.keys(body).length === 0)
break;
data.push(body);
}
return data;
});
}
getTableRow(table, columns) {
return __awaiter(this, void 0, void 0, function* () {
const config = {
data: {
TableName: table,
ColumnNames: columns,
},
params: { cmd: 'ats_retrieve_row' },
};
const response = yield this._api.get(this._url, config);
return response.data;
});
}
getTableSize(table, column) {
return __awaiter(this, void 0, void 0, function* () {
let tableSize = 0;
const config = {
data: {
TableName: table,
},
params: { cmd: 'ats_retrieve_table_size' },
};
if (column) {
config.data['ColumName'] = column;
}
try {
const response = yield this._api.post(this._url, config);
if (response.data && response.data.TableLength)
tableSize = response.data.TableLength;
}
catch (error) {
this._logger.error('getTableSize:', error.message);
}
return tableSize;
});
}
sendTableRow(table, columns, values, type) {
return __awaiter(this, void 0, void 0, function* () {
const config = {
data: {
TableName: table,
ColumnNames: columns,
ColumnValues: values,
Type: type ? type : 'ROW',
},
params: { cmd: 'ats_send_row' },
};
const response = yield this._api.post(this._url, config);
return response.data;
});
}
}
exports.ATSRest = ATSRest;
//# sourceMappingURL=ats-rest.js.map