From 1c3744304ee1a0c57eb24e28d91933bd4ae844ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marti=CC=81n=20M?= Date: Fri, 28 Jun 2019 23:34:54 -0300 Subject: [PATCH] added serverles example --- README.md | 2 +- demo/{example.js => node-script.js} | 0 demo/serverless.js | 25 +++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) rename demo/{example.js => node-script.js} (100%) create mode 100644 demo/serverless.js diff --git a/README.md b/README.md index fbcbfe9..c5049d7 100644 --- a/README.md +++ b/README.md @@ -24,4 +24,4 @@ const ewelink = require('ewelink-api'); })(); ``` -Check `demo/example.js` for more examples. \ No newline at end of file +Check `demo/` directory for more examples. \ No newline at end of file diff --git a/demo/example.js b/demo/node-script.js similarity index 100% rename from demo/example.js rename to demo/node-script.js diff --git a/demo/serverless.js b/demo/serverless.js new file mode 100644 index 0000000..3ec6127 --- /dev/null +++ b/demo/serverless.js @@ -0,0 +1,25 @@ +const ewelink = require('../main'); + +(async () => { + /* first request: get access token and api key */ + const conn1 = new ewelink({ + email: '', + password: '', + }); + const login = await conn1.login(); + const accessToken = login.at; + + /* second request: use access token to request devices */ + const conn2 = new ewelink({ at: accessToken }); + const devices = await conn2.getDevices(); + console.log(devices); + + /* third request: use access token to request specific device info */ + const conn3 = new ewelink({ at: accessToken }); + const device = await conn3.getDevice(''); + console.log(device); + + /* fourth request: use access token to toggle specific device info */ + const conn4 = new ewelink({ at: accessToken }); + await conn4.toggleDevice(''); +})();