@bridgerakol/samsung-smart-api
Version:
Node Module For Connecting Samsung Smartthings API
78 lines (77 loc) • 3.55 kB
JavaScript
;
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 Locations {
constructor(BearerToken, BaseUrl) {
this.getList = () => __awaiter(this, void 0, void 0, function* () {
let url = `${this.BaseUrl}/locations`;
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.getDetail = (locationId) => __awaiter(this, void 0, void 0, function* () {
let url = `${this.BaseUrl}/locations/${locationId}`;
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 = (payload) => __awaiter(this, void 0, void 0, function* () {
let url = `${this.BaseUrl}/locations/`;
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) => __awaiter(this, void 0, void 0, function* () {
let url = `${this.BaseUrl}/locations/${locationId}`;
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, payload) => __awaiter(this, void 0, void 0, function* () {
let url = `${this.BaseUrl}/locations/${locationId}`;
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 = Locations;