Modified:
/trunk/autogen/nodemapper.js
/trunk/autogen/nodemapper_debug.js
/trunk/autogen/nodemapper_tests.js
/trunk/nodemapper-base.js
/trunk/sites/amazon.js
=======================================
--- /trunk/autogen/nodemapper.js Wed Mar 10 09:31:52 2010
+++ /trunk/autogen/nodemapper.js Mon Mar 22 09:49:40 2010
@@ -285,6 +285,9 @@
}
var keyName = opt_opts.keyName || 'ident'; // ident= or pk=; TODO:
enforce valid key names?
var value = (opt_opts.casePreserve ? m[1] : m[1].toLowerCase());
+ if (opt_opts.upperCase) {
+ value = value.toUpperCase(); // overrides casePreserve if set
+ }
if (opt_opts.notUsernames && opt_opts.notUsernames[value]) {
return opt_opts.fallbackHandler ?
opt_opts.fallbackHandler(url, host, path) :
@@ -384,25 +387,49 @@
debug = function() {};
}
(function(){
+var AMAZON_PK_RE = new RegExp("^[A-Za-z0-9]{14}$");
+var AMAZON_PROFILE_PK_RE = new RegExp("gp/pdp/profile/([A-Za-z0-9]{14})");
var amazonPkHandler = nodemapper.createFirstMatchHandler([
- nodemapper.createSomethingSlashUsernameHandler(
- "gp/pdp/profile", "amazon.com",
- {keyName: "pk", casePreserve: 1}),
- nodemapper.createSomethingSlashUsernameHandler(
- "rss/people", "amazon.com",
- {keyName: "pk", casePreserve: 1})]);
+ nodemapper.createSomethingSlashUsernameHandler(
+ "gp/pdp/profile/friends", "amazon.com",
+ {keyName: "pk", upperCase: 1}),
+ nodemapper.createPathRegexpHandler(
+ "amazon.com", AMAZON_PROFILE_PK_RE,
+ {keyName: "pk", upperCase: 1}),
+ nodemapper.createSomethingSlashUsernameHandler(
+ "rss/people", "amazon.com",
+ {keyName: "pk", upperCase: 1})]);
nodemapper.registerDomain("amazon.com", {
- accountToSgn: { pk: ["amazon.com", /^\w{14,14}$/] },
- urlToGraphNode: amazonPkHandler,
- name: "Amazon.com"
-});
-nodemapper.registerDomain("amazon.co.uk", {
- urlToGraphNode: amazonPkHandler
-});
-nodemapper.addSimpleHandler("amazon.com", "pk_to_profile",
- "http://www.amazon.com/gp/pdp/profile/");
+ accountToSgn: { pk: ["amazon.com", AMAZON_PK_RE] },
+ urlToGraphNode: amazonPkHandler,
+ name: "Amazon.com"
+ }
+);
+nodemapper.addSimpleHandler("amazon.com", "pk_to_profile",
+ "http://www.amazon.com/gp/pdp/profile/");
+nodemapper.addSimpleHandler("amazon.com", "pk_to_friends",
+ "http://www.amazon.com/gp/pdp/profile/friends/");
nodemapper.addSimpleHandler("amazon.com", "pk_to_rss",
- "http://www.amazon.com/rss/people/", "/reviews");
+ "http://www.amazon.com/rss/people/", "/reviews");
+var AMAZON_I18N_DOMAINS = ["amazon.co.uk", "amazon.co.jp", "amazon.ca",
+ "amazon.fr", "amazon.de"];
+var pkToProfileHandler = function(domain) {
+ return function(pk) { return "http://www." + domain + "/gp/pdp/profile/"
+ pk; }
+};
+for (var i = 0; i < AMAZON_I18N_DOMAINS.length; i++) {
+ var domain = AMAZON_I18N_DOMAINS[i];
+ var urlToGraphNodeHandler = nodemapper.createPathRegexpHandler(
+ domain,
+ AMAZON_PROFILE_PK_RE,
+ {keyName: "pk", upperCase: 1}
+ );
+ nodemapper.registerDomain(domain, {
+ name: domain,
+ urlToGraphNode: urlToGraphNodeHandler,
+ accountToSgn: { pk: [domain, AMAZON_PK_RE] },
+ pk_to_profile: pkToProfileHandler(domain)
+ });
+}
})();
(function(){
var AIM_REGEX = /^aim:(?:goim\?(?:message=[^&\s]+&)?screenname=)?([%\w
\+]+)$/i;
=======================================
--- /trunk/autogen/nodemapper_debug.js Wed Mar 10 09:31:52 2010
+++ /trunk/autogen/nodemapper_debug.js Mon Mar 22 09:49:40 2010
@@ -501,6 +501,7 @@
* must match the username.
* @param {Object} opt_opts Optional object with extra options:
* - casePreserve: if true, don't lowercase the ident/pk
+ * - upperCase: (overrides casePreserve), if true, upcase ident/pk
* - fallbackHandler: to run if no match (rather than returning URL
back)
* - keyName: type of identifier in the URL (default: "ident", or "pk")
* - slashAnything: if true, allow (and ignore) any /xyz/abc after the
match
@@ -522,6 +523,9 @@
}
var keyName = opt_opts.keyName || 'ident'; // ident= or pk=; TODO:
enforce valid key names?
var value = (opt_opts.casePreserve ? m[1] : m[1].toLowerCase());
+ if (opt_opts.upperCase) {
+ value = value.toUpperCase(); // overrides casePreserve if set
+ }
if (opt_opts.notUsernames && opt_opts.notUsernames[value]) {
// fail. this username is marked as not a real username.
return opt_opts.fallbackHandler ?
@@ -712,29 +716,61 @@
//
=========================================================================
// Begin included file sites/amazon.js
(function(){
-// TODO(bradfitz): this isn't actually case-sensitive. jsmarr said it
was. :)
+// I. Amazon.com (US)
+
+// Search RegExp for Amazon PK is case-insensitive. However, the
normalized PK
+// is upper case. Thus the upperCase flag is passed into
createPathRegexpHandler.
+var AMAZON_PK_RE = new RegExp("^[A-Za-z0-9]{14}$");
+var AMAZON_PROFILE_PK_RE = new RegExp("gp/pdp/profile/([A-Za-z0-9]{14})");
+
var amazonPkHandler = nodemapper.createFirstMatchHandler([
- nodemapper.createSomethingSlashUsernameHandler(
- "gp/pdp/profile", "amazon.com",
- {keyName: "pk", casePreserve: 1}),
- nodemapper.createSomethingSlashUsernameHandler(
- "rss/people", "amazon.com",
- {keyName: "pk", casePreserve: 1})]);
+ nodemapper.createSomethingSlashUsernameHandler(
+ "gp/pdp/profile/friends", "amazon.com",
+ {keyName: "pk", upperCase: 1}),
+ nodemapper.createPathRegexpHandler(
+ "amazon.com", AMAZON_PROFILE_PK_RE,
+ {keyName: "pk", upperCase: 1}),
+ nodemapper.createSomethingSlashUsernameHandler(
+ "rss/people", "amazon.com",
+ {keyName: "pk", upperCase: 1})]);
nodemapper.registerDomain("amazon.com", {
- accountToSgn: { pk: ["amazon.com", /^\w{14,14}$/] },
- urlToGraphNode: amazonPkHandler,
- name: "Amazon.com"
-});
-
-nodemapper.registerDomain("amazon.co.uk", {
- urlToGraphNode: amazonPkHandler
-});
-
-nodemapper.addSimpleHandler("amazon.com", "pk_to_profile",
- "http://www.amazon.com/gp/pdp/profile/");
+ accountToSgn: { pk: ["amazon.com", AMAZON_PK_RE] },
+ urlToGraphNode: amazonPkHandler,
+ name: "Amazon.com"
+ }
+);
+
+nodemapper.addSimpleHandler("amazon.com", "pk_to_profile",
+ "http://www.amazon.com/gp/pdp/profile/");
+nodemapper.addSimpleHandler("amazon.com", "pk_to_friends",
+ "http://www.amazon.com/gp/pdp/profile/friends/");
nodemapper.addSimpleHandler("amazon.com", "pk_to_rss",
- "http://www.amazon.com/rss/people/", "/reviews");
+ "http://www.amazon.com/rss/people/", "/reviews");
+
+// II. Amazon international TLDs
+var AMAZON_I18N_DOMAINS = ["amazon.co.uk", "amazon.co.jp", "amazon.ca",
+ "amazon.fr", "amazon.de"];
+
+var pkToProfileHandler = function(domain) {
+ // function used to wrap domain variable scope
+ return function(pk) { return "http://www." + domain + "/gp/pdp/profile/"
+ pk; }
+};
+
+for (var i = 0; i < AMAZON_I18N_DOMAINS.length; i++) {
+ var domain = AMAZON_I18N_DOMAINS[i];
+ var urlToGraphNodeHandler = nodemapper.createPathRegexpHandler(
+ domain,
+ AMAZON_PROFILE_PK_RE,
+ {keyName: "pk", upperCase: 1}
+ );
+ nodemapper.registerDomain(domain, {
+ name: domain,
+ urlToGraphNode: urlToGraphNodeHandler,
+ accountToSgn: { pk: [domain, AMAZON_PK_RE] },
+ pk_to_profile: pkToProfileHandler(domain)
+ });
+}
})();
// (end of included file sites/amazon.js)
=======================================
--- /trunk/autogen/nodemapper_tests.js Wed Mar 10 09:31:52 2010
+++ /trunk/autogen/nodemapper_tests.js Mon Mar 22 09:49:40 2010
@@ -1,13 +1,32 @@
// Auto-generated test data from sites/*.js test sections at bottom.
var nodemapper_tests = [
["urlToGraphNode", "http://www.amazon.com/gp/pdp/profile/A2Q1GI13N0TVRC", "sgn://amazon.com/?pk=A2Q1GI13N0TVRC"],
+
["urlToGraphNode", "http://www.amazon.com/gp/pdp/profile/A2Q1GI13N0tvrc", "sgn://amazon.com/?pk=A2Q1GI13N0TVRC"],
["urlToGraphNode", "http://amazon.com/gp/pdp/profile/A2Q1GI13N0TVRC", "sgn://amazon.com/?pk=A2Q1GI13N0TVRC"],
-
["urlToGraphNode", "http://www.amazon.co.uk/gp/pdp/profile/A2Q1GI13N0TVRC", "sgn://amazon.com/?pk=A2Q1GI13N0TVRC"],
+
["urlToGraphNode", "http://amazon.com/gp/pdp/profile/friends/A2Q1GI13N0TVRC", "sgn://amazon.com/?pk=A2Q1GI13N0TVRC"],
+
["urlToGraphNode", "http://www.amazon.co.uk/gp/pdp/profile/A2Q1GI13N0TVRC", "sgn://amazon.co.uk/?pk=A2Q1GI13N0TVRC"],
+
["urlToGraphNode", "http://amazon.ca/gp/pdp/profile/A2Q1GI13N0TVRC", "sgn://amazon.ca/?pk=A2Q1GI13N0TVRC"],
+
["urlToGraphNode", "http://amazon.fr/gp/pdp/profile/A2Q1GI13N0TVRC", "sgn://amazon.fr/?pk=A2Q1GI13N0TVRC"],
+
["urlToGraphNode", "http://amazon.de/gp/pdp/profile/A2Q1GI13N0TVRC", "sgn://amazon.de/?pk=A2Q1GI13N0TVRC"],
+
["urlToGraphNode", "http://amazon.co.jp/gp/pdp/profile/A2Q1GI13N0TVRC", "sgn://amazon.co.jp/?pk=A2Q1GI13N0TVRC"],
["urlToGraphNode", "http://www.amazon.com/rss/people/A2Q1GI13N0TVRC/reviews", "sgn://amazon.com/?pk=A2Q1GI13N0TVRC"],
["urlFromGraphNode", "sgn://amazon.com/?pk=A2Q1GI13N0TVRC", "profile", "http://www.amazon.com/gp/pdp/profile/A2Q1GI13N0TVRC"],
["urlToGraphNode", "http://www.amazon.com/gp/pdp/profile/A2Q1GI13N0TVRC", "sgn://amazon.com/?pk=A2Q1GI13N0TVRC"],
+
["urlFromGraphNode", "sgn://amazon.co.uk/?pk=A2Q1GI13N0TVRC", "profile", "http://www.amazon.co.uk/gp/pdp/profile/A2Q1GI13N0TVRC"],
+
["urlToGraphNode", "http://www.amazon.co.uk/gp/pdp/profile/A2Q1GI13N0TVRC", "sgn://amazon.co.uk/?pk=A2Q1GI13N0TVRC"],
+
["urlFromGraphNode", "sgn://amazon.co.jp/?pk=A2Q1GI13N0TVRC", "profile", "http://www.amazon.co.jp/gp/pdp/profile/A2Q1GI13N0TVRC"],
+
["urlToGraphNode", "http://www.amazon.co.jp/gp/pdp/profile/A2Q1GI13N0TVRC", "sgn://amazon.co.jp/?pk=A2Q1GI13N0TVRC"],
+
["urlFromGraphNode", "sgn://amazon.ca/?pk=A2Q1GI13N0TVRC", "profile", "http://www.amazon.ca/gp/pdp/profile/A2Q1GI13N0TVRC"],
+
["urlToGraphNode", "http://www.amazon.ca/gp/pdp/profile/A2Q1GI13N0TVRC", "sgn://amazon.ca/?pk=A2Q1GI13N0TVRC"],
+
["urlFromGraphNode", "sgn://amazon.fr/?pk=A2Q1GI13N0TVRC", "profile", "http://www.amazon.fr/gp/pdp/profile/A2Q1GI13N0TVRC"],
+
["urlToGraphNode", "http://www.amazon.fr/gp/pdp/profile/A2Q1GI13N0TVRC", "sgn://amazon.fr/?pk=A2Q1GI13N0TVRC"],
+
["urlFromGraphNode", "sgn://amazon.de/?pk=A2Q1GI13N0TVRC", "profile", "http://www.amazon.de/gp/pdp/profile/A2Q1GI13N0TVRC"],
+
["urlToGraphNode", "http://www.amazon.de/gp/pdp/profile/A2Q1GI13N0TVRC", "sgn://amazon.de/?pk=A2Q1GI13N0TVRC"],
["urlFromGraphNode", "sgn://amazon.com/?pk=A2Q1GI13N0TVRC", "rss", "http://www.amazon.com/rss/people/A2Q1GI13N0TVRC/reviews"],
["urlToGraphNode", "http://www.amazon.com/rss/people/A2Q1GI13N0TVRC/reviews", "sgn://amazon.com/?pk=A2Q1GI13N0TVRC"],
+ ["urlToGraphNode", "http://www.amazon.com", "http://www.amazon.com"],
+
["urlToGraphNode", "http://www.amazon.com/gp/pdp/profile/interesting/A2GS4P0VOJYU96", "http://www.amazon.com/gp/pdp/profile/interesting/A2GS4P0VOJYU96"],
+
["urlToGraphNode", "http://www.amazon.com/gp/history/", "http://www.amazon.com/gp/history/"],
["urlToGraphNode", "aim:goim?message=Hi!+I+found+you+on+Xxxx...&screenname=Foo%20Bar", "sgn://aol.com/?ident=foobar"],
["urlToGraphNode", "aim:GoIM?screenname=fooBar", "sgn://aol.com/?ident=foobar"],
["urlToGraphNode", "aim:goim?Screenname=foo+Bar", "sgn://aol.com/?ident=foobar"],
=======================================
--- /trunk/nodemapper-base.js Thu Feb 18 15:39:56 2010
+++ /trunk/nodemapper-base.js Mon Mar 22 09:49:40 2010
@@ -496,6 +496,7 @@
* must match the username.
* @param {Object} opt_opts Optional object with extra options:
* - casePreserve: if true, don't lowercase the ident/pk
+ * - upperCase: (overrides casePreserve), if true, upcase ident/pk
* - fallbackHandler: to run if no match (rather than returning URL
back)
* - keyName: type of identifier in the URL (default: "ident", or "pk")
* - slashAnything: if true, allow (and ignore) any /xyz/abc after the
match
@@ -517,6 +518,9 @@
}
var keyName = opt_opts.keyName || 'ident'; // ident= or pk=; TODO:
enforce valid key names?
var value = (opt_opts.casePreserve ? m[1] : m[1].toLowerCase());
+ if (opt_opts.upperCase) {
+ value = value.toUpperCase(); // overrides casePreserve if set
+ }
if (opt_opts.notUsernames && opt_opts.notUsernames[value]) {
// fail. this username is marked as not a real username.
return opt_opts.fallbackHandler ?
=======================================
--- /trunk/sites/amazon.js Wed Jun 25 14:52:44 2008
+++ /trunk/sites/amazon.js Mon Mar 22 09:49:40 2010
@@ -1,34 +1,84 @@
-// TODO(bradfitz): this isn't actually case-sensitive. jsmarr said it
was. :)
+// I. Amazon.com (US)
+
+// Search RegExp for Amazon PK is case-insensitive. However, the
normalized PK
+// is upper case. Thus the upperCase flag is passed into
createPathRegexpHandler.
+var AMAZON_PK_RE = new RegExp("^[A-Za-z0-9]{14}$");
+var AMAZON_PROFILE_PK_RE = new RegExp("gp/pdp/profile/([A-Za-z0-9]{14})");
+
var amazonPkHandler = nodemapper.createFirstMatchHandler([
- nodemapper.createSomethingSlashUsernameHandler(
- "gp/pdp/profile", "amazon.com",
- {keyName: "pk", casePreserve: 1}),
- nodemapper.createSomethingSlashUsernameHandler(
- "rss/people", "amazon.com",
- {keyName: "pk", casePreserve: 1})]);
+ nodemapper.createSomethingSlashUsernameHandler(
+ "gp/pdp/profile/friends", "amazon.com",
+ {keyName: "pk", upperCase: 1}),
+ nodemapper.createPathRegexpHandler(
+ "amazon.com", AMAZON_PROFILE_PK_RE,
+ {keyName: "pk", upperCase: 1}),
+ nodemapper.createSomethingSlashUsernameHandler(
+ "rss/people", "amazon.com",
+ {keyName: "pk", upperCase: 1})]);
nodemapper.registerDomain("amazon.com", {
- accountToSgn: { pk: ["amazon.com", /^\w{14,14}$/] },
- urlToGraphNode: amazonPkHandler,
- name: "Amazon.com"
-});
-
-nodemapper.registerDomain("amazon.co.uk", {
- urlToGraphNode: amazonPkHandler
-});
-
-nodemapper.addSimpleHandler("amazon.com", "pk_to_profile",
- "http://www.amazon.com/gp/pdp/profile/");
+ accountToSgn: { pk: ["amazon.com", AMAZON_PK_RE] },
+ urlToGraphNode: amazonPkHandler,
+ name: "Amazon.com"
+ }
+);
+
+nodemapper.addSimpleHandler("amazon.com", "pk_to_profile",
+ "http://www.amazon.com/gp/pdp/profile/");
+nodemapper.addSimpleHandler("amazon.com", "pk_to_friends",
+ "http://www.amazon.com/gp/pdp/profile/friends/");
nodemapper.addSimpleHandler("amazon.com", "pk_to_rss",
- "http://www.amazon.com/rss/people/", "/reviews");
+ "http://www.amazon.com/rss/people/", "/reviews");
+
+// II. Amazon international TLDs
+var AMAZON_I18N_DOMAINS = ["amazon.co.uk", "amazon.co.jp", "amazon.ca",
+ "amazon.fr", "amazon.de"];
+
+var pkToProfileHandler = function(domain) {
+ // function used to wrap domain variable scope
+ return function(pk) { return "http://www." + domain + "/gp/pdp/profile/"
+ pk; }
+};
+
+for (var i = 0; i < AMAZON_I18N_DOMAINS.length; i++) {
+ var domain = AMAZON_I18N_DOMAINS[i];
+ var urlToGraphNodeHandler = nodemapper.createPathRegexpHandler(
+ domain,
+ AMAZON_PROFILE_PK_RE,
+ {keyName: "pk", upperCase: 1}
+ );
+ nodemapper.registerDomain(domain, {
+ name: domain,
+ urlToGraphNode: urlToGraphNodeHandler,
+ accountToSgn: { pk: [domain, AMAZON_PK_RE] },
+ pk_to_profile: pkToProfileHandler(domain)
+ });
+}
__END__
http://www.amazon.com/gp/pdp/profile/A2Q1GI13N0TVRC
sgn://amazon.com/?pk=A2Q1GI13N0TVRC
+http://www.amazon.com/gp/pdp/profile/A2Q1GI13N0tvrc
sgn://amazon.com/?pk=A2Q1GI13N0TVRC
http://amazon.com/gp/pdp/profile/A2Q1GI13N0TVRC
sgn://amazon.com/?pk=A2Q1GI13N0TVRC
-http://www.amazon.co.uk/gp/pdp/profile/A2Q1GI13N0TVRC
sgn://amazon.com/?pk=A2Q1GI13N0TVRC
+http://amazon.com/gp/pdp/profile/friends/A2Q1GI13N0TVRC
sgn://amazon.com/?pk=A2Q1GI13N0TVRC
+
+http://www.amazon.co.uk/gp/pdp/profile/A2Q1GI13N0TVRC
sgn://amazon.co.uk/?pk=A2Q1GI13N0TVRC
+http://amazon.ca/gp/pdp/profile/A2Q1GI13N0TVRC
sgn://amazon.ca/?pk=A2Q1GI13N0TVRC
+http://amazon.fr/gp/pdp/profile/A2Q1GI13N0TVRC
sgn://amazon.fr/?pk=A2Q1GI13N0TVRC
+http://amazon.de/gp/pdp/profile/A2Q1GI13N0TVRC
sgn://amazon.de/?pk=A2Q1GI13N0TVRC
+http://amazon.co.jp/gp/pdp/profile/A2Q1GI13N0TVRC
sgn://amazon.co.jp/?pk=A2Q1GI13N0TVRC
http://www.amazon.com/rss/people/A2Q1GI13N0TVRC/reviews
sgn://amazon.com/?pk=A2Q1GI13N0TVRC
profile(sgn://amazon.com/?pk=A2Q1GI13N0TVRC)
http://www.amazon.com/gp/pdp/profile/A2Q1GI13N0TVRC
+
+profile(sgn://amazon.co.uk/?pk=A2Q1GI13N0TVRC)
http://www.amazon.co.uk/gp/pdp/profile/A2Q1GI13N0TVRC
+profile(sgn://amazon.co.jp/?pk=A2Q1GI13N0TVRC)
http://www.amazon.co.jp/gp/pdp/profile/A2Q1GI13N0TVRC
+profile(sgn://amazon.ca/?pk=A2Q1GI13N0TVRC)
http://www.amazon.ca/gp/pdp/profile/A2Q1GI13N0TVRC
+profile(sgn://amazon.fr/?pk=A2Q1GI13N0TVRC)
http://www.amazon.fr/gp/pdp/profile/A2Q1GI13N0TVRC
+profile(sgn://amazon.de/?pk=A2Q1GI13N0TVRC)
http://www.amazon.de/gp/pdp/profile/A2Q1GI13N0TVRC
+
rss(sgn://amazon.com/?pk=A2Q1GI13N0TVRC)
http://www.amazon.com/rss/people/A2Q1GI13N0TVRC/reviews
+
+http://www.amazon.com http://www.amazon.com
+http://www.amazon.com/gp/pdp/profile/interesting/A2GS4P0VOJYU96
http://www.amazon.com/gp/pdp/profile/interesting/A2GS4P0VOJYU96
+http://www.amazon.com/gp/history/ http://www.amazon.com/gp/history/