Skip to content

Commit

Permalink
Call Google Sheets API (#4)
Browse files Browse the repository at this point in the history
* calling Google Sheets API

* exposing secrets in Action

* run tests only if all required env variables present
  • Loading branch information
eebbesen authored Oct 13, 2024
1 parent 795977b commit 1369308
Show file tree
Hide file tree
Showing 13 changed files with 2,678 additions and 10 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ jobs:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Run tests
run: bundle exec rspec
env:
GOOGLE_ACCOUNT_TYPE: ${{ secrets.GOOGLE_ACCOUNT_TYPE }}
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
GOOGLE_API_SPREADSHEET_ID: ${{ secrets.GOOGLE_API_SPREADSHEET_ID }}
GOOGLE_CLIENT_EMAIL: ${{ secrets.GOOGLE_CLIENT_EMAIL }}
GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }}
GOOGLE_PRIVATE_KEY: ${{ secrets.GOOGLE_PRIVATE_KEY }}
run: bundle exec rake spec
- name: Run RuboCop
run: bundle exec rubocop
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@

# rspec failure tracking
.rspec_status

.byebug_history

3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ group :development, :test do
end

group :test do
gem 'byebug', require: false
gem 'rspec', require: false
gem 'simplecov', require: false
gem 'vcr', require: false
gem 'webmock', require: false
end
70 changes: 70 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,76 @@ PATH
remote: .
specs:
sheet_zoukas (0.1.0)
google-apis-sheets_v4

GEM
remote: https://rubygems.org/
specs:
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.8)
byebug (11.1.3)
crack (1.0.0)
bigdecimal
rexml
declarative (0.0.20)
diff-lcs (1.5.1)
docile (1.4.1)
faraday (2.12.0)
faraday-net_http (>= 2.0, < 3.4)
json
logger
faraday-net_http (3.3.0)
net-http
google-apis-core (0.15.1)
addressable (~> 2.5, >= 2.5.1)
googleauth (~> 1.9)
httpclient (>= 2.8.3, < 3.a)
mini_mime (~> 1.0)
mutex_m
representable (~> 3.0)
retriable (>= 2.0, < 4.a)
google-apis-sheets_v4 (0.36.0)
google-apis-core (>= 0.15.0, < 2.a)
google-cloud-env (2.2.1)
faraday (>= 1.0, < 3.a)
googleauth (1.11.1)
faraday (>= 1.0, < 3.a)
google-cloud-env (~> 2.1)
jwt (>= 1.4, < 3.0)
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
hashdiff (1.1.1)
httpclient (2.8.3)
json (2.7.2)
jwt (2.9.3)
base64
language_server-protocol (3.17.0.3)
logger (1.6.1)
mini_mime (1.1.5)
multi_json (1.15.0)
mutex_m (0.2.0)
net-http (0.4.1)
uri
os (1.1.4)
parallel (1.26.3)
parser (3.3.5.0)
ast (~> 2.4.1)
racc
public_suffix (6.0.1)
racc (1.8.1)
rainbow (3.1.1)
rake (13.2.1)
regexp_parser (2.9.2)
representable (3.2.0)
declarative (< 0.1.0)
trailblazer-option (>= 0.1.1, < 0.2.0)
uber (< 0.2.0)
retriable (3.1.2)
rexml (3.3.8)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
Expand Down Expand Up @@ -49,26 +102,43 @@ GEM
rubocop-rspec (3.1.0)
rubocop (~> 1.61)
ruby-progressbar (1.13.0)
signet (0.19.0)
addressable (~> 2.8)
faraday (>= 0.17.5, < 3.a)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-html (0.13.1)
simplecov_json_formatter (0.1.4)
trailblazer-option (0.1.2)
uber (0.1.0)
unicode-display_width (2.6.0)
uri (0.13.1)
vcr (6.3.1)
base64
webmock (3.24.0)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)

PLATFORMS
arm64-darwin-23
ruby

DEPENDENCIES
byebug
rake (~> 13.0)
rspec
rubocop
rubocop-rake
rubocop-rspec
sheet_zoukas!
simplecov
vcr
webmock

BUNDLED WITH
2.5.16
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# SheetZoukas

TODO: Delete this and the text below, and describe your gem

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sheet_zoukas`. To experiment with that code, run `bin/console` for an interactive prompt.
Expose Google Sheets as JSON.

## Installation

Expand All @@ -16,7 +14,6 @@ If bundler is not being used to manage dependencies, install the gem by executin

## Usage

TODO: Write usage instructions here

## Development

Expand Down
1 change: 0 additions & 1 deletion lib/sheet_zoukas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@

module SheetZoukas
class Error < StandardError; end
# Your code goes here...
end
29 changes: 29 additions & 0 deletions lib/sheet_zoukas/google_sheets.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

require 'google/apis/sheets_v4'
require 'googleauth'

module SheetZoukas
# Interact with Google Sheets API
class GoogleSheets
DEFAULT_SCOPE = 'https://www.googleapis.com/auth/spreadsheets.readonly'

def initialize(scope = DEFAULT_SCOPE)
@authorizer = Google::Auth::ServiceAccountCredentials.from_env(scope: scope)
end

def retrieve_sheet(sheet_id, tab_name, range = nil)
sheets = Google::Apis::SheetsV4::SheetsService.new
sheets.authorization = @authorizer

computed_range = SheetZoukas::GoogleSheets.send :create_range, tab_name, range
sheets.get_spreadsheet_values(sheet_id, computed_range)
end

private_class_method def self.create_range(tab_name, range = nil)
return tab_name unless range

"#{tab_name}!#{range}"
end
end
end
1 change: 1 addition & 0 deletions sheet_zoukas.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

# spec.add_development_dependency 'rspec'
spec.add_dependency 'google-apis-sheets_v4'

spec.metadata['rubygems_mfa_required'] = 'true'
end
Loading

0 comments on commit 1369308

Please sign in to comment.