sheet_zoukas 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -3
- data/README.md +16 -6
- data/lib/sheet_zoukas/data_converter.rb +3 -1
- data/lib/sheet_zoukas/google_sheets.rb +8 -1
- data/lib/sheet_zoukas/utils.rb +17 -0
- data/lib/sheet_zoukas/version.rb +1 -1
- data/lib/sheet_zoukas.rb +9 -0
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0057764f973d861a12f04accb01afc6f91fc171fb07328150ca71713505c636a
|
4
|
+
data.tar.gz: 3febdb00ec05067411785995216b6b1ad040b843846ddc7e0c75533848b97f6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa413e397f10552953258d66590dac927dd60364a534818c33f783254034202a6fc2ee8ede64ae962642deac6df5be9ae6b097907a9c7b72d75a01c167cc592a
|
7
|
+
data.tar.gz: 1f071f85f0dd4625f2c9aabe05e706b2b5185761c4d012531b7b06dc300bec1409c588c2c15ee205511963d82dcbc921c98920e75b5ca20c12ee63de84357e3c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
|
-
## [Unreleased]
|
2
|
-
|
3
1
|
## [0.1.0] - 2024-10-13
|
4
2
|
|
5
|
-
- Initial release
|
3
|
+
- Initial release v0.1.0
|
4
|
+
|
5
|
+
## [0.2.0] - 2024-10-15
|
6
|
+
|
7
|
+
- Added check for required environment variables before call to Google Sheets API
|
8
|
+
|
9
|
+
## [0.3.0] - 2024-10-16
|
10
|
+
|
11
|
+
- Convert Google Sheet contents to JSON, not just to Ruby hash
|
data/README.md
CHANGED
@@ -2,11 +2,16 @@
|
|
2
2
|
|
3
3
|
Expose Google Sheets as JSON data
|
4
4
|
|
5
|
+
[](https://badge.fury.io/rb/sheet_zoukas)
|
6
|
+
|
5
7
|

|
6
8
|
|
7
9
|
[](https://github.com/rubocop/rubocop)
|
8
10
|
|
9
|
-
Created to allow Google Sheets to be used as read-only
|
11
|
+
Created to allow Google Sheets to be used as read-only datastores. Associates each row's values with the corresponding header ("column") name.
|
12
|
+
|
13
|
+
## Why is it called `SheetZoukas`?
|
14
|
+
The name is a questionable portmanteau of [Jason Mantzoukas](https://en.wikipedia.org/wiki/Jason_Mantzoukas) and Google Sheets. Because JSON.
|
10
15
|
|
11
16
|
## Installation
|
12
17
|
|
@@ -24,7 +29,8 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
24
29
|
|
25
30
|
This gem assumes the existence of a [Google service account](https://developers.google.com/identity/protocols/oauth2/service-account) with [the Google Sheets API](https://console.cloud.google.com/apis/library/sheets.googleapis.com) enabled. Several environment variables are required for this gem to work.
|
26
31
|
|
27
|
-
#### Google auth
|
32
|
+
#### Required Google auth variables
|
33
|
+
`SheetZoukas::REQUIRED_VARS`
|
28
34
|
|
29
35
|
* GOOGLE_ACCOUNT_TYPE
|
30
36
|
* GOOGLE_API_KEY
|
@@ -34,10 +40,11 @@ This gem assumes the existence of a [Google service account](https://developers.
|
|
34
40
|
|
35
41
|
|
36
42
|
### Notes
|
37
|
-
*
|
38
|
-
* All data
|
43
|
+
* Sheets are accessed with the https://www.googleapis.com/auth/spreadsheets.readonly scope
|
44
|
+
* All data exposed as strings. You can convert data to other types as you ingest this gem's output.
|
45
|
+
* All data is exposed as the value you see when viewing the sheet
|
39
46
|
* This impacts dates. For example, if your spreadsheet does not display the year as part of a date, this gem will not include a year in it's output for those cells.
|
40
|
-
* No `nil` values, just empty
|
47
|
+
* No `nil` values, just empty strings. You can convert empty strings to `nil` as you ingest this gem's output.
|
41
48
|
* Row values outside of header range will not be captured. You must have a non-blank header for the row data to be included in this gem's output.
|
42
49
|
* Performance: this gem has not been tested with large Google Sheets. If you encounter performance issues consider passing in cell ranges to iteratively get your dataset ala pagination.
|
43
50
|
|
@@ -55,13 +62,15 @@ GitHub Action runs
|
|
55
62
|
|
56
63
|
### testing
|
57
64
|
|
58
|
-
|
65
|
+
$ rake spec
|
59
66
|
|
60
67
|
## Release
|
61
68
|
Build
|
69
|
+
|
62
70
|
$ rake build
|
63
71
|
|
64
72
|
Test
|
73
|
+
|
65
74
|
$ gem install pkg/sheet_zoukas-<VERSION>.gem
|
66
75
|
$ irb
|
67
76
|
|
@@ -69,6 +78,7 @@ Test
|
|
69
78
|
irb(main):002> SheetZoukas.retrieve_sheet_json('<GOOGLE_SPREADSHEET_ID>', '<TAB_NAME>')
|
70
79
|
|
71
80
|
Release
|
81
|
+
|
72
82
|
$ rake release
|
73
83
|
|
74
84
|
## Contributing
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'json'
|
4
|
+
|
3
5
|
module SheetZoukas
|
4
6
|
# convert spreadsheet data to JSON
|
5
7
|
class DataConverter
|
@@ -13,7 +15,7 @@ module SheetZoukas
|
|
13
15
|
|
14
16
|
@rows.map do |row|
|
15
17
|
@headers.zip(row).to_h
|
16
|
-
end
|
18
|
+
end.to_json
|
17
19
|
end
|
18
20
|
|
19
21
|
private
|
@@ -9,7 +9,7 @@ module SheetZoukas
|
|
9
9
|
DEFAULT_SCOPE = 'https://www.googleapis.com/auth/spreadsheets.readonly'
|
10
10
|
|
11
11
|
def initialize(scope = DEFAULT_SCOPE)
|
12
|
-
|
12
|
+
init_authorizer(scope)
|
13
13
|
end
|
14
14
|
|
15
15
|
def retrieve_sheet(sheet_id, tab_name, range = nil)
|
@@ -25,5 +25,12 @@ module SheetZoukas
|
|
25
25
|
|
26
26
|
"#{tab_name}!#{range}"
|
27
27
|
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
# overriden in spec_helper so we don't try to authenticate with Google for tests
|
32
|
+
def init_authorizer(scope)
|
33
|
+
@authorizer = Google::Auth::ServiceAccountCredentials.from_env(scope: scope)
|
34
|
+
end
|
28
35
|
end
|
29
36
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SheetZoukas
|
4
|
+
# Utility methods
|
5
|
+
class Utils
|
6
|
+
def self.vars_present?(required_vars, message)
|
7
|
+
all_present = true
|
8
|
+
required_vars.each do |var|
|
9
|
+
if ENV.fetch(var, '').strip.empty?
|
10
|
+
all_present = false
|
11
|
+
puts "⛔️ #{var} #{message}."
|
12
|
+
end
|
13
|
+
end
|
14
|
+
all_present
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/sheet_zoukas/version.rb
CHANGED
data/lib/sheet_zoukas.rb
CHANGED
@@ -3,16 +3,25 @@
|
|
3
3
|
require_relative 'sheet_zoukas/data_converter'
|
4
4
|
require_relative 'sheet_zoukas/google_sheets'
|
5
5
|
require_relative 'sheet_zoukas/version'
|
6
|
+
require_relative 'sheet_zoukas/utils'
|
6
7
|
|
7
8
|
# Retrieve Google Sheets data
|
8
9
|
module SheetZoukas
|
9
10
|
class Error < StandardError; end
|
11
|
+
REQUIRED_VARS = %w[GOOGLE_ACCOUNT_TYPE GOOGLE_API_KEY GOOGLE_CLIENT_EMAIL GOOGLE_CLIENT_ID GOOGLE_PRIVATE_KEY].freeze
|
10
12
|
|
11
13
|
class << self
|
12
14
|
def retrieve_sheet_json(sheet_id, tab_name, range = nil)
|
15
|
+
SheetZoukas.exit_program unless SheetZoukas::Utils.vars_present?(REQUIRED_VARS,
|
16
|
+
'required for Google Sheets API calls')
|
17
|
+
|
13
18
|
sheet = GoogleSheets.new
|
14
19
|
data = sheet.retrieve_sheet(sheet_id, tab_name, range)
|
15
20
|
DataConverter.new(data.values).convert
|
16
21
|
end
|
22
|
+
|
23
|
+
def exit_program
|
24
|
+
raise StandardError, 'Error encountered'
|
25
|
+
end
|
17
26
|
end
|
18
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sheet_zoukas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- eebbesen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-apis-sheets_v4
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- lib/sheet_zoukas.rb
|
42
42
|
- lib/sheet_zoukas/data_converter.rb
|
43
43
|
- lib/sheet_zoukas/google_sheets.rb
|
44
|
+
- lib/sheet_zoukas/utils.rb
|
44
45
|
- lib/sheet_zoukas/version.rb
|
45
46
|
- sig/sheet_zoukas.rbs
|
46
47
|
homepage: https://github.com/eebbesen/sheet_zoukas
|
@@ -48,9 +49,9 @@ licenses:
|
|
48
49
|
- MIT
|
49
50
|
metadata:
|
50
51
|
homepage_uri: https://github.com/eebbesen/sheet_zoukas
|
51
|
-
changelog_uri: https://github.com/eebbesen/sheet_zoukas/releases/tag/v0.
|
52
|
+
changelog_uri: https://github.com/eebbesen/sheet_zoukas/releases/tag/v0.3.0
|
52
53
|
source_code_uri: https://github.com/eebbesen/sheet_zoukas
|
53
|
-
documentation_uri: https://github.com/eebbesen/sheet_zoukas/0.
|
54
|
+
documentation_uri: https://github.com/eebbesen/sheet_zoukas/0.3.0/
|
54
55
|
bug_tracker_uri: https://github.com/eebbesen/sheet_zoukas/issues
|
55
56
|
rubygems_mfa_required: 'true'
|
56
57
|
post_install_message:
|