diff options
author | XeonCore <xeoncore@get-popcorn.com> | 2014-10-01 16:28:19 +1000 |
---|---|---|
committer | XeonCore <xeoncore@get-popcorn.com> | 2014-10-01 16:28:19 +1000 |
commit | 5ae49767855cb0f4944d823120dbdc09af9cc7fb (patch) | |
tree | 796bae14438fa02e9e17eee0bdba45c89c71a059 | |
parent | eaa1dd141e15d852e9fb4ab5b5286ef0040a7f00 (diff) | |
download | popcorn-api-origin/v2.zip popcorn-api-origin/v2.tar.gz popcorn-api-origin/v2.tar.bz2 |
Provider: Added base provider classorigin/v2
-rw-r--r-- | config.js | 43 | ||||
-rw-r--r-- | config/development.json | 40 | ||||
-rw-r--r-- | config/production.json | 46 | ||||
-rw-r--r-- | lib/helpersv2.js | 21 | ||||
-rwxr-xr-x | package.json | 6 | ||||
-rw-r--r-- | providers/provider.js | 55 |
6 files changed, 173 insertions, 38 deletions
@@ -1,37 +1,6 @@ -module.exports = { - master: false, - port: 5000, - workers: 2, - scrapeTime: '00 00 3,15 * * *', - scrapeTtl: 1000 * 60 * 60 * 10, - pageSize: 50, - dbHosts: [ - 'fr.ptnet', - 'us-chi.ptnet', - 'us-mia.ptnet', - 'us-dal.ptnet', - 'za.ptnet', - 'br.ptnet', - 'uk.ptnet', - ], - map: { - 'louie': 'louie-2010', - 'battlestar-galactica': 'battlestar-galactica-2003', - 'the-killing': 'the-killing-us', - 'hawaii-five-0-2010': 'hawaii-fiveo-2010', - 'the-goldbergs': 'the-goldbergs-2013', - 'vikings-us': 'vikings', - 'resurrection-us': 'resurrection', - 'golden-boy': 'golden-boy-2013', - 'the-office': 'the-office-us', - 'the-fosters': 'the-fosters-2013', - 'brooklyn-nine-nine': 'brooklyn-ninenine', - 'cracked': 'cracked-2013', - 'the-good-guys': 'the-good-guys-2010', - 'black-box': 'the-black-box', - 'hank': 'hank-2009', - 'legit': 'legit-2013', - 'power-2014': 'power', - 'scandal-us': 'scandal-2012', - } -} +var fs = require('fs'); + +module.exports = function(env) { + env = env || process.env.NODE_ENV; + return require('./config/' + env + '.json'); +};
\ No newline at end of file diff --git a/config/development.json b/config/development.json new file mode 100644 index 0000000..b5f991f --- /dev/null +++ b/config/development.json @@ -0,0 +1,40 @@ +{ + "master": false, + "port": 5000, + "workers": 2, + "scrapeTime": "00 00 3,15 * * *", + "scrapeTtl": 36000000, + "pageSize": 50, + "log": { + "console": { + "level": "debug" + }, + "file": { + "filename": "logs/dev.log", + "level": "silly" + } + }, + "dbHosts": [ + "localhost" + ], + "map": { + "louie": "louie-2010", + "battlestar-galactica": "battlestar-galactica-2003", + "the-killing": "the-killing-us", + "hawaii-five-0-2010": "hawaii-fiveo-2010", + "the-goldbergs": "the-goldbergs-2013", + "vikings-us": "vikings", + "resurrection-us": "resurrection", + "golden-boy": "golden-boy-2013", + "the-office": "the-office-us", + "the-fosters": "the-fosters-2013", + "brooklyn-nine-nine": "brooklyn-ninenine", + "cracked": "cracked-2013", + "the-good-guys": "the-good-guys-2010", + "black-box": "the-black-box", + "hank": "hank-2009", + "legit": "legit-2013", + "power-2014": "power", + "scandal-us": "scandal-2012" + } +}
\ No newline at end of file diff --git a/config/production.json b/config/production.json new file mode 100644 index 0000000..340b282 --- /dev/null +++ b/config/production.json @@ -0,0 +1,46 @@ +{ + "master": false, + "port": 5000, + "workers": 2, + "scrapeTime": "00 00 3,15 * * *", + "scrapeTtl": 36000000, + "pageSize": 50, + "log": { + "console": { + "level": "warn" + }, + "file": { + "filename": "logs/prod.log", + "level": "info" + } + }, + "dbHosts": [ + "fr.ptnet", + "us-chi.ptnet", + "us-mia.ptnet", + "us-dal.ptnet", + "za.ptnet", + "br.ptnet", + "uk.ptnet" + ], + "map": { + "louie": "louie-2010", + "battlestar-galactica": "battlestar-galactica-2003", + "the-killing": "the-killing-us", + "hawaii-five-0-2010": "hawaii-fiveo-2010", + "the-goldbergs": "the-goldbergs-2013", + "vikings-us": "vikings", + "resurrection-us": "resurrection", + "golden-boy": "golden-boy-2013", + "the-office": "the-office-us", + "the-fosters": "the-fosters-2013", + "brooklyn-nine-nine": "brooklyn-ninenine", + "cracked": "cracked-2013", + "the-good-guys": "the-good-guys-2010", + "black-box": "the-black-box", + "hank": "hank-2009", + "legit": "legit-2013", + "power-2014": "power", + "scandal-us": "scandal-2012" + } +}
\ No newline at end of file diff --git a/lib/helpersv2.js b/lib/helpersv2.js new file mode 100644 index 0000000..be90b1c --- /dev/null +++ b/lib/helpersv2.js @@ -0,0 +1,21 @@ +var winston = require('winston'); + +var config = require('../config')(); + +module.exports = { + createLogger: function(name, label) { + return winston.loggers.add(name, { + console: { + level: config.log.console.level, + colorize: true, + label: label + }, + file: { + level: config.log.file.level, + filename: config.log.file.filename, + json: false, + label: label + } + }); + } +}
\ No newline at end of file diff --git a/package.json b/package.json index 37d6bc7..7c32aae 100755 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "poporn-api", "version": "2.0.0", "dependencies": { + "URIjs": "^1.14.0", "async": "^0.9.0", "body-parser": "^1.9.0", "cheerio": "^0.17.0", @@ -9,9 +10,12 @@ "express": "^4.9.5", "moment": "^2.8.3", "mongoose": "^3.8.16", + "q": "^1.0.1", "request": "^2.44.0", "response-time": "^2.2.0", - "trakt": "0.0.6" + "trakt": "0.0.6", + "underscore": "^1.7.0", + "winston": "^0.8.0" }, "engines": { "node": ">=0.10.x", diff --git a/providers/provider.js b/providers/provider.js new file mode 100644 index 0000000..767810f --- /dev/null +++ b/providers/provider.js @@ -0,0 +1,55 @@ +var _ = require('underscore') + , EventEmitter = require('events').EventEmitter; + +var helpers = require('../lib/helpersv2.js'); + +module.exports = Provider; + +function Provider() { + this.log = helpers.createLogger(); + this.log.info('Provider Instantiated'); + EventEmitter.call(this); +} + +// Extend Provider with EventEmitter +Provider.prototype = Object.create(EventEmitter.prototype, { + constructor: { + value: Provider, + enumerable: false, + writable: true, + configurable: true + } +}); + +// Helper function to correctly set up the prototype chain, for subclasses. +// Inspired by Backbonejs and Node.js inherits +Provider.extend = function(instProps, statProps) { + var baseclass = this; + var subclass; + + if (instProps && _.has(instProps, 'constructor')) { + subclass = instProps.constructor; + } else { + subclass = function() { + return baseclass.apply(this, arguments); + }; + } + + _.extend(subclass, baseclass, statProps); + + subclass.prototype = Object.create(baseclass.prototype, { + constructor: { + value: subclass, + enumerable: false, + writable: true, + configurable: true + } + }); + + if (instProps) + _.extend(subclass.prototype, instProps); + + subclass.__super__ = baseclass; + + return subclass; +}
\ No newline at end of file |