Permalink
Browse files

Added a helper function to fetch activities from acct uri in one call.

  • Loading branch information...
eschnou committed Feb 20, 2011
1 parent cc2c74a commit d4022f271f31a6353bedf4172cb5e66ccadc1e18
Showing with 63 additions and 31 deletions.
  1. +10 −30 bin/status.js
  2. +50 −0 lib/ostatus/helper.js
  3. +3 −1 lib/ostatus/index.js
View
@@ -23,9 +23,7 @@
*/
var Ostatus = require('ostatus'),
- Hcard = Ostatus.hcard,
- Atom = Ostatus.atom,
- Webfinger = Ostatus.webfinger;
+ Util = require('util');
var _main = function(argv) {
// Parse the command line arguments
@@ -34,46 +32,28 @@ var _main = function(argv) {
process.exit(-1);
}
- // Webfinger require acct: identifier, we add if required
- var identifier = argv[2];
- if (identifier.length<5 || identifier.substring(0,5) != "acct:") {
- identifier = "acct:" + identifier;
- }
-
// Wrap the request in a try.. catch to nicely die on errors
try {
- Webfinger.lookup(identifier, function(err, result) {
+ Ostatus.activities(argv[2], function(err, result) {
if (err) _error(err);
- var links = result.documentElement.getElementsByTagName("Link");
- for (i=0;i<links.length;i++) {
- var attributes = links[i].attributes;
- var rel = attributes.getNamedItem("rel");
- if (rel.nodeValue == "http://schemas.google.com/g/2010#updates-from") {
- var href = attributes.getNamedItem("href");
- Atom.parseFeed(href.nodeValue, _result);
- }
- }
+ _result(result);
});
} catch (error) {
_error(error);
}
};
var _error = function(error) {
- console.log("Error: " + error.message);
+ console.log("Error: " + error);
process.exit(-1);
};
-var _result = function(error, result) {
- if (error) {
- _error(error);
- } else {
- if (result != undefined) {
- var item = result[0];
- var time = item['postedTime'];
- var title = item['title'];
- console.log(time + "\n" + title);
- }
+var _result = function(result) {
+ if (result != undefined) {
+ var item = result.items[0];
+ var time = item['postedTime'];
+ var title = item['title'];
+ console.log(time + "\n" + title);
}
};
View
@@ -0,0 +1,50 @@
+/*
+ * node-ostatus - An implementation of OStatus for node.js
+ *
+ * Copyright (C) 2010 Laurent Eschenauer <laurent@eschenauer.be>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+*/
+
+var Hcard = require("./hcard")
+, Atom = require("./atom")
+, Webfinger = require("./webfinger");
+
+function activities(identifier, callback) {
+ // Fix arguments
+ if (identifier.length<5 || identifier.substring(0,5) != "acct:") {
+ identifier = "acct:" + identifier;
+ }
+
+ // Wrap the request in a try.. catch to nicely die on errors
+ Webfinger.lookup(identifier, function(err, result) {
+ if (err) callback(err);
+ var links = result.documentElement.getElementsByTagName("Link");
+ for (i=0;i<links.length;i++) {
+ var attributes = links[i].attributes;
+ var rel = attributes.getNamedItem("rel");
+ if (rel.nodeValue == "http://schemas.google.com/g/2010#updates-from") {
+ var href = attributes.getNamedItem("href");
+ Atom.parseFeed(href.nodeValue, callback);
+ }
+ }
+ });
+};
+
+exports.activities = activities;
View
@@ -22,8 +22,10 @@
* THE SOFTWARE.
*/
+var helper = require('./helper.js');
+
exports.atom = require('./atom.js');
exports.push = require('./push.js');
exports.hcard = require('./hcard.js');
exports.webfinger = require('./webfinger.js');
-
+exports.activities = helper.activities;

0 comments on commit d4022f2

Please sign in to comment.