sheet_zoukas 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4bd39b81cba9d9a4da4202e20062bf10ee50b12570ae929bf0ab33f3773d9614
4
- data.tar.gz: d3579fdec88d34bbd76a504a0740c8ca15710bcfe92b026783ff6b80dedf358a
3
+ metadata.gz: 663a950de628221d592c40858718e1b92319135cd8f551cb4bd7973b505faf2c
4
+ data.tar.gz: 91fa4dc394f038fe894c5d7c9bf7ee6ab5d99887e7d3dfc52955cf675db0dcc4
5
5
  SHA512:
6
- metadata.gz: ea44d0116850abefdfadf3bd353f09ca0d7155c16137e31410c13e3f24f4772c9f773b42270aa8e8fcdb738c2a4d1dc39d67ad132f3510a34d944d2f15f2bbf7
7
- data.tar.gz: 530d626076a0fdd2db2759195d49d14300fa807db5e87de0e0b11d9c01b98276a1d1cde06175370d0399ddae0b87533ba3fac40cdc58e39dda26a739d358669d
6
+ metadata.gz: 752a3996cecaebb55dca1628cf8fbf6049573093e4891c89af4e26a7cb40824342f35571602237ddc20369c7e00bfd602395efa38aa6c3f3a5fa63339c4fdb22
7
+ data.tar.gz: 3f4304f53f08dd6498ba8e18cff7b62a61562a777008925f6e15e9011c46405ebe178c288f0be40a48fa40e13ace91fabb3ce3e3e05ea3eabef919be4539af70
data/CHANGELOG.md CHANGED
@@ -1,5 +1,7 @@
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] - UNRELEASED
6
+
7
+ - Added check for required environment variables before call to Google Sheets API
data/README.md CHANGED
@@ -2,11 +2,16 @@
2
2
 
3
3
  Expose Google Sheets as JSON data
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/sheet_zoukas.svg)](https://badge.fury.io/rb/sheet_zoukas)
6
+
5
7
  ![Tests](https://github.com/eebbesen/sheet_zoukas/actions/workflows/ruby.yml/badge.svg)
6
8
 
7
9
  [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
8
10
 
9
- Created to allow Google Sheets to be used as read-only databases. Associates each row's values with the corresponding header ("row") name.
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 values
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
- * All data exposed as Strings. You can convert data to other types as you ingest this gem's output.
38
- * All data is exposed as the display value
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 Strings. You can convert empty strings to `nil` as you ingest this gem's output.
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
- RSpec tests require the environment variables listed in spec_helper.rb's `REQUIRED_VARS` constant. Out of the box your tests that call Google (mocked with VCR) will fail because you do (should) not have access to my test account credentials.
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
@@ -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
- @authorizer = Google::Auth::ServiceAccountCredentials.from_env(scope: scope)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SheetZoukas
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
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.1.0
4
+ version: 0.2.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-13 00:00:00.000000000 Z
11
+ date: 2024-10-15 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.1.0
52
+ changelog_uri: https://github.com/eebbesen/sheet_zoukas/releases/tag/v0.2.0
52
53
  source_code_uri: https://github.com/eebbesen/sheet_zoukas
53
- documentation_uri: https://github.com/eebbesen/sheet_zoukas/0.1.0/
54
+ documentation_uri: https://github.com/eebbesen/sheet_zoukas/0.2.0/
54
55
  bug_tracker_uri: https://github.com/eebbesen/sheet_zoukas/issues
55
56
  rubygems_mfa_required: 'true'
56
57
  post_install_message: