Skip to content

Instantly share code, notes, and snippets.

@josephnle
Last active December 16, 2017 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephnle/1de011baede880cdb954786f759f3140 to your computer and use it in GitHub Desktop.
Save josephnle/1de011baede880cdb954786f759f3140 to your computer and use it in GitHub Desktop.
Code to send Pushbullet message with updates on cryptocurrency prices
const currencies = ['BTC', 'ETH', 'LTC']; // Coinbase currencies
Promise.all(currencies.map(coin => {
return fetch(`https://api.coinbase.com/v2/prices/${coin}-USD/spot`)
.then(res => res.json())
.then(data => data.data.amount)
.then(amount => `${coin}: $${amount}`)
}))
.then(amounts => {
return fetch('https://api.kraken.com/0/public/Ticker?pair=XRPUSD')
.then(res => res.json())
.then(data => data.result.XXRPZUSD.c[0])
.then(amount => {
amounts.push(`XRP: $${parseFloat(amount).toString()}`);
return amounts;
})
})
.then(amounts => {
const message = amounts.join(' ');
return fetch('https://api.pushbullet.com/v2/pushes',
{
method: 'POST',
body: JSON.stringify({title: message, type: 'note'}),
headers: {
'Access-Token': inputData.pushbulletAcessToken, // Generate and pass thru using inputData
'Content-Type': 'application/json'
}
});
})
.then(res => callback(null, res.json()));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment