google-api-wrapper
Advanced tools
Comparing version
@@ -10,3 +10,4 @@ const { google } = require('googleapis'); | ||
*/ | ||
init: function(auth) { | ||
init: function(manager, auth) { | ||
this.manager = manager; | ||
this.drive = google.drive({ version: 'v3', auth }); | ||
@@ -13,0 +14,0 @@ }, |
@@ -62,3 +62,3 @@ const fs = require('fs'); | ||
const auth = this.getAuth(); | ||
Sheet.init(auth); | ||
Sheet.init(this, auth); | ||
this.sheet = Sheet; | ||
@@ -78,3 +78,3 @@ } | ||
const auth = this.getAuth(); | ||
Drive.init(auth); | ||
Drive.init(this, auth); | ||
this.drive = Drive; | ||
@@ -81,0 +81,0 @@ } |
@@ -15,3 +15,4 @@ const { google } = require('googleapis'); | ||
*/ | ||
init: function(auth) { | ||
init: function(manager, auth) { | ||
this.manager = manager; | ||
this.auth = auth; | ||
@@ -45,5 +46,4 @@ this.sheets = google.sheets({ version: 'v4', auth}); | ||
if(folderId) { | ||
const Drive = require('./Drive'); | ||
Drive.init(this.auth); | ||
await Drive.move(this.id, folderId); | ||
const drive = this.manager.getDrive(); | ||
await drive.move(this.id, folderId); | ||
} | ||
@@ -58,3 +58,3 @@ return this.id; | ||
*/ | ||
read: async function(id, range) { | ||
read: async function(id, range, options) { | ||
this.set(id, range); | ||
@@ -70,6 +70,33 @@ let sheets = this.sheets; | ||
readDocs: async function(id, range, options = {}) { | ||
/** | ||
* read from a spreadsheet. | ||
* similar to read(), but uses name to retrieve file from Drive. | ||
*/ | ||
readByName: async function(name, range) { | ||
const drive = this.manager.getDrive(); | ||
const file = await drive.byName(name); | ||
if(!file || !file.id) { | ||
throw new Error('sheet not found: ' + name); | ||
} | ||
return await this.read(file.id, range); | ||
}, | ||
readDocs: async function(id_or_name, range, options = {}) { | ||
const _ = require('lodash'); | ||
let rows = await this.read(id, range); | ||
let row; | ||
if(options.byName) { | ||
rows = await this.readByName(id_or_name, range); | ||
} | ||
else { | ||
rows = await this.read(id_or_name, range); | ||
} | ||
let header_row = rows.shift(); | ||
if(options.slugify) { | ||
if(options.slugify === 'kebab') { | ||
header_row = header_row.map(_.kebabCase); | ||
} | ||
else { | ||
header_row = header_row.map(_.snakeCase); | ||
} | ||
} | ||
let docs = []; | ||
@@ -76,0 +103,0 @@ for(let row of rows) { |
{ | ||
"name": "google-api-wrapper", | ||
"version": "1.4.1", | ||
"version": "1.5.0", | ||
"description": "Google API Wrapper", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
18593
5.02%426
6.77%