Skip to content

Commit

Permalink
v2.7.4. Improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Nov 12, 2013
1 parent c439f5c commit cf37a5b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 32 deletions.
5 changes: 4 additions & 1 deletion 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
Expand Down
5 changes: 2 additions & 3 deletions README.md
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion 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": {
Expand Down
44 changes: 37 additions & 7 deletions src/lib/feedr.coffee
Expand Up @@ -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 {}
Expand All @@ -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) ->
Expand Down Expand Up @@ -86,7 +105,7 @@ class Feedr

# Read Feed
# next(err,data)
readFeed: (feedDetails,next) ->
readFeed: (args...) ->
# Prepare
feedr = @

Expand All @@ -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
Expand Down
40 changes: 20 additions & 20 deletions test/fixtures.json
Expand Up @@ -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": ""
}
}
],
Expand Down Expand Up @@ -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": ""
}
}
],
Expand Down Expand Up @@ -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": ""
}
}
],
Expand Down Expand Up @@ -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": ""
}
}
],
Expand Down Expand Up @@ -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": ""
}
}
],
Expand Down Expand Up @@ -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": ""
}
}
],
Expand Down Expand Up @@ -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": ""
}
}
],
Expand Down Expand Up @@ -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": ""
}
}
],
Expand Down Expand Up @@ -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": ""
}
}
],
Expand Down Expand Up @@ -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": ""
}
}
],
Expand Down Expand Up @@ -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": ""
}
}
],
Expand Down Expand Up @@ -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": ""
}
}
],
Expand Down Expand Up @@ -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": ""
}
}
],
Expand Down Expand Up @@ -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": ""
}
}
],
Expand Down Expand Up @@ -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": ""
}
}
],
Expand Down Expand Up @@ -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": ""
}
}
],
Expand Down Expand Up @@ -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": ""
}
}
],
Expand Down Expand Up @@ -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": ""
}
}
],
Expand Down Expand Up @@ -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": ""
}
}
],
Expand Down Expand Up @@ -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": ""
}
}
],
Expand Down

0 comments on commit cf37a5b

Please sign in to comment.