[google-sgnodemapper] r236 committed - 1. Add foursquare.com...

4 views
Skip to first unread message

codesite...@google.com

unread,
Aug 24, 2010, 3:18:27 PM8/24/10
to sgnodemapp...@googlegroups.com
Revision: 236
Author: mattr...@google.com
Date: Tue Aug 24 12:17:37 2010
Log: 1. Add foursquare.com
2. Add nodemapper.createSomethingThenUsernameHandler
3. In handlers that allow something after a username, stop on '?', along
with '/' and end-of-string.

http://code.google.com/p/google-sgnodemapper/source/detail?r=236

Modified:
/trunk/autogen/nodemapper.js
/trunk/autogen/nodemapper_debug.js
/trunk/autogen/nodemapper_tests.js
/trunk/nodemapper-base.js
/trunk/sites/simple.js

=======================================
--- /trunk/autogen/nodemapper.js Mon Aug 23 15:02:11 2010
+++ /trunk/autogen/nodemapper.js Tue Aug 24 12:17:37 2010
@@ -312,7 +312,7 @@
nodemapper.createSlashUsernameHandler = function(domain, opt_opts) {
var slashUsernameRE = /^\/(\w+)\/?$/;
if (opt_opts && opt_opts.slashAnything) {
- slashUsernameRE = /^\/(\w+)(?:\/|$)/;
+ slashUsernameRE = /^\/(\w+)(?:\/|$|\?)/;
}
return nodemapper.createPathRegexpHandler(domain, slashUsernameRE,
opt_opts);
};
@@ -320,11 +320,19 @@
domain,
opt_opts) {
var slashSomethingUserRE = new RegExp("^/" + prefix + "/" +
- "(\\w+)(?:/|$)");
+ "(\\w+)(?:/|$|\\?)");
return nodemapper.createPathRegexpHandler(domain,
slashSomethingUserRE,
opt_opts);
};
+nodemapper.createSomethingThenUsernameHandler = function(prefix,
+ domain,
+ opt_opts) {
+ var thenSomethingUserRE = new RegExp("^/" + prefix + "(\\w+)(?:/|$|\\?)")
+ return nodemapper.createPathRegexpHandler(domain,
+ thenSomethingUserRE,
+ opt_opts);
+}
nodemapper.createUserIsSubdomainHandler = function(domain) {
var subdomainRE = new RegExp("([\\w\\-]+)\." + domain + "$", "i");
return nodemapper.createHostRegexpHandler(domain, subdomainRE);
@@ -1795,6 +1803,13 @@
});
nodemapper.addSimpleHandler("tripit.com", "ident_to_profile",
"http://tripit.com/people/");
+nodemapper.registerDomain(
+ "foursquare.com",
+ {name: "foursquare.com",
+ urlToGraphNode: nodemapper.createSomethingThenUsernameHandler(
+ "user/-", "foursquare.com", {keyName: "pk"})});
+nodemapper.addSimpleHandler("foursquare.com", "pk_to_profile",
+ "http://foursquare.com/user/-");
})();
(function(){
spinPkHandler = function(url, host, path) {
=======================================
--- /trunk/autogen/nodemapper_debug.js Mon Aug 23 15:02:11 2010
+++ /trunk/autogen/nodemapper_debug.js Tue Aug 24 12:17:37 2010
@@ -575,7 +575,7 @@
nodemapper.createSlashUsernameHandler = function(domain, opt_opts) {
var slashUsernameRE = /^\/(\w+)\/?$/;
if (opt_opts && opt_opts.slashAnything) {
- slashUsernameRE = /^\/(\w+)(?:\/|$)/;
+ slashUsernameRE = /^\/(\w+)(?:\/|$|\?)/;
}
return nodemapper.createPathRegexpHandler(domain, slashUsernameRE,
opt_opts);
};
@@ -597,12 +597,33 @@
domain,
opt_opts) {
var slashSomethingUserRE = new RegExp("^/" + prefix + "/" +
- "(\\w+)(?:/|$)");
+ "(\\w+)(?:/|$|\\?)");
return nodemapper.createPathRegexpHandler(domain,
slashSomethingUserRE,
opt_opts);
};

+/**
+ * Returns an sgn parser function which parses URLs with
+ * paths of the form /[prefix][username]/ (with optional trailing
+ * slash)
+ *
+ * @param {String} prefix The prefix path before the username
+ * @param {String} domain sgn:// domain to return on match
+ * @param {Object} opt_opts Optional object with extra options
+ * (see list options in nodemapper.createPathRegexpHandler method
comment)
+ * @return {function) An sgn parser function.
+ * @see nodemapper#createPathRegexpHandler
+ */
+nodemapper.createSomethingThenUsernameHandler = function(prefix,
+ domain,
+ opt_opts) {
+ var thenSomethingUserRE = new RegExp("^/" + prefix + "(\\w+)(?:/|$|\\?)")
+ return nodemapper.createPathRegexpHandler(domain,
+ thenSomethingUserRE,
+ opt_opts);
+}
+

/**
* Creates a URL handler that parses out the subdomain
@@ -2555,6 +2576,14 @@
nodemapper.addSimpleHandler("tripit.com", "ident_to_profile",
"http://tripit.com/people/");

+nodemapper.registerDomain(
+ "foursquare.com",
+ {name: "foursquare.com",
+ urlToGraphNode: nodemapper.createSomethingThenUsernameHandler(
+ "user/-", "foursquare.com", {keyName: "pk"})});
+nodemapper.addSimpleHandler("foursquare.com", "pk_to_profile",
+ "http://foursquare.com/user/-");
+
})();
// (end of included file sites/simple.js)

=======================================
--- /trunk/autogen/nodemapper_tests.js Mon Aug 23 15:02:11 2010
+++ /trunk/autogen/nodemapper_tests.js Tue Aug 24 12:17:37 2010
@@ -798,6 +798,11 @@

["urlToGraphNode", "http://www.tripit.com/people/trying?what", "sgn://tripit.com/?ident=trying"],

["urlFromGraphNode", "sgn://tripit.com/?ident=foobar", "profile", "http://tripit.com/people/foobar"],

["urlToGraphNode", "http://tripit.com/people/foobar", "sgn://tripit.com/?ident=foobar"],
+
["urlToGraphNode", "http://foursquare.com/user/-123456789", "sgn://foursquare.com/?pk=123456789"],
+
["urlToGraphNode", "http://foursquare.com/user/-123456789/", "sgn://foursquare.com/?pk=123456789"],
+
["urlToGraphNode", "http://foursquare.com/user/-123456789?mode=foo", "sgn://foursquare.com/?pk=123456789"],
+
["urlFromGraphNode", "sgn://foursquare.com/?pk=987654321", "profile", "http://foursquare.com/user/-987654321"],
+
["urlToGraphNode", "http://foursquare.com/user/-987654321", "sgn://foursquare.com/?pk=987654321"],
["pairToGraphNode", "spin.de", "Warp", "sgn://spin.de/?ident=warp"],

["urlToGraphNode", "http://www.spin.de/hp/Warp", "sgn://spin.de/?ident=warp"],

["urlToGraphNode", "http://www.spin.de/hp/warp", "sgn://spin.de/?ident=warp"],
=======================================
--- /trunk/nodemapper-base.js Mon Mar 22 09:49:40 2010
+++ /trunk/nodemapper-base.js Tue Aug 24 12:17:37 2010
@@ -570,7 +570,7 @@
nodemapper.createSlashUsernameHandler = function(domain, opt_opts) {
var slashUsernameRE = /^\/(\w+)\/?$/;
if (opt_opts && opt_opts.slashAnything) {
- slashUsernameRE = /^\/(\w+)(?:\/|$)/;
+ slashUsernameRE = /^\/(\w+)(?:\/|$|\?)/;
}
return nodemapper.createPathRegexpHandler(domain, slashUsernameRE,
opt_opts);
};
@@ -592,11 +592,32 @@
domain,
opt_opts) {
var slashSomethingUserRE = new RegExp("^/" + prefix + "/" +
- "(\\w+)(?:/|$)");
+ "(\\w+)(?:/|$|\\?)");
return nodemapper.createPathRegexpHandler(domain,
slashSomethingUserRE,
opt_opts);
};
+
+/**
+ * Returns an sgn parser function which parses URLs with
+ * paths of the form /[prefix][username]/ (with optional trailing
+ * slash)
+ *
+ * @param {String} prefix The prefix path before the username
+ * @param {String} domain sgn:// domain to return on match
+ * @param {Object} opt_opts Optional object with extra options
+ * (see list options in nodemapper.createPathRegexpHandler method
comment)
+ * @return {function) An sgn parser function.
+ * @see nodemapper#createPathRegexpHandler
+ */
+nodemapper.createSomethingThenUsernameHandler = function(prefix,
+ domain,
+ opt_opts) {
+ var thenSomethingUserRE = new RegExp("^/" + prefix + "(\\w+)(?:/|$|\\?)")
+ return nodemapper.createPathRegexpHandler(domain,
+ thenSomethingUserRE,
+ opt_opts);
+}


/**
=======================================
--- /trunk/sites/simple.js Mon Aug 23 15:02:11 2010
+++ /trunk/sites/simple.js Tue Aug 24 12:17:37 2010
@@ -542,6 +542,14 @@
nodemapper.addSimpleHandler("tripit.com", "ident_to_profile",
"http://tripit.com/people/");

+nodemapper.registerDomain(
+ "foursquare.com",
+ {name: "foursquare.com",
+ urlToGraphNode: nodemapper.createSomethingThenUsernameHandler(
+ "user/-", "foursquare.com", {keyName: "pk"})});
+nodemapper.addSimpleHandler("foursquare.com", "pk_to_profile",
+ "http://foursquare.com/user/-");
+
__END__

http://digg.com/users/foobar sgn://digg.com/?ident=foobar
@@ -833,3 +841,8 @@
http://www.tripit.com/people/meEE.123 sgn://tripit.com/?ident=meee.123
http://www.tripit.com/people/trying?what sgn://tripit.com/?ident=trying
profile(sgn://tripit.com/?ident=foobar) http://tripit.com/people/foobar
+
+http://foursquare.com/user/-123456789 sgn://foursquare.com/?pk=123456789
+http://foursquare.com/user/-123456789/ sgn://foursquare.com/?pk=123456789
+http://foursquare.com/user/-123456789?mode=foo
sgn://foursquare.com/?pk=123456789
+profile(sgn://foursquare.com/?pk=987654321)
http://foursquare.com/user/-987654321

Reply all
Reply to author
Forward
0 new messages