webclient-node.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. body: options.body,
  19. headers: options.headers
  20. };
  21. const result = request(rpOptions);
  22. return result;
  23. });
  24. }
  25. requestJSON(options) {
  26. return __awaiter(this, void 0, void 0, function* () {
  27. if (!options.headers) {
  28. options.headers = {};
  29. }
  30. if (options.body) {
  31. options.headers['content-type'] = 'application/json';
  32. if (typeof options.body === 'object') {
  33. options.body = JSON.stringify(options.body);
  34. }
  35. }
  36. options.headers.accept = 'application/json';
  37. return JSON.parse(yield this.request(options));
  38. });
  39. }
  40. }
  41. exports.default = WebClientNode;
  42. //# sourceMappingURL=webclient-node.js.map