"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _react = _interopRequireDefault(require("react")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function checkIt(resp) { if (parseInt(resp.status / 100, 10) === 2) { return resp; } else { throw resp; } } function catchIt(err) { if (parseInt(err.status / 100, 10) === 5 || parseInt(err.status / 100, 10) === 4) { throw err; } else { return err; } } var API = /*#__PURE__*/ function () { function API(baseURL) { _classCallCheck(this, API); this.baseURL = ''; } _createClass(API, [{ key: "setUrl", value: function setUrl(url) { this.baseURL = url; } }, { key: "get", value: function get(url, token) { url = this.baseURL + url; return window.fetch(url, { method: 'GET', headers: { 'token': token } }).then(checkIt).then(function (r) { return r.json(); }).catch(catchIt); } }, { key: "post", value: function post(url, body, token) { var urb = this.baseURL + url; return window.fetch(urb, { method: 'POST', headers: { 'Content-Type': 'application/json', 'token': token }, body: JSON.stringify(body) }).then(checkIt).then(function (r) { return r.json(); }).catch(catchIt); } }]); return API; }(); var _default = new API(); exports.default = _default;