-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f603f98
commit 6ccd4e9
Showing
6 changed files
with
26 additions
and
10 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,24 @@ | ||
'use strict'; | ||
|
||
var request = require('request'); | ||
var chalk = require('chalk'); | ||
|
||
/* eslint consistent-return: 0 */ | ||
function convertBTC() { | ||
var currency = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'USD'; | ||
var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
|
||
return amount + ' BTC to ' + currency + ' = 2000.00'; | ||
var url = 'https://apiv2.bitcoinaverage.com/convert/global?from=BTC&to=' + currency + '&amount=' + amount; | ||
request(url, function (error, response, body) { | ||
var apiResponse = void 0; | ||
try { | ||
apiResponse = JSON.parse(body); | ||
} catch (parseError) { | ||
console.log(chalk.red('Something went wrong with the API. Try in a few minutes.')); | ||
return parseError; | ||
} | ||
console.log(chalk.magenta(amount) + ' BTC to ' + chalk.cyan(currency) + ' = ' + chalk.blue(apiResponse.price)); | ||
}); | ||
} | ||
|
||
module.exports = convertBTC; |
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
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
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
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
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