google-cloud-vision 0.31.0 → 0.32.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.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +2 -9
  3. data/LICENSE +1 -1
  4. data/README.md +94 -0
  5. data/lib/google/cloud/vision.rb +200 -535
  6. data/lib/google/cloud/vision/v1.rb +129 -55
  7. data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/image_annotator.rb +9 -0
  8. data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/product_search.rb +88 -0
  9. data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/product_search_service.rb +539 -0
  10. data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/text_annotation.rb +3 -3
  11. data/lib/google/cloud/vision/v1/doc/google/cloud/vision/v1/web_detection.rb +2 -1
  12. data/lib/google/cloud/vision/{version.rb → v1/doc/google/protobuf/empty.rb} +13 -6
  13. data/lib/google/cloud/vision/v1/doc/google/protobuf/field_mask.rb +230 -0
  14. data/lib/google/cloud/vision/v1/doc/google/protobuf/timestamp.rb +109 -0
  15. data/lib/google/cloud/vision/v1/geometry_pb.rb +1 -0
  16. data/lib/google/cloud/vision/v1/helpers.rb +972 -0
  17. data/lib/google/cloud/vision/v1/image_annotator_client.rb +4 -4
  18. data/lib/google/cloud/vision/v1/image_annotator_pb.rb +5 -0
  19. data/lib/google/cloud/vision/v1/image_annotator_services_pb.rb +2 -1
  20. data/lib/google/cloud/vision/v1/product_search_client.rb +1337 -0
  21. data/lib/google/cloud/vision/v1/product_search_client_config.json +116 -0
  22. data/lib/google/cloud/vision/v1/product_search_pb.rb +45 -0
  23. data/lib/google/cloud/vision/v1/product_search_service_pb.rb +191 -0
  24. data/lib/google/cloud/vision/v1/product_search_service_services_pb.rb +224 -0
  25. data/lib/google/cloud/vision/v1p3beta1.rb +233 -0
  26. data/lib/google/cloud/vision/v1p3beta1/credentials.rb +42 -0
  27. data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/geometry.rb +72 -0
  28. data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/image_annotator.rb +763 -0
  29. data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/product_search.rb +154 -0
  30. data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/product_search_service.rb +533 -0
  31. data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/text_annotation.rb +254 -0
  32. data/lib/google/cloud/vision/v1p3beta1/doc/google/cloud/vision/v1p3beta1/web_detection.rb +101 -0
  33. data/lib/google/cloud/vision/v1p3beta1/doc/google/longrunning/operations.rb +93 -0
  34. data/lib/google/cloud/vision/v1p3beta1/doc/google/protobuf/any.rb +130 -0
  35. data/lib/google/cloud/vision/v1p3beta1/doc/google/protobuf/empty.rb +29 -0
  36. data/lib/google/cloud/vision/v1p3beta1/doc/google/protobuf/field_mask.rb +230 -0
  37. data/lib/google/cloud/vision/v1p3beta1/doc/google/protobuf/timestamp.rb +109 -0
  38. data/lib/google/cloud/vision/v1p3beta1/doc/google/protobuf/wrappers.rb +90 -0
  39. data/lib/google/cloud/vision/v1p3beta1/doc/google/rpc/status.rb +84 -0
  40. data/lib/google/cloud/vision/v1p3beta1/doc/google/type/color.rb +156 -0
  41. data/lib/google/cloud/vision/v1p3beta1/doc/google/type/latlng.rb +65 -0
  42. data/lib/google/cloud/vision/v1p3beta1/geometry_pb.rb +43 -0
  43. data/lib/google/cloud/vision/v1p3beta1/helpers.rb +972 -0
  44. data/lib/google/cloud/vision/v1p3beta1/image_annotator_client.rb +302 -0
  45. data/lib/google/cloud/vision/v1p3beta1/image_annotator_client_config.json +36 -0
  46. data/lib/google/cloud/vision/v1p3beta1/image_annotator_pb.rb +304 -0
  47. data/lib/google/cloud/vision/v1p3beta1/image_annotator_services_pb.rb +55 -0
  48. data/lib/google/cloud/vision/v1p3beta1/product_search_client.rb +1351 -0
  49. data/lib/google/cloud/vision/v1p3beta1/product_search_client_config.json +116 -0
  50. data/lib/google/cloud/vision/v1p3beta1/product_search_pb.rb +64 -0
  51. data/lib/google/cloud/vision/v1p3beta1/product_search_service_pb.rb +191 -0
  52. data/lib/google/cloud/vision/v1p3beta1/product_search_service_services_pb.rb +222 -0
  53. data/lib/google/cloud/vision/v1p3beta1/text_annotation_pb.rb +94 -0
  54. data/lib/google/cloud/vision/v1p3beta1/web_detection_pb.rb +51 -0
  55. metadata +53 -122
  56. data/AUTHENTICATION.md +0 -179
  57. data/CHANGELOG.md +0 -109
  58. data/CODE_OF_CONDUCT.md +0 -40
  59. data/CONTRIBUTING.md +0 -188
  60. data/LOGGING.md +0 -32
  61. data/OVERVIEW.md +0 -202
  62. data/TROUBLESHOOTING.md +0 -37
  63. data/lib/google-cloud-vision.rb +0 -146
  64. data/lib/google/cloud/vision/annotate.rb +0 -303
  65. data/lib/google/cloud/vision/annotation.rb +0 -553
  66. data/lib/google/cloud/vision/annotation/crop_hint.rb +0 -126
  67. data/lib/google/cloud/vision/annotation/entity.rb +0 -225
  68. data/lib/google/cloud/vision/annotation/face.rb +0 -1497
  69. data/lib/google/cloud/vision/annotation/normalized_vertex.rb +0 -76
  70. data/lib/google/cloud/vision/annotation/object_localization.rb +0 -115
  71. data/lib/google/cloud/vision/annotation/properties.rb +0 -220
  72. data/lib/google/cloud/vision/annotation/safe_search.rb +0 -153
  73. data/lib/google/cloud/vision/annotation/text.rb +0 -1015
  74. data/lib/google/cloud/vision/annotation/vertex.rb +0 -91
  75. data/lib/google/cloud/vision/annotation/web.rb +0 -420
  76. data/lib/google/cloud/vision/credentials.rb +0 -57
  77. data/lib/google/cloud/vision/image.rb +0 -832
  78. data/lib/google/cloud/vision/location.rb +0 -98
  79. data/lib/google/cloud/vision/project.rb +0 -367
  80. data/lib/google/cloud/vision/service.rb +0 -83
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b97dd452706561fd304da05cf2572636618d8695e0d13e9db8fe0e000cd3a876
4
- data.tar.gz: d1c466ff99ff655bb881d382e444846605a927a5820e2645f2068cd5a8e053b3
3
+ metadata.gz: 9f8e0d1755f74466a7f690802a403fe5188c3fea88c7909837e1064d892a936a
4
+ data.tar.gz: c2964cf1822eb5a8322a77d375330bc08c9387556104b65ed15d082965a6d3f6
5
5
  SHA512:
