Skip to content

Commit 096573e

Browse files
authored
Replace manual Vision library with GAPIC and helpers (googleapis#1959)
This PR replaces the existing Vision client library with an autogenerated library supplemented with helpers, following the reference of [NodeJS](https://github.com/googleapis/nodejs-vision) and [Python](https://github.com/GoogleCloudPlatform/google-cloud-python/tree/master/vision). As such, it substantially changes the public surface. (See also googleapis#1828 for analogous change to Language.)
1 parent b6fc30a commit 096573e

90 files changed

Lines changed: 1088 additions & 14077 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

acceptance/data/file.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
expected content

google-cloud-vision/.autotest

Lines changed: 0 additions & 15 deletions
This file was deleted.

google-cloud-vision/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ jsondoc/*
77

88
# Ignore YARD stuffs
99
.yardoc
10+
11+
# IDE settings
12+
.idea
13+
*.iml

google-cloud-vision/.rubocop.yml

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
AllCops:
22
Exclude:
3-
- "acceptance/**/*"
4-
- "support/**/*"
53
- "google-cloud-vision.gemspec"
4+
- "lib/google/cloud/vision.rb"
5+
- "lib/google/cloud/vision/*"
6+
- "lib/google/cloud/vision/v1/*pb.rb"
7+
- "lib/google/cloud/vision/v1/image_annotator_client.rb"
8+
- "lib/google/cloud/vision/v1/doc/**/*"
69
- "Rakefile"
7-
- "lib/google/cloud/vision/v1.rb"
8-
- "lib/google/cloud/vision/v1/**/*"
9-
- "test/**/*"
10+
- "test/**/*client_test.rb"
11+
- "acceptance/**/*smoke_test.rb"
1012

1113
Documentation:
1214
Enabled: false
@@ -15,26 +17,15 @@ Style/StringLiterals:
1517
EnforcedStyle: double_quotes
1618
Style/MethodDefParentheses:
1719
EnforcedStyle: require_no_parentheses
18-
Style/TrivialAccessors:
19-
Enabled: false
20-
Style/FormatStringToken: # we have many uses of this, we don't want to change
21-
Enabled: false
20+
Metrics/BlockLength:
21+
Exclude:
22+
- "acceptance/google/cloud/vision/v1/image_annotator_feature_methods_test.rb"
23+
- "test/**/*"
2224
Metrics/CyclomaticComplexity:
2325
Max: 10
2426
Metrics/PerceivedComplexity:
2527
Max: 10
2628
Metrics/AbcSize:
2729
Max: 25
28-
Metrics/ClassLength:
29-
Enabled: false
3030
Metrics/MethodLength:
31-
Max: 20
32-
Exclude:
33-
- "lib/google/cloud/vision.rb"
34-
Metrics/ParameterLists:
35-
Enabled: false
36-
Layout/EmptyLines: # for the extra line between copyright and code
37-
Enabled: false
38-
Naming/FileName:
39-
Exclude:
40-
- "lib/google-cloud-vision.rb"
31+
Max: 25

google-cloud-vision/.yardopts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--no-private
2-
--title=Google Cloud Vision
3-
--exclude lib/google/cloud/vision/v1.rb
2+
--title=Google Cloud Vision API
3+
--exclude _pb\.rb$
44
--markup markdown
55

66
./lib/**/*.rb

google-cloud-vision/Gemfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ gemspec
55
gem "gcloud-jsondoc",
66
git: "https://github.com/GoogleCloudPlatform/google-cloud-ruby.git",
77
branch: "gcloud-jsondoc"
8-
gem "google-cloud-core", path: "../google-cloud-core"
9-
gem "google-cloud-env", path: "../google-cloud-env"
10-
gem "google-cloud-storage", path: "../google-cloud-storage"
8+
119
# WORKAROUND: builds are having problems since the release of 3.0.0
1210
# pin to the last known good version
1311
gem "public_suffix", "~> 2.0"

google-cloud-vision/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Apache License
1+
Apache License
22
Version 2.0, January 2004
33
https://www.apache.org/licenses/
44

google-cloud-vision/README.md

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,42 @@
1-
# google-cloud-vision
1+
# Ruby Client for Google Cloud Vision API ([Alpha](https://github.com/GoogleCloudPlatform/google-cloud-ruby#versioning))
22

3-
[Google Cloud Vision](https://cloud.google.com/vision/) ([docs](https://cloud.google.com/vision/docs)) allows developers to easily integrate vision detection features within applications, including image labeling, face and landmark detection, optical character recognition (OCR), and tagging of explicit content.
4-
5-
- [google-cloud-vision API documentation](http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-vision/latest)
6-
- [google-cloud-vision on RubyGems](https://rubygems.org/gems/google-cloud-vision)
7-
- [Google Cloud Vision documentation](https://cloud.google.com/vision/docs)
3+
[Google Cloud Vision API][Product Documentation]:
4+
Integrates Google Vision features, including image labeling, face, logo, and
5+
landmark detection, optical character recognition (OCR), and detection of
6+
explicit content, into applications.
7+
- [Client Library Documentation][]
8+
- [Product Documentation][]
89

910
## Quick Start
11+
In order to use this library, you first need to go through the following
12+
steps:
13+
14+
1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project)
15+
2. [Enable billing for your project.](https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project)
16+
3. [Enable the Google Cloud Vision API.](https://console.cloud.google.com/apis/api/vision)
17+
4. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud/master/guides/authentication)
1018

11-
```sh
19+
### Installation
20+
```
1221
$ gem install google-cloud-vision
1322
```
1423

15-
## Authentication
16-
17-
This library uses Service Account credentials to connect to Google Cloud services. When running on Compute Engine the credentials will be discovered automatically. When running on other environments the Service Account credentials can be specified by providing the path to the JSON file, or the JSON itself, in environment variables.
18-
19-
Instructions and configuration options are covered in the [Authentication Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-vision/guides/authentication).
20-
21-
## Example
22-
23-
```ruby
24+
### Preview
25+
#### ImageAnnotatorClient
26+
```rb
2427
require "google/cloud/vision"
2528

26-
vision = Google::Cloud::Vision.new
27-
28-
image = vision.image "path/to/landmark.jpg"
29-
30-
landmark = image.landmark
31-
landmark.description #=> "Mount Rushmore"
29+
image_annotator_client = Google::Cloud::Vision.new
30+
landmarks = image_annotator_client.landmark_detection("path/to/landmark.jpg")
3231
```
3332

34-
## Supported Ruby Versions
35-
36-
This library is supported on Ruby 2.0+.
37-
38-
## Versioning
39-
40-
This library follows [Semantic Versioning](http://semver.org/).
41-
42-
It is currently in major version zero (0.y.z), which means that anything may change at any time and the public API should not be considered stable.
43-
44-
## Contributing
45-
46-
Contributions to this library are always welcome and highly encouraged.
47-
48-
See the [Contributing Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/guides/contributing) for more information on how to get started.
49-
50-
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See [Code of Conduct](../CODE_OF_CONDUCT.md) for more information.
51-
52-
## License
53-
54-
This library is licensed under Apache 2.0. Full license text is available in [LICENSE](LICENSE).
55-
56-
## Support
33+
### Next Steps
34+
- Read the [Client Library Documentation][] for Google Cloud Vision API
35+
to see other available methods on the client.
36+
- Read the [Google Cloud Vision API Product documentation][Product Documentation]
37+
to learn more about the product and see How-to Guides.
38+
- View this [repository's main README](https://github.com/GoogleCloudPlatform/google-cloud-ruby/blob/master/README.md)
39+
to see the full list of Cloud APIs that we cover.
5740

58-
Please [report bugs at the project on Github](https://github.com/GoogleCloudPlatform/google-cloud-ruby/issues).
59-
Don't hesitate to [ask questions](http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby) about the client or APIs on [StackOverflow](http://stackoverflow.com).
41+
[Client Library Documentation]: https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-vision/latest/google/cloud/vision/v1
42+
[Product Documentation]: https://cloud.google.com/vision

google-cloud-vision/Rakefile

Lines changed: 61 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# Copyright 2018 Google LLC
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# https://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
114
require "bundler/setup"
215
require "bundler/gem_tasks"
316

@@ -7,97 +20,91 @@ RuboCop::RakeTask.new
720
desc "Run tests."
821
task :test do
922
$LOAD_PATH.unshift "lib", "test"
10-
Dir.glob("test/**/*_test.rb").each { |file| require_relative file }
23+
Dir.glob("test/**/*test.rb")
24+
.reject { |file| file.include? "smoke_test" }
25+
.each { |file| require_relative file }
1126
end
1227

1328
namespace :test do
14-
desc "Run tests with coverage."
29+
desc "Runs tests with coverage."
1530
task :coverage do
1631
require "simplecov"
1732
SimpleCov.start do
1833
command_name "google-cloud-vision"
1934
track_files "lib/**/*.rb"
2035
add_filter "test/"
21-
add_filter "lib/google/cloud/vision/v1/"
2236
end
2337

2438
Rake::Task["test"].invoke
2539
end
2640
end
2741

42+
desc "Runs the smoke tests."
43+
task :smoke_test do
44+
$LOAD_PATH.unshift "lib", "smoke_test"
45+
Dir.glob("acceptance/**/*smoke_test.rb").each { |file| require_relative file }
46+
end
47+
48+
namespace :smoke_test do
49+
desc "Runs smoke tests with coverage."
50+
task :coverage do
51+
require "simplecov"
52+
SimpleCov.start do
53+
command_name "google-cloud-vision"
54+
track_files "lib/**/*.rb"
55+
add_filter "test/"
56+
end
57+
58+
Rake::Task["smoke_test"].invoke
59+
end
60+
end
61+
2862
# Acceptance tests
29-
desc "Run the vision acceptance tests."
63+
desc "Run the google-cloud-vision acceptance tests."
3064
task :acceptance, :project, :keyfile do |t, args|
3165
project = args[:project]
32-
project ||= ENV["VISION_TEST_PROJECT"] || ENV["GCLOUD_TEST_PROJECT"]
66+
project ||=
67+
ENV["VISION_TEST_PROJECT"] ||
68+
ENV["GCLOUD_TEST_PROJECT"]
3369
keyfile = args[:keyfile]
34-
keyfile ||= ENV["VISION_TEST_KEYFILE"] || ENV["GCLOUD_TEST_KEYFILE"]
70+
keyfile ||=
71+
ENV["VISION_TEST_KEYFILE"] ||
72+
ENV["GCLOUD_TEST_KEYFILE"]
3573
if keyfile
3674
keyfile = File.read keyfile
3775
else
38-
keyfile ||= ENV["VISION_TEST_KEYFILE_JSON"] || ENV["GCLOUD_TEST_KEYFILE_JSON"]
76+
keyfile ||=
77+
ENV["VISION_TEST_KEYFILE_JSON"] ||
78+
ENV["GCLOUD_TEST_KEYFILE_JSON"]
3979
end
4080
if project.nil? || keyfile.nil?
4181
fail "You must provide a project and keyfile. e.g. rake acceptance[test123, /path/to/keyfile.json] or VISION_TEST_PROJECT=test123 VISION_TEST_KEYFILE=/path/to/keyfile.json rake acceptance"
4282
end
43-
# clear any env var already set
4483
require "google/cloud/vision/credentials"
4584
(Google::Cloud::Vision::Credentials::PATH_ENV_VARS +
4685
Google::Cloud::Vision::Credentials::JSON_ENV_VARS).each do |path|
4786
ENV[path] = nil
4887
end
49-
require "google/cloud/storage/credentials"
50-
(Google::Cloud::Storage::Credentials::PATH_ENV_VARS +
51-
Google::Cloud::Storage::Credentials::JSON_ENV_VARS).each do |path|
52-
ENV[path] = nil
53-
end
54-
# always overwrite when running tests
5588
ENV["VISION_PROJECT"] = project
89+
ENV["VISION_TEST_PROJECT"] = project
5690
ENV["VISION_KEYFILE_JSON"] = keyfile
57-
ENV["STORAGE_PROJECT"] = project
58-
ENV["STORAGE_KEYFILE_JSON"] = keyfile
5991

6092
Rake::Task["acceptance:run"].invoke
6193
end
6294

6395
namespace :acceptance do
64-
desc "Run acceptance tests with coverage."
65-
task :coverage, :project, :keyfile do |t, args|
66-
require "simplecov"
67-
SimpleCov.start do
68-
command_name "google-cloud-vision"
69-
track_files "lib/**/*.rb"
70-
add_filter "acceptance/"
71-
end
72-
73-
Rake::Task["acceptance"].invoke
74-
end
75-
7696
task :run do
7797
$LOAD_PATH.unshift "lib", "acceptance"
7898
Dir.glob("acceptance/**/*_test.rb").each { |file| require_relative file }
7999
end
80-
end
81-
82-
desc "Run yard-doctest example tests."
83-
task doctest: :yard do
84-
sh "bundle exec yard config -a autoload_plugins yard-doctest"
85-
sh "bundle exec yard doctest"
86-
end
87-
88-
desc "Start an interactive shell."
89-
task :console do
90-
require "irb"
91-
require "irb/completion"
92-
require "pp"
93-
94-
$LOAD_PATH.unshift "lib"
95100

96-
require "google-cloud-vision"
97-
def gcloud; @gcloud ||= Google::Cloud.new; end
101+
desc "Run acceptance tests with coverage."
102+
task :coverage do
103+
end
98104

99-
ARGV.clear
100-
IRB.start
105+
desc "Run acceptance cleanup."
106+
task :cleanup do
107+
end
101108
end
102109

103110
require "yard"
@@ -128,10 +135,6 @@ task :jsondoc => :yard do
128135
{
129136
title: "Google::Rpc",
130137
include: ["google/rpc"]
131-
},
132-
{
133-
title: "Google::Type",
134-
include: ["google/type"]
135138
}
136139
]
137140
}
@@ -143,7 +146,12 @@ task :jsondoc => :yard do
143146
generate: toc_config
144147
rm_rf "jsondoc", verbose: true
145148
generator.write_to "jsondoc"
146-
cp ["docs/authentication.md", "docs/toc.json"], "jsondoc", verbose: true
149+
cp ["docs/toc.json"], "jsondoc", verbose: true
150+
end
151+
152+
desc "Run yard-doctest example tests."
153+
task :doctest do
154+
puts "The google-cloud-vision gem does not have doctest tests."
147155
end
148156

149157
desc "Run the CI build"
@@ -158,6 +166,7 @@ task :ci do
158166
header "google-cloud-vision test", "*"
159167
sh "bundle exec rake test"
160168
end
169+
161170
namespace :ci do
162171
desc "Run the CI build, with acceptance tests."
163172
task :acceptance do

0 commit comments

Comments
 (0)