Last active
December 16, 2017 07:18
-
-
Save josephnle/1de011baede880cdb954786f759f3140 to your computer and use it in GitHub Desktop.
Code to send Pushbullet message with updates on cryptocurrency prices
This file contains hidden or 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 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