Skip to content

Instantly share code, notes, and snippets.

@ramonfritsch
Created February 5, 2022 13:33
Show Gist options
  • Save ramonfritsch/52458f3f0a3c3e3a45ffd1d5688a3dd1 to your computer and use it in GitHub Desktop.
Save ramonfritsch/52458f3f0a3c3e3a45ffd1d5688a3dd1 to your computer and use it in GitHub Desktop.
scriptable-mrr
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