From cf37a5b0058883b5c35c6056e9d5b938f9e00e48 Mon Sep 17 00:00:00 2001 From: Benjamin Lupton Date: Wed, 13 Nov 2013 09:29:26 +1100 Subject: [PATCH] v2.7.4. Improvement --- History.md | 5 ++++- README.md | 5 ++--- package.json | 2 +- src/lib/feedr.coffee | 44 +++++++++++++++++++++++++++++++++++++------- test/fixtures.json | 40 ++++++++++++++++++++-------------------- 5 files changed, 64 insertions(+), 32 deletions(-) diff --git a/History.md b/History.md index a79fb40..acee61e 100644 --- a/History.md +++ b/History.md @@ -1,4 +1,7 @@ -## History +# History + +- v2.7.4 November 13, 2013 + - `readFeeds` can now accept default options to apply to each feed that will be ready - v2.7.3 October 31, 2013 - Can now parse CSON files diff --git a/README.md b/README.md index 90474ea..e92a07c 100644 --- a/README.md +++ b/README.md @@ -57,18 +57,17 @@ feeds = { }; // Read a single feed -feedr.readFeed(feeds.github, function(err, data, headers){ +feedr.readFeed(feeds.github, {/* optional configuration*/}, function(err, data, headers){ console.log(err, data, headers); }); // Read all the feeds together -feedr.readFeeds(feeds, function(err, result){ +feedr.readFeeds(feeds, {/* optional configuration*/}, function(err, result){ console.log(err, result.github, result.twitter); }); ``` - ## Configuration Global configuration properties are: diff --git a/package.json b/package.json index 62aefe5..587e3f0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "title": "Feedr", "name": "feedr", - "version": "2.7.3", + "version": "2.7.4", "description": "Feedr takes in a remote feed (regardless of format type) and converts it into JSON data", "homepage": "http://bevry.me/project/feedr", "license": { diff --git a/src/lib/feedr.coffee b/src/lib/feedr.coffee index b774001..292c247 100644 --- a/src/lib/feedr.coffee +++ b/src/lib/feedr.coffee @@ -34,11 +34,29 @@ class Feedr # Read Feeds # feeds = {feedName:feedDetails} # next(err,result) - readFeeds: (feeds,next) -> + readFeeds: (args...) -> # Prepare feedr = @ failures = 0 + # Prepare options + feeds = null + defaultFeedDetails = {} + next = null + + # Extract the configuration from the arguments + for arg,index in args + switch true + when typeChecker.isFunction(arg) + next = arg + when typeChecker.isArray(arg) + feeds = arg + when typeChecker.isPlainObject(arg) + if index is 0 + feeds = arg + else + extendr.extend(defaultFeedDetails, arg) + # Extract isArray = typeChecker.isArray(feeds) result = if isArray then [] else {} @@ -52,8 +70,9 @@ class Feedr eachr feeds, (feedDetails,feedName) -> tasks.addTask (complete) -> # Prepare if typeChecker.isString(feedDetails) - feedDetails = {url:feedDetails} + feedDetails = {url: feedDetails} feedDetails.name ?= feedName + feedDetails = extendr.extend({}, defaultFeedDetails, feedDetails) # Read feedr.readFeed feedDetails, (err,data) -> @@ -86,7 +105,7 @@ class Feedr # Read Feed # next(err,data) - readFeed: (feedDetails,next) -> + readFeed: (args...) -> # Prepare feedr = @ @@ -95,12 +114,23 @@ class Feedr safeps.getTmpPath (err,tmpPath) -> return next(err) if err feedr.config.tmpPath = tmpPath - feedr.readFeed(feedDetails, next) + feedr.readFeed(args...) return @ - # Parse string if necessary - feedDetails ?= {} - feedDetails = {url:feedDetails,name:feedDetails} if typeChecker.isString(feedDetails) + # Prepare options + feedDetails = {} + next = null + + # Extract the configuration from the arguments + for arg in args + switch true + when typeChecker.isString(arg) + feedDetails.name ?= arg + feedDetails.url = arg + when typeChecker.isFunction(arg) + next = arg + when typeChecker.isPlainObject(arg) + extendr.extend(feedDetails, arg) # Check for url return next(new Error('feed url was not supplied'), null, null) unless feedDetails.url diff --git a/test/fixtures.json b/test/fixtures.json index 682d09f..75fb9cd 100644 --- a/test/fixtures.json +++ b/test/fixtures.json @@ -55,7 +55,7 @@ "$": { "height": "30", "width": "30", - "url": "https://2.gravatar.com/avatar/9400cb5aeb155ccec614652542fd274d?d=https%3A%2F%2Fidenticons.github.com%2F28fbafb0c2a98d9a643600bd876de1b4.png&r=x&s=30" + "url": "" } } ], @@ -102,7 +102,7 @@ "$": { "height": "30", "width": "30", - "url": "https://2.gravatar.com/avatar/9400cb5aeb155ccec614652542fd274d?d=https%3A%2F%2Fidenticons.github.com%2F28fbafb0c2a98d9a643600bd876de1b4.png&r=x&s=30" + "url": "" } } ], @@ -149,7 +149,7 @@ "$": { "height": "30", "width": "30", - "url": "https://2.gravatar.com/avatar/9400cb5aeb155ccec614652542fd274d?d=https%3A%2F%2Fidenticons.github.com%2F28fbafb0c2a98d9a643600bd876de1b4.png&r=x&s=30" + "url": "" } } ], @@ -196,7 +196,7 @@ "$": { "height": "30", "width": "30", - "url": "https://2.gravatar.com/avatar/9400cb5aeb155ccec614652542fd274d?d=https%3A%2F%2Fidenticons.github.com%2F28fbafb0c2a98d9a643600bd876de1b4.png&r=x&s=30" + "url": "" } } ], @@ -243,7 +243,7 @@ "$": { "height": "30", "width": "30", - "url": "https://2.gravatar.com/avatar/9400cb5aeb155ccec614652542fd274d?d=https%3A%2F%2Fidenticons.github.com%2F28fbafb0c2a98d9a643600bd876de1b4.png&r=x&s=30" + "url": "" } } ], @@ -290,7 +290,7 @@ "$": { "height": "30", "width": "30", - "url": "https://2.gravatar.com/avatar/9400cb5aeb155ccec614652542fd274d?d=https%3A%2F%2Fidenticons.github.com%2F28fbafb0c2a98d9a643600bd876de1b4.png&r=x&s=30" + "url": "" } } ], @@ -337,7 +337,7 @@ "$": { "height": "30", "width": "30", - "url": "https://2.gravatar.com/avatar/9400cb5aeb155ccec614652542fd274d?d=https%3A%2F%2Fidenticons.github.com%2F28fbafb0c2a98d9a643600bd876de1b4.png&r=x&s=30" + "url": "" } } ], @@ -384,7 +384,7 @@ "$": { "height": "30", "width": "30", - "url": "https://2.gravatar.com/avatar/9400cb5aeb155ccec614652542fd274d?d=https%3A%2F%2Fidenticons.github.com%2F28fbafb0c2a98d9a643600bd876de1b4.png&r=x&s=30" + "url": "" } } ], @@ -431,7 +431,7 @@ "$": { "height": "30", "width": "30", - "url": "https://2.gravatar.com/avatar/9400cb5aeb155ccec614652542fd274d?d=https%3A%2F%2Fidenticons.github.com%2F28fbafb0c2a98d9a643600bd876de1b4.png&r=x&s=30" + "url": "" } } ], @@ -478,7 +478,7 @@ "$": { "height": "30", "width": "30", - "url": "https://2.gravatar.com/avatar/9400cb5aeb155ccec614652542fd274d?d=https%3A%2F%2Fidenticons.github.com%2F28fbafb0c2a98d9a643600bd876de1b4.png&r=x&s=30" + "url": "" } } ], @@ -525,7 +525,7 @@ "$": { "height": "30", "width": "30", - "url": "https://2.gravatar.com/avatar/9400cb5aeb155ccec614652542fd274d?d=https%3A%2F%2Fidenticons.github.com%2F28fbafb0c2a98d9a643600bd876de1b4.png&r=x&s=30" + "url": "" } } ], @@ -572,7 +572,7 @@ "$": { "height": "30", "width": "30", - "url": "https://2.gravatar.com/avatar/9400cb5aeb155ccec614652542fd274d?d=https%3A%2F%2Fidenticons.github.com%2F28fbafb0c2a98d9a643600bd876de1b4.png&r=x&s=30" + "url": "" } } ], @@ -619,7 +619,7 @@ "$": { "height": "30", "width": "30", - "url": "https://2.gravatar.com/avatar/9400cb5aeb155ccec614652542fd274d?d=https%3A%2F%2Fidenticons.github.com%2F28fbafb0c2a98d9a643600bd876de1b4.png&r=x&s=30" + "url": "" } } ], @@ -666,7 +666,7 @@ "$": { "height": "30", "width": "30", - "url": "https://2.gravatar.com/avatar/9400cb5aeb155ccec614652542fd274d?d=https%3A%2F%2Fidenticons.github.com%2F28fbafb0c2a98d9a643600bd876de1b4.png&r=x&s=30" + "url": "" } } ], @@ -713,7 +713,7 @@ "$": { "height": "30", "width": "30", - "url": "https://2.gravatar.com/avatar/9400cb5aeb155ccec614652542fd274d?d=https%3A%2F%2Fidenticons.github.com%2F28fbafb0c2a98d9a643600bd876de1b4.png&r=x&s=30" + "url": "" } } ], @@ -760,7 +760,7 @@ "$": { "height": "30", "width": "30", - "url": "https://2.gravatar.com/avatar/9400cb5aeb155ccec614652542fd274d?d=https%3A%2F%2Fidenticons.github.com%2F28fbafb0c2a98d9a643600bd876de1b4.png&r=x&s=30" + "url": "" } } ], @@ -807,7 +807,7 @@ "$": { "height": "30", "width": "30", - "url": "https://2.gravatar.com/avatar/9400cb5aeb155ccec614652542fd274d?d=https%3A%2F%2Fidenticons.github.com%2F28fbafb0c2a98d9a643600bd876de1b4.png&r=x&s=30" + "url": "" } } ], @@ -854,7 +854,7 @@ "$": { "height": "30", "width": "30", - "url": "https://2.gravatar.com/avatar/9400cb5aeb155ccec614652542fd274d?d=https%3A%2F%2Fidenticons.github.com%2F28fbafb0c2a98d9a643600bd876de1b4.png&r=x&s=30" + "url": "" } } ], @@ -901,7 +901,7 @@ "$": { "height": "30", "width": "30", - "url": "https://2.gravatar.com/avatar/9400cb5aeb155ccec614652542fd274d?d=https%3A%2F%2Fidenticons.github.com%2F28fbafb0c2a98d9a643600bd876de1b4.png&r=x&s=30" + "url": "" } } ], @@ -948,7 +948,7 @@ "$": { "height": "30", "width": "30", - "url": "https://2.gravatar.com/avatar/9400cb5aeb155ccec614652542fd274d?d=https%3A%2F%2Fidenticons.github.com%2F28fbafb0c2a98d9a643600bd876de1b4.png&r=x&s=30" + "url": "" } } ],