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 configsvar gSheeter = ; var sheet = ; sheet;
Get all tabs w/ authentication
//node modules and global configsvar gSheeter = googleService = ; var sheet = ; ...
Get some tabs w/ authentication
... // exclude the 'config' tab var sheet = ; ...
Convert data array to an object
Make the slug
label the key for each row
... var options = rowsToObject: 'slug' sheet; ...
Make the slug
+ type
labels + index
the key for each row
... var options = { return rowslug + rowtype + 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' { return rowslug + 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