Skip to content

Commit

Permalink
Added profile lookup helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
eschnou committed Feb 28, 2011
1 parent b7e3d96 commit c456d6b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 28 deletions.
28 changes: 8 additions & 20 deletions bin/profile.js
Expand Up @@ -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);
Expand All @@ -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]);
}
}
};

Expand Down
38 changes: 30 additions & 8 deletions lib/ostatus/helper.js
Expand Up @@ -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;
1 change: 1 addition & 0 deletions lib/ostatus/index.js
Expand Up @@ -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.