umbot
Version:
Universal bot(vk, telegram, viber) or skills for Yandex.Alisa, Маруся and sber
39 lines (38 loc) • 1.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.YandexRequest = void 0;
const Request_1 = require("./request/Request");
const mmApp_1 = require("../mmApp");
class YandexRequest {
_request;
_oauth;
_error;
constructor(oauth = null) {
this.setOAuth(oauth || mmApp_1.mmApp.params.yandex_token || null);
this._request = new Request_1.Request();
this._request.maxTimeQuery = 1500;
this._error = null;
}
setOAuth(oauth) {
this._oauth = oauth;
if (this._request.header) {
this._request.header = { 'Authorization: OAuth ': this._oauth };
}
}
async call(url = null) {
const data = await this._request.send(url);
if (data.status && data.data) {
if (data.data.hasOwnProperty('error')) {
this._error = JSON.stringify(data.data.error);
}
return data.data;
}
this._log(data.err);
return null;
}
_log(error = '') {
error = `\n${Date}Произошла ошибка при отправке запроса по адресу: ${this._request.url}\nОшибка:\n${error}\n${this._error}\n`;
mmApp_1.mmApp.saveLog('YandexApi.log', error);
}
}
exports.YandexRequest = YandexRequest;