-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.js
50 lines (42 loc) · 1.08 KB
/
example.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
var DailyConnect = require('./index.js')
var async = require('async')
var dateformat = require('dateformat')
var user = process.argv[2]
var pass = process.argv[3]
var mydc = new DailyConnect(user, pass)
function gatherKidsLatestStatus (userInfo, cb) {
var latestKidEvents = []
async.each(userInfo.myKids, getLatestEvent, function (err) {
if (err) {
return cb(err)
}
cb(null, latestKidEvents)
})
function getLatestEvent (kid, cb) {
mydc.getKidStatus(kid.Id, function (err, kidStatus) {
if (err) {
return cb(err)
}
var status = 'no activity'
var ts = ''
if (kidStatus.list.length > 0) {
var entry = kidStatus.list[kidStatus.list.length - 1]
status = entry.Txt
ts = entry.e
}
latestKidEvents.push(dateformat(ts, 'isoDateTime') + ': ' + kid.Name + ': ' + status)
cb(null)
})
}
}
function completed (err, result) {
if (err) {
console.error(err)
}
console.log(result)
}
async.waterfall([
mydc.login.bind(mydc),
mydc.getUserInfo.bind(mydc),
gatherKidsLatestStatus
], completed)