mini-sheets
v2.0.3
Published
Minified and simplified Google Sheets
Downloads
5
Maintainers
Readme
Mini Sheets
Minified and simplified Google Sheets with Promises
Example Usage
const {Drive, Spreadsheets} = require('minisheets');
const minisheets = new Spreadsheets(CLIENT_ID, TOKEN);
minisheets.createSpreadsheet(spreadsheetTitle, {sheet1: [[1]]})
.then(worksheet=>console.log(worksheet))
.catch(err=>console.log(err));
Table of Contents
gAPI
constructor(clientId, token)
Initialize gAPI (parent class of Drive & Spreadsheets)
Arguments:
clientId
<String|Object>: string of client id- Can be an <Object> containing a client_id and client_secret
token
<Object>: authentication token object
Spreadsheets
const {Spreadsheets} = require('minisheets');
let worksheets = new Spreadsheets(clientId, token);
Worksheet Object
Object returned from using Spreadsheets methods
{
id: spreadsheetId,
title: spreadsheetTitle,
sheets: {
Sheet1: [[String, Number],
[...]],
Sheet2: ...,
...
},
metadata: {
Sheet1: {
key1: String,
key2: Number,
...
},
...
}
}
Grid Data Format
{
sheetTitle: [[String, Number],
[..., ...]],
...
}
Metadata Format
{
sheetTitle: {
key: value,
...
},
...
}
createSpreadsheet(title, gridData, metadata)
Creates a new Google Sheets spreadsheet
Arguments:
title
<String>: ID of Google Sheets spreadsheetgridData
<Grid Data Format>: Object of sheetsmetadata
<Metadata Format>: Object of metadata
Returns Promise:
Usage:
worksheets.createSpreadsheet(newTitle, {sheet1: [['Hello', 'World', 1]]}, {sheet1: {key1: 'Hello World'}}).then(console.log);
/*{
title: newTitle,
id: generatedId,
sheets: {
sheet1: [['Hello', 'World', 1]]
},
metadata: {
sheet1: {
key1: 'Hello World'
}
}
}*/
getSpreadsheet(spreadsheetId, _options)
Gets the data of a Google Sheets spreadsheet
Arguments:
spreadsheetId
<String>: ID of Google Sheets spreadsheet- (OPTIONAL) <Object>: options Object
include
<String|Array>: only include sheets with specified titles
Returns Promise:
Usage:
worksheets.getSpreadsheet(spreadsheetId, {include: ['sheet1']}).then(console.log);
/*{
title: spreadsheetTitle,
id: spreadsheetId,
sheets: {
sheet1: [['Hello', 'World', 1]]
},
metadata: {
sheet1: {
key1: 'Hello World'
}
}
}*/
setSpreadsheet(spreadsheetId, gridData, metadata)
Changes a Google Sheets spreadsheet
Arguments:
spreadsheetId
<String>: ID of Google Sheets spreadsheetgridData
<Grid Data Format>: Object of sheetsmetadata
<Metadata Format>: Object of metadata
Returns Promise:
Usage:
worksheets.setSpreadsheet(spreadsheetId, {sheet1: [['Hello', 'World', 2]]}, {sheet1: {key1: 'Hello There'}}).then(console.log);
/*{
title: spreadsheetTitle,
id: spreadsheetId,
sheets: {
sheet1: [['Hello', 'World', 2]]
},
metadata: {
sheet1: {
key1: 'Hello There'
}
}
}*/
Drive
const {Drive} = require('minisheets');
let files = new Drive(clientId, token);
getFile(fileId)
Fetches the properties of a file within Google Drive
Arguments:
fileId
<String>: ID of file
Returns Promise:
- <Object>: metadata
null
if file does not exist
Usage:
files.getFile(fileId).then(console.log);
/*{
"kind": "drive#file",
"id": String,
"name": String,
"mimeType": String
}*/
setFile(fileId, properties)
Alters properties of a file within Google Drive
Arguments:
fileId
<String>: ID of file
Returns Promise:
- <Object>: metadata
null
if file does not exist
Usage:
files.deleteFile(fileId).then(console.log); // true
deleteFile(fileId)
Deletes a file within Google Drive
Arguments:
fileId
<String>: ID of file
Returns Promise:
- <Boolean>:
false
if the file does not exist
Usage:
files.setFile(fileId, {name: newName}).then(console.log);
/*{
"kind": "drive#file",
"id": String,
"name": String,
"mimeType": String,
...
}*/