Permalink
Browse files

Documentation update.

  • Loading branch information...
1 parent c727c08 commit f80aaed8d77b650add86274ce6d7ff07e2aed3ab @eschnou committed Feb 28, 2011
Showing with 43 additions and 12 deletions.
  1. +25 −6 lib/ostatus/hcard.js
  2. +18 −6 lib/ostatus/webfinger.js
View
@@ -29,22 +29,40 @@ var Sys = require('sys'),
Path = require('path'),
Mu = require('mu');
-function lookup(profile, callback) {
- console.log("Requesting hcard at " + profile);
- Http.get(profile, function(err, response, body) {
+/*
+ * Lookup for HCard content at the given profile url.
+ *
+ * The page is parsed for hcard markup and a JSON profile object is returned.
+ *
+ * @param {String} url
+ * the url of the profile page containing some hcard markup
+ * @param {Function} callback
+ * a callback function in the form function(err, result)
+ *
+ * TODO Support for HTML pages that are not valid XML.
+ */
+function lookup(url, callback) {
+ console.log("Requesting hcard at " + url);
+ Http.get(url, function(err, response, body) {
if (response.statusCode == 200) {
var doc = Xml.parseFromString(body);
- vcardNode = _findVcardNode(doc);
+ var vcardNode = _findVcardNode(doc);
if (vcardNode != undefined) {
- elements = _findVcardElements(vcardNode);
- callback(null, elements);
+ var elements = _findVcardElements(vcardNode);
+ return callback(null, elements);
+ } else {
+ callback(new Error("No HCard content in this profile page"));
}
} else {
callback(new Error("HCard lookup returned HTTP status " + response.statusCode));
}
});
}
+/*
+ * Render a HCard HTML page from a JSON profile object. In practice, the profile
+ * is simply used as input to the hcard.html.mu template.
+ */
function render(profile, callback) {
Mu.compile('hcard.html.mu', function (err, parsed) {
if (err) return callback(err);
@@ -58,6 +76,7 @@ function render(profile, callback) {
});
}
+///// Private functions
function _findVcardNode(doc) {
var nodes = doc.documentElement.selectNodes("//@class");
for (i=0; i<nodes.length; i++) {
View
@@ -68,7 +68,7 @@ function hostXrd(host, callback) {
* @param {Function} callback
* a callback function in the form function(err, result)
*
- * The links have the form:
+ * A link has the form:
* var link = {
* "href": "..",
* "rel" : "..",
@@ -111,6 +111,7 @@ function userXrd(subject, alias, links, callback) {
* "links" : an array of links
* }
*
+ * TODO Add support for HTTP URIs
*/
function lookup(identifier, callback) {
var url = Url.parse(identifier);
@@ -133,11 +134,12 @@ function lookup(identifier, callback) {
*
* @param {String} pAcct
* a string representing an acct: uri (prefix can be omitted)
- *
+ *
* @return
* an object with a username and hostname property
*
- * Example: parseAcct("user@example.com") will return:
+ * Example:
+ * parseAcct("user@example.com") will return:
* { "username": "user", "hostname": "example.com"}
*/
function parseAcct(pAcct) {
@@ -160,6 +162,10 @@ function parseAcct(pAcct) {
}
/////// Private helper functions
+
+/*
+ * Get the host XRD.
+ */
function _fetchHostMeta(host, callback) {
var url = "http://" + host + "/.well-known/host-meta";
console.log("Requesting host meta at " + url);
@@ -175,6 +181,9 @@ function _fetchHostMeta(host, callback) {
});
}
+/*
+ * Get a user XRD from a trmplate URI and an identifier.
+ */
function _fetchUserMeta(template, identifier, callback) {
var url = template.replace("{uri}", identifier);
console.log("Requesting user meta at " + url);
@@ -190,19 +199,22 @@ function _fetchUserMeta(template, identifier, callback) {
});
}
+/*
+ * Parse a user XRD into a JSON object.
+ */
function _parseUserMeta(xml) {
var result = {
"alias": [],
"links": []
};
- // parse the subject
+ // Parse the subject
var subjects = xml.documentElement.getElementsByTagName("Subject");
if (subjects.length > 0) {
result.subject = subjects[0].nodeValue;
}
- // parse the links
+ // Parse the links
var links = xml.documentElement.getElementsByTagName("Link");
for (i=0;i<links.length;i++) {
var link = {};
@@ -214,7 +226,7 @@ function _parseUserMeta(xml) {
result.links.push(link);
}
- // parse the aliases
+ // Parse the aliases
var alias = xml.documentElement.getElementsByTagName("Alias");
for (i=0;i<alias.length;i++) {
result.alias.push(alias[i].nodeValue);

0 comments on commit f80aaed

Please sign in to comment.