Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Film spreadsheet integration #5

Merged
merged 9 commits into from
Feb 20, 2021
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# 2.0.0 ????
## New
- Tests and CI using Github Actions to repo

## Changes
- Fixed security vulnerabilities reported by `npm audit`
- Updated google-spreadsheet depenedncy
- Removed support for public published sheets due to deprecated authentication options
- Examples now use async await
- Changed internal workings to use 0 based indexes for rows and columns
- Changed internal workings to use cleaner async await code
- Introduced standard js as the enforced linter as part of the CI actions

# 1.0.0
## New
- Service Account auth support
Expand Down
74 changes: 39 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
google-spreadsheet-to-json
==========================

** warning : this is a deliberate fork of the original bassarisse/google-spreadsheet-to-json project **
** 2020-02-20 : This fork of `bassarisse/google-spreadsheet-to-json` project adds more tests; implements against the Google v4 API using the latest version of `theoephraim/node-google-spreadsheet` and Service Account credentials. **

New goals as follows:
- ✅ Use github actions and PR flow to manage change
- ❎ Focus on new v4 google API using theoephraim/node-google-spreadsheet at v3.1.15 with enforced authentication
- ❎ Add a CI test for end-to-end authentication flow using github secrets
- ❎ Update README
- ❎ Use async await pattern instead of promises in examples

Please raise an issue / suggestions on this repo if you see space for improvements.
Please raise an issue or suggestions on the original repo and tag me @johnbeech you see space for improvements - like missing tests or broken functionality.

## Description

A simple tool to export Google Spreadsheets to JSON files. Can be used though Node API or CLI.


## Installation

Command-line:
Expand All @@ -29,7 +21,6 @@ Node API:
$ npm install --save google-spreadsheet-to-json
```


## Help

```
Expand Down Expand Up @@ -77,34 +68,40 @@ You can also redirect the output if you omit the filename:
$ gsjson abc123456789 >> data.json
```


## Usage (Node API)

With the exception of `beautify` and the file path, the same options from the CLI applies here (options like `include-header` becomes `includeHeader`).

```javascript
var gsjson = require('google-spreadsheet-to-json');

gsjson({
spreadsheetId: 'abc123456789',
// other options...
})
.then(function(result) {
console.log(result.length);
console.log(result);
})
.catch(function(err) {
console.log(err.message);
console.log(err.stack);
});
const gsjson = require('google-spreadsheet-to-json');

const credentials = {
client_email: process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL,
private_key: process.env.GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY
}

async function example () {
try {
const result = await gsjson({
spreadsheetId: 'abc123456789',
credentials
// other options...
})
console.log(result.length)
console.log(result)
} catch (ex) {
console.log(ex.message)
console.log(ex.stack)
}
}

example()
```


### Notes

- A spreadsheet ID can be extracted from its URL.
- If an array is passed on the `worksheet` option (in CLI, this can be done by repeating the argument) or the `allWorksheets` option is used, the output from each worksheet is returned inside an array (the order is not guaranteed).

- A spreadsheet ID can be extracted from its URL - for example `https://docs.google.com/spreadsheets/d/1G2_YLuQeKXCtpOWshqIBazzUeefuOMDZ5q10F2u9MHw/edit#gid=0` becomes `1G2_YLuQeKXCtpOWshqIBazzUeefuOMDZ5q10F2u9MHw`
- If an array is passed on the `worksheet` option (in CLI, this can be done by repeating the argument) or the `allWorksheets` option is used, the output from each worksheet is returned inside an array; however the order is not guaranteed.

## About authentication

Expand All @@ -119,22 +116,29 @@ For quick tests, there's a method to acquire a temporary token:

For more detailed information regarding auth methods: https://github.com/theoephraim/node-google-spreadsheet


## Known issues

- Public spreadsheets can only be used without authentication if the option "File > Publish to the web" is used in the Google Spreadsheets GUI, even if the spreadsheet is visible to everyone. This problem won't occur when authenticated.
- Public spreadsheets are not currently supported - although there is a way to access raw JSON from a spreadsheet which could be supported in future: `https://spreadsheets.google.com/feeds/cells/1G2_YLuQeKXCtpOWshqIBazzUeefuOMDZ5q10F2u9MHw/1/public/full?alt=json` - this works if the option "File > Publish to the web" is used in the Google Spreadsheets GUI, even if the spreadsheet is visible to everyone. This problem won't occur when authenticated.

## Examples

## Examples & change log
See [EXAMPLES.md](./EXAMPLES.md)

See specific files.
## Change Log

See [CHANGELOG.md](./CHANGELOG.md)

## TO-DO

- Improve options documentation (especially header size)
- Create more test cases


## License
google-spreadsheet-to-json is free and unencumbered public domain software. For more information, see the accompanying UNLICENSE file.


## Contributors

- @bassarisse Bruno Assarisse
- @cigolpl Mateusz
- @johnbeech John Beech (Connected Web)
34 changes: 22 additions & 12 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
const gsjson = require('./index')
const gsjson = require('./')

gsjson({
spreadsheetId: 'spreadsheetId',
token: 'token'
})
.then(function (res) {
console.log(res)
console.log(res.length)
})
.catch(function (err) {
console.log(err.stack)
})
const credentials = {
client_email: process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL,
private_key: process.env.GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY
}

async function example () {
try {
const result = await gsjson({
spreadsheetId: 'abc123456789',
credentials
// other options...
})
console.log(result.length)
console.log(result)
} catch (ex) {
console.log(ex.message)
console.log(ex.stack)
}
}

example()
Loading