googlesheets 0.1.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/README.md +2 -0
- data/googlesheets.gemspec +1 -1
- data/lib/googlesheets.rb +46 -4
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8f5d17077c83d17f62a0c18e129e1a1b88cfe1059606b22ca012b349b6ec682
|
4
|
+
data.tar.gz: 34029b089e78a8e32cd1572971c248e5ff05d4e1e9d772754df26bfd5d6a3461
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd7ff047f1181c713132bb09b6ac4b876c681b8fc6c89d657e2d2cf0a63aa2dc3bef9f973f8f92419f89035eb290d9b2f8a47ef020ad29326532eec2a41de57c
|
7
|
+
data.tar.gz: 1bb3e0cc4fec63b073698ff2a33638d70e04a008a92a9d067d0f2c6de7d6b57a8e89caac3d9a83951cea41ace67f59eed0e1f557b83714ddf8e1e8f1ab863f82
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.6
|
1
|
+
2.6.5
|
data/README.md
CHANGED
data/googlesheets.gemspec
CHANGED
data/lib/googlesheets.rb
CHANGED
@@ -8,11 +8,13 @@ module Enumerable
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
+
# https://googleapis.dev/ruby/google-api-client/latest/Google/Apis/SheetsV4/Request.html
|
12
|
+
|
11
13
|
class GoogleSheets
|
12
14
|
attr_accessor :api
|
13
15
|
|
14
16
|
def initialize(ssid, **opts)
|
15
|
-
@ssid = ssid
|
17
|
+
@ssid = ssid =~ /^https?:/ ? ssid.split('/')[5] : ssid
|
16
18
|
|
17
19
|
@json = opts[:credentials] || 'credentials.json'
|
18
20
|
@yaml = opts[:token ] || 'token.yaml'
|
@@ -70,6 +72,19 @@ class GoogleSheets
|
|
70
72
|
end
|
71
73
|
end
|
72
74
|
|
75
|
+
def filter_criteria(hash)
|
76
|
+
hash.inject({}) do |h, (k,v)|
|
77
|
+
l = Array(v)
|
78
|
+
h[biject(k.to_s) - 1] = {
|
79
|
+
condition: {
|
80
|
+
type: "TEXT_EQ",
|
81
|
+
values: l.map {|e| { user_entered_value: e} },
|
82
|
+
}
|
83
|
+
}
|
84
|
+
h
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
73
88
|
def range(area)
|
74
89
|
sh, rc = area.split('!', 2); rc, sh = sh, nil if sh.nil?
|
75
90
|
as, ae = rc.split(':', 2); ae ||= as
|
@@ -119,6 +134,26 @@ class GoogleSheets
|
|
119
134
|
end
|
120
135
|
end
|
121
136
|
|
137
|
+
def resolve_sheet(area)
|
138
|
+
area.sub(/^(#\d+)(?=!)/) {|num| sheet_name(num)}
|
139
|
+
end
|
140
|
+
|
141
|
+
def sheet_rename(pick, name=nil)
|
142
|
+
shid = sheet_id(pick)
|
143
|
+
name ||= yield(sheet_name(shid)) if block_given?
|
144
|
+
|
145
|
+
reqs = []
|
146
|
+
reqs.push(update_sheet_properties: {
|
147
|
+
properties: {
|
148
|
+
sheet_id: shid,
|
149
|
+
title: name,
|
150
|
+
},
|
151
|
+
fields: 'title',
|
152
|
+
})
|
153
|
+
resp = api.batch_update_spreadsheet(@ssid, { requests: reqs }, {})
|
154
|
+
true
|
155
|
+
end
|
156
|
+
|
122
157
|
def sheet_color(pick, color=nil) # NOTE: ignores alpha
|
123
158
|
reqs = []
|
124
159
|
reqs.push(update_sheet_properties: {
|
@@ -132,16 +167,19 @@ class GoogleSheets
|
|
132
167
|
true
|
133
168
|
end
|
134
169
|
|
135
|
-
def sheet_filter(area)
|
170
|
+
def sheet_filter(area, want=nil)
|
171
|
+
area = resolve_sheet(area)
|
136
172
|
range = range(area)
|
173
|
+
criteria = filter_criteria(want) if want
|
137
174
|
reqs = []
|
138
175
|
reqs.push(clear_basic_filter: { sheet_id: range[:sheet_id] })
|
139
|
-
reqs.push(set_basic_filter: { filter: { range: range } })
|
176
|
+
reqs.push(set_basic_filter: { filter: { range: range, criteria: criteria}.compact })
|
140
177
|
resp = api.batch_update_spreadsheet(@ssid, { requests: reqs }, {})
|
141
178
|
true
|
142
179
|
end
|
143
180
|
|
144
181
|
def sheet_format(area, pattern)
|
182
|
+
area = resolve_sheet(area)
|
145
183
|
reqs = []
|
146
184
|
reqs.push(repeat_cell: {
|
147
185
|
range: range(area),
|
@@ -160,15 +198,19 @@ class GoogleSheets
|
|
160
198
|
end
|
161
199
|
|
162
200
|
def sheet_clear(area)
|
201
|
+
area = resolve_sheet(area)
|
202
|
+
area.sub!(/^(#\d+)(?=!)/) {|num| sheet_name(num)}
|
163
203
|
api.clear_values(@ssid, area)
|
164
204
|
end
|
165
205
|
|
166
206
|
def sheet_read(area)
|
207
|
+
area = resolve_sheet(area)
|
208
|
+
area.sub!(/^(#\d+)(?=!)/) {|num| sheet_name(num)}
|
167
209
|
api.get_spreadsheet_values(@ssid, area).values
|
168
210
|
end
|
169
211
|
|
170
212
|
def sheet_save(area, rows, log=false)
|
171
|
-
area
|
213
|
+
area = resolve_sheet(area)
|
172
214
|
gasv = Google::Apis::SheetsV4::ValueRange.new(range: area, values: rows)
|
173
215
|
done = api.update_spreadsheet_value(@ssid, area, gasv, value_input_option: "USER_ENTERED")
|
174
216
|
puts "#{done.updated_cells} cells updated." if log
|
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.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Shreeve
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This gem allows easy access to Google Sheets API V4.
|
14
14
|
email: steve.shreeve@gmail.com
|
@@ -26,7 +26,7 @@ homepage: https://github.com/shreeve/googlesheets
|
|
26
26
|
licenses:
|
27
27
|
- MIT
|
28
28
|
metadata: {}
|
29
|
-
post_install_message:
|
29
|
+
post_install_message:
|
30
30
|
rdoc_options: []
|
31
31
|
require_paths:
|
32
32
|
- lib
|
@@ -41,8 +41,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '0'
|
43
43
|
requirements: []
|
44
|
-
rubygems_version: 3.
|
45
|
-
signing_key:
|
44
|
+
rubygems_version: 3.2.16
|
45
|
+
signing_key:
|
46
46
|
specification_version: 4
|
47
47
|
summary: Ruby gem for Google Sheets
|
48
48
|
test_files: []
|