UNPKG

webex-teams-api-wrapper

Version:
71 lines (70 loc) 2.19 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const webex_1 = __importDefault(require("../webex")); const got_1 = __importDefault(require("got")); class Request { /** * Sending GET request to the endpoint * * @param endpoint the endpoint * @param params payload */ static get(endpoint, body) { const queryString = []; if (body) { for (let x in body) { queryString.push(x + "=" + body[x]); } } return Request.send("get", webex_1.default.getApiUrl() + "/" + endpoint + (body ? "?" + queryString.join("&") : "")); } /** * Sending POST request to the endpoint * * @param endpoint the endpoint * @param body payload */ static post(endpoint, body) { return Request.send("post", webex_1.default.getApiUrl() + "/" + endpoint, body); } /** * Sending DELETE request to the endpoint * * @param endpoint the endpoint */ static delete(endpoint) { return Request.send("delete", webex_1.default.getApiUrl() + "/" + endpoint); } /** * Sending PUT request to the endpoint * * @param endpoint the endpoint * @param body payload */ static put(endpoint, body) { return Request.send("put", webex_1.default.getApiUrl() + "/" + endpoint, body); } /** * Sending the request * * @param method The request method * @param url The URL * @param body payload */ static send(method, url, body) { return got_1.default(url, { method: method, headers: { "Authorization": `Bearer ${webex_1.default.getAccesToken()}`, "Content-Type": "application/json" }, resolveBodyOnly: true, responseType: "json", body: body ? JSON.stringify(body) : undefined }); } } exports.default = Request;