1.0.2 • Published 10 years ago
g-sheeter v1.0.2
g-sheeter
A middleware based upon google-spreadsheet for collecting (and eventually editing) google spreadsheet data.
Install
$ npm install --save g-sheeterSetup
- Follow the Service Account instructions here.
- Make sure to
require()your Google-provided service account information, otherwise refence this.
Examples
Get all tabs w/o authentication
//node modules and global configs
var gSheeter = require('./lib/constructor');
var sheet = gSheeter(
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
null
);
sheet.getData(
function(data){
//...thank you Google!
}
);Get all tabs w/ authentication
//node modules and global configs
var gSheeter = require('g-sheeter'),
googleService = require('[path to service file]');
var sheet = gSheeter(
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
googleService
);
...Get some tabs w/ authentication
...
// exclude the 'config' tab
var sheet = gSheeter(
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
googleService,
{
excludeTabs: ['config']
}
);
...Convert data array to an object
Make the slug label the key for each row
...
var options = {
rowsToObject: 'slug'
}
sheet.getData(
options,
function(data){
//...thank you Google!
}
);
...Make the slug + type labels + index the key for each row
...
var options = {
rowsToObject: function(row, index){
return row.slug + row.type + index;
}
}
...Tab1: Make the slug label the key for each row
Tab2: Make the slug label + index the key for each row
...
// Tab1 and Tab2 below correspond to tabs on the Google spreadsheet.
var options = {
rowsToObject: {
Tab1: 'slug'
Tab2: function(row, index){
return row.slug + index;
}
}
}
...Note: When using the tab-specific method, be sure to specify every tab in the options. Otherwise, not all the data will be returned int he callback.
API
gSheeter
Main g-sheeter class.
new gSheeter(key, auth, options)
key-string- required Google Sheet unique identifier Ex: docs.google.com/spreadsheets/d/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxauth-objectornull- reqired Google Service Account credentials See setup instructionsoptions-object- optional *excludeTabs-arrayof tabs in the Google Sheet to ignorereturnsgoogle sheet object
sheet.getData(options, callback)
options- objectrowsToObject-stringORfunctionORobject- Determine how the returning array in the callback shoud be converted into an object instead of the default array whenstring- builds whole row key from matching row item label whenfunction- builds whole row key from custom function - see example whenobject- each key of this object must bestringorfunction, and the keys supplied should match ALL Google Sheet tab names