Naughty Praying Mantis

    g-sheeter

    1.0.2 • Public • Published

    g-sheeter

    A middleware based upon google-spreadsheet for collecting (and eventually editing) google spreadsheet data.

    Install

    $ npm install --save g-sheeter
    

    Setup

    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 or null - reqired
    • options - object - optional
      • excludeTabs - array of tabs in the Google Sheet to ignore
    • returns google sheet object

    sheet.getData(options, callback)

    • options - object
      • rowsToObject - string OR function OR object - 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 be string or function, and the keys supplied should match ALL Google Sheet tab names

    Keywords

    none

    Install

    npm i g-sheeter

    DownloadsWeekly Downloads

    9

    Version

    1.0.2

    License

    MIT

    Last publish

    Collaborators

    • kmiddlesworth