6
- metadata.gz: d12d2ecd9e3c996af934dff0ae9508a377cb373ba92852d2b7c3aff0e6e34039403f0f54c5ba15f05c911ea490c80794aef2d3a7eac70ab5842377bec9567260
7
- data.tar.gz: ed0e16cb06817bb8cecaf574247e44466db8c4f1f96d2c064ef3bfb17c5e37b6df75310bacebc2f58bc7841fd25bce38f27ce5bd2e6fbe52d2c8a0c22a304cc2
6
+ metadata.gz: 4a0b49386304f05fc46c76b1983912e1499379925485503f49c6481d7c577fcedfd70a66ceed9b10211debfdbbe6705db1ca3a187e3929367b673f46fa66ecab
7
+ data.tar.gz: d59ff7b92bcae64f6f20714ea9609ef9e73c4bb591692e6ebb7770172cbadd1ff7613a4b4574828a0279b084d83cf1a290a123998b45718bf0b97f332c475973
data/.yardopts CHANGED
@@ -1,17 +1,10 @@
1
1
  --no-private
2
- --title=Google Cloud Vision
2
+ --title=Cloud Vision API
3
3
  --exclude _pb\.rb$
4
4
  --markup markdown
5
5
  --markup-provider redcarpet
6
- --main OVERVIEW.md
7
6
 
8
7
  ./lib/**/*.rb
9
8
  -
10
- OVERVIEW.md
11
- AUTHENTICATION.md
12
- LOGGING.md
13
- CONTRIBUTING.md
14
- TROUBLESHOOTING.md
15
- CHANGELOG.md
16
- CODE_OF_CONDUCT.md
9
+ README.md
17
10
  LICENSE
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Apache License
1
+ Apache License
2
2
  Version 2.0, January 2004
3
3
  https://www.apache.org/licenses/
4
4
 
