[backend/gdocs][s]: minor improvement to support handling spreadsheet urls where #gid=xxx is missing.
This commit is contained in:
@@ -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'
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user