@bridgerakol/samsung-smart-api
Version:
Node Module For Connecting Samsung Smartthings API
73 lines (68 loc) • 2.67 kB
text/typescript
import axios from 'axios';
import { locationPayload, locationResponse, listLocation } from './payloadType';
export default class Locations {
BaseUrl: string;
ReqHeader: Object
constructor(BearerToken: string, BaseUrl: string) {
this.BaseUrl = BaseUrl;
this.ReqHeader = {
"Authorization": BearerToken,
"Content-Type": "application/json"
}
}
getList = async () => {
let url = `${this.BaseUrl}/locations`
return axios.get(url, { headers: this.ReqHeader })
.then((res: any) => {
let Rdata: listLocation = res.data
return { data: Rdata, status: true }
})
.catch((err: any) => {
return { data: err.response, status: false }
})
}
getDetail = async (locationId: string) => {
let url = `${this.BaseUrl}/locations/${locationId}`
return axios.get(url, { headers: this.ReqHeader })
.then((res: any) => {
let Rdata: locationResponse = res.data;
return { data: Rdata, status: true }
})
.catch((err: any) => {
return { data: err.response, status: false }
})
}
create = async (payload: locationPayload) => {
let url = `${this.BaseUrl}/locations/`
return axios.post(url, payload, { headers: this.ReqHeader })
.then((res: any) => {
let Rdata: locationResponse = res.data;
return { data: Rdata, status: true }
})
.catch((err: any) => {
return { data: err.response, status: false }
})
}
remove = async (locationId: string) => {
let url = `${this.BaseUrl}/locations/${locationId}`
return axios.delete(url, { headers: this.ReqHeader })
.then((res: any) => {
let Rdata: {} = res.data
return { data: Rdata, status: true }
})
.catch((err: any) => {
return { data: err.response, status: false }
})
}
update = async (locationId: string, payload: locationPayload) => {
let url = `${this.BaseUrl}/locations/${locationId}`
return axios.put(url, payload, { headers: this.ReqHeader })
.then((res: any) => {
let Rdata: locationResponse = res.data;
return { data: Rdata, status: true }
})
.catch((err: any) => {
return { data: err.response, status: false }
})
}
}