123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- "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 || parseInt(resp.status / 100, 10) === 3) {
- return resp;
- } else {
- throw resp;
- }
- }
- function catchIt(err) {
- if (err.message === "Unexpected token O in JSON at position 0") {
- return "OK";
- }
- if (parseInt(err.status / 100, 10) === 4) {
- throw err;
- } else if (parseInt(err.status / 100, 10) === 5) {
- throw err;
- } else {
- return err;
- }
- }
- var API =
- /*#__PURE__*/
- function () {
- function API() {
- var baseURL = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
- var token = arguments.length > 1 ? arguments[1] : undefined;
- _classCallCheck(this, API);
- // if (process.env.NODE_ENV === 'production' && !baseURL.includes('http')) {
- baseURL = "/api/" + baseURL; // }
- this.baseURL = baseURL;
- this.token = token;
- }
- _createClass(API, [{
- key: "setToken",
- value: function setToken(t) {
- this.token = t;
- }
- }, {
- key: "get",
- value: function get(url) {
- var urb = this.baseURL + url;
- return window.fetch(urb, {
- method: 'GET',
- headers: {
- 'Content-Type': 'application/json',
- 'Token': this.token
- }
- }).then(checkIt).then(function (r) {
- return r.json();
- }).catch(catchIt);
- }
- }, {
- key: "post",
- value: function post(url, body) {
- var urb = this.baseURL + url;
- return window.fetch(urb, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'Token': this.token
- },
- body: JSON.stringify(body)
- }).then(checkIt).then(function (r) {
- return r.json();
- }).catch(catchIt);
- }
- }, {
- key: "put",
- value: function put(url, body) {
- var urb = this.baseURL + url;
- return window.fetch(urb, {
- method: 'PUT',
- headers: {
- 'Content-Type': 'application/json',
- 'Token': this.token
- },
- body: JSON.stringify(body)
- }).then(checkIt).then(function (r) {
- return r.json();
- }).catch(catchIt);
- }
- }, {
- key: "delete",
- value: function _delete(url) {
- var urb = this.baseURL + url;
- return window.fetch(urb, {
- method: 'DELETE',
- headers: {
- 'Content-Type': 'application/json',
- 'Token': this.token
- }
- }).then(checkIt).then(function (r) {
- return r.json();
- }).catch(catchIt);
- }
- }]);
- return API;
- }();
- var _default = API;
- exports.default = _default;
|