sheets_v4 0.9.0 → 0.10.1
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 +4 -4
- data/.commitlintrc.yml +16 -0
- data/.husky/commit-msg +1 -0
- data/.markdownlint.yml +1 -1
- data/.release-please-manifest.json +3 -0
- data/.rubocop.yml +5 -35
- data/.yardopts +3 -1
- data/CHANGELOG.md +35 -0
- data/LICENSE.txt +1 -1
- data/README.md +116 -44
- data/Rakefile +9 -10
- data/examples/README.md +230 -47
- data/examples/create_spreadsheet +11 -0
- data/examples/{set_background_color → set_background_color1} +21 -8
- data/examples/set_background_color2 +11 -21
- data/lib/sheets_v4/color.rb +2 -2
- data/lib/sheets_v4/convert_dates_and_times.rb +2 -2
- data/lib/sheets_v4/google_extensions/sheet.rb +0 -1
- data/lib/sheets_v4/google_extensions/sheets_service.rb +0 -1
- data/lib/sheets_v4/google_extensions/spreadsheet.rb +0 -1
- data/lib/sheets_v4/version.rb +1 -1
- data/lib/sheets_v4.rb +0 -36
- data/package.json +11 -0
- data/release-please-config.json +22 -0
- metadata +67 -25
- data/lib/sheets_v4/api_object_validation/load_schemas.rb +0 -155
- data/lib/sheets_v4/api_object_validation/resolve_schema_ref.rb +0 -72
- data/lib/sheets_v4/api_object_validation/traverse_object_tree.rb +0 -82
- data/lib/sheets_v4/api_object_validation/validate_api_object.rb +0 -87
- data/lib/sheets_v4/validate_api_objects/validate_api_object.rb +0 -87
- data/lib/sheets_v4/validate_api_objects.rb +0 -20
data/examples/README.md
CHANGED
@@ -1,49 +1,232 @@
|
|
1
1
|
# Google Sheets Examples
|
2
2
|
|
3
|
-
* [
|
4
|
-
[
|
5
|
-
* [
|
6
|
-
* [
|
7
|
-
* [
|
8
|
-
* [
|
9
|
-
* [
|
10
|
-
|
11
|
-
|
12
|
-
* [
|
13
|
-
* [ ]
|
14
|
-
* [
|
15
|
-
* [
|
16
|
-
* [
|
17
|
-
* [
|
18
|
-
* [
|
19
|
-
* [
|
20
|
-
* [ ]
|
21
|
-
* [
|
22
|
-
* [
|
23
|
-
* [
|
24
|
-
* [
|
25
|
-
* [ ]
|
26
|
-
* [
|
27
|
-
* [ ]
|
28
|
-
* [
|
29
|
-
* [
|
30
|
-
* [
|
31
|
-
* [
|
32
|
-
* [
|
33
|
-
* [
|
34
|
-
* [
|
35
|
-
* [ ]
|
36
|
-
* [
|
37
|
-
* [
|
38
|
-
* [
|
39
|
-
* [
|
40
|
-
* [
|
41
|
-
* [
|
42
|
-
* [
|
43
|
-
* [ ]
|
44
|
-
* [
|
45
|
-
* [ ]
|
46
|
-
* [
|
47
|
-
|
48
|
-
|
49
|
-
|
3
|
+
* [✅︎ Creating a Google API service account](#︎-creating-a-google-api-service-account)
|
4
|
+
* [✅︎ Create a SheetsService instance](#︎-create-a-sheetsservice-instance)
|
5
|
+
* [✅︎ Set background color](#︎-set-background-color)
|
6
|
+
* [Creating Google Sheets files](#creating-google-sheets-files)
|
7
|
+
* [Writing data to a sheet](#writing-data-to-a-sheet)
|
8
|
+
* [Reading data from a sheet](#reading-data-from-a-sheet)
|
9
|
+
* [Data formatting basics](#data-formatting-basics)
|
10
|
+
* [Creating charts](#creating-charts)
|
11
|
+
* [Data validation](#data-validation)
|
12
|
+
* [Cut, copy, and paste](#cut-copy-and-paste)
|
13
|
+
* [Duplicate sheets](#duplicate-sheets)
|
14
|
+
* [List sheets in a spreadsheet](#list-sheets-in-a-spreadsheet)
|
15
|
+
* [Set column width and row height](#set-column-width-and-row-height)
|
16
|
+
* [Append rows and columns](#append-rows-and-columns)
|
17
|
+
* [Delete rows and columns](#delete-rows-and-columns)
|
18
|
+
* [Insert rows and columns](#insert-rows-and-columns)
|
19
|
+
* [Move rows and columns](#move-rows-and-columns)
|
20
|
+
* [Clear data](#clear-data)
|
21
|
+
* [Add and delete sheets](#add-and-delete-sheets)
|
22
|
+
* [Copy sheet from one spreadsheet to another](#copy-sheet-from-one-spreadsheet-to-another)
|
23
|
+
* [Add a new sheet to an existing spreadsheet](#add-a-new-sheet-to-an-existing-spreadsheet)
|
24
|
+
* [Export a sheet to a CSV file](#export-a-sheet-to-a-csv-file)
|
25
|
+
* [Sort sheets](#sort-sheets)
|
26
|
+
* [Add calculated fields into a pivot table](#add-calculated-fields-into-a-pivot-table)
|
27
|
+
* [Named ranges](#named-ranges)
|
28
|
+
* [Create a pivot table](#create-a-pivot-table)
|
29
|
+
* [Calculated pivot fields](#calculated-pivot-fields)
|
30
|
+
* [Delete a pivot table](#delete-a-pivot-table)
|
31
|
+
* [Add pivot fields](#add-pivot-fields)
|
32
|
+
* [Add pivot filters](#add-pivot-filters)
|
33
|
+
* [Collapse/expand pivot table groups](#collapseexpand-pivot-table-groups)
|
34
|
+
* [Extract pivot table metadata](#extract-pivot-table-metadata)
|
35
|
+
* [Filter views](#filter-views)
|
36
|
+
* [Locate the last row in a column](#locate-the-last-row-in-a-column)
|
37
|
+
* [Autofill](#autofill)
|
38
|
+
* [Rename a sheet](#rename-a-sheet)
|
39
|
+
* [Find and replace](#find-and-replace)
|
40
|
+
* [Add and delete sheets](#add-and-delete-sheets-1)
|
41
|
+
* [Sum across sheets](#sum-across-sheets)
|
42
|
+
* [Freeze rows / columns](#freeze-rows--columns)
|
43
|
+
* [Protected ranges](#protected-ranges)
|
44
|
+
* [Resize a sheet](#resize-a-sheet)
|
45
|
+
* [Retrying on error](#retrying-on-error)
|
46
|
+
* [Set a custom datetime or decimal format for a range](#set-a-custom-datetime-or-decimal-format-for-a-range)
|
47
|
+
|
48
|
+
Annotated examples written in Ruby.
|
49
|
+
|
50
|
+
Checked (✅︎) topics are completed. Topics without a check still need to be added.
|
51
|
+
|
52
|
+
### ✅︎ Creating a Google API service account
|
53
|
+
|
54
|
+
<sup>[1](https://www.youtube.com/watch?v=sAgWCbGMzTo&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=1)</sup>
|
55
|
+
|
56
|
+
<sup>[2](https://www.youtube.com/watch?v=sVURhxyc6jE&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=43)</sup>
|
57
|
+
|
58
|
+
See the [Getting started](https://github.com/main-branch/sheets_v4#getting-started)
|
59
|
+
section in the project README.md
|
60
|
+
|
61
|
+
### ✅︎ Create a SheetsService instance
|
62
|
+
|
63
|
+
See [Obtaining an authenticated SheetsService](https://github.com/main-branch/sheets_v4#obtaining-an-authenticated-sheetsservice)
|
64
|
+
section in the project README.md
|
65
|
+
|
66
|
+
### ✅︎ Set background color
|
67
|
+
|
68
|
+
[examples/set_background_color1](https://github.com/main-branch/sheets_v4/blob/main/examples/set_background_color1):
|
69
|
+
set background colors building requests using `Google::Apis::SheetsV4::*` objects.
|
70
|
+
See the [Building a request](https://github.com/main-branch/sheets_v4/blob/main/README.md#building-a-request)
|
71
|
+
section in the project README.md.
|
72
|
+
|
73
|
+
[examples/set_background_color2](https://github.com/main-branch/sheets_v4/blob/main/examples/set_background_color2):
|
74
|
+
set background colors building requests using `Hash` objects.
|
75
|
+
See the [Building a request](https://github.com/main-branch/sheets_v4/blob/main/README.md#building-a-request)
|
76
|
+
section in the project README.md.
|
77
|
+
|
78
|
+
### Creating Google Sheets files
|
79
|
+
|
80
|
+
<sup>[1](https://www.youtube.com/watch?v=JRUxeQ6ZCy0&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=2)</sup>
|
81
|
+
|
82
|
+
### Writing data to a sheet
|
83
|
+
|
84
|
+
<sup>[1](https://www.youtube.com/watch?v=YF7Ad-7pvks&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=3)</sup>
|
85
|
+
|
86
|
+
### Reading data from a sheet
|
87
|
+
|
88
|
+
<sup>[1](https://www.youtube.com/watch?v=gkglr8GID5E&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=4)</sup>
|
89
|
+
|
90
|
+
Reading data
|
91
|
+
|
92
|
+
Reading formulas
|
93
|
+
|
94
|
+
### Data formatting basics
|
95
|
+
|
96
|
+
<sup>[1](https://www.youtube.com/watch?v=R4EN3iPRris&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=5)</sup>
|
97
|
+
|
98
|
+
### Creating charts
|
99
|
+
|
100
|
+
<sup>[1](https://www.youtube.com/watch?v=xt3p5I8mNWE&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=6)</sup>
|
101
|
+
|
102
|
+
### Data validation
|
103
|
+
|
104
|
+
<sup>[1](https://www.youtube.com/watch?v=n_Z2565gu6Y&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=7)</sup>
|
105
|
+
|
106
|
+
### Cut, copy, and paste
|
107
|
+
|
108
|
+
<sup>[1](https://www.youtube.com/watch?v=r8GWH2E_ehw&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=8)</sup>
|
109
|
+
|
110
|
+
### Duplicate sheets
|
111
|
+
|
112
|
+
<sup>[1](https://www.youtube.com/watch?v=BgQoPcoOiGY&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=9)</sup>
|
113
|
+
|
114
|
+
### List sheets in a spreadsheet
|
115
|
+
|
116
|
+
<sup>[1](https://www.youtube.com/watch?v=BgQoPcoOiGY&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=9)</sup>
|
117
|
+
|
118
|
+
### Set column width and row height
|
119
|
+
|
120
|
+
<sup>[1](https://www.youtube.com/watch?v=H3uMEaPqTVE&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=11)</sup>
|
121
|
+
|
122
|
+
### Append rows and columns
|
123
|
+
|
124
|
+
<sup>[1](https://www.youtube.com/watch?v=txfiwEjb7sk&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=12)</sup>
|
125
|
+
|
126
|
+
### Delete rows and columns
|
127
|
+
|
128
|
+
<sup>[1](https://www.youtube.com/watch?v=w1jrCxWx7Tc&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=13)</sup>
|
129
|
+
|
130
|
+
### Insert rows and columns
|
131
|
+
|
132
|
+
<sup>[1](https://www.youtube.com/watch?v=FL7WSsO5EVs&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=14)</sup>
|
133
|
+
|
134
|
+
### Move rows and columns
|
135
|
+
|
136
|
+
<sup>[1](https://www.youtube.com/watch?v=YHk3305dkOc&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=15)</sup>
|
137
|
+
|
138
|
+
### Clear data
|
139
|
+
|
140
|
+
<sup>[1](https://www.youtube.com/watch?v=mvbnhfdDrro&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=16)</sup>
|
141
|
+
|
142
|
+
### Add and delete sheets
|
143
|
+
|
144
|
+
<sup>[1](https://www.youtube.com/watch?v=X9PVQQVoJFc&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=17)</sup>
|
145
|
+
|
146
|
+
### Copy sheet from one spreadsheet to another
|
147
|
+
|
148
|
+
<sup>[1](https://www.youtube.com/watch?v=aIEM7Ts4n-c&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=18)</sup>
|
149
|
+
|
150
|
+
### Add a new sheet to an existing spreadsheet
|
151
|
+
|
152
|
+
### Export a sheet to a CSV file
|
153
|
+
|
154
|
+
<sup>[1](https://www.youtube.com/watch?v=Dz22fsWsLhI&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=25)</sup>
|
155
|
+
|
156
|
+
### Sort sheets
|
157
|
+
|
158
|
+
<sup>[1](https://www.youtube.com/watch?v=qbBZX7uBM1M&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=27)</sup>
|
159
|
+
|
160
|
+
### Add calculated fields into a pivot table
|
161
|
+
|
162
|
+
<sup>[1](https://www.youtube.com/watch?v=VR8zOz5ATLU&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=32)</sup>
|
163
|
+
|
164
|
+
### Named ranges
|
165
|
+
|
166
|
+
<sup>[1](https://www.youtube.com/watch?v=LTPdfXS_LHA&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=42)</sup>
|
167
|
+
|
168
|
+
### Create a pivot table
|
169
|
+
|
170
|
+
<sup>[1](https://www.youtube.com/watch?v=preFnuL7ua0&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=28)</sup>
|
171
|
+
|
172
|
+
### Calculated pivot fields
|
173
|
+
|
174
|
+
<sup>[1](https://www.youtube.com/watch?v=QLssI4uvjk4&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=33)</sup>
|
175
|
+
|
176
|
+
### Delete a pivot table
|
177
|
+
|
178
|
+
### Add pivot fields
|
179
|
+
|
180
|
+
<sup>[1](https://www.youtube.com/watch?v=VR8zOz5ATLU&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=32)</sup>
|
181
|
+
|
182
|
+
### Add pivot filters
|
183
|
+
|
184
|
+
<sup>[1](https://www.youtube.com/watch?v=EKikw-eIcbY&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=29)</sup>
|
185
|
+
|
186
|
+
### Collapse/expand pivot table groups
|
187
|
+
|
188
|
+
<sup>[1](https://www.youtube.com/watch?v=-S9bs5-ZJ5E&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=31)</sup>
|
189
|
+
|
190
|
+
### Extract pivot table metadata
|
191
|
+
|
192
|
+
<sup>[1](https://www.youtube.com/watch?v=H1SGdqbaL4w&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=30)</sup>
|
193
|
+
|
194
|
+
### Filter views
|
195
|
+
|
196
|
+
<sup>[1](https://www.youtube.com/watch?v=GyRxsSlx0GU&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=34)</sup>
|
197
|
+
|
198
|
+
### Locate the last row in a column
|
199
|
+
|
200
|
+
<sup>[1](https://www.youtube.com/watch?v=NWWHleJll28&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=35)</sup>
|
201
|
+
|
202
|
+
### Autofill
|
203
|
+
|
204
|
+
<sup>[1](https://www.youtube.com/watch?v=guHGNmODdpM&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=36)</sup>
|
205
|
+
|
206
|
+
### Rename a sheet
|
207
|
+
|
208
|
+
<sup>[1](https://www.youtube.com/watch?v=iuiDUJ4NrQI&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=37)</sup>
|
209
|
+
|
210
|
+
### Find and replace
|
211
|
+
|
212
|
+
<sup>[1](https://www.youtube.com/watch?v=YaFR0bu5CrY&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=39)</sup>
|
213
|
+
|
214
|
+
### Add and delete sheets
|
215
|
+
|
216
|
+
<sup>[1](https://www.youtube.com/watch?v=gMD4v8F8vlc&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=38)</sup>
|
217
|
+
|
218
|
+
### Sum across sheets
|
219
|
+
|
220
|
+
<sup>[1](https://www.youtube.com/watch?v=7QNk-MXkPC4&list=PL3JVwFmb_BnSee8RFaRPZ3nykuMRlaQp1&index=44)</sup>
|
221
|
+
|
222
|
+
### Freeze rows / columns
|
223
|
+
|
224
|
+
### Protected ranges
|
225
|
+
|
226
|
+
### Resize a sheet
|
227
|
+
|
228
|
+
### Retrying on error
|
229
|
+
|
230
|
+
### Set a custom datetime or decimal format for a range
|
231
|
+
|
232
|
+
<sup>[1](https://developers.google.com/sheets/api/samples/formatting#set_a_custom_datetime_or_decimal_format_for_a_range)</sup>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'sheets_v4'
|
5
|
+
|
6
|
+
# Requires one of the following Auth scopes:
|
7
|
+
# * https://www.googleapis.com/auth/drive
|
8
|
+
# * https://www.googleapis.com/auth/drive.file
|
9
|
+
# * https://www.googleapis.com/auth/spreadsheets
|
10
|
+
|
11
|
+
SheetsV4.sheets_service.create_spreadsheet
|
@@ -17,38 +17,51 @@ require 'googleauth'
|
|
17
17
|
|
18
18
|
def name_rows
|
19
19
|
SheetsV4.color_names.map do |color_name|
|
20
|
-
|
20
|
+
Google::Apis::SheetsV4::RowData.new(
|
21
|
+
values: [
|
22
|
+
Google::Apis::SheetsV4::CellData.new(
|
23
|
+
user_entered_value: Google::Apis::SheetsV4::ExtendedValue.new(string_value: color_name.to_s)
|
24
|
+
)
|
25
|
+
]
|
26
|
+
)
|
27
|
+
# { values: [{ user_entered_value: { string_value: color_name.to_s } }] }
|
21
28
|
end
|
22
29
|
end
|
23
30
|
|
24
31
|
def write_names
|
25
32
|
rows = name_rows
|
26
33
|
fields = 'user_entered_value'
|
27
|
-
start =
|
28
|
-
|
34
|
+
start = Google::Apis::SheetsV4::GridCoordinate.new(sheet_id: 0, row_index: 1, column_index: 0)
|
35
|
+
Google::Apis::SheetsV4::Request.new(
|
36
|
+
update_cells: Google::Apis::SheetsV4::UpdateCellsRequest.new(rows:, fields:, start:)
|
37
|
+
)
|
29
38
|
end
|
30
39
|
|
31
40
|
def background_color_rows
|
32
41
|
SheetsV4.color_names.map { |color_name| SheetsV4.color(color_name) }.map do |color|
|
33
|
-
|
42
|
+
background_color = Google::Apis::SheetsV4::Color.new(**color)
|
43
|
+
user_entered_format = Google::Apis::SheetsV4::CellFormat.new(background_color:)
|
44
|
+
cell_data = Google::Apis::SheetsV4::CellData.new(user_entered_format:)
|
45
|
+
Google::Apis::SheetsV4::RowData.new(values: [cell_data])
|
34
46
|
end
|
35
47
|
end
|
36
48
|
|
37
49
|
def set_background_colors
|
38
50
|
rows = background_color_rows
|
39
51
|
fields = 'user_entered_format'
|
40
|
-
start =
|
41
|
-
|
52
|
+
start = Google::Apis::SheetsV4::GridCoordinate.new(sheet_id: 0, row_index: 1, column_index: 1)
|
53
|
+
update_cells = Google::Apis::SheetsV4::UpdateCellsRequest.new(rows:, fields:, start:)
|
54
|
+
Google::Apis::SheetsV4::Request.new(update_cells:)
|
42
55
|
end
|
43
56
|
|
44
|
-
def requests =
|
57
|
+
def requests = Google::Apis::SheetsV4::BatchUpdateSpreadsheetRequest.new(requests: [write_names, set_background_colors])
|
45
58
|
|
46
59
|
# OPTIONAL: validate the requests against the schema before sending them to the API.
|
47
60
|
#
|
48
61
|
# While not necessary, it can be helpful to identify errors since the API will return
|
49
62
|
# an error if the request is invalid but does not tell you where the problem is.
|
50
63
|
#
|
51
|
-
SheetsV4.validate_api_object(schema_name: 'batch_update_spreadsheet_request', object: requests)
|
64
|
+
SheetsV4.validate_api_object(schema_name: 'batch_update_spreadsheet_request', object: requests.to_h)
|
52
65
|
|
53
66
|
spreadsheet_id = '18FAcgotK7nDfLTOTQuGCIjKwxkJMAguhn1OVzpFFgWY'
|
54
67
|
SheetsV4.sheets_service.batch_update_spreadsheet(spreadsheet_id, requests)
|
@@ -1,6 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require 'discovery_v1'
|
5
|
+
require 'discovery_v1/google_extensions'
|
4
6
|
require 'sheets_v4'
|
5
7
|
require 'googleauth'
|
6
8
|
|
@@ -17,51 +19,39 @@ require 'googleauth'
|
|
17
19
|
|
18
20
|
def name_rows
|
19
21
|
SheetsV4.color_names.map do |color_name|
|
20
|
-
|
21
|
-
values: [
|
22
|
-
Google::Apis::SheetsV4::CellData.new(
|
23
|
-
user_entered_value: Google::Apis::SheetsV4::ExtendedValue.new(string_value: color_name.to_s)
|
24
|
-
)
|
25
|
-
]
|
26
|
-
)
|
27
|
-
# { values: [{ user_entered_value: { string_value: color_name.to_s } }] }
|
22
|
+
{ values: [{ user_entered_value: { string_value: color_name.to_s } }] }
|
28
23
|
end
|
29
24
|
end
|
30
25
|
|
31
26
|
def write_names
|
32
27
|
rows = name_rows
|
33
28
|
fields = 'user_entered_value'
|
34
|
-
start =
|
35
|
-
|
36
|
-
update_cells: Google::Apis::SheetsV4::UpdateCellsRequest.new(rows:, fields:, start:)
|
37
|
-
)
|
29
|
+
start = { sheet_id: 0, row_index: 1, column_index: 0 }
|
30
|
+
{ update_cells: { rows:, fields:, start: } }
|
38
31
|
end
|
39
32
|
|
40
33
|
def background_color_rows
|
41
34
|
SheetsV4.color_names.map { |color_name| SheetsV4.color(color_name) }.map do |color|
|
42
|
-
background_color
|
43
|
-
user_entered_format = Google::Apis::SheetsV4::CellFormat.new(background_color:)
|
44
|
-
cell_data = Google::Apis::SheetsV4::CellData.new(user_entered_format:)
|
45
|
-
Google::Apis::SheetsV4::RowData.new(values: [cell_data])
|
35
|
+
{ values: [{ user_entered_format: { background_color: color } }] }
|
46
36
|
end
|
47
37
|
end
|
48
38
|
|
49
39
|
def set_background_colors
|
50
40
|
rows = background_color_rows
|
51
41
|
fields = 'user_entered_format'
|
52
|
-
start =
|
53
|
-
update_cells
|
54
|
-
Google::Apis::SheetsV4::Request.new(update_cells:)
|
42
|
+
start = { sheet_id: 0, row_index: 1, column_index: 1 }
|
43
|
+
{ update_cells: { rows:, fields:, start: } }
|
55
44
|
end
|
56
45
|
|
57
|
-
def requests =
|
46
|
+
def requests = { requests: [write_names, set_background_colors] }
|
58
47
|
|
59
48
|
# OPTIONAL: validate the requests against the schema before sending them to the API.
|
60
49
|
#
|
61
50
|
# While not necessary, it can be helpful to identify errors since the API will return
|
62
51
|
# an error if the request is invalid but does not tell you where the problem is.
|
63
52
|
#
|
64
|
-
|
53
|
+
rest_description = DiscoveryV1.discovery_service.get_rest_api('sheets', 'v4')
|
54
|
+
rest_description.validate_object(schema_name: 'batch_update_spreadsheet_request', object: requests)
|
65
55
|
|
66
56
|
spreadsheet_id = '18FAcgotK7nDfLTOTQuGCIjKwxkJMAguhn1OVzpFFgWY'
|
67
57
|
SheetsV4.sheets_service.batch_update_spreadsheet(spreadsheet_id, requests)
|
data/lib/sheets_v4/color.rb
CHANGED
@@ -141,13 +141,13 @@ module SheetsV4
|
|
141
141
|
malibu_tint: { red: 0.96862745098, green: 0.68235294118, blue: 0.80000000000 },
|
142
142
|
sea_foam_tint: { red: 0.74901960784, green: 0.92549019608, blue: 0.92156862745 },
|
143
143
|
|
144
|
-
#
|
144
|
+
# Health colors
|
145
145
|
#
|
146
146
|
health_green: { red: 0.00000000000, green: 0.69019607843, blue: 0.31372549020 },
|
147
147
|
health_yellow: { red: 1.00000000000, green: 0.65490196078, blue: 0.00000000000 },
|
148
148
|
health_red: { red: 1.00000000000, green: 0.00000000000, blue: 0.00000000000 },
|
149
149
|
|
150
|
-
#
|
150
|
+
# Fuji design color palette
|
151
151
|
#
|
152
152
|
fuji_color_watermelon: { red: 1.00000000000, green: 0.32156862745, blue: 0.34117647059 },
|
153
153
|
fuji_color_solo_cup: { red: 0.92156862745, green: 0.05882352941, blue: 0.16078431373 },
|
@@ -1,5 +1,3 @@
|
|
1
|
-
# Copyright (c) 2023 Yahoo
|
2
|
-
|
3
1
|
# frozen_string_literal: true
|
4
2
|
|
5
3
|
require 'active_support'
|
@@ -182,6 +180,7 @@ module SheetsV4
|
|
182
180
|
# @return [Integer] number of seconds in a day
|
183
181
|
#
|
184
182
|
SECONDS_PER_DAY = 86_400
|
183
|
+
private_constant :SECONDS_PER_DAY
|
185
184
|
|
186
185
|
# The number of seconds between the Google Sheets Epoch and Unix Epoch
|
187
186
|
#
|
@@ -191,6 +190,7 @@ module SheetsV4
|
|
191
190
|
# @return [Integer] the number of seconds
|
192
191
|
#
|
193
192
|
SECONDS_BETWEEN_GS_AND_UNIX_EPOCHS = 25_569 * 86_400
|
193
|
+
private_constant :SECONDS_BETWEEN_GS_AND_UNIX_EPOCHS
|
194
194
|
|
195
195
|
# Convert a gs_datetime to unix time
|
196
196
|
#
|
data/lib/sheets_v4/version.rb
CHANGED
data/lib/sheets_v4.rb
CHANGED
@@ -4,7 +4,6 @@ require_relative 'sheets_v4/version'
|
|
4
4
|
require_relative 'sheets_v4/color'
|
5
5
|
require_relative 'sheets_v4/convert_dates_and_times'
|
6
6
|
require_relative 'sheets_v4/create_credential'
|
7
|
-
require_relative 'sheets_v4/api_object_validation'
|
8
7
|
|
9
8
|
require 'active_support'
|
10
9
|
require 'active_support/values/time_zone'
|
@@ -57,41 +56,6 @@ module SheetsV4
|
|
57
56
|
end
|
58
57
|
end
|
59
58
|
|
60
|
-
# @!group Validation
|
61
|
-
|
62
|
-
# Validate the object using the named JSON schema
|
63
|
-
#
|
64
|
-
# The JSON schemas are loaded from the Google Disocvery API. The schemas names are
|
65
|
-
# returned by `SheetsV4.api_object_schema_names`.
|
66
|
-
#
|
67
|
-
# @example
|
68
|
-
# schema_name = 'batch_update_spreadsheet_request'
|
69
|
-
# object = { 'requests' => [] }
|
70
|
-
# SheetsV4.validate_api_object(schema_name:, object:)
|
71
|
-
#
|
72
|
-
# @param schema_name [String] the name of the schema to validate against
|
73
|
-
# @param object [Object] the object to validate
|
74
|
-
# @param logger [Logger] the logger to use for logging error, info, and debug message
|
75
|
-
#
|
76
|
-
# @raise [RuntimeError] if the object does not conform to the schema
|
77
|
-
#
|
78
|
-
# @return [void]
|
79
|
-
#
|
80
|
-
def validate_api_object(schema_name:, object:, logger: Logger.new(nil))
|
81
|
-
SheetsV4::ApiObjectValidation::ValidateApiObject.new(logger:).call(schema_name:, object:)
|
82
|
-
end
|
83
|
-
|
84
|
-
# List the names of the schemas available to use in the Google Sheets API
|
85
|
-
#
|
86
|
-
# @example List the name of the schemas available
|
87
|
-
# SheetsV4.api_object_schema_names #=> ["add_banding_request", "add_banding_response", ...]
|
88
|
-
#
|
89
|
-
# @return [Array<String>] the names of the schemas available
|
90
|
-
#
|
91
|
-
def api_object_schema_names(logger: Logger.new(nil))
|
92
|
-
SheetsV4::ApiObjectValidation::LoadSchemas.new(logger:).call.keys.sort
|
93
|
-
end
|
94
|
-
|
95
59
|
# @!group Colors
|
96
60
|
|
97
61
|
# Given the name of the color, return a Google Sheets API color object
|
data/package.json
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
{
|
2
|
+
"bootstrap-sha": "fd7d9e1b7ebd09c404929cf9ff1dd6a38498f669",
|
3
|
+
"packages": {
|
4
|
+
".": {
|
5
|
+
"release-type": "ruby",
|
6
|
+
"package-name": "sheets_v4",
|
7
|
+
"changelog-path": "CHANGELOG.md",
|
8
|
+
"version-file": "lib/sheets_v4/version.rb",
|
9
|
+
"bump-minor-pre-major": true,
|
10
|
+
"bump-patch-for-minor-pre-major": true,
|
11
|
+
"draft": false,
|
12
|
+
"prerelease": false,
|
13
|
+
"include-component-in-tag": false
|
14
|
+
}
|
15
|
+
},
|
16
|
+
"plugins": [
|
17
|
+
{
|
18
|
+
"type": "sentence-case"
|
19
|
+
}
|
20
|
+
],
|
21
|
+
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json"
|
22
|
+
}
|