[backend/gdocs][s]: minor improvement to support handling spreadsheet urls where #gid=xxx is missing.

This commit is contained in:
Rufus Pollock
2012-10-20 01:40:37 +01:00
parent d5b648cc89
commit 97dcf08780
2 changed files with 9 additions and 2 deletions

View File

@@ -130,7 +130,7 @@ this.recline.Backend.GDocs = this.recline.Backend.GDocs || {};
// Convenience function to get GDocs JSON API Url from standard URL // Convenience function to get GDocs JSON API Url from standard URL
my.getGDocsAPIUrls = function(url) { my.getGDocsAPIUrls = function(url) {
// https://docs.google.com/spreadsheet/ccc?key=XXXX#gid=YYY // https://docs.google.com/spreadsheet/ccc?key=XXXX#gid=YYY
var regex = /.*spreadsheet\/ccc?.*key=([^#?&+]+).*gid=([\d]+).*/; var regex = /.*spreadsheet\/ccc?.*key=([^#?&+]+)[^#]*(#gid=([\d]+).*)?/;
var matches = url.match(regex); var matches = url.match(regex);
var key; var key;
var worksheet; var worksheet;
@@ -139,7 +139,10 @@ this.recline.Backend.GDocs = this.recline.Backend.GDocs || {};
if(!!matches) { if(!!matches) {
key = matches[1]; key = matches[1];
// the gid in url is 0-based and feed url is 1-based // the gid in url is 0-based and feed url is 1-based
worksheet = parseInt(matches[2]) + 1; worksheet = parseInt(matches[3]) + 1;
if (isNaN(worksheet)) {
worksheet = 1;
}
urls = { urls = {
worksheet : 'https://spreadsheets.google.com/feeds/list/'+ key +'/'+ worksheet +'/public/values?alt=json', worksheet : 'https://spreadsheets.google.com/feeds/list/'+ key +'/'+ worksheet +'/public/values?alt=json',
spreadsheet: 'https://spreadsheets.google.com/feeds/worksheets/'+ key +'/public/basic?alt=json' spreadsheet: 'https://spreadsheets.google.com/feeds/worksheets/'+ key +'/public/basic?alt=json'

View File

@@ -310,6 +310,10 @@ test("GDocs Backend.getUrl", function() {
var exp2 = 'https://spreadsheets.google.com/feeds/worksheets/' + key + '/public/basic?alt=json' var exp2 = 'https://spreadsheets.google.com/feeds/worksheets/' + key + '/public/basic?alt=json'
equal(exp1, out.worksheet); equal(exp1, out.worksheet);
equal(exp2, out.spreadsheet); equal(exp2, out.spreadsheet);
var url = 'https://docs.google.com/spreadsheet/ccc?key=' + key;
var out = recline.Backend.GDocs.getGDocsAPIUrls(url);
equal(out.worksheet, exp1);
}); });
})(this.jQuery); })(this.jQuery);