sheets_v4 0.7.0 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +34 -0
- data/Rakefile +3 -0
- data/lib/sheets_v4/google_extensions/sheet.rb +32 -0
- data/lib/sheets_v4/google_extensions/sheets_service.rb +99 -0
- data/lib/sheets_v4/google_extensions/spreadsheet.rb +24 -0
- data/lib/sheets_v4/google_extensions.rb +42 -0
- data/lib/sheets_v4/version.rb +1 -1
- data/lib/sheets_v4.rb +6 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aaee6f486ac124cdefd974acfe3f18357ade8e9f90655a46e746ebfad53a391b
|
4
|
+
data.tar.gz: 0f3c1e513b45a841052be82817e5bcf157aba492282999f401bb069e048e2263
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3762e42b88065e6bc76e5e749d629dc02073c2584053a9c979fd8b46196e70e155c2f06d87a768b511a93b30d38d09c5da6592ef875a9fb70cb7bd97b67ed7a
|
7
|
+
data.tar.gz: 64bed7345bcc3ee05d204b47770b297e8a53d05cc1deb6611bd114197cb46690df2683549e772b7b9453fbf158eba492efc05faf93e966047f57055e9d203d87
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,16 @@ Changes for each release are listed in this file.
|
|
4
4
|
|
5
5
|
This project adheres to [Semantic Versioning](https://semver.org/) for its releases.
|
6
6
|
|
7
|
+
## v0.8.0 (2023-10-15)
|
8
|
+
|
9
|
+
[Full Changelog](https://github.com/main-branch/sheets_v4/compare/v0.7.0..v0.8.0)
|
10
|
+
|
11
|
+
Changes since v0.7.0:
|
12
|
+
|
13
|
+
* d8f695c Add extensions to Google::Apis::SheetsV4 classes (#26)
|
14
|
+
* ed2dc0e Show the cop names on Rubocop offenses when Rubocop is run from Rake (#25)
|
15
|
+
* c5bfcc1 Group the SheetsV4 methods in the Yard Docs to make them easier to find (#24)
|
16
|
+
|
7
17
|
## v0.7.0 (2023-10-08)
|
8
18
|
|
9
19
|
[Full Changelog](https://github.com/main-branch/sheets_v4/compare/v0.6.0..v0.7.0)
|
data/README.md
CHANGED
@@ -25,6 +25,10 @@ Unofficial helpers for the Google Sheets V4 API
|
|
25
25
|
* [Method 2: constructing requests using hashes](#method-2-constructing-requests-using-hashes)
|
26
26
|
* [Which method should be used?](#which-method-should-be-used)
|
27
27
|
* [Validating requests](#validating-requests)
|
28
|
+
* [Google Extensions](#google-extensions)
|
29
|
+
* [SheetsService Extensions](#sheetsservice-extensions)
|
30
|
+
* [Spreadsheet Extensions](#spreadsheet-extensions)
|
31
|
+
* [Sheet Extensions](#sheet-extensions)
|
28
32
|
* [Working with dates and times](#working-with-dates-and-times)
|
29
33
|
* [Colors](#colors)
|
30
34
|
* [Development](#development)
|
@@ -274,6 +278,36 @@ request:
|
|
274
278
|
SheetsV4.validate_api_object(schema: 'batch_update_spreadsheet_request', object: requests)
|
275
279
|
```
|
276
280
|
|
281
|
+
### Google Extensions
|
282
|
+
|
283
|
+
The `SheetsV4::GoogleExtensions` module provides extensions to the `Google::Apis::SheetsV4`
|
284
|
+
classes to simplify use of the SheetsV4 API.
|
285
|
+
|
286
|
+
These extensions are not loaded by default and are not required to use other parts
|
287
|
+
of this Gem. To enable these extension, you must:
|
288
|
+
|
289
|
+
```Ruby
|
290
|
+
require 'sheets_v4/google_extensions'
|
291
|
+
```
|
292
|
+
|
293
|
+
#### SheetsService Extensions
|
294
|
+
|
295
|
+
Functionality is added to `get_spreadsheet` to set the `sheets_service` attribute on
|
296
|
+
the returned spreadsheet and set the `sheets_service` and `spreadsheet` attributes
|
297
|
+
on the sheets contained in the spreadsheet.
|
298
|
+
|
299
|
+
This can simplify complex spreadsheet updates because you won't have to pass a
|
300
|
+
sheets_service, spreadsheet, and sheet objects separately.
|
301
|
+
|
302
|
+
#### Spreadsheet Extensions
|
303
|
+
|
304
|
+
The `sheets_service` attribute is added and is set by `SheetsService#get_spreadsheet`.
|
305
|
+
|
306
|
+
#### Sheet Extensions
|
307
|
+
|
308
|
+
The `sheets_service` and `spreadsheet` attributes are added. Both are set when the
|
309
|
+
sheet's spreadsheet is loaded by `SheetsService#get_spreadsheet`.
|
310
|
+
|
277
311
|
### Working with dates and times
|
278
312
|
|
279
313
|
Google Sheets, similar to other spreadsheet programs, stores dates and date-time
|
data/Rakefile
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Copyright (c) 2022 Yahoo
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'google/apis/sheets_v4'
|
5
|
+
require 'googleauth'
|
6
|
+
|
7
|
+
module SheetsV4
|
8
|
+
module GoogleExtensions
|
9
|
+
# The SheetsService class implements handling credentials on top of the
|
10
|
+
# Google::Apis::SheetsV4::SheetsService class.
|
11
|
+
#
|
12
|
+
# @api public
|
13
|
+
#
|
14
|
+
module Sheet
|
15
|
+
# The sheets_service object used to create this sheet
|
16
|
+
#
|
17
|
+
# @example
|
18
|
+
# sheets_service = sheet.sheets_service
|
19
|
+
#
|
20
|
+
# @return [Google::Apis::SheetsV4::SheetsService]
|
21
|
+
attr_reader :sheets_service
|
22
|
+
|
23
|
+
# The spreadsheet object that contains this sheet
|
24
|
+
#
|
25
|
+
# @example
|
26
|
+
# spreadsheet = sheet.spreadsheet
|
27
|
+
#
|
28
|
+
# @return [Google::Apis::SheetsV4::Spreadsheet]
|
29
|
+
attr_reader :spreadsheet
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# Copyright (c) 2022 Yahoo
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module SheetsV4
|
5
|
+
module GoogleExtensions
|
6
|
+
# This module extends the `Google::Apis::SheetsV4::SheetsService` class to add
|
7
|
+
# attributes to the `Google::Apis::SheetsV4::Spreadsheet` and `Google::Apis::SheetsV4::Sheet`
|
8
|
+
# classes that reference the `SheetsService` instance used to retrieve them.
|
9
|
+
#
|
10
|
+
# Similarly, an attribute is added to the `Google::Apis::SheetsV4::Sheet` class
|
11
|
+
# that references the `Google::Apis::SheetsV4::Spreadsheet` instance that contains it.
|
12
|
+
#
|
13
|
+
# This allows getting the `SheetsService` object from a spreadsheet or sheet object,
|
14
|
+
# making it unnecessary to pass the `SheetsService` object around with the spreadsheet
|
15
|
+
# and its sheets.
|
16
|
+
#
|
17
|
+
# @example
|
18
|
+
# require 'sheets_v4/google_extensions'
|
19
|
+
# sheets_service = SheetsV4::SheetsService.new
|
20
|
+
# spreadsheet = sheets_service.get_spreadsheet('1nT_q0TrQzC3dLZXuI3K9V5P3mArBVZpVd_vRsOpvcyk')
|
21
|
+
#
|
22
|
+
# spreadsheet.sheets_service == sheets_service # => true
|
23
|
+
# spreadsheet.sheets.each do |sheet|
|
24
|
+
# sheet.sheets_service == sheets_service # => true
|
25
|
+
# sheet.spreadsheet == spreadsheet # => true
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# @api public
|
29
|
+
#
|
30
|
+
module SheetsService
|
31
|
+
# Replace the prepending class's `get_spreadsheet` implementation
|
32
|
+
#
|
33
|
+
# When this module is prepended to a class, class's `get_spreadsheet` method
|
34
|
+
# is replaced wity `new_get_spreadsheet` method from this module. The class's
|
35
|
+
# original `get_spreadsheet` method is renamed to `original_get_spreadsheet`.
|
36
|
+
#
|
37
|
+
# @example
|
38
|
+
# Google::Apis::SheetsV4::SheetsService.prepend(
|
39
|
+
# SheetsV4::GoogleExtensions::SheetsService
|
40
|
+
# )
|
41
|
+
#
|
42
|
+
# @return [void]
|
43
|
+
#
|
44
|
+
# @private
|
45
|
+
#
|
46
|
+
def self.prepended(prepended_to_class)
|
47
|
+
prepended_to_class.send(:alias_method, :original_get_spreadsheet, :get_spreadsheet)
|
48
|
+
prepended_to_class.send(:remove_method, :get_spreadsheet)
|
49
|
+
prepended_to_class.send(:alias_method, :get_spreadsheet, :new_get_spreadsheet)
|
50
|
+
end
|
51
|
+
|
52
|
+
# @!method get_spreadsheet(spreadsheet_id, include_grid_data, ranges, fields, quota_user, options, &block)
|
53
|
+
#
|
54
|
+
# @api public
|
55
|
+
#
|
56
|
+
# Gets an existing spreadsheet
|
57
|
+
#
|
58
|
+
# Creates a spreadsheet object by calling the original
|
59
|
+
# Google::Apis::SheetsV4::SheetsService#get_spreadsheet method and then does
|
60
|
+
# the following:
|
61
|
+
#
|
62
|
+
# * Sets the `sheets_service` attribute for the returned spreadsheet.
|
63
|
+
# * Sets the `sheets_service` and `spreadsheet` attributes all the sheets contained in the spreadsheet.
|
64
|
+
#
|
65
|
+
# See the documentation for Google::Apis::SheetsV4::SheetsService#get_spreadsheet for
|
66
|
+
# details on the parameters and return value.
|
67
|
+
#
|
68
|
+
# @example Get a spreadsheet object and output new attributes:
|
69
|
+
# require 'sheets_v4'
|
70
|
+
# require 'sheets_v4/google_extensions'
|
71
|
+
#
|
72
|
+
# sheets_service = SheetsV4::SheetsService.new
|
73
|
+
# spreadsheet_id = '1nT_q0TrQzC3dLZXuI3K9V5P3mArBVZpVd_vRsOpvcyk'
|
74
|
+
#
|
75
|
+
# spreadsheet = sheets_service.get_spreadsheet(spreadsheet_id)
|
76
|
+
#
|
77
|
+
# @return [Google::Apis::SheetsV4::Spreadsheet] the spreadsheet whose ID is `spreadsheet_id`
|
78
|
+
|
79
|
+
# Replaces the `get_spreadsheet` method implementation in the prepended class
|
80
|
+
#
|
81
|
+
# @example
|
82
|
+
# spreadsheet = sheets_service.new_get_spreadsheet(spreadsheet_id)
|
83
|
+
#
|
84
|
+
# @private
|
85
|
+
#
|
86
|
+
# @return [Google::Apis::SheetsV4::Spreadsheet]
|
87
|
+
#
|
88
|
+
def new_get_spreadsheet(...)
|
89
|
+
original_get_spreadsheet(...)&.tap do |spreadsheet|
|
90
|
+
spreadsheet.instance_variable_set(:@sheets_service, self)
|
91
|
+
spreadsheet.sheets.each do |sheet|
|
92
|
+
sheet.instance_variable_set(:@sheets_service, self)
|
93
|
+
sheet.instance_variable_set(:@spreadsheet, spreadsheet)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# Copyright (c) 2022 Yahoo
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'google/apis/sheets_v4'
|
5
|
+
require 'googleauth'
|
6
|
+
|
7
|
+
module SheetsV4
|
8
|
+
module GoogleExtensions
|
9
|
+
# The SheetsService class implements handling credentials on top of the
|
10
|
+
# Google::Apis::SheetsV4::SheetsService class.
|
11
|
+
#
|
12
|
+
# @api public
|
13
|
+
#
|
14
|
+
module Spreadsheet
|
15
|
+
# The sheets_service object used to create this spreadsheet
|
16
|
+
#
|
17
|
+
# @example
|
18
|
+
# sheets_service = spreadsheet.sheets_service
|
19
|
+
#
|
20
|
+
# @return [Google::Apis::SheetsV4::SheetsService]
|
21
|
+
attr_reader :sheets_service
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SheetsV4
|
4
|
+
# The Google extensions are additions directly to Google::Apis::SheetsV4 classes
|
5
|
+
#
|
6
|
+
# These additions are optional and provide convenience methods and attributes
|
7
|
+
# that simplify use of the Google Sheets API.
|
8
|
+
#
|
9
|
+
# To use these extensions, require the `sheets_v4/google_extensions` file.
|
10
|
+
#
|
11
|
+
# @example
|
12
|
+
# require 'sheets_v4/google_extensions'
|
13
|
+
#
|
14
|
+
module GoogleExtensions; end
|
15
|
+
end
|
16
|
+
|
17
|
+
require_relative 'google_extensions/sheets_service'
|
18
|
+
require_relative 'google_extensions/spreadsheet'
|
19
|
+
require_relative 'google_extensions/sheet'
|
20
|
+
|
21
|
+
# @private
|
22
|
+
module Google
|
23
|
+
module Apis
|
24
|
+
# Add SheetsV4 extensions to Google::Apis::SheetsV4 classes
|
25
|
+
module SheetsV4
|
26
|
+
# Add SheetsV4 extensions to Google::Apis::SheetsV4::SheetsService
|
27
|
+
class SheetsService
|
28
|
+
prepend ::SheetsV4::GoogleExtensions::SheetsService
|
29
|
+
end
|
30
|
+
|
31
|
+
# Add SheetsV4 extensions to Google::Apis::SheetsV4::Spreadsheet
|
32
|
+
class Spreadsheet
|
33
|
+
prepend ::SheetsV4::GoogleExtensions::Spreadsheet
|
34
|
+
end
|
35
|
+
|
36
|
+
# Add SheetsV4 extensions to Google::Apis::SheetsV4::Sheet
|
37
|
+
class Sheet
|
38
|
+
prepend ::SheetsV4::GoogleExtensions::Sheet
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/sheets_v4/version.rb
CHANGED
data/lib/sheets_v4.rb
CHANGED
@@ -57,6 +57,8 @@ module SheetsV4
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
+
# @!group Validation
|
61
|
+
|
60
62
|
# Validate the object using the named JSON schema
|
61
63
|
#
|
62
64
|
# The JSON schemas are loaded from the Google Disocvery API. The schemas names are
|
@@ -90,6 +92,8 @@ module SheetsV4
|
|
90
92
|
SheetsV4::ApiObjectValidation::LoadSchemas.new(logger:).call.keys.sort
|
91
93
|
end
|
92
94
|
|
95
|
+
# @!group Colors
|
96
|
+
|
93
97
|
# Given the name of the color, return a Google Sheets API color object
|
94
98
|
#
|
95
99
|
# Available color names are listed using `SheetsV4.color_names`.
|
@@ -117,6 +121,8 @@ module SheetsV4
|
|
117
121
|
#
|
118
122
|
def color_names = SheetsV4::Color::COLORS.keys
|
119
123
|
|
124
|
+
# @!group Date and DateTime Conversions
|
125
|
+
|
120
126
|
# @!attribute [rw] default_spreadsheet_tz
|
121
127
|
#
|
122
128
|
# Set the default time zone for date and time conversions
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sheets_v4
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Couball
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-10-
|
11
|
+
date: 2023-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler-audit
|
@@ -268,6 +268,10 @@ files:
|
|
268
268
|
- lib/sheets_v4/color.rb
|
269
269
|
- lib/sheets_v4/convert_dates_and_times.rb
|
270
270
|
- lib/sheets_v4/create_credential.rb
|
271
|
+
- lib/sheets_v4/google_extensions.rb
|
272
|
+
- lib/sheets_v4/google_extensions/sheet.rb
|
273
|
+
- lib/sheets_v4/google_extensions/sheets_service.rb
|
274
|
+
- lib/sheets_v4/google_extensions/spreadsheet.rb
|
271
275
|
- lib/sheets_v4/validate_api_objects.rb
|
272
276
|
- lib/sheets_v4/validate_api_objects/validate_api_object.rb
|
273
277
|
- lib/sheets_v4/version.rb
|