UNPKG

@bridgerakol/samsung-smart-api

Version:

Node Module For Connecting Samsung Smartthings API

87 lines (86 loc) 4.08 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const axios_1 = require("axios"); class Rooms { constructor(BearerToken, BaseUrl) { this.getList = (locationId) => __awaiter(this, void 0, void 0, function* () { let url = `${this.BaseUrl}/locations/${locationId}/rooms`; return axios_1.default.get(url, { headers: this.ReqHeader }) .then((res) => { let Rdata = res.data; return { data: Rdata, status: true }; }) .catch((err) => { return { data: err.response, status: false }; }); }); this.getBulkList = (locations) => __awaiter(this, void 0, void 0, function* () { // let url = `${this.BaseUrl}/locations/${locationId}/rooms`; let promises = []; locations.forEach(loc => { promises.push(this.getList(loc)); }); let result = yield Promise.all(promises); return result; }); this.getDetail = (locationId, roomId) => __awaiter(this, void 0, void 0, function* () { let url = `${this.BaseUrl}/locations/${locationId}/rooms/${roomId}`; return axios_1.default.get(url, { headers: this.ReqHeader }) .then((res) => { let Rdata = res.data; return { data: Rdata, status: true }; }) .catch((err) => { return { data: err.response, status: false }; }); }); this.create = (locationId, payload) => __awaiter(this, void 0, void 0, function* () { let url = `${this.BaseUrl}/locations/${locationId}/rooms`; return axios_1.default.post(url, payload, { headers: this.ReqHeader }) .then((res) => { let Rdata = res.data; return { data: Rdata, status: true }; }) .catch((err) => { return { data: err.response, status: false }; }); }); this.remove = (locationId, roomId) => __awaiter(this, void 0, void 0, function* () { let url = `${this.BaseUrl}/locations/${locationId}/rooms/${roomId}`; return axios_1.default.delete(url, { headers: this.ReqHeader }) .then((res) => { let Rdata = res.data; return { data: Rdata, status: true }; }) .catch((err) => { return { data: err.response, status: false }; }); }); this.update = (locationId, roomId, payload) => __awaiter(this, void 0, void 0, function* () { let url = `${this.BaseUrl}/locations/${locationId}/rooms/${roomId}`; return axios_1.default.put(url, payload, { headers: this.ReqHeader }) .then((res) => { let Rdata = res.data; return { data: Rdata, status: true }; }) .catch((err) => { return { data: err.response, status: false }; }); }); this.BaseUrl = BaseUrl; this.ReqHeader = { "Authorization": BearerToken, "Content-Type": "application/json" }; } } exports.default = Rooms;