diff --git a/package.json b/package.json index 2c56753..37db430 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "body-parser": "^1.17.2", "express": "^4.15.3", "feedparser-promised": "^1.3.0", - "jsonfile": "^3.0.1" + "jsonfile": "^3.0.1", + "rethinkdb": "^2.3.3" }, "scripts": { "start": "nodemon src/server.js" diff --git a/src/data/index.js b/src/data/index.js index 62cbab4..f6b225e 100644 --- a/src/data/index.js +++ b/src/data/index.js @@ -1,36 +1,8 @@ -module.exports = { - NewsAPI: require('./sources/news-api'), - CoinMarketCap: require('./sources/coin-market-cap'), - HackerNews: require('./sources/hacker-news'), - Sidebar: require('./sources/sidebar'), - Reddit: require('./sources/reddit'), - ProductHunt: require('./sources/product-hunt'), - IndieHackers: require('./sources/indie-hackers'), - DesignerNews: require('./sources/designer-news'), - BetaList: require('./sources/beta-list'), - TheOutline: require('./sources/the-outline'), - AVClub: require('./sources/av-club'), - MacRumors: require('./sources/mac-rumors'), - FiveThirtyEight: require('./sources/538'), -}; +const types = require('./types'); -/* -Refactor feeds to use pubsubhhubbub +module.exports = Object.keys(types).reduce((acc, type) => { + let typeString = types[type]; + acc[type] = require(`./sources/${typeString}`); + return acc; +}, {}); -Things that should be feeds: -hackernews -sidebar - -DONE: -producthunt: https://www.producthunt.com/ -SCRAP - indiehackers: https://www.indiehackers.com/ -designernews: https://www.designernews.co/?format=rss -betalist: https://betalist.com/ -theoutline: https://theoutline.com/feeds/recent.rss -avclub: http://www.avclub.com/rss/ -fivethirtyeight: https://fivethirtyeight.com/features/feed/ - -TODOS: -macrumors: https://www.macrumors.com/ - -*/ diff --git a/src/data/sources/538.js b/src/data/sources/538.js index 1c3571d..4b960a0 100644 --- a/src/data/sources/538.js +++ b/src/data/sources/538.js @@ -1,8 +1,9 @@ const Feed = require('./feed'); +const types = require('../types'); class FiveThirtyEight extends Feed { constructor() { - super('https://fivethirtyeight.com/features/feed/'); + super('https://fivethirtyeight.com/features/feed/', types.FiveThirtyEight); } } diff --git a/src/data/sources/api.js b/src/data/sources/api.js index 537a8e4..81079c6 100644 --- a/src/data/sources/api.js +++ b/src/data/sources/api.js @@ -33,7 +33,7 @@ class API { }; } - constructor(baseURL, apiKey) { + constructor(baseURL, type, apiKey) { const axiosConfig = API.createAxiosConfig(baseURL, apiKey); this.fetch = API.fetch(axiosConfig); } diff --git a/src/data/sources/av-club.js b/src/data/sources/av-club.js index dc03b5a..a19d493 100644 --- a/src/data/sources/av-club.js +++ b/src/data/sources/av-club.js @@ -1,8 +1,9 @@ const Feed = require('./feed'); +const types = require('../types'); class AVClub extends Feed { constructor() { - super('http://www.avclub.com/feeds/rss/'); + super('http://www.avclub.com/feeds/rss/', types.AVClub); } } diff --git a/src/data/sources/beta-list.js b/src/data/sources/beta-list.js index ad7b02d..5baf2ee 100644 --- a/src/data/sources/beta-list.js +++ b/src/data/sources/beta-list.js @@ -1,8 +1,9 @@ const Feed = require('./feed'); +const types = require('../types'); class BetaList extends Feed { constructor() { - super('http://feeds.feedburner.com/BetaList'); + super('http://feeds.feedburner.com/BetaList', types.BetaList); } } diff --git a/src/data/sources/coin-market-cap.js b/src/data/sources/coin-market-cap.js index 1d017b3..ca44ed0 100644 --- a/src/data/sources/coin-market-cap.js +++ b/src/data/sources/coin-market-cap.js @@ -1,9 +1,10 @@ const API = require('./api'); +const types = require('../types'); class CoinMarketCap extends API { constructor() { const baseURL = 'https://api.coinmarketcap.com/v1/' - super(baseURL); + super(baseURL, types.CoinMarketCap); } getLatestTicker(limit = 5) { diff --git a/src/data/sources/designer-news.js b/src/data/sources/designer-news.js index 466a752..7fb5e27 100644 --- a/src/data/sources/designer-news.js +++ b/src/data/sources/designer-news.js @@ -1,8 +1,9 @@ const Feed = require('./feed'); +const types = require('../types'); class DesignerNews extends Feed { constructor() { - super('https://www.designernews.co/?format=rss'); + super('https://www.designernews.co/?format=rss', types.DesignerNews); } } diff --git a/src/data/sources/feed.js b/src/data/sources/feed.js index 40c6b00..0d29cc5 100644 --- a/src/data/sources/feed.js +++ b/src/data/sources/feed.js @@ -1,7 +1,6 @@ const FeedParser = require('feedparser-promised'); class Feed { - constructor(uri, type) { const options = { uri, diff --git a/src/data/sources/hacker-news.js b/src/data/sources/hacker-news.js index a87cef0..4b0ff81 100644 --- a/src/data/sources/hacker-news.js +++ b/src/data/sources/hacker-news.js @@ -1,9 +1,10 @@ const API = require('./api'); +const types = require('../types'); class HackerNews extends API { constructor() { const baseURL = 'https://hacker-news.firebaseio.com/v0/'; - super(baseURL); + super(baseURL, types.HackerNews); } async getTopStories() { diff --git a/src/data/sources/indie-hackers.js b/src/data/sources/indie-hackers.js index 555ea87..25c01c2 100644 --- a/src/data/sources/indie-hackers.js +++ b/src/data/sources/indie-hackers.js @@ -1,4 +1,5 @@ const Feed = require('./feed'); +const types = require('../types'); // All their articles are published at the same time so they'd apprear // grouped together diff --git a/src/data/sources/mac-rumors.js b/src/data/sources/mac-rumors.js index c848ee8..1d9e3e6 100644 --- a/src/data/sources/mac-rumors.js +++ b/src/data/sources/mac-rumors.js @@ -1,8 +1,9 @@ const Feed = require('./feed'); +const types = require('../types'); class MacRumors extends Feed { constructor() { - super('http://feeds.macrumors.com/MacRumors-All'); + super('http://feeds.macrumors.com/MacRumors-All', 'mac-rumors', types.MacRumors); } } diff --git a/src/data/sources/product-hunt.js b/src/data/sources/product-hunt.js index 607adf2..a890d86 100644 --- a/src/data/sources/product-hunt.js +++ b/src/data/sources/product-hunt.js @@ -1,8 +1,9 @@ const Feed = require('./feed'); +const types = require('../types'); class ProductHunt extends Feed { constructor() { - super('https://www.producthunt.com/feed'); + super('https://www.producthunt.com/feed', types.ProductHunt); } } diff --git a/src/data/sources/reddit.js b/src/data/sources/reddit.js index c3d4338..4e5ae77 100644 --- a/src/data/sources/reddit.js +++ b/src/data/sources/reddit.js @@ -1,9 +1,10 @@ const API = require('./api'); +const types = require('../types'); class Reddit extends API { constructor() { const baseURL = 'http://reddit.com/api/v1'; - super(baseURL); + super(baseURL, types.Reddit); } getHotListings() { diff --git a/src/data/sources/sidebar.js b/src/data/sources/sidebar.js index 45cf859..e0052bc 100644 --- a/src/data/sources/sidebar.js +++ b/src/data/sources/sidebar.js @@ -1,9 +1,10 @@ const API = require('./api'); +const types = require('../types'); class Sidebar extends API { constructor() { const baseURL = 'https://sidebar.io/'; - super(baseURL); + super(baseURL, types.Sidebar); } getListing() { diff --git a/src/data/sources/the-outline.js b/src/data/sources/the-outline.js index 68c1b52..0c34025 100644 --- a/src/data/sources/the-outline.js +++ b/src/data/sources/the-outline.js @@ -1,8 +1,9 @@ const Feed = require('./feed'); +const types = require('../types'); class TheOutline extends Feed { constructor() { - super('https://theoutline.com/feeds/recent.rss'); + super('https://theoutline.com/feeds/recent.rss', types.TheOutline); } } diff --git a/src/data/types.js b/src/data/types.js new file mode 100644 index 0000000..567e67c --- /dev/null +++ b/src/data/types.js @@ -0,0 +1,20 @@ +/* + Constants of our data sources and their string representations. The strings + are tied to file name, since index.js requires each type's class + based on these strings. +*/ +module.exports = { + 538: '538', + AVClub: 'av-club', + BetaList: 'beta-list', + CoinMarketCap: 'coin-market-cap', + DesignerNews: 'designer-news', + HackerNews: 'hacker-news', + IndieHackers: 'indie-hackers', + MacRumors: 'mac-rumors', + ProductHunt: 'product-hunt', + Reddit: 'reddit', + Sidebar: 'sidebar', + TheOutline: 'the-outline', + NewsAPI: 'news-api' +}; diff --git a/src/server.js b/src/server.js index 1d7519c..71480bb 100644 --- a/src/server.js +++ b/src/server.js @@ -8,7 +8,7 @@ const app = express(); const PORT = process.env.PORT || 9999; const data = require('./data'); - +const types = require('./data/types'); // Middleware app.use(bodyParser.urlencoded({ extended: false })); diff --git a/yarn.lock b/yarn.lock index b624817..411a978 100644 --- a/yarn.lock +++ b/yarn.lock @@ -95,6 +95,10 @@ bcrypt-pbkdf@^1.0.0: dependencies: tweetnacl "^0.14.3" +"bluebird@>= 2.3.2 < 3": + version "2.11.0" + resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-2.11.0.tgz#534b9033c022c9579c56ba3b3e5a5caafbb650e1" + body-parser@^1.17.2: version "1.17.2" resolved "https://registry.yarnpkg.com/body-parser/-/body-parser-1.17.2.tgz#f8892abc8f9e627d42aedafbca66bf5ab99104ee" @@ -569,6 +573,12 @@ request@^2.79.0: tunnel-agent "^0.6.0" uuid "^3.0.0" +rethinkdb@^2.3.3: + version "2.3.3" + resolved "https://registry.yarnpkg.com/rethinkdb/-/rethinkdb-2.3.3.tgz#3dc6586e22fa1dabee0d254e64bd0e379fad2f72" + dependencies: + bluebird ">= 2.3.2 < 3" + safe-buffer@^5.0.1, safe-buffer@~5.1.0, safe-buffer@~5.1.1: version "5.1.1" resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853"