From b87aca566b4f8e0d1dd229694ebd67112b6a2e6a Mon Sep 17 00:00:00 2001 From: Todd Treece Date: Sat, 1 Aug 2015 20:06:00 -0400 Subject: [PATCH] adds main npr module --- index.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 index.js diff --git a/index.js b/index.js new file mode 100644 index 0000000..564615e --- /dev/null +++ b/index.js @@ -0,0 +1,56 @@ +/************************ DEPENDENCIES *****************************/ +var shim = require('es6-shim'), + util = require('util'), + bunyan = require('bunyan'), + One = require('./lib/one'), + Helpers = require('./lib/helpers'); + +var proto = NPR.prototype; +exports = module.exports = NPR; + +/************************* CONSTRUCTOR ****************************/ +function NPR(config) { + + if (! (this instanceof NPR)) + return new NPR(config); + + util._extend(this, config || {}); + + if (! this.client_id) + throw('OAuth Client ID not supplied'); + + if (! this.client_secret) + throw('OAuth Client Secret not supplied'); + + if (! this.username) + throw('NPR username not supplied'); + + if (! this.password) + throw('NPR password not supplied'); + + if (! this.log) + this.log = bunyan.createLogger({name: 'npr'}); + + this.one = One({ + log: this.log.child({ module: 'one' }), + credentials: { + client_id: this.client_id, + client_secret: this.client_secret, + username: this.username, + password: this.password + } + }); + +} + +/**************************** STATIC ******************************/ +NPR.Helpers = Helpers; +NPR.One = One; + +/*************************** DEFAULTS *****************************/ +proto.client_id = false; +proto.client_secret = false; +proto.username = false; +proto.password = false; +proto.one = false; +proto.log = false;