googlesheets 0.6.4 → 0.8.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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -2
  3. data/bin/shat +19 -5
  4. data/lib/googlesheets.rb +8 -1
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 52c14fb11d7e85e0466fa150a46b7403bfba5f4693e7332130536e60082c62c1
4
- data.tar.gz: f487d35ebd512ecec19676c08471bc6f7155e6e937dc2dc5106b1e5e99569402
3
+ metadata.gz: a378458e86791442a1e6b45251b8e4dab9197de444176c466d169fed24069659
4
+ data.tar.gz: 1033e1300425d32aa74aec56246e5ead5ce52bead75ff1a91b6a34cab914b2ab
5
5
  SHA512:
6
- metadata.gz: 5ff5b9ef469d0822e598e72ad9a3eb557f913d8f50c48f23d60169092c14cfff1edf1473470ec0bf169d4ebbd4050f87e8114dab38d711789093111d1ecd7c96
7
- data.tar.gz: fab7b3b54481bbef23d835bd4b887247badb779bf3b373cbe90ac1652a873a32ca78c3bb1b9086af38c1a3d91e61335ed8224626b10339d53dc403ec3ebaf90c
6
+ metadata.gz: 95ca848033baeed961898db87d52f2a21658a0aa67a722ded7226a37dfd5510fe359f4068247765263f03f1a1cab37bfa7cb22759111bcfca8d9286b4cab0e5c
7
+ data.tar.gz: bba5b7cc4f3c0bd64780fc88f615661bc76eef80e7f60247988ffc7d9f6d478bbc17fc348b58403a3205b2765174b8fb9544c72ce0355ea0e208f2f8ea1f3fed
data/README.md CHANGED
@@ -1,5 +1,3 @@
1
1
  # googlesheets
2
2
 
3
3
  Ruby gem for Google Sheets API
4
-
5
- ### NOTE: gem install google-api-client
data/bin/shat CHANGED
@@ -16,11 +16,16 @@ trap("INT" ) { abort "\n" }
16
16
  OptionParser.new.instance_eval do
17
17
  @banner = "usage: #{program_name} [options] <url>"
18
18
 
19
- on "-f", "--fill" , "Fill each row with as many cells as the first row"
20
- on "-h", "--help" , "Show help and command usage" do Kernel.abort to_s; end
21
- on "-t", "--trim" , "Trim leading and trailing whitespace"
22
- on "-v", "--version" , "Show version number" do Kernel.abort "#{program_name} #{GoogleSheets::VERSION}"; end
19
+ on "-f", "--fill" , "Fill each row with as many cells as the first row"
20
+ on "-h", "--help" , "Show help and command usage" do Kernel.abort to_s; end
21
+ on "-s", "--strip" , "Strip leading and trailing whitespace"
22
+ on "-v", "--version", "Show version number" do Kernel.abort "#{program_name} #{GoogleSheets::VERSION}"; end
23
23
 
24
+ on "--csv" , "Output comma separated data (default)"
25
+ on "--psv" , "Output pipe separated data"
26
+ on "--tsv" , "Output tab separated data"
27
+
28
+ Kernel.abort to_s if ARGV.empty?
24
29
  self
25
30
  end.parse!(into: opts={}) rescue abort($!.message)
26
31
 
@@ -28,6 +33,15 @@ fill = opts[:fill]
28
33
  link = ARGV.shift or abort("no url provided")
29
34
  trim = opts[:trim]
30
35
 
36
+ # handle separators
37
+ xcsv = opts[:csv ]
38
+ xpsv = opts[:psv ]
39
+ xtsv = opts[:tsv ]
40
+ hits = [xcsv, xpsv, xtsv].compact.size
41
+ hits > 1 and abort "only one of csv, psv, or tsv allowed"
42
+ xcsv = true if hits.zero?
43
+ seps = xtsv ? "\t" : xpsv ? "|" : ","
44
+
31
45
  goog = GoogleSheets.new(link)
32
46
  rows = goog.sheet_read
33
47
  rows.each {|cols| cols.map(&:strip!) } if trim
@@ -41,4 +55,4 @@ if fill and need = rows[0]&.size
41
55
  end
42
56
  end
43
57
 
44
- Censive.writer {|csv| rows.each {|row| csv << row }}
58
+ Censive.writer(seps: seps) {|csv| rows.each {|row| csv << row }}
data/lib/googlesheets.rb CHANGED
@@ -19,7 +19,7 @@ class Object
19
19
  end
20
20
 
21
21
  class GoogleSheets
22
- VERSION = "0.6.4"
22
+ VERSION = "0.8.0"
23
23
 
24
24
  attr_accessor :api
25
25
 
@@ -31,6 +31,13 @@ class GoogleSheets
31
31
  @json = opts[:credentials] || "credentials.json"
32
32
  @yaml = opts[:token ] || "token.yaml"
33
33
 
34
+ if !File.exist?(@json)
35
+ base = File.expand_path(File.join(ENV["HOME"], ".google"))
36
+ abort "unable to file Google API credentials" unless File.exist?(base)
37
+ @json = File.join(base, @json)
38
+ @yaml = File.join(base, @yaml)
39
+ end
40
+
34
41
  if opts[:debug] == true
35
42
  $stdout.sync = true
36
43
  Google::Apis.logger = Logger.new(STDERR)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: googlesheets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Shreeve
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-17 00:00:00.000000000 Z
11
+ date: 2023-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-api-client
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0'
58
58
  requirements: []
59
- rubygems_version: 3.4.8
59
+ rubygems_version: 3.4.9
60
60
  signing_key:
61
61
  specification_version: 4
62
62
  summary: Ruby library for Google Sheets