Skip to content

Commit

Permalink
Add loader
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreKavalerski committed Dec 28, 2017
1 parent 4a39f31 commit 9dc75e3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bin/ConvertBTC.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@

var request = require('request');
var chalk = require('chalk');
var ora = require('ora');

var spinner = ora({
text: 'Retrieving Bitcoin data...',
color: 'yellow'
});

/* 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;

var url = 'https://apiv2.bitcoinaverage.com/convert/global?from=BTC&to=' + currency + '&amount=' + amount;
spinner.start();
request(url, function (error, response, body) {
var apiResponse = void 0;
spinner.stop();
try {
apiResponse = JSON.parse(body);
} catch (parseError) {
Expand Down
8 changes: 8 additions & 0 deletions src/ConvertBTC.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
const request = require('request');
const chalk = require('chalk');
const ora = require('ora');

const spinner = ora({
text: 'Retrieving Bitcoin data...',
color: 'yellow',
});

/* eslint consistent-return: 0 */
function convertBTC(currency = 'USD', amount = 1) {
const url = `https://apiv2.bitcoinaverage.com/convert/global?from=BTC&to=${currency}&amount=${amount}`;
spinner.start();
request(url, (error, response, body) => {
let apiResponse;
spinner.stop();
try {
apiResponse = JSON.parse(body);
} catch (parseError) {
Expand Down
1 change: 1 addition & 0 deletions tests/ConvertBTC.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const chai = require('chai');
const sinon = require('sinon');
const sinonChai = require('sinon-chai');
const chalk = require('chalk');
const ora = require('ora');

const expect = chai.expect;

Expand Down

0 comments on commit 9dc75e3

Please sign in to comment.