-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
56 lines (47 loc) · 1.48 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const Homey = require('homey');
const fetch = require('node-fetch');
class MyZonneplanApp extends Homey.App {
/**
* onInit is called when the app is initialized.
*/
async onInit() {
this.log('MyZonneplanApp has been initialized');
}
async activate(email) {
const res = await fetch('https://app-api.zonneplan.nl/auth/request', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
referrerPolicy: "no-referrer",
credentials: "include",
body: JSON.stringify({ email: email }),
});
const resp = await res.json();
return resp;
}
async getOTP(uuid) {
console.log('uuid value ', uuid)
const res = await fetch('https://app-api.zonneplan.nl/auth/request/' + uuid, {
method: 'GET',
headers: { 'Content-Type': 'application/json' },
referrerPolicy: "no-referrer",
credentials: "include",
});
const resp = await res.json();
return resp;
}
async getToken(email, password) {
let url = 'https://app-api.zonneplan.nl/oauth/token';
console.log('making call to get token')
const res = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
referrerPolicy: "no-referrer",
credentials: "include",
body: JSON.stringify({ email: email, password: password, grant_type: "one_time_password" }),
});
const resp = await res.json();
console.log('we got token ', resp)
return resp;
}
}
module.exports = MyZonneplanApp;