const getWebData = async function (source, file, url) { if (!validateSource(source)) { throw new Error('Source contains invalid characters') } const response = await request.getAsync(`${url}/api/data/${source}/${file.split('.')[0]}`) return response.body }
const getNewestVersion = async function () { try { const version = await request.getAsync('https://bell.plus/api/version') return JSON.parse(version.body).version } catch (e) { // Failed to check for a new version throw new Error('Failed to check for a new version') } }
request.getAsync({ url: url, jar: true, encoding: options.encoding, gzip: true, timeout: options.timeout || 8000, time: !!options.time, followAllRedirects: options.followAllRedirects || true, headers: options.headers || {'accept-languages': 'en'}, forever: options.forever === false ? false : true }) .then(function(res) { if (res.statusCode === 429) { throw new Error('Request blocked with: 429'); } else if (res.statusCode !== 200) { throw new Error('Non 200 status code: ' + res.statusCode); } return { body: res.body, headers: res.headers, timingPhases: res.timingPhases, http: { statusCode: res.statusCode }, url: res.request.href, originalUrl: url }; })