Skip to content

Commit

Permalink
bug 765642: Expose kuma.fetchFeed() to wrap FeedParser access
Browse files Browse the repository at this point in the history
  • Loading branch information
lmorchard committed Nov 22, 2013
1 parent cef1c78 commit 2eaec27
Show file tree
Hide file tree
Showing 8 changed files with 2,101 additions and 2 deletions.
20 changes: 19 additions & 1 deletion lib/kumascript/api.js
Expand Up @@ -93,7 +93,25 @@ var KumaAPI = ks_utils.Class(BaseAPI, {
replace(/>/g,'>').
replace(/</g,'&lt;').
replace(/"/g,'&quot;');
}
},

// #### fetchFeed(url)
// Fetch an Atom/RSS feed, return an object with properties error, meta,
// and articles containing the parsed data
fetchFeed: function (url) {
var FeedParser = require('feedparser'),
parser = new FeedParser(),
result = {error: null, meta: {}, articles: []},
f = new Future();
parser.parseUrl(url, function (error, meta, articles) {
result.error = error;
result.meta = meta;
result.articles = articles;
f['return']();
});
f.wait();
return result;
},

});

Expand Down
2 changes: 1 addition & 1 deletion lib/kumascript/utils.js
Expand Up @@ -91,7 +91,7 @@ function getStatsD (options) {
prefix: conf.prefix || 'kumascript.' + host_key + '.',
mock: !conf.enabled,
mockCallback: function (msg) {
util.debug("STATSD: " + msg);
// util.debug("STATSD: " + msg);
}
});
return statsd;
Expand Down
4 changes: 4 additions & 0 deletions package.json
Expand Up @@ -31,6 +31,10 @@
"memcached": "0.0.9",
"http-proxy": "0.8.1",
"ejs": "0.6.1",
"sax": "0.5.x",
"xml2js": "0.2.x",
"feedparser": "0.10.x",
"html5": "0.3.x",
"node-statsd": "git://github.com/sivy/node-statsd.git#c9b3767d0aac67435a8f96d26c74942a6d8fcaf8",
"firelogger": "git://github.com/lmorchard/node-firelogger.git",
"hirelings": "git://github.com/lmorchard/node-hirelings.git"
Expand Down
24 changes: 24 additions & 0 deletions tests/fixtures/documents/feeds-expected.txt
@@ -0,0 +1,24 @@
This should be a feed:

Mozilla Hacks - the Web developer blog

* Firefox OS Security: Part 2 – User Experience and Security Updates
* Handling click-to-activate plugins using JavaScript
* The Pond – building a multi-platform HTML5 game
* Launching developer Q&amp;A on Stack Overflow
* Firefox OS Security: Part 1 – The Web Security Model
* Introducing the Whiteboard Drum – WebRTC and Web Audio API magic
* Live editing WebGL shaders with Firefox Developer Tools
* Make your Firefox OS app feel alive with video and audio
* Firefox Developer Tools: Episode 27 – Edit as HTML, Codemirror &amp; more
* Designing Web Apps For Multiple Devices
* Reintroducing the Firefox Developer Tools, part 2: the Scratchpad and the Style Editor
* Monetization with Inneractive on Firefox OS
* Halloween artist
* Songs of Diridum: Pushing the Web Audio API to Its Limits
* Progress report on cross-platform Open Web Apps
* Building a Firefox OS App for my favorite Internet radio station
* Working with receipts for paid apps
* Fast retro gaming on mobile
* Announcing the winners of the July 2013 Dev Derby!
* awsbox, a PaaS layer for Node.js: An Update on Latest Developments
3 changes: 3 additions & 0 deletions tests/fixtures/documents/feeds.txt
@@ -0,0 +1,3 @@
This should be a feed:

{{ fetch-feed('http://localhost:9001/hacks.rss') }}
2,040 changes: 2,040 additions & 0 deletions tests/fixtures/hacks.rss

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions tests/fixtures/templates/fetch-feed.ejs
@@ -0,0 +1,4 @@
<% result = kuma.fetchFeed($0); %><%= result.meta.title %>

<% for (var i=0; i<result.articles.length; i++) { %>* <%= result.articles[i].title %>
<% } %>
6 changes: 6 additions & 0 deletions tests/test-api.js
Expand Up @@ -133,6 +133,12 @@ module.exports = {
var expected_fn = __dirname + '/fixtures/documents/memcache-expected.txt',
result_url = 'http://localhost:9000/docs/memcache';
performTestRequest(test, expected_fn, result_url);
},

"The API offers access to an RSS/Atom feed parser": function (test) {
var expected_fn = __dirname + '/fixtures/documents/feeds-expected.txt',
result_url = 'http://localhost:9000/docs/feeds';
performTestRequest(test, expected_fn, result_url);
}

/* TODO: Fix this test. It relies on in-process macro processing, breaks
Expand Down

0 comments on commit 2eaec27

Please sign in to comment.