Skip to content

Commit fe165b1

Browse files
authored
Film spreadsheet integration (#5)
* Add end-to-end test for an actual spreadsheet * Rewrite of helper.js to use new google-spreadsheet module API * Implement correct search behaviour for mapping data * Fix test to work on CI environment * Remove work in progress console.log * Update README and CHANGELOG * Add note about fixed security vulnerabilities * Add test-example.js to check equivalent code in README
1 parent e61a6b1 commit fe165b1

File tree

8 files changed

+205
-121
lines changed

8 files changed

+205
-121
lines changed

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# 2.0.0 ????
2+
## New
3+
- Tests and CI using Github Actions to repo
4+
5+
## Changes
6+
- Fixed security vulnerabilities reported by `npm audit`
7+
- Updated google-spreadsheet depenedncy
8+
- Removed support for public published sheets due to deprecated authentication options
9+
- Examples now use async await
10+
- Changed internal workings to use 0 based indexes for rows and columns
11+
- Changed internal workings to use cleaner async await code
12+
- Introduced standard js as the enforced linter as part of the CI actions
13+
114
# 1.0.0
215
## New
316
- Service Account auth support

README.md

+39-35
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,14 @@
11
google-spreadsheet-to-json
22
==========================
33

4-
** warning : this is a deliberate fork of the original bassarisse/google-spreadsheet-to-json project **
4+
** 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. **
55

6-
New goals as follows:
7-
- ✅ Use github actions and PR flow to manage change
8-
- ❎ Focus on new v4 google API using theoephraim/node-google-spreadsheet at v3.1.15 with enforced authentication
9-
- ❎ Add a CI test for end-to-end authentication flow using github secrets
10-
- ❎ Update README
11-
- ❎ Use async await pattern instead of promises in examples
12-
13-
Please raise an issue / suggestions on this repo if you see space for improvements.
6+
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.
147

158
## Description
169

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

19-
2012
## Installation
2113

2214
Command-line:
@@ -29,7 +21,6 @@ Node API:
2921
$ npm install --save google-spreadsheet-to-json
3022
```
3123

32-
3324
## Help
3425

3526
```
@@ -77,34 +68,40 @@ You can also redirect the output if you omit the filename:
7768
$ gsjson abc123456789 >> data.json
7869
```
7970

80-
8171
## Usage (Node API)
8272

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

8575
```javascript
86-
var gsjson = require('google-spreadsheet-to-json');
87-
88-
gsjson({
89-
spreadsheetId: 'abc123456789',
90-
// other options...
91-
})
92-
.then(function(result) {
93-
console.log(result.length);
94-
console.log(result);
95-
})
96-
.catch(function(err) {
97-
console.log(err.message);
98-
console.log(err.stack);
99-
});
76+
const gsjson = require('google-spreadsheet-to-json');
77+
78+
const credentials = {
79+
client_email: process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL,
80+
private_key: process.env.GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY
81+
}
82+
83+
async function example () {
84+
try {
85+
const result = await gsjson({
86+
spreadsheetId: 'abc123456789',
87+
credentials
88+
// other options...
89+
})
90+
console.log(result.length)
91+
console.log(result)
92+
} catch (ex) {
93+
console.log(ex.message)
94+
console.log(ex.stack)
95+
}
96+
}
97+
98+
example()
10099
```
101100

102-
103101
### Notes
104102

105-
- A spreadsheet ID can be extracted from its URL.
106-
- 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).
107-
103+
- 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`
104+
- 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.
108105

109106
## About authentication
110107

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

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

122-
123119
## Known issues
124120

125-
- 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.
121+
- 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.
126122

123+
## Examples
127124

128-
## Examples & change log
125+
See [EXAMPLES.md](./EXAMPLES.md)
129126

130-
See specific files.
127+
## Change Log
131128

129+
See [CHANGELOG.md](./CHANGELOG.md)
132130

133131
## TO-DO
134132

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

138-
139136
## License
140137
google-spreadsheet-to-json is free and unencumbered public domain software. For more information, see the accompanying UNLICENSE file.
138+
139+
140+
## Contributors
141+
142+
- @bassarisse Bruno Assarisse
143+
- @cigolpl Mateusz
144+
- @johnbeech John Beech (Connected Web)

example.js

+22-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1-
const gsjson = require('./index')
1+
const gsjson = require('./')
22

3-
gsjson({
4-
spreadsheetId: 'spreadsheetId',
5-
token: 'token'
6-
})
7-
.then(function (res) {
8-
console.log(res)
9-
console.log(res.length)
10-
})
11-
.catch(function (err) {
12-
console.log(err.stack)
13-
})
3+
const credentials = {
4+
client_email: process.env.GOOGLE_SERVICE_ACCOUNT_EMAIL,
5+
private_key: process.env.GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY
6+
}
7+
8+
async function example () {
9+
try {
10+
const result = await gsjson({
11+
spreadsheetId: 'abc123456789',
12+
credentials
13+
// other options...
14+
})
15+
console.log(result.length)
16+
console.log(result)
17+
} catch (ex) {
18+
console.log(ex.message)
19+
console.log(ex.stack)
20+
}
21+
}
22+
23+
example()

0 commit comments

Comments
 (0)