add tag task and varioius cleanup

This commit is contained in:
Dave Horton
2020-01-29 15:27:20 -05:00
parent bed4fa1f42
commit 92acd50595
17 changed files with 278 additions and 111 deletions

View File

@@ -4,26 +4,25 @@ const makeTask = require('../tasks/make_task');
const normalizeJamones = require('./normalize-jamones');
function retrieveUrl(logger, url, method, auth, qs, body) {
logger.debug(`body: ${body}`);
const opts = {url, method, auth, qs, json: true};
if (body) {
logger.debug('adding body');
Object.assign(opts, {body});
}
function retrieveUrl(logger, url, method, auth, obj) {
const opts = {url, method, auth, json: true};
if (method === 'GET') Object.assign(opts, {qs: obj});
else Object.assign(opts, {body: obj});
return new Promise((resolve, reject) => {
request(opts, (err, response, body) => {
if (err) throw err;
if (body) logger.debug({body}, 'retrieveUrl: customer returned an application');
resolve(body);
});
});
}
async function retrieveApp(logger, url, method, auth, qs, body) {
async function retrieveApp(logger, url, method, auth, obj) {
let json;
if (typeof url === 'object') json = url;
else json = await retrieveUrl(logger, url, method, auth, qs, body);
else json = await retrieveUrl(logger, url, method, auth, obj);
return normalizeJamones(logger, json).map((tdata) => makeTask(logger, tdata));
}