g-sheeter
v1.0.2
Published
Google Sheets update and read tool
Downloads
0
Readme
g-sheeter
A middleware based upon google-spreadsheet for collecting (and eventually editing) google spreadsheet data.
Install
$ npm install --save g-sheeter
Setup
- 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/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
auth
-object
ornull
- reqired- Google Service Account credentials
- See setup instructions
options
-object
- optionalexcludeTabs
-array
of tabs in the Google Sheet to ignore
returns
google sheet object
sheet.getData(options, callback)
options
- objectrowsToObject
-string
ORfunction
ORobject
- Determine how the returning array in the callback shoud be converted into an object instead of the default array- when
string
- builds whole row key from matching row item label - when
function
- builds whole row key from custom function - see example - when
object
- each key of this object must bestring
orfunction
, and the keys supplied should match ALL Google Sheet tab names
- when