Created
February 5, 2022 13:33
-
-
Save ramonfritsch/52458f3f0a3c3e3a45ffd1d5688a3dd1 to your computer and use it in GitHub Desktop.
scriptable-mrr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const API_KEY = 'YOUR_API_KEY'; | |
const auth = 'Basic ' + btoa(`${API_KEY}:`); | |
const currentYear = new Date().getYear(); | |
const startDate = `${currentYear}-01-01`; | |
const endDate = `${currentYear}-12-31`; | |
const endpoint = `https://api.chartmogul.com/v1/metrics/mrr?start-date=${startDate}&end-date=${endDate}`; | |
function loadItems() { | |
const req = new Request(endpoint); | |
req.headers = { Authorization: auth }; | |
return req.loadJSON(); | |
} | |
const json = await loadItems(); | |
const MRR = Math.floor(json.summary.current / 100).toString(); | |
const w = new ListWidget(); | |
w.backgroundColor = new Color('#000000'); | |
let t = w.addText('COMPANY_NAME'); | |
t.textColor = Color.white(); | |
t.font = new Font('Avenir', 12); | |
w.addSpacer(); | |
// Formating number i.e 19000 -> $19,000 | |
t = w.addText(`\$${new Intl.NumberFormat('en-US').format(MRR)}`); | |
t.textColor = Color.white(); | |
t.font = new Font('Avenir-Heavy', 32); | |
if (config.runsInWidget) { | |
Script.setWidget(w); | |
} else { | |
w.presentSmall(); | |
} | |
Script.complete(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment