From 29625666791287c88322f354147d6538bf28870d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marti=CC=81n=20M?= Date: Fri, 28 Jun 2019 23:24:46 -0300 Subject: [PATCH] class refactor --- main.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index 5b918e1..a5d0142 100644 --- a/main.js +++ b/main.js @@ -13,19 +13,23 @@ const { } = require('./lib/ewelink-helper'); class eWeLink { - constructor({ region = 'us', email, password }) { + constructor({ region = 'us', email, password, at, apiKey }) { + if (!at && (!email && !password)) { + return { error: 'No credentials provided' }; + } + this.apiUrl = `https://${region}-api.coolkit.cc:8080/api`; this.apiWebSocket = 'wss://us-pconnect3.coolkit.cc:8080/api/ws'; this.email = email; this.password = password; - this.apiKey = ''; - this.at = ''; + this.at = at; + this.apiKey = apiKey; } async makeRequest({ method = 'GET', uri, body = {}, qs = {} }) { - const { apiKey, at } = this; + const { at } = this; - if (!apiKey && !at) { + if (!at) { await this.login(); }