discovery_v1 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +36 -0
- data/CHANGELOG.md +13 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE.txt +21 -0
- data/README.md +178 -0
- data/Rakefile +101 -0
- data/examples/list_schemas +17 -0
- data/examples/validate_object +32 -0
- data/lib/discovery_v1/google_extensions/rest_description.rb +68 -0
- data/lib/discovery_v1/google_extensions.rb +3 -0
- data/lib/discovery_v1/validation/load_schemas.rb +225 -0
- data/lib/discovery_v1/validation/resolve_schema_ref.rb +85 -0
- data/lib/discovery_v1/validation/traverse_object_tree.rb +80 -0
- data/lib/discovery_v1/validation/validate_object.rb +99 -0
- data/lib/discovery_v1/validation.rb +21 -0
- data/lib/discovery_v1/version.rb +6 -0
- data/lib/discovery_v1.rb +69 -0
- data/sig/discovery_v1.rbs +4 -0
- metadata +269 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 137199efc3b5f475875b508cf68d20c51ea82f2d29d3d70d2218866f67d765a0
|
4
|
+
data.tar.gz: 709788ca0001c121c94d5f95dfae6b794be0fa68f1c926e874c73a2e1aa028e1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 42b2fa6f84a491d7366d11539a50ae71e059526ce6d9f883e6f40027c1f61efb3c17e4bf05137e6827b8829a7f3aa309700b22bdb9ba116f0f85eee5dc3e0214
|
7
|
+
data.tar.gz: 1f2e89c1dd89c67c22a1ff16ecf7c2f0ec03ff16e68d16292840b6b4d9bef0ef1db97fde783aabcf9411456072247cbffa10872feb4ef8ee57321a3f1c11a77f
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
# Output extra information for each offense to make it easier to diagnose:
|
4
|
+
DisplayCopNames: true
|
5
|
+
DisplayStyleGuide: true
|
6
|
+
ExtraDetails: true
|
7
|
+
SuggestExtensions: false
|
8
|
+
# RuboCop enforces rules depending on the oldest version of Ruby which
|
9
|
+
# your project supports:
|
10
|
+
TargetRubyVersion: 3.1
|
11
|
+
|
12
|
+
Gemspec/DevelopmentDependencies:
|
13
|
+
EnforcedStyle: gemspec
|
14
|
+
|
15
|
+
# The default max line length is 80 characters
|
16
|
+
Layout/LineLength:
|
17
|
+
Max: 120
|
18
|
+
|
19
|
+
# The DSL for RSpec and the gemspec file make it very hard to limit block length:
|
20
|
+
Metrics/BlockLength:
|
21
|
+
Exclude:
|
22
|
+
- "spec/spec_helper.rb"
|
23
|
+
- "spec/**/*_spec.rb"
|
24
|
+
- "*.gemspec"
|
25
|
+
|
26
|
+
Metrics/ModuleLength:
|
27
|
+
CountAsOne: ['hash']
|
28
|
+
|
29
|
+
# When writing minitest tests, it is very hard to limit test class length:
|
30
|
+
Metrics/ClassLength:
|
31
|
+
CountAsOne: ['hash']
|
32
|
+
Exclude:
|
33
|
+
- "test/**/*_test.rb"
|
34
|
+
|
35
|
+
Style/AsciiComments:
|
36
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
Changes for each release are listed in this file.
|
4
|
+
|
5
|
+
This project adheres to [Semantic Versioning](https://semver.org/) for its releases.
|
6
|
+
|
7
|
+
## v0.1.0 (2023-11-21)
|
8
|
+
|
9
|
+
[Full Changelog](https://github.com/main-branch/discovery_v1/compare/6e9fb12..v0.1.0)
|
10
|
+
|
11
|
+
Changes:
|
12
|
+
|
13
|
+
* 6e9fb12 Initial commit
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at jcouball@yahoo.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 James Couball
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
# DiscoveryV1
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/discovery_v1.svg)](https://badge.fury.io/rb/discovery_v1)
|
4
|
+
[![Documentation](https://img.shields.io/badge/Documentation-Latest-green)](https://rubydoc.info/gems/discovery_v1/)
|
5
|
+
[![Change Log](https://img.shields.io/badge/CHANGELOG-Latest-green)](https://rubydoc.info/gems/discovery_v1/file/CHANGELOG.md)
|
6
|
+
[![Build Status](https://github.com/main-branch/discovery_v1/workflows/CI%20Build/badge.svg?branch=main)](https://github.com/main-branch/discovery_v1/actions?query=workflow%3ACI%20Build)
|
7
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/aeebc016487c5cad881e/maintainability)](https://codeclimate.com/github/main-branch/discovery_v1/maintainability)
|
8
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/aeebc016487c5cad881e/test_coverage)](https://codeclimate.com/github/main-branch/discovery_v1/test_coverage)
|
9
|
+
|
10
|
+
Unofficial helpers and extensions for the Google Discovery V1 API
|
11
|
+
|
12
|
+
* [Installation](#installation)
|
13
|
+
* [Examples](#examples)
|
14
|
+
* [Important links](#important-links)
|
15
|
+
* [DiscoveryV1 documenation](#discoveryv1-documenation)
|
16
|
+
* [General API documentation](#general-api-documentation)
|
17
|
+
* [Ruby implementation of the Discovery API](#ruby-implementation-of-the-discovery-api)
|
18
|
+
* [Usage](#usage)
|
19
|
+
* [Obtaining a DiscoveryService](#obtaining-a-discoveryservice)
|
20
|
+
* [Downloading an API discovery document](#downloading-an-api-discovery-document)
|
21
|
+
* [Validating API objects](#validating-api-objects)
|
22
|
+
* [Development](#development)
|
23
|
+
* [Contributing](#contributing)
|
24
|
+
* [License](#license)
|
25
|
+
* [Code of Conduct](#code-of-conduct)
|
26
|
+
|
27
|
+
## Installation
|
28
|
+
|
29
|
+
Install the gem and add to the application's Gemfile by executing:
|
30
|
+
|
31
|
+
```shell
|
32
|
+
bundle add discovery_v1
|
33
|
+
```
|
34
|
+
|
35
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
36
|
+
|
37
|
+
```shell
|
38
|
+
gem install discovery_v1
|
39
|
+
```
|
40
|
+
|
41
|
+
## Examples
|
42
|
+
|
43
|
+
TODO
|
44
|
+
|
45
|
+
## Important links
|
46
|
+
|
47
|
+
### DiscoveryV1 documenation
|
48
|
+
|
49
|
+
This Gem's YARD documentation is hosted on [rubydoc.info](https://rubydoc.info/gems/discovery_v1/).
|
50
|
+
|
51
|
+
### General API documentation
|
52
|
+
|
53
|
+
* [Google Discovery API Overview](https://developers.google.com/discovery/v1/getting_started)
|
54
|
+
* [Google Discovery API Reference](https://developers.google.com/discovery/v1/reference)
|
55
|
+
|
56
|
+
### Ruby implementation of the Discovery API
|
57
|
+
|
58
|
+
* [DiscoveryService Class](https://github.com/googleapis/google-api-ruby-client/blob/main/generated/google-apis-discovery_v1/lib/google/apis/discovery_v1/service.rb)
|
59
|
+
* [All Other Discovery Classes](https://github.com/googleapis/google-api-ruby-client/blob/main/generated/google-apis-discovery_v1/lib/google/apis/discovery_v1/classes.rb)
|
60
|
+
|
61
|
+
## Usage
|
62
|
+
|
63
|
+
[Detailed API documenation](https://rubydoc.info/gems/discovery_v1/) is hosted on rubygems.org.
|
64
|
+
|
65
|
+
### Obtaining a DiscoveryService
|
66
|
+
|
67
|
+
No credential file is needed to access the discovery service.
|
68
|
+
|
69
|
+
```Ruby
|
70
|
+
discovery_service = DiscoveryV1.discovery_service
|
71
|
+
```
|
72
|
+
|
73
|
+
### Downloading an API discovery document
|
74
|
+
|
75
|
+
The Discovery API provides a list of Google APIs and a machine-readable "Discovery
|
76
|
+
Document" for each API. Both capabilities are provided by
|
77
|
+
[`Google::Apis::DirectoryV1::DirectoryService`](https://rubydoc.info/gems/google-apis-discovery_v1/Google/Apis/DiscoveryV1/DiscoveryService)
|
78
|
+
instance methods:
|
79
|
+
|
80
|
+
* [`#list_apis`](https://rubydoc.info/gems/google-apis-discovery_v1/Google/Apis/DiscoveryV1/DiscoveryService#list_apis-instance_method)
|
81
|
+
returns the list of supported APIs
|
82
|
+
* [`#get_rest_api`](https://rubydoc.info/gems/google-apis-discovery_v1/Google/Apis/DiscoveryV1/DiscoveryService#get_rest_api-instance_method)
|
83
|
+
returns the "discovery document" which is a description of a particular version
|
84
|
+
of an api
|
85
|
+
|
86
|
+
Each discovery document includes schemas for the objects that can be passed as
|
87
|
+
parameters to methods in that API.
|
88
|
+
|
89
|
+
### Validating API objects
|
90
|
+
|
91
|
+
This gem can use the schemas that are part of a discovery document to validate
|
92
|
+
objects that parameters to an API method call.
|
93
|
+
|
94
|
+
This can be helpful to troubleshoot invalid requests since requests can become
|
95
|
+
very large and complex.
|
96
|
+
|
97
|
+
The [`DiscoveryV4.validate_object`](https://todo.com)
|
98
|
+
method can be used to validate a request object before an API call. This method
|
99
|
+
requires the following information:
|
100
|
+
|
101
|
+
1. the Discovery Document returned from `DirectoryService#get_read_api`
|
102
|
+
2. the name of the schema for the object being validated (must be one returned from `DirectoryService.object_schema_names`)
|
103
|
+
3. the object being validated
|
104
|
+
|
105
|
+
For example, in the Google Sheets API, speradsheets are often updated by calling
|
106
|
+
`SheetsService#batch_update_spreadsheet`. This API method requires a
|
107
|
+
`BatchUpdateSpreadsheetRequest` object.
|
108
|
+
|
109
|
+
Here is an example that builds a request to write the value 'A' to cell A1 but it
|
110
|
+
contains an error (see if you can spot the error):
|
111
|
+
|
112
|
+
```Ruby
|
113
|
+
require 'discovery_v1'
|
114
|
+
|
115
|
+
batch_update_spreadsheet_request = {
|
116
|
+
requests: [
|
117
|
+
{
|
118
|
+
update_cells: {
|
119
|
+
rows: [
|
120
|
+
{ values: [ { user_entered_value: { string_value: 'A' } } ] }
|
121
|
+
],
|
122
|
+
fields: '*',
|
123
|
+
start: { sheet_id: 0, row_index: '1', column_index: 'A' }
|
124
|
+
}
|
125
|
+
}
|
126
|
+
],
|
127
|
+
response_include_grid_data: false
|
128
|
+
}
|
129
|
+
|
130
|
+
api_name = 'sheets'
|
131
|
+
api_version = 'v4'
|
132
|
+
discovery_service = DiscoveryV1.discovery_service
|
133
|
+
rest_description = discovery_service.get_rest_api(api_name, api_version)
|
134
|
+
schema_name = 'batch_update_spreadsheet_request'
|
135
|
+
|
136
|
+
begin
|
137
|
+
DiscoveryV1.validate_object(rest_description:, schema_name:, object: batch_update_spreadsheet_request)
|
138
|
+
rescue => e
|
139
|
+
puts e.message
|
140
|
+
end
|
141
|
+
```
|
142
|
+
|
143
|
+
Running this example shows the following output:
|
144
|
+
|
145
|
+
```Text
|
146
|
+
Object does not conform to batch_update_spreadsheet_request: value at `/requests/0/update_cells/start/row_index` is not an integer
|
147
|
+
```
|
148
|
+
|
149
|
+
The [`DiscoveryV1.validate_object`](https://rubydoc.info/gems/discovery_v1/DiscoveryV1#validate_object-class_method)
|
150
|
+
method can be used to validate objects prior to using them in a Google API request
|
151
|
+
described by the Discovery service.
|
152
|
+
|
153
|
+
This method takes a `schema_name` and an `object` to validate. Schema names for a
|
154
|
+
schema can be listed using
|
155
|
+
[`DiscoveryV1.object_schema_names`](https://rubydoc.info/gems/discovery_v1/DiscoveryV1#object_schema_names-class_method).
|
156
|
+
|
157
|
+
`validate_object` will either return `true` if `object` conforms to the schema OR it
|
158
|
+
will raise a RuntimeError noting where the object structure did not conform to
|
159
|
+
the schema. `RuntimeError#message` will give details about where the structure did
|
160
|
+
not conform.
|
161
|
+
|
162
|
+
## Development
|
163
|
+
|
164
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
165
|
+
|
166
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
167
|
+
|
168
|
+
## Contributing
|
169
|
+
|
170
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/discovery_v1. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/discovery_v1/blob/main/CODE_OF_CONDUCT.md).
|
171
|
+
|
172
|
+
## License
|
173
|
+
|
174
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
175
|
+
|
176
|
+
## Code of Conduct
|
177
|
+
|
178
|
+
Everyone interacting in the DiscoveryV1 project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/discovery_v1/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
desc 'Run the same tasks that the CI build will run'
|
4
|
+
if RUBY_PLATFORM == 'java'
|
5
|
+
task default: %w[spec rubocop bundle:audit build]
|
6
|
+
else
|
7
|
+
task default: %w[spec rubocop yard bundle:audit build]
|
8
|
+
end
|
9
|
+
|
10
|
+
# Bundler Audit
|
11
|
+
|
12
|
+
require 'bundler/audit/task'
|
13
|
+
Bundler::Audit::Task.new
|
14
|
+
|
15
|
+
# Bundler Gem Build
|
16
|
+
|
17
|
+
require 'bundler'
|
18
|
+
require 'bundler/gem_tasks'
|
19
|
+
|
20
|
+
begin
|
21
|
+
Bundler.setup(:default, :development)
|
22
|
+
rescue Bundler::BundlerError => e
|
23
|
+
warn e.message
|
24
|
+
warn 'Run `bundle install` to install missing gems'
|
25
|
+
exit e.status_code
|
26
|
+
end
|
27
|
+
|
28
|
+
CLEAN << 'pkg'
|
29
|
+
CLEAN << 'Gemfile.lock'
|
30
|
+
|
31
|
+
# RSpec
|
32
|
+
|
33
|
+
require 'rspec/core/rake_task'
|
34
|
+
|
35
|
+
RSpec::Core::RakeTask.new do
|
36
|
+
if RUBY_PLATFORM == 'java'
|
37
|
+
ENV['JAVA_OPTS'] = '-Djdk.io.File.enableADS=true'
|
38
|
+
ENV['JRUBY_OPTS'] = '--debug'
|
39
|
+
ENV['NOCOV'] = 'TRUE'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
CLEAN << 'coverage'
|
44
|
+
CLEAN << '.rspec_status'
|
45
|
+
CLEAN << 'rspec-report.xml'
|
46
|
+
|
47
|
+
# Rubocop
|
48
|
+
|
49
|
+
require 'rubocop/rake_task'
|
50
|
+
|
51
|
+
RuboCop::RakeTask.new do |t|
|
52
|
+
t.options = %w[
|
53
|
+
--display-cop-names
|
54
|
+
--display-style-guide
|
55
|
+
--extra-details
|
56
|
+
--format progress
|
57
|
+
--format json --out rubocop-report.json
|
58
|
+
]
|
59
|
+
end
|
60
|
+
|
61
|
+
CLEAN << 'rubocop-report.json'
|
62
|
+
|
63
|
+
unless RUBY_PLATFORM == 'java'
|
64
|
+
# yard:build
|
65
|
+
|
66
|
+
require 'yard'
|
67
|
+
|
68
|
+
YARD::Rake::YardocTask.new('yard:build') do |t|
|
69
|
+
t.files = %w[lib/**/*.rb]
|
70
|
+
t.stats_options = ['--list-undoc']
|
71
|
+
end
|
72
|
+
|
73
|
+
CLEAN << '.yardoc'
|
74
|
+
CLEAN << 'doc'
|
75
|
+
|
76
|
+
# yard:audit
|
77
|
+
|
78
|
+
desc 'Run yardstick to show missing YARD doc elements'
|
79
|
+
task :'yard:audit' do
|
80
|
+
sh "yardstick 'lib/**/*.rb'"
|
81
|
+
end
|
82
|
+
|
83
|
+
# yard:coverage
|
84
|
+
|
85
|
+
require 'yardstick/rake/verify'
|
86
|
+
|
87
|
+
Yardstick::Rake::Verify.new(:'yard:coverage') do |verify|
|
88
|
+
verify.threshold = 100
|
89
|
+
verify.require_exact_threshold = false
|
90
|
+
end
|
91
|
+
|
92
|
+
task yard: %i[yard:build yard:audit yard:coverage]
|
93
|
+
|
94
|
+
# github-pages:publish
|
95
|
+
|
96
|
+
require 'github_pages_rake_tasks'
|
97
|
+
GithubPagesRakeTasks::PublishTask.new do |task|
|
98
|
+
# task.doc_dir = 'documentation'
|
99
|
+
task.verbose = true
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'discovery_v1'
|
5
|
+
|
6
|
+
print 'API name [sheets]: '
|
7
|
+
api_name = gets.chomp
|
8
|
+
api_name = 'sheets' if api_name.empty?
|
9
|
+
|
10
|
+
print 'API version [v4]: '
|
11
|
+
api_version = gets.chomp
|
12
|
+
api_version = 'v4' if api_version.empty?
|
13
|
+
|
14
|
+
discovery_service = DiscoveryV1.discovery_service
|
15
|
+
rest_description = discovery_service.get_rest_api(api_name, api_version)
|
16
|
+
|
17
|
+
pp DiscoveryV1.object_schema_names(rest_description:)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'discovery_v1'
|
5
|
+
|
6
|
+
batch_update_spreadsheet_request = {
|
7
|
+
requests: [
|
8
|
+
{
|
9
|
+
update_cells: {
|
10
|
+
rows: [
|
11
|
+
{ values: [{ user_entered_value: { string_value: 'A' } }] }
|
12
|
+
],
|
13
|
+
fields: '*',
|
14
|
+
start: { sheet_id: 0, column_index: 'A', row_index: 1 }
|
15
|
+
}
|
16
|
+
}
|
17
|
+
],
|
18
|
+
response_include_grid_data: false
|
19
|
+
}
|
20
|
+
|
21
|
+
api_name = 'sheets'
|
22
|
+
api_version = 'v4'
|
23
|
+
discovery_service = DiscoveryV1.discovery_service
|
24
|
+
rest_description = discovery_service.get_rest_api(api_name, api_version)
|
25
|
+
schema_name = 'batch_update_spreadsheet_request'
|
26
|
+
|
27
|
+
begin
|
28
|
+
DiscoveryV1.validate_object(rest_description:, schema_name:, object: batch_update_spreadsheet_request)
|
29
|
+
puts 'Object is valid'
|
30
|
+
rescue RuntimeError => e
|
31
|
+
puts e.message
|
32
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'google/apis/discovery_v1'
|
4
|
+
require 'discovery_v1'
|
5
|
+
|
6
|
+
# Google extensions
|
7
|
+
module Google
|
8
|
+
# Google::Apis extensions
|
9
|
+
module Apis
|
10
|
+
# Google::Apis::DiscoveryV1 extensions
|
11
|
+
module DiscoveryV1
|
12
|
+
# Extensions to the Google::Apis::DiscoveryV1::RestDescription class
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# require 'discovery_v1/google_extensions'
|
16
|
+
# rest_description = DiscoveryV1.discovery_service.get_rest_api('sheets', 'v4')
|
17
|
+
# schema = 'batch_update_spreadsheet_request'
|
18
|
+
#
|
19
|
+
# # This is a valid object for the schema -- you'll probably have something
|
20
|
+
# # more interesting
|
21
|
+
# object = { 'requests' => [] }
|
22
|
+
#
|
23
|
+
# # These are the extensions:
|
24
|
+
# rest_description.validate_object(schema_name:, object: { 'requests' => [] })
|
25
|
+
# rest_description.object_schema_names #=> ["add_banding_request", "add_banding_response", ...]
|
26
|
+
#
|
27
|
+
# @api public
|
28
|
+
#
|
29
|
+
class RestDescription
|
30
|
+
# Validate the object using the named JSON schema
|
31
|
+
#
|
32
|
+
# The JSON schemas are loaded from the Google Disocvery API. The schemas names are
|
33
|
+
# returned by `DiscoveryV1.api_object_schema_names`.
|
34
|
+
#
|
35
|
+
# @example
|
36
|
+
# schema_name = 'batch_update_spreadsheet_request'
|
37
|
+
# object = { 'requests' => [] }
|
38
|
+
# DiscoveryV1.validate_api_object(schema_name:, object:)
|
39
|
+
#
|
40
|
+
# @param schema_name [String] the name of the schema to validate against
|
41
|
+
# @param object [Object] the object to validate
|
42
|
+
# @param logger [Logger] the logger to use for logging error, info, and debug message
|
43
|
+
#
|
44
|
+
# @raise [RuntimeError] if the object does not conform to the schema
|
45
|
+
#
|
46
|
+
# @return [void]
|
47
|
+
#
|
48
|
+
def validate_object(schema_name:, object:, logger: Logger.new(nil))
|
49
|
+
::DiscoveryV1::Validation::ValidateObject.new(rest_description: self, logger:).call(schema_name:, object:)
|
50
|
+
end
|
51
|
+
|
52
|
+
# List the names of the schemas available to use in the Google Discovery V1 API
|
53
|
+
#
|
54
|
+
# @example List the name of the schemas available
|
55
|
+
# rest_description = DiscoveryV1.discovery_service.get_rest_api('sheets', 'v4')
|
56
|
+
# DiscoveryV1.api_object_schema_names #=> ["add_banding_request", "add_banding_response", ...]
|
57
|
+
#
|
58
|
+
# @param logger [Logger] the logger to use for logging error, info, and debug message
|
59
|
+
#
|
60
|
+
# @return [Array<String>] the names of the schemas available
|
61
|
+
#
|
62
|
+
def object_schema_names(logger: Logger.new(nil))
|
63
|
+
::DiscoveryV1::Validation::LoadSchemas.new(rest_description: self, logger:).call.keys.sort
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|