-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·81 lines (72 loc) · 1.47 KB
/
index.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
#!/usr/bin/env /usr/local/bin/node
'use strict'
const path = require('path')
const fetch = require('node-fetch')
const bitbar = require('bitbar')
require('dotenv').config({
path: path.resolve(__dirname, '.env'),
})
const endpoint = process.env.ACKEE_ENDPOINT
const token = process.env.ACKEE_TOKEN
const timeZone = new Intl.DateTimeFormat().resolvedOptions().timeZone
;(async () => {
const response = await fetch(endpoint, {
method: 'post',
headers: {
'Authorization': `Bearer ${ token }`,
'Content-Type': 'application/json',
'Time-Zone': timeZone,
},
body: JSON.stringify({
query: `
{
facts {
viewsToday
activeVisitors
}
domains {
title
facts {
viewsToday
activeVisitors
}
}
}
`,
}),
})
if (response.ok === false) {
const text = await response.text()
throw new Error(text)
}
const json = await response.json()
if (json.errors != null) {
const message = json.errors[0].message
throw new Error(message)
}
const domains = json.data.domains.map((domain) => {
return {
text: domain.title,
submenu: [
{
text: `${ domain.facts.viewsToday } views`,
},
{
text: `${ domain.facts.activeVisitors } active visitors`,
},
],
}
})
return bitbar([
{
text: `${ json.data.facts.viewsToday } views`,
dropdown: false,
},
bitbar.separator,
{
text: `${ json.data.facts.activeVisitors } active visitors`,
},
bitbar.separator,
...domains,
])
})()