Skip to content

Commit

Permalink
feat(dmuse): cached response won't decrement usage
Browse files Browse the repository at this point in the history
  • Loading branch information
drawnepicenter committed Aug 25, 2016
1 parent ce2130f commit 3973511
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
16 changes: 12 additions & 4 deletions build/cmds/dmuse_cmds/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ exports.handler = function (argv) {
var ctstyle = _.get(chalk, theme.content.style);
http({ url: url }, function (error, response) {
if (!error && response.statusCode === 200) {
if (response.headers['x-gg-state'] === 'cached') {
config.dmuse.date.remain++;
noon.save(CFILE, config);
if (config.usage) console.log('Cached response, not decrementing usage.');
}
var resp = JSON.parse(response.body);
for (var i = 0; i <= resp.length - 1; i++) {
var item = resp[i];
Expand All @@ -111,10 +116,13 @@ exports.handler = function (argv) {
}
}
if (argv.o) tools.outFile(argv.o, argv.f, tofile);
if (reset) {
console.log(config.dmuse.date.remain + '/' + config.dmuse.date.limit + ' requests remaining today.');
} else {
if (config.usage) console.log(config.dmuse.date.remain + '/' + config.dmuse.date.limit + ' requests remaining today, will reset in ' + (23 - hours) + ' hours, ' + (59 - minutes) + ' minutes.');
if (config.usage) {
if (reset) {
console.log('Timestamp expired, reset usage limits.');
console.log(config.dmuse.date.remain + '/' + config.dmuse.date.limit + ' requests remaining today.');
} else {
console.log(config.dmuse.date.remain + '/' + config.dmuse.date.limit + ' requests remaining today, will reset in ' + (23 - hours) + ' hours, ' + (59 - minutes) + ' minutes.');
}
}
} else {
throw new Error('HTTP ' + response.statusCode + ': ' + error);
Expand Down
16 changes: 12 additions & 4 deletions src/cmds/dmuse_cmds/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ exports.handler = (argv) => {
const ctstyle = _.get(chalk, theme.content.style)
http({ url }, (error, response) => {
if (!error && response.statusCode === 200) {
if (response.headers['x-gg-state'] === 'cached') {
config.dmuse.date.remain++
noon.save(CFILE, config)
if (config.usage) console.log('Cached response, not decrementing usage.')
}
const resp = JSON.parse(response.body)
for (let i = 0; i <= resp.length - 1; i++) {
const item = resp[i]
Expand All @@ -108,10 +113,13 @@ exports.handler = (argv) => {
}
}
if (argv.o) tools.outFile(argv.o, argv.f, tofile)
if (reset) {
console.log(`${config.dmuse.date.remain}/${config.dmuse.date.limit} requests remaining today.`)
} else {
if (config.usage) console.log(`${config.dmuse.date.remain}/${config.dmuse.date.limit} requests remaining today, will reset in ${23 - hours} hours, ${59 - minutes} minutes.`)
if (config.usage) {
if (reset) {
console.log('Timestamp expired, reset usage limits.')
console.log(`${config.dmuse.date.remain}/${config.dmuse.date.limit} requests remaining today.`)
} else {
console.log(`${config.dmuse.date.remain}/${config.dmuse.date.limit} requests remaining today, will reset in ${23 - hours} hours, ${59 - minutes} minutes.`)
}
}
} else {
throw new Error(`HTTP ${response.statusCode}: ${error}`)
Expand Down

0 comments on commit 3973511

Please sign in to comment.