buddy

node MVC discord bot
Log | Files | Refs | README

common.js (643B)


      1 
      2 const config = require('./config');
      3 const querystring = require('querystring');
      4 
      5 
      6 module.exports = function(request, key, options, cb){
      7     if(!key && typeof cb === 'function')
      8       return cb(new Error('API Key is required'));
      9     else if(!key) throw new Error('API Key is required');
     10     fillData(key , options);
     11     const q = querystring.stringify(config.options);
     12   if(typeof cb === 'function')
     13     request(config.URL+q).then(res => cb(null,res)).catch(err => cb(err));
     14   else
     15     return request(config.URL+q);
     16 }
     17 
     18 function fillData(key , options){
     19   config.options.key = key;
     20   for(let i in options)
     21     config.options[i] = options[i];
     22 }