sheet_zoukas 0.1.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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +80 -0
- data/Rakefile +16 -0
- data/lib/sheet_zoukas/data_converter.rb +29 -0
- data/lib/sheet_zoukas/google_sheets.rb +29 -0
- data/lib/sheet_zoukas/version.rb +5 -0
- data/lib/sheet_zoukas.rb +18 -0
- data/sig/sheet_zoukas.rbs +4 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4bd39b81cba9d9a4da4202e20062bf10ee50b12570ae929bf0ab33f3773d9614
|
4
|
+
data.tar.gz: d3579fdec88d34bbd76a504a0740c8ca15710bcfe92b026783ff6b80dedf358a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ea44d0116850abefdfadf3bd353f09ca0d7155c16137e31410c13e3f24f4772c9f773b42270aa8e8fcdb738c2a4d1dc39d67ad132f3510a34d944d2f15f2bbf7
|
7
|
+
data.tar.gz: 530d626076a0fdd2db2759195d49d14300fa807db5e87de0e0b11d9c01b98276a1d1cde06175370d0399ddae0b87533ba3fac40cdc58e39dda26a739d358669d
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 J2EEbbesen
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 eebbesen
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# SheetZoukas
|
2
|
+
|
3
|
+
Expose Google Sheets as JSON data
|
4
|
+
|
5
|
+

