webclient-node.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. "use strict";
  2. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  3. return new (P || (P = Promise))(function (resolve, reject) {
  4. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  5. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  6. function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
  7. step((generator = generator.apply(thisArg, _arguments || [])).next());
  8. });
  9. };
  10. Object.defineProperty(exports, "__esModule", { value: true });
  11. const request = require("request-promise");
  12. class WebClientNode {
  13. request(options) {
  14. return __awaiter(this, void 0, void 0, function* () {
  15. const rpOptions = {
  16. method: options.method,
  17. uri: options.url
  18. };
  19. const result = request(rpOptions);
  20. return result;
  21. });
  22. }
  23. requestJSON(options) {
  24. return __awaiter(this, void 0, void 0, function* () {
  25. if (!options.headers) {
  26. options.headers = {};
  27. }
  28. if (options.body) {
  29. options.headers['content-type'] = 'application/json';
  30. if (typeof options.body === 'object') {
  31. options.body = JSON.stringify(options.body);
  32. }
  33. }
  34. options.headers.accept = 'application/json';
  35. return JSON.parse(yield this.request(options));
  36. });
  37. }
  38. }
  39. exports.default = WebClientNode;
  40. //# sourceMappingURL=webclient-node.js.map