Skip to content
Browse files

Added profile lookup helper function

  • Loading branch information...
1 parent b7e3d96 commit c456d6b1e5e3d5cda959773ee9265c7e327a7811 @eschnou committed Feb 28, 2011
Showing with 39 additions and 28 deletions.
  1. +8 −20 bin/profile.js
  2. +30 −8 lib/ostatus/helper.js
  3. +1 −0 lib/ostatus/index.js
View
28 bin/profile.js
@@ -42,17 +42,9 @@ var _main = function(argv) {
// Wrap the request in a try.. catch to nicely die on errors
try {
- Webfinger.lookup(identifier, 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://microformats.org/profile/hcard") {
- var href = attributes.getNamedItem("href");
- Hcard.lookup(href.nodeValue, _result);
- }
- }
+ Ostatus.profile(argv[2], function(err, result) {
+ if (err) return _error(err);
+ _result(result);
});
} catch (error) {
_error(error);
@@ -64,15 +56,11 @@ var _error = function(error) {
process.exit(-1);
};
-var _result = function(error, result) {
- if (error) {
- _error(error);
- } else {
- if (result != undefined) {
- for(key in result) {
- console.log(key + ": " + result[key]);
- }
- }
+var _result = function(result) {
+ if (result != undefined) {
+ for(key in result) {
+ console.log(key + ": " + result[key]);
+ }
}
};
View
38 lib/ostatus/helper.js
@@ -32,19 +32,41 @@ function activities(identifier, callback) {
identifier = "acct:" + identifier;
}
- // Wrap the request in a try.. catch to nicely die on errors
+ // Perform a webfinger lookup on the identifier,
+ // then search for the activities link and if there is one,
+ // fetch the feed and parse it to Json.
Webfinger.lookup(identifier, function(err, result) {
if (err) callback(err);
- var links = result.documentElement.getElementsByTagName("Link");
+ var links = result.links;
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.getFeed(href.nodeValue, callback);
+ var link = links[i];
+ if (link.rel == "http://schemas.google.com/g/2010#updates-from") {
+ Atom.getFeed(link.href, callback);
}
}
});
};
-exports.activities = activities;
+function profile(identifier, callback) {
+ // Fix arguments
+ if (identifier.length<5 || identifier.substring(0,5) != "acct:") {
+ identifier = "acct:" + identifier;
+ }
+
+ // Perform a webfinger lookup on the identifier,
+ // then search for the hcard link and if there is one,
+ // fetch the page and parse it to Json.
+ Webfinger.lookup(identifier, function(err, result) {
+ if (err) callback(err);
+ var links = result.links;
+ for (i=0;i<links.length;i++) {
+ var link = links[i];
+ if (link.rel == "http://microformats.org/profile/hcard") {
+ Hcard.lookup(link.href, callback);
+ }
+ }
+ });
+}
+
+exports.activities = activities;
+exports.profile = profile;
View
1 lib/ostatus/index.js
@@ -29,3 +29,4 @@ exports.push = require('./push.js');
exports.hcard = require('./hcard.js');
exports.webfinger = require('./webfinger.js');
exports.activities = helper.activities;
+exports.profile = helper.profile;

0 comments on commit c456d6b

Please sign in to comment.
Something went wrong with that request. Please try again.