-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGlowRawAPI.js
88 lines (77 loc) · 2.13 KB
/
GlowRawAPI.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"use strict";
var https = require('https');
class GlowRawAPI {
static fetchLoginToken(email, password, callback) {
var options = {
host: 'baby.glowing.com',
path: '/android/user/sign_in',
method: 'POST'
};
var req = https.request(options, response => {
var body = '';
response.on('data', d => {
body += d;
});
response.on('end', () => {
var parsed = JSON.parse(body);
if (parsed.msg) {
console.log("ERROR");
console.log(body);
return;
}
callback(parsed);
});
});
req.write(JSON.stringify({email: email, password: password}))
req.end();
}
static fetchSyncData(login_token, baby_sync_token, user_sync_token, baby_id, callback) {
// Stuff I copied from the Android app
var headers = {
'GlowOccurTime': '1501282746855',
'Request-Id': '559aaae19e0b1535-1501282746855',
'Authorization': login_token,
'Content-Type': 'application/json; charset=utf-8',
'Host': 'baby.glowing.com',
'User-Agent': 'okhttp/3.4.1'
};
var babies = [];
var user = {};
if (baby_id && baby_sync_token) {
babies = [{sync_token: baby_sync_token, baby_id: baby_id}];
}
if (user_sync_token) {
user.sync_token = user_sync_token;
}
var dataString = JSON.stringify({
data: {
babies: babies,
user: user
}
});
var options = {
path: 'https://baby.glowing.com/android/user/pull?hl=en_US&random=7645523890115&device_id=79906fb6942e9c92&android_version=1.7.4&vc=10704&tz=America/New_York&code_name=noah',
host: 'baby.glowing.com',
method: 'POST',
headers: headers,
};
var req = https.request(options, function(response) {
var body = '';
response.on('data', function(d) {
body += d;
});
response.on('end', function() {
callback(body);
});
response.on('error', function() {
console.log('errrrrr');
});
});
req.write(dataString);
req.on('error', function(e) {
console.log(e);
});
req.end();
}
}
module.exports = GlowRawAPI;