|
6
|
+
|
7
|
+
[](https://github.com/rubocop/rubocop)
|
8
|
+
|
9
|
+
Created to allow Google Sheets to be used as read-only databases. Associates each row's values with the corresponding header ("row") name.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Install the gem and add to the application's Gemfile by executing:
|
14
|
+
|
15
|
+
$ bundle add sheet_zoukas
|
16
|
+
|
17
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
18
|
+
|
19
|
+
$ gem install sheet_zoukas
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Requirements
|
24
|
+
|
25
|
+
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
|
+
|
27
|
+
#### Google auth values
|
28
|
+
|
29
|
+
* GOOGLE_ACCOUNT_TYPE
|
30
|
+
* GOOGLE_API_KEY
|
31
|
+
* GOOGLE_CLIENT_EMAIL
|
32
|
+
* GOOGLE_CLIENT_ID
|
33
|
+
* GOOGLE_PRIVATE_KEY
|
34
|
+
|
35
|
+
|
36
|
+
### 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
|
39
|
+
* 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.
|
41
|
+
* 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
|
+
* 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
|
+
|
44
|
+
## Development
|
45
|
+
|
46
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
47
|
+
|
48
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
49
|
+
|
50
|
+
### linting
|
51
|
+
|
52
|
+
GitHub Action runs
|
53
|
+
* RuboCop
|
54
|
+
* Bundler Audit
|
55
|
+
|
56
|
+
### testing
|
57
|
+
|
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.
|
59
|
+
|
60
|
+
## Release
|
61
|
+
Build
|
62
|
+
$ rake build
|
63
|
+
|
64
|
+
Test
|
65
|
+
$ gem install pkg/sheet_zoukas-<VERSION>.gem
|
66
|
+
$ irb
|
67
|
+
|
68
|
+
irb(main):001> require 'sheet_zoukas'
|
69
|
+
irb(main):002> SheetZoukas.retrieve_sheet_json('<GOOGLE_SPREADSHEET_ID>', '<TAB_NAME>')
|
70
|
+
|
71
|
+
Release
|
72
|
+
$ rake release
|
73
|
+
|
74
|
+
## Contributing
|
75
|
+
|
76
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/eebbesen/sheet_zoukas.
|
77
|
+
|
78
|
+
## License
|
79
|
+
|
80
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
require 'rubocop/rake_task'
|
9
|
+
|
10
|
+
RuboCop::RakeTask.new
|
11
|
+
|
12
|
+
task default: %i[spec rubocop]
|
13
|
+
|
14
|
+
require 'bundler/audit/task'
|
15
|
+
|
16
|
+
Bundler::Audit::Task.new
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SheetZoukas
|
4
|
+
# convert spreadsheet data to JSON
|
5
|
+
class DataConverter
|
6
|
+
def initialize(data)
|
7
|
+
@data = data
|
8
|
+
end
|
9
|
+
|
10
|
+
def convert
|
11
|
+
init_headers
|
12
|
+
init_rows
|
13
|
+
|
14
|
+
@rows.map do |row|
|
15
|
+
@headers.zip(row).to_h
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def init_headers
|
22
|
+
@headers = @data[0]
|
23
|
+
end
|
24
|
+
|
25
|
+
def init_rows
|
26
|
+
@rows = @data[1..]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'google/apis/sheets_v4'
|
4
|
+
require 'googleauth'
|
5
|
+
|
6
|
+
module SheetZoukas
|
7
|
+
# Interact with Google Sheets API
|
8
|
+
class GoogleSheets
|
9
|
+
DEFAULT_SCOPE = 'https://www.googleapis.com/auth/spreadsheets.readonly'
|
10
|
+
|
11
|
+
def initialize(scope = DEFAULT_SCOPE)
|
12
|
+
@authorizer = Google::Auth::ServiceAccountCredentials.from_env(scope: scope)
|
13
|
+
end
|
14
|
+
|
15
|
+
def retrieve_sheet(sheet_id, tab_name, range = nil)
|
16
|
+
sheets = Google::Apis::SheetsV4::SheetsService.new
|
17
|
+
sheets.authorization = @authorizer
|
18
|
+
|
19
|
+
computed_range = SheetZoukas::GoogleSheets.send :create_range, tab_name, range
|
20
|
+
sheets.get_spreadsheet_values(sheet_id, computed_range)
|
21
|
+
end
|
22
|
+
|
23
|
+
private_class_method def self.create_range(tab_name, range = nil)
|
24
|
+
return tab_name unless range
|
25
|
+
|
26
|
+
"#{tab_name}!#{range}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/sheet_zoukas.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'sheet_zoukas/data_converter'
|
4
|
+
require_relative 'sheet_zoukas/google_sheets'
|
5
|
+
require_relative 'sheet_zoukas/version'
|
6
|
+
|
7
|
+
# Retrieve Google Sheets data
|
8
|
+
module SheetZoukas
|
9
|
+
class Error < StandardError; end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def retrieve_sheet_json(sheet_id, tab_name, range = nil)
|
13
|
+
sheet = GoogleSheets.new
|
14
|
+
data = sheet.retrieve_sheet(sheet_id, tab_name, range)
|
15
|
+
DataConverter.new(data.values).convert
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sheet_zoukas
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- eebbesen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-10-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: google-apis-sheets_v4
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Expose Google Sheets as JSON data
|
28
|
+
email:
|
29
|
+
- eebbesen.git@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".rspec"
|
35
|
+
- ".rubocop.yml"
|
36
|
+
- CHANGELOG.md
|
37
|
+
- LICENSE
|
38
|
+
- LICENSE.txt
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- lib/sheet_zoukas.rb
|
42
|
+
- lib/sheet_zoukas/data_converter.rb
|
43
|
+
- lib/sheet_zoukas/google_sheets.rb
|
44
|
+
- lib/sheet_zoukas/version.rb
|
45
|
+
- sig/sheet_zoukas.rbs
|
46
|
+
homepage: https://github.com/eebbesen/sheet_zoukas
|
47
|
+
licenses:
|
48
|
+
- MIT
|
49
|
+
metadata:
|
50
|
+
homepage_uri: https://github.com/eebbesen/sheet_zoukas
|
51
|
+
changelog_uri: https://github.com/eebbesen/sheet_zoukas/releases/tag/v0.1.0
|
52
|
+
source_code_uri: https://github.com/eebbesen/sheet_zoukas
|
53
|
+
documentation_uri: https://github.com/eebbesen/sheet_zoukas/0.1.0/
|
54
|
+
bug_tracker_uri: https://github.com/eebbesen/sheet_zoukas/issues
|
55
|
+
rubygems_mfa_required: 'true'
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 3.0.0
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubygems_version: 3.5.16
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: Expose Google Sheets as JSON data
|
75
|
+
test_files: []
|