@@ -0,0 +1,94 @@
1
+ # Ruby Client for Cloud Vision API ([Alpha](https://github.com/googleapis/google-cloud-ruby#versioning))
2
+
3
+ [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][]
9
+
10
+ ## 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 Cloud Vision API.](https://console.cloud.google.com/apis/library/vision.googleapis.com)
17
+ 4. [Setup Authentication.](https://googleapis.github.io/google-cloud-ruby/#/docs/google-cloud/master/guides/authentication)
18
+
19
+ ### Installation
20
+ ```
21
+ $ gem install google-cloud-vision
22
+ ```
23
+
24
+ ### Migration Guide
25
+
26
+ The 0.32.0 release introduced breaking changes relative to the previous release,
27
+ 0.31.0. For more details and instructions to migrate your code, please visit the
28
+ [migration
29
+ guide](https://cloud.google.com/vision/docs/ruby-client-migration).
30
+
31
+ ### Preview
32
+ #### ImageAnnotatorClient
33
+ ```rb
34
+ require "google/cloud/vision"
35
+
36
+ image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new
37
+ gcs_image_uri = "gs://gapic-toolkit/President_Barack_Obama.jpg"
38
+ source = { gcs_image_uri: gcs_image_uri }
39
+ image = { source: source }
40
+ type = :FACE_DETECTION
41
+ features_element = { type: type }
42
+ features = [features_element]
43
+ requests_element = { image: image, features: features }
44
+ requests = [requests_element]
45
+ response = image_annotator_client.batch_annotate_images(requests)
46
+ ```
47
+
48
+ ### Next Steps
49
+ - Read the [Client Library Documentation][] for Cloud Vision API
50
+ to see other available methods on the client.
51
+ - Read the [Cloud Vision API Product documentation][Product Documentation]
52
+ to learn more about the product and see How-to Guides.
53
+ - View this [repository's main README](https://github.com/googleapis/google-cloud-ruby/blob/master/README.md)
54
+ to see the full list of Cloud APIs that we cover.
55
+
56
+ [Client Library Documentation]: https://googleapis.github.io/google-cloud-ruby/#/docs/google-cloud-vision/latest/google/cloud/vision/v1
57
+ [Product Documentation]: https://cloud.google.com/vision
58
+
59
+ ## Enabling Logging
60
+
61
+ To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library.
62
+ The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as shown below,
63
+ or a [`Google::Cloud::Logging::Logger`](https://googleapis.github.io/google-cloud-ruby/#/docs/google-cloud-logging/latest/google/cloud/logging/logger)
64
+ that will write logs to [Stackdriver Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb)
65
+ and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information.
66
+
67
+ Configuring a Ruby stdlib logger:
68
+
69
+ ```ruby
70
+ require "logger"
71
+
72
+ module MyLogger
73
+ LOGGER = Logger.new $stderr, level: Logger::WARN
74
+ def logger
75
+ LOGGER
76
+ end
77
+ end
78
+
79
+ # Define a gRPC module-level logger method before grpc/logconfig.rb loads.
80
+ module GRPC
81
+ extend MyLogger
82
+ end
83
+ ```
84
+
85
+ ## Supported Ruby Versions
86
+
87
+ This library is supported on Ruby 2.3+.
88
+
89
+ Google provides official support for Ruby versions that are actively supported
90
+ by Ruby Core—that is, Ruby versions that are either in normal maintenance or
91
+ in security maintenance, and not end of life. Currently, this means Ruby 2.3
92
+ and later. Older versions of Ruby _may_ still work, but are unsupported and not
93
+ recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details
94
+ about the Ruby support schedule.
@@ -1,4 +1,4 @@
1
- # Copyright 2016 Google LLC
1
+ # Copyright 2018 Google LLC
2
2
  #
3
3
  # Licensed under the Apache License, Version 2.0 (the "License");
4
4
  # you may not use this file except in compliance with the License.
@@ -13,557 +13,222 @@
13
13
  # limitations under the License.
14
14
 
15
15
 
16
- require "google-cloud-vision"
17
- require "google/cloud/vision/project"
18
- require "google/cloud/config"
19
- require "google/cloud/env"
16
+ require "google/gax"
17
+ require "pathname"
20
18
 
21
19
  module Google
22
20
  module Cloud
21
+ # rubocop:disable LineLength
22
+
23
23
  ##
24
- # # Google Cloud Vision
24
+ # # Ruby Client for Cloud Vision API ([Alpha](https://github.com/googleapis/google-cloud-ruby#versioning))
25
+ #
26
+ # [Cloud Vision API][Product Documentation]:
27
+ # Integrates Google Vision features, including image labeling, face, logo, and
28
+ # landmark detection, optical character recognition (OCR), and detection of
29
+ # explicit content, into applications.
30
+ # - [Product Documentation][]
31
+ #
32
+ # ## Quick Start
33
+ # In order to use this library, you first need to go through the following
34
+ # steps:
35
+ #
36
+ # 1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project)
37
+ # 2. [Enable billing for your project.](https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project)
38
+ # 3. [Enable the Cloud Vision API.](https://console.cloud.google.com/apis/library/vision.googleapis.com)
39
+ # 4. [Setup Authentication.](https://googleapis.github.io/google-cloud-ruby/#/docs/google-cloud/master/guides/authentication)
40
+ #
41
+ # ### Installation
42
+ # ```
43
+ # $ gem install google-cloud-vision
44
+ # ```
45
+ #
46
+ # ### Migration Guide
47
+ #
48
+ # The 0.32.0 release introduced breaking changes relative to the previous
49
+ # release, 0.31.0. For more details and instructions to migrate your code,
50
+ # please visit the [migration
51
+ # guide](https://cloud.google.com/vision/docs/ruby-client-migration).
52
+ #
53
+ # ### Preview
54
+ # #### ImageAnnotatorClient
55
+ # ```rb
56
+ # require "google/cloud/vision"
57
+ #
58
+ # image_annotator_client = Google::Cloud::Vision::ImageAnnotator.new
59
+ # gcs_image_uri = "gs://gapic-toolkit/President_Barack_Obama.jpg"
60
+ # source = { gcs_image_uri: gcs_image_uri }
61
+ # image = { source: source }
62
+ # type = :FACE_DETECTION
63
+ # features_element = { type: type }
64
+ # features = [features_element]
65
+ # requests_element = { image: image, features: features }
66
+ # requests = [requests_element]
67
+ # response = image_annotator_client.batch_annotate_images(requests)
68
+ # ```
69
+ #
70
+ # ### Next Steps
71
+ # - Read the [Cloud Vision API Product documentation][Product Documentation]
72
+ # to learn more about the product and see How-to Guides.
73
+ # - View this [repository's main README](https://github.com/googleapis/google-cloud-ruby/blob/master/README.md)
74
+ # to see the full list of Cloud APIs that we cover.
75
+ #
76
+ # [Product Documentation]: https://cloud.google.com/vision
77
+ #
78
+ # ## Enabling Logging
25
79
  #
26
- # Google Cloud Vision allows developers to easily integrate vision
27
- # detection features within applications, including image labeling, face
28
- # and landmark detection, optical character recognition (OCR), and tagging
29
- # of explicit content.
80
+ # To enable logging for this library, set the logger for the underlying [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library.
81
+ # The logger that you set may be a Ruby stdlib [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as shown below,
82
+ # or a [`Google::Cloud::Logging::Logger`](https://googleapis.github.io/google-cloud-ruby/#/docs/google-cloud-logging/latest/google/cloud/logging/logger)
83
+ # that will write logs to [Stackdriver Logging](https://cloud.google.com/logging/). See [grpc/logconfig.rb](https://github.com/grpc/grpc/blob/master/src/ruby/lib/grpc/logconfig.rb)
84
+ # and the gRPC [spec_helper.rb](https://github.com/grpc/grpc/blob/master/src/ruby/spec/spec_helper.rb) for additional information.
30
85
  #
31
- # For more information about Cloud Vision, read the [Google Cloud Vision API
32
- # Documentation](https://cloud.google.com/vision/docs/).
86
+ # Configuring a Ruby stdlib logger:
33
87
  #
34
- # See {file:OVERVIEW.md Vision Overview}.
88
+ # ```ruby
89
+ # require "logger"
90
+ #
91
+ # module MyLogger
92
+ # LOGGER = Logger.new $stderr, level: Logger::WARN
93
+ # def logger
94
+ # LOGGER
95
+ # end
96
+ # end
97
+ #
98
+ # # Define a gRPC module-level logger method before grpc/logconfig.rb loads.
99
+ # module GRPC
100
+ # extend MyLogger
101
+ # end
102
+ # ```
35
103
  #
36
104
  module Vision
37
- class << self
38
- ##
39
- # The default max results to return for facial detection requests. This
40
- # is used on {Project#annotate} as well as {Image#faces}.
41
- #
42
- # The default value is `100`.
43
- #
44
- # This is also available on the configuration as
45
- # `Google::Cloud::Vision.configure.default_max_faces`
46
- #
47
- # @example Using the default setting on {Project#annotate}:
48
- # require "google/cloud/vision"
49
- #
50
- # vision = Google::Cloud::Vision.new
51
- #
52
- # Google::Cloud::Vision.default_max_faces #=> 100
53
- #
54
- # annotation = vision.annotate "path/to/faces.jpg", faces: true
55
- # # This is the same as calling
56
- # # annotation = vision.annotate "path/to/faces.jpg", faces: 100
57
- #
58
- # @example Updating the default setting on {Project#annotate}:
59
- # require "google/cloud/vision"
60
- #
61
- # vision = Google::Cloud::Vision.new
62
- #
63
- # # Set a new default
64
- # Google::Cloud::Vision.default_max_faces = 5
65
- #
66
- # annotation = vision.annotate "path/to/faces.jpg", faces: true
67
- # # This is the same as calling
68
- # # annotation = vision.annotate "path/to/faces.jpg", faces: 5
69
- #
70
- #
71
- # @example Using the default setting on {Image#faces}:
72
- # require "google/cloud/vision"
73
- #
74
- # vision = Google::Cloud::Vision.new
75
- #
76
- # Google::Cloud::Vision.default_max_faces #=> 100
77
- #
78
- # faces = vision.image("path/to/faces.jpg").faces
79
- # # This is the same as calling
80
- # # faces = vision.image("path/to/faces.jpg").faces 100
81
- #
82
- # @example Updating the default setting on {Image#faces}:
83
- # require "google/cloud/vision"
84
- #
85
- # vision = Google::Cloud::Vision.new
86
- #
87
- # # Set a new default
88
- # Google::Cloud::Vision.default_max_faces = 5
89
- #
90
- # faces = vision.image("path/to/faces.jpg").faces
91
- # # This is the same as calling
92
- # # faces = vision.image("path/to/faces.jpg").faces 5
93
- #
94
- def default_max_faces= value
95
- configure.default_max_faces = value
96
- end
97
-
98
- ##
99
- # The default max results to return for face detection requests.
100
- #
101
- def default_max_faces
102
- configure.default_max_faces
103
- end
104
-
105
- ##
106
- # The default max results to return for landmark detection requests.
107
- # This is used on {Project#annotate} as well as {Image#landmarks}.
108
- #
109
- # The default value is 100.
110
- #
111
- # This is also available on the configuration as
112
- # `Google::Cloud::Vision.configure.default_max_landmarks`
113
- #
114
- # @example Using the default setting on {Project#annotate}:
115
- # require "google/cloud/vision"
116
- #
117
- # vision = Google::Cloud::Vision.new
118
- #
119
- # Google::Cloud::Vision.default_max_landmarks #=> 100
120
- #
121
- # img = "path/to/landmarks.jpg"
122
- # annotation = vision.annotate img, landmarks: true
123
- # # This is the same as calling
124
- # # annotation = vision.annotate img, landmarks: 100
125
- #
126
- # @example Updating the default setting on {Project#annotate}:
127
- # require "google/cloud/vision"
128
- #
129
- # vision = Google::Cloud::Vision.new
130
- #
131
- # # Set a new default
132
- # Google::Cloud::Vision.default_max_landmarks = 5
133
- #
134
- # img = "path/to/landmarks.jpg"
135
- # annotation = vision.annotate img, landmarks: true
136
- # # This is the same as calling
137
- # # annotation = vision.annotate img, landmarks: 5
138
- #
139
- #
140
- # @example Using the default setting on {Image#landmarks}:
141
- # require "google/cloud/vision"
142
- #
143
- # vision = Google::Cloud::Vision.new
144
- #
145
- # Google::Cloud::Vision.default_max_landmarks #=> 100
146
- #
147
- # landmarks = vision.image("path/to/landmarks.jpg").landmarks
148
- # # This is the same as calling
149
- # # landmarks = vision.image("path/to/landmarks.jpg").landmarks 100
150
- #
151
- # @example Updating the default setting on {Image#landmarks}:
152
- # require "google/cloud/vision"
153
- #
154
- # vision = Google::Cloud::Vision.new
155
- #
156
- # # Set a new default
157
- # Google::Cloud::Vision.default_max_landmarks = 5
158
- #
159
- # landmarks = vision.image("path/to/landmarks.jpg").landmarks
160
- # # This is the same as calling
161
- # # landmarks = vision.image("path/to/landmarks.jpg").landmarks 5
162
- #
163
- def default_max_landmarks= value
164
- configure.default_max_landmarks = value
165
- end
166
-
167
- ##
168
- # The default max results to return for landmark detection requests.
169
- #
170
- def default_max_landmarks
171
- configure.default_max_landmarks
172
- end
173
-
174
- ##
175
- # The default max results to return for logo detection requests. This is
176
- # used on {Project#annotate} as well as {Image#logos}.
177
- #
178
- # The default value is 100.
179
- #
180
- # This is also available on the configuration as
181
- # `Google::Cloud::Vision.configure.default_max_logos`
182
- #
183
- # @example Using the default setting on {Project#annotate}:
184
- # require "google/cloud/vision"
185
- #
186
- # vision = Google::Cloud::Vision.new
187
- #
188
- # Google::Cloud::Vision.default_max_logos #=> 100
189
- #
190
- # annotation = vision.annotate "path/to/logos.jpg", logos: true
191
- # # This is the same as calling
192
- # # annotation = vision.annotate "path/to/logos.jpg", logos: 100
193
- #
194
- # @example Updating the default setting on {Project#annotate}:
195
- # require "google/cloud/vision"
196
- #
197
- # vision = Google::Cloud::Vision.new
198
- #
199
- # # Set a new default
200
- # Google::Cloud::Vision.default_max_logos = 5
201
- #
202
- # annotation = vision.annotate "path/to/logos.jpg", logos: true
203
- # # This is the same as calling
204
- # # annotation = vision.annotate "path/to/logos.jpg", logos: 5
205
- #
206
- #
207
- # @example Using the default setting on {Image#logos}:
208
- # require "google/cloud/vision"
209
- #
210
- # vision = Google::Cloud::Vision.new
211
- #
212
- # Google::Cloud::Vision.default_max_logos #=> 100
213
- #
214
- # logos = vision.image("path/to/logos.jpg").logos
215
- # # This is the same as calling
216
- # # logos = vision.image("path/to/logos.jpg").logos 100
217
- #
218
- # @example Updating the default setting on {Image#logos}:
219
- # require "google/cloud/vision"
220
- #
221
- # vision = Google::Cloud::Vision.new
222
- #
223
- # # Set a new default
224
- # Google::Cloud::Vision.default_max_logos = 5
225
- #
226
- # logos = vision.image("path/to/logos.jpg").logos
227
- # # This is the same as calling
228
- # # logos = vision.image("path/to/logos.jpg").logos 5
229
- #
230
- def default_max_logos= value
231
- configure.default_max_logos = value
232
- end
233
-
234
- ##
235
- # The default max results to return for logo detection requests.
236
- #
237
- def default_max_logos
238
- configure.default_max_logos
239
- end
240
-
241
- ##
242
- # The default max results to return for label detection requests. This
243
- # is used on {Project#annotate} as well as {Image#labels}.
244
- #
245
- # The default value is 100.
246
- #
247
- # This is also available on the configuration as
248
- # `Google::Cloud::Vision.configure.default_max_labels`
249
- #
250
- # @example Using the default setting on {Project#annotate}:
251
- # require "google/cloud/vision"
252
- #
253
- # vision = Google::Cloud::Vision.new
254
- #
255
- # Google::Cloud::Vision.default_max_labels #=> 100
256
- #
257
- # annotation = vision.annotate "path/to/labels.jpg", labels: true
258
- # # This is the same as calling
259
- # # annotation = vision.annotate "path/to/labels.jpg", labels: 100
260
- #
261
- # @example Updating the default setting on {Project#annotate}:
262
- # require "google/cloud/vision"
263
- #
264
- # vision = Google::Cloud::Vision.new
265
- #
266
- # # Set a new default
267
- # Google::Cloud::Vision.default_max_labels = 5
268
- #
269
- # annotation = vision.annotate "path/to/labels.jpg", labels: true
270
- # # This is the same as calling
271
- # # annotation = vision.annotate "path/to/labels.jpg", labels: 5
272
- #
273
- #
274
- # @example Using the default setting on {Image#labels}:
275
- # require "google/cloud/vision"
276
- #
277
- # vision = Google::Cloud::Vision.new
278
- #
279
- # Google::Cloud::Vision.default_max_labels #=> 100
280
- #
281
- # labels = vision.image("path/to/labels.jpg").labels
282
- # # This is the same as calling
283
- # # labels = vision.image("path/to/labels.jpg").labels 100
284
- #
285
- # @example Updating the default setting on {Image#labels}:
286
- # require "google/cloud/vision"
287
- #
288
- # vision = Google::Cloud::Vision.new
289
- #
290
- # # Set a new default
291
- # Google::Cloud::Vision.default_max_labels = 5
292
- #
293
- # labels = vision.image("path/to/labels.jpg").labels
294
- # # This is the same as calling
295
- # # labels = vision.image("path/to/labels.jpg").labels 5
296
- #
297
- def default_max_labels= value
298
- configure.default_max_labels = value
299
- end
300
-
301
- ##
302
- # The default max results to return for label detection requests.
303
- #
304
- def default_max_labels
305
- configure.default_max_labels
306
- end
307
-
308
- ##
309
- # The default max results to return for crop hints detection requests.
310
- # This is used on {Project#annotate} as well as {Image#crop_hints}.
311
- #
312
- # The default value is 100.
313
- #
314
- # This is also available on the configuration as
315
- # `Google::Cloud::Vision.configure.default_max_crop_hints`
316
- #
317
- # @example Using the default setting on {Project#annotate}:
318
- # require "google/cloud/vision"
319
- #
320
- # vision = Google::Cloud::Vision.new
321
- #
322
- # Google::Cloud::Vision.default_max_crop_hints #=> 100
323
- #
324
- # img = "path/to/landmarks.jpg"
325
- # annotation = vision.annotate img, crop_hints: true
326
- # # This is the same as calling
327
- # # annotation = vision.annotate img, crop_hints: 100
328
- #
329
- # @example Updating the default setting on {Project#annotate}:
330
- # require "google/cloud/vision"
331
- #
332
- # vision = Google::Cloud::Vision.new
333
- #
334
- # # Set a new default
335
- # Google::Cloud::Vision.default_max_crop_hints = 5
336
- #
337
- # img = "path/to/landmarks.jpg"
338
- # annotation = vision.annotate img, crop_hints: true
339
- # # This is the same as calling
340
- # # annotation = vision.annotate img, crop_hints: 5
341
- #
342
- #
343
- # @example Using the default setting on {Image#crop_hints}:
344
- # require "google/cloud/vision"
345
- #
346
- # vision = Google::Cloud::Vision.new
347
- #
348
- # Google::Cloud::Vision.default_max_crop_hints #=> 100
349
- #
350
- # crop_hints = vision.image("path/to/landmarks.jpg").crop_hints
351
- # # This is the same as calling
352
- # # crop_hints = vision.image("path/to/landmarks.jpg").crop_hints 100
353
- #
354
- # @example Updating the default setting on {Image#crop_hints}:
355
- # require "google/cloud/vision"
356
- #
357
- # vision = Google::Cloud::Vision.new
358
- #
359
- # # Set a new default
360
- # Google::Cloud::Vision.default_max_crop_hints = 5
361
- #
362
- # crop_hints = vision.image("path/to/landmarks.jpg").crop_hints
363
- # # This is the same as calling
364
- # # crop_hints = vision.image("path/to/landmarks.jpg").crop_hints 5
365
- #
366
- def default_max_crop_hints= value
367
- configure.default_max_crop_hints = value
368
- end
105
+ # rubocop:enable LineLength
369
106
 
370
- ##
371
- # The default max results to return for crop hints detection requests.
372
- #
373
- def default_max_crop_hints
374
- configure.default_max_crop_hints
375
- end
107
+ FILE_DIR = File.realdirpath(Pathname.new(__FILE__).join("..").join("vision"))
376
108
 
377
- ##
378
- # The default max results to return for web detection requests.
379
- # This is used on {Project#annotate} as well as {Image#web}.
380
- #
381
- # The default value is 100.
382
- #
383
- # This is also available on the configuration as
384
- # `Google::Cloud::Vision.configure.default_max_web`
385
- #
386
- # @example Using the default setting on {Project#annotate}:
387
- # require "google/cloud/vision"
388
- #
389
- # vision = Google::Cloud::Vision.new
390
- #
391
- # Google::Cloud::Vision.default_max_web #=> 100
392
- #
393
- # img = "path/to/landmarks.jpg"
394
- # annotation = vision.annotate img, web: true
395
- # # This is the same as calling
396
- # # annotation = vision.annotate img, web: 100
397
- #
398
- # @example Updating the default setting on {Project#annotate}:
399
- # require "google/cloud/vision"
400
- #
401
- # vision = Google::Cloud::Vision.new
402
- #
403
- # # Set a new default
404
- # Google::Cloud::Vision.default_max_web = 5
405
- #
406
- # img = "path/to/landmarks.jpg"
407
- # annotation = vision.annotate img, web: true
408
- # # This is the same as calling
409
- # # annotation = vision.annotate img, web: 5
410
- #
411
- #
412
- # @example Using the default setting on {Image#web}:
413
- # require "google/cloud/vision"
414
- #
415
- # vision = Google::Cloud::Vision.new
416
- #
417
- # Google::Cloud::Vision.default_max_web #=> 100
418
- #
419
- # web = vision.image("path/to/landmarks.jpg").web
420
- # # This is the same as calling
421
- # # web = vision.image("path/to/landmarks.jpg").web 100
422
- #
423
- # @example Updating the default setting on {Image#web}:
424
- # require "google/cloud/vision"
425
- #
426
- # vision = Google::Cloud::Vision.new
427
- #
428
- # # Set a new default
429
- # Google::Cloud::Vision.default_max_web = 5
430
- #
431
- # web = vision.image("path/to/landmarks.jpg").web
432
- # # This is the same as calling
433
- # # web = vision.image("path/to/landmarks.jpg").web 5
434
- #
435
- def default_max_web= value
436
- configure.default_max_web = value
437
- end
109
+ AVAILABLE_VERSIONS = Dir["#{FILE_DIR}/*"]
110
+ .select { |file| File.directory?(file) }
111
+ .select { |dir| Google::Gax::VERSION_MATCHER.match(File.basename(dir)) }
112
+ .select { |dir| File.exist?(dir + ".rb") }
113
+ .map { |dir| File.basename(dir) }
438
114
 
115
+ module ProductSearch
439
116
  ##
440
- # The default max results to return for web detection requests.
441
- #
442
- def default_max_web
443
- configure.default_max_web
444
- end
445
-
446
- def default_max_object_localizations= value
447
- configure.default_max_object_localizations = value
448
- end
449
-
450
- def default_max_object_localizations
451
- configure.default_max_object_localizations
117
+ # Manages Products and ProductSets of reference images for use in product
118
+ # search. It uses the following resource model:
119
+ #
120
+ # * The API has a collection of {Google::Cloud::Vision::V1::ProductSet ProductSet} resources, named
121
+ # `projects/*/locations/*/productSets/*`, which acts as a way to put different
122
+ # products into groups to limit identification.
123
+ #
124
+ # In parallel,
125
+ #
126
+ # * The API has a collection of {Google::Cloud::Vision::V1::Product Product} resources, named
127
+ # `projects/*/locations/*/products/*`
128
+ #
129
+ # * Each {Google::Cloud::Vision::V1::Product Product} has a collection of {Google::Cloud::Vision::V1::ReferenceImage ReferenceImage} resources, named
130
+ # `projects/*/locations/*/products/*/referenceImages/*`
131
+ #
132
+ # @param version [Symbol, String]
133
+ # The major version of the service to be used. By default :v1
134
+ # is used.
135
+ # @overload new(version:, credentials:, scopes:, client_config:, timeout:)
136
+ # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
137
+ # Provides the means for authenticating requests made by the client. This parameter can
138
+ # be many types.
139
+ # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
140
+ # authenticating requests made by this client.
141
+ # A `String` will be treated as the path to the keyfile to be used for the construction of
142
+ # credentials for this client.
143
+ # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
144
+ # credentials for this client.
145
+ # A `GRPC::Core::Channel` will be used to make calls through.
146
+ # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
147
+ # should already be composed with a `GRPC::Core::CallCredentials` object.
148
+ # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
149
+ # metadata for requests, generally, to give OAuth credentials.
150
+ # @param scopes [Array<String>]
151
+ # The OAuth scopes for this service. This parameter is ignored if
152
+ # an updater_proc is supplied.
153
+ # @param client_config [Hash]
154
+ # A Hash for call options for each method. See
155
+ # Google::Gax#construct_settings for the structure of
156
+ # this data. Falls back to the default config if not specified
157
+ # or the specified config is missing data points.
158
+ # @param timeout [Numeric]
159
+ # The default timeout, in seconds, for calls made through this client.
160
+ # @param metadata [Hash]
161
+ # Default metadata to be sent with each request. This can be overridden on a per call basis.
162
+ # @param exception_transformer [Proc]
163
+ # An optional proc that intercepts any exceptions raised during an API call to inject
164
+ # custom error handling.
165
+ def self.new(*args, version: :v1, **kwargs)
166
+ unless AVAILABLE_VERSIONS.include?(version.to_s.downcase)
167
+ raise "The version: #{version} is not available. The available versions " \
168
+ "are: [#{AVAILABLE_VERSIONS.join(", ")}]"
169
+ end
170
+
171
+ require "#{FILE_DIR}/#{version.to_s.downcase}"
172
+ version_module = Google::Cloud::Vision
173
+ .constants
174
+ .select {|sym| sym.to_s.downcase == version.to_s.downcase}
175
+ .first
176
+ Google::Cloud::Vision.const_get(version_module)::ProductSearch.new(*args, **kwargs)
452
177
  end
453
178
  end
454
179
 
455
- ##
456
- # Creates a new object for connecting to the Vision service.
457
- # Each call creates a new connection.
458
- #
459
- # @param [String] project_id Project identifier for the Vision service you
460
- # are connecting to. If not present, the default project for the
461
- # credentials is used.
462
- # @param [String, Hash, Google::Auth::Credentials] credentials The path to
463
- # the keyfile as a String, the contents of the keyfile as a Hash, or a
464
- # Google::Auth::Credentials object. (See {Vision::Credentials})
465
- # @param [String, Array<String>] scope The OAuth 2.0 scopes controlling
466
- # the set of resources and operations that the connection can access.
467
- # See [Using OAuth 2.0 to Access Google
468
- # APIs](https://developers.google.com/identity/protocols/OAuth2).
469
- #
470
- # The default scope is:
471
- #
472
- # * `https://www.googleapis.com/auth/cloud-platform`
473
- # @param [Integer] timeout Default timeout to use in requests. Optional.
474
- # @param [Hash] client_config A hash of values to override the default
475
- # behavior of the API client. Optional.
476
- # @param [String] project Alias for the `project_id` argument. Deprecated.
477
- # @param [String] keyfile Alias for the `credentials` argument.
478
- # Deprecated.
479
- #
480
- # @return [Google::Cloud::Vision::Project]
481
- #
482
- # @example
483
- # require "google/cloud/vision"
484
- #
485
- # vision = Google::Cloud::Vision.new
486
- #
487
- # image = vision.image "path/to/landmark.jpg"
488
- #
489
- # landmark = image.landmark
490
- # landmark.description #=> "Mount Rushmore"
491
- #
492
- def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
493
- client_config: nil, project: nil, keyfile: nil
494
- project_id ||= (project || default_project_id)
495
- project_id = project_id.to_s # Always cast to a string
496
- raise ArgumentError, "project_id is missing" if project_id.empty?
497
-
498
- scope ||= configure.scope
499
- timeout ||= configure.timeout
500
- client_config ||= configure.client_config
501
- credentials ||= (keyfile || default_credentials(scope: scope))
502
- unless credentials.is_a? Google::Auth::Credentials
503
- credentials = Vision::Credentials.new credentials, scope: scope
180
+ module ImageAnnotator
181
+ ##
182
+ # Service that performs Google Cloud Vision API detection tasks over client
183
+ # images, such as face, landmark, logo, label, and text detection. The
184
+ # ImageAnnotator service returns detected entities from the images.
185
+ #
186
+ # @param version [Symbol, String]
187
+ # The major version of the service to be used. By default :v1
188
+ # is used.
189
+ # @overload new(version:, credentials:, scopes:, client_config:, timeout:)
190
+ # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
191
+ # Provides the means for authenticating requests made by the client. This parameter can
192
+ # be many types.
193
+ # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
194
+ # authenticating requests made by this client.
195
+ # A `String` will be treated as the path to the keyfile to be used for the construction of
196
+ # credentials for this client.
197
+ # A `Hash` will be treated as the contents of a keyfile to be used for the construction of
198
+ # credentials for this client.
199
+ # A `GRPC::Core::Channel` will be used to make calls through.
200
+ # A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
201
+ # should already be composed with a `GRPC::Core::CallCredentials` object.
202
+ # A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
203
+ # metadata for requests, generally, to give OAuth credentials.
204
+ # @param scopes [Array<String>]
205
+ # The OAuth scopes for this service. This parameter is ignored if
206
+ # an updater_proc is supplied.
207
+ # @param client_config [Hash]
208
+ # A Hash for call options for each method. See
209
+ # Google::Gax#construct_settings for the structure of
210
+ # this data. Falls back to the default config if not specified
211
+ # or the specified config is missing data points.
212
+ # @param timeout [Numeric]
213
+ # The default timeout, in seconds, for calls made through this client.
214
+ # @param metadata [Hash]
215
+ # Default metadata to be sent with each request. This can be overridden on a per call basis.
216
+ # @param exception_transformer [Proc]
217
+ # An optional proc that intercepts any exceptions raised during an API call to inject
218
+ # custom error handling.
219
+ def self.new(*args, version: :v1, **kwargs)
220
+ unless AVAILABLE_VERSIONS.include?(version.to_s.downcase)
221
+ raise "The version: #{version} is not available. The available versions " \
222
+ "are: [#{AVAILABLE_VERSIONS.join(", ")}]"
223
+ end
224
+
225
+ require "#{FILE_DIR}/#{version.to_s.downcase}"
226
+ version_module = Google::Cloud::Vision
227
+ .constants
228
+ .select {|sym| sym.to_s.downcase == version.to_s.downcase}
229
+ .first
230
+ Google::Cloud::Vision.const_get(version_module)::ImageAnnotator.new(*args, **kwargs)
504
231
  end
505
-
506
- Vision::Project.new(
507
- Vision::Service.new(
508
- project_id, credentials, timeout: timeout,
509
- client_config: client_config
510
- )
511
- )
512
- end
513
-
514
- ##
515
- # Configure the Google Cloud Vision library.
516
- #
517
- # The following Vision configuration parameters are supported:
518
- #
519
- # * `project_id` - (String) Identifier for a Vision project. (The
520
- # parameter `project` is considered deprecated, but may also be used.)
521
- # * `credentials` - (String, Hash, Google::Auth::Credentials) The path to
522
- # the keyfile as a String, the contents of the keyfile as a Hash, or a
523
- # Google::Auth::Credentials object. (See {Vision::Credentials}) (The
524
- # parameter `keyfile` is considered deprecated, but may also be used.)
525
- # * `scope` - (String, Array<String>) The OAuth 2.0 scopes controlling
526
- # the set of resources and operations that the connection can access.
527
- # * `timeout` - (Integer) Default timeout to use in requests.
528
- # * `client_config` - (Hash) A hash of values to override the default
529
- # behavior of the API client.
530
- # * `default_max_faces` - (Integer) The default max results to return for
531
- # facial detection requests. See {Vision.default_max_faces=}.
532
- # * `default_max_landmarks` - (Integer) The default max results to return
533
- # for landmark detection requests. See {Vision.default_max_landmarks=}.
534
- # * `default_max_logos` - (Integer) The default max results to return for
535
- # logo detection requests. See {Vision.default_max_logos=}.
536
- # * `default_max_labels` - (Integer) The default max results to return for
537
- # label detection requests. See {Vision.default_max_labels=}.
538
- # * `default_max_crop_hints` - (Integer) The default max results to return
539
- # for crop hints detection requests. See
540
- # {Vision.default_max_crop_hints=}.
541
- # * `default_max_web` - (Integer) The default max results to return for
542
- # web detection requests. See {Vision.default_max_faces=}.
543
- #
544
- # @return [Google::Cloud::Config] The configuration object the
545
- # Google::Cloud::Vision library uses.
546
- #
547
- def self.configure
548
- yield Google::Cloud.configure.vision if block_given?
549
-
550
- Google::Cloud.configure.vision
551
- end
552
-
553
- ##
554
- # @private Default project.
555
- def self.default_project_id
556
- Google::Cloud.configure.vision.project_id ||
557
- Google::Cloud.configure.project_id ||
558
- Google::Cloud.env.project_id
559
- end
560
-
561
- ##
562
- # @private Default credentials.
563
- def self.default_credentials scope: nil
564
- Google::Cloud.configure.vision.credentials ||
565
- Google::Cloud.configure.credentials ||
566
- Vision::Credentials.default(scope: scope)
567
232
  end
568
233
  end
569
234
  end