UNPKG

holly-sdk

Version:
48 lines (38 loc) 1.87 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DevicesAPI = undefined; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _got = require("got"); var _got2 = _interopRequireDefault(_got); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var DevicesAPI = exports.DevicesAPI = function () { function DevicesAPI(app) { _classCallCheck(this, DevicesAPI); this.app = app; } _createClass(DevicesAPI, [{ key: "getAll", value: function getAll(with_latest_event) { return (0, _got2.default)(this.app.api.url + "/devices?with_latest_event=" + (with_latest_event ? 1 : 0), { method: "GET", json: true }).then(function (res) { return res.body.devices; }); } }, { key: "instruct", value: function instruct(deviceId, instruction) { return (0, _got2.default)(this.app.api.url + "/devices/" + deviceId + "/instructions", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ instruction: instruction }), json: true }); } }]); return DevicesAPI; }();