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(''); +})();