google-cloud-document_ai-v1 0.1.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 (41) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +12 -0
  3. data/AUTHENTICATION.md +169 -0
  4. data/LICENSE.md +201 -0
  5. data/README.md +139 -0
  6. data/lib/google-cloud-document_ai-v1.rb +21 -0
  7. data/lib/google/cloud/document_ai/v1.rb +38 -0
  8. data/lib/google/cloud/document_ai/v1/document_processor_service.rb +53 -0
  9. data/lib/google/cloud/document_ai/v1/document_processor_service/client.rb +581 -0
  10. data/lib/google/cloud/document_ai/v1/document_processor_service/credentials.rb +51 -0
  11. data/lib/google/cloud/document_ai/v1/document_processor_service/operations.rb +655 -0
  12. data/lib/google/cloud/document_ai/v1/document_processor_service/paths.rb +71 -0
  13. data/lib/google/cloud/document_ai/v1/version.rb +28 -0
  14. data/lib/google/cloud/documentai/v1/document_io_pb.rb +54 -0
  15. data/lib/google/cloud/documentai/v1/document_pb.rb +298 -0
  16. data/lib/google/cloud/documentai/v1/document_processor_service_pb.rb +107 -0
  17. data/lib/google/cloud/documentai/v1/document_processor_service_services_pb.rb +54 -0
  18. data/lib/google/cloud/documentai/v1/geometry_pb.rb +34 -0
  19. data/lib/google/cloud/documentai/v1/operation_metadata_pb.rb +36 -0
  20. data/proto_docs/README.md +4 -0
  21. data/proto_docs/google/api/field_behavior.rb +65 -0
  22. data/proto_docs/google/api/resource.rb +283 -0
  23. data/proto_docs/google/cloud/documentai/v1/document.rb +791 -0
  24. data/proto_docs/google/cloud/documentai/v1/document_io.rb +100 -0
  25. data/proto_docs/google/cloud/documentai/v1/document_processor_service.rb +221 -0
  26. data/proto_docs/google/cloud/documentai/v1/geometry.rb +65 -0
  27. data/proto_docs/google/cloud/documentai/v1/operation_metadata.rb +65 -0
  28. data/proto_docs/google/longrunning/operations.rb +164 -0
  29. data/proto_docs/google/protobuf/any.rb +141 -0
  30. data/proto_docs/google/protobuf/duration.rb +98 -0
  31. data/proto_docs/google/protobuf/empty.rb +36 -0
  32. data/proto_docs/google/protobuf/field_mask.rb +229 -0
  33. data/proto_docs/google/protobuf/timestamp.rb +129 -0
  34. data/proto_docs/google/protobuf/wrappers.rb +121 -0
  35. data/proto_docs/google/rpc/status.rb +46 -0
  36. data/proto_docs/google/type/color.rb +173 -0
  37. data/proto_docs/google/type/date.rb +53 -0
  38. data/proto_docs/google/type/datetime.rb +99 -0
  39. data/proto_docs/google/type/money.rb +43 -0
  40. data/proto_docs/google/type/postal_address.rb +135 -0
  41. metadata +231 -0
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2021 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # Auto-generated by gapic-generator-ruby. DO NOT EDIT!
18
+
19
+ # This gem does not autoload during Bundler.require. To load this gem,
20
+ # issue explicit require statements for the packages desired, e.g.:
21
+ # require "google/cloud/document_ai/v1"
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2021 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # Auto-generated by gapic-generator-ruby. DO NOT EDIT!
18
+
19
+ require "google/cloud/document_ai/v1/document_processor_service"
20
+ require "google/cloud/document_ai/v1/version"
21
+
22
+ module Google
23
+ module Cloud
24
+ module DocumentAI
25
+ ##
26
+ # To load this package, including all its services, and instantiate a client:
27
+ #
28
+ # require "google/cloud/document_ai/v1"
29
+ # client = ::Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client.new
30
+ #
31
+ module V1
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ helper_path = ::File.join __dir__, "v1", "_helpers.rb"
38
+ require "google/cloud/document_ai/v1/_helpers" if ::File.file? helper_path
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2021 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # Auto-generated by gapic-generator-ruby. DO NOT EDIT!
18
+
19
+ require "gapic/common"
20
+ require "gapic/config"
21
+ require "gapic/config/method"
22
+
23
+ require "google/cloud/document_ai/v1/version"
24
+
25
+ require "google/cloud/document_ai/v1/document_processor_service/credentials"
26
+ require "google/cloud/document_ai/v1/document_processor_service/paths"
27
+ require "google/cloud/document_ai/v1/document_processor_service/operations"
28
+ require "google/cloud/document_ai/v1/document_processor_service/client"
29
+
30
+ module Google
31
+ module Cloud
32
+ module DocumentAI
33
+ module V1
34
+ ##
35
+ # Service to call Cloud DocumentAI to process documents according to the
36
+ # processor's definition. Processors are built using state-of-the-art Google
37
+ # AI such as natural language, computer vision, and translation to extract
38
+ # structured information from unstructured or semi-structured documents.
39
+ #
40
+ # To load this service and instantiate a client:
41
+ #
42
+ # require "google/cloud/document_ai/v1/document_processor_service"
43
+ # client = ::Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client.new
44
+ #
45
+ module DocumentProcessorService
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ helper_path = ::File.join __dir__, "document_processor_service", "helpers.rb"
53
+ require "google/cloud/document_ai/v1/document_processor_service/helpers" if ::File.file? helper_path
@@ -0,0 +1,581 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2021 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ # Auto-generated by gapic-generator-ruby. DO NOT EDIT!
18
+
19
+ require "google/cloud/errors"
20
+ require "google/cloud/documentai/v1/document_processor_service_pb"
21
+
22
+ module Google
23
+ module Cloud
24
+ module DocumentAI
25
+ module V1
26
+ module DocumentProcessorService
27
+ ##
28
+ # Client for the DocumentProcessorService service.
29
+ #
30
+ # Service to call Cloud DocumentAI to process documents according to the
31
+ # processor's definition. Processors are built using state-of-the-art Google
32
+ # AI such as natural language, computer vision, and translation to extract
33
+ # structured information from unstructured or semi-structured documents.
34
+ #
35
+ class Client
36
+ include Paths
37
+
38
+ # @private
39
+ attr_reader :document_processor_service_stub
40
+
41
+ ##
42
+ # Configure the DocumentProcessorService Client class.
43
+ #
44
+ # See {::Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client::Configuration}
45
+ # for a description of the configuration fields.
46
+ #
47
+ # ## Example
48
+ #
49
+ # To modify the configuration for all DocumentProcessorService clients:
50
+ #
51
+ # ::Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client.configure do |config|
52
+ # config.timeout = 10.0
53
+ # end
54
+ #
55
+ # @yield [config] Configure the Client client.
56
+ # @yieldparam config [Client::Configuration]
57
+ #
58
+ # @return [Client::Configuration]
59
+ #
60
+ def self.configure
61
+ @configure ||= begin
62
+ namespace = ["Google", "Cloud", "DocumentAI", "V1"]
63
+ parent_config = while namespace.any?
64
+ parent_name = namespace.join "::"
65
+ parent_const = const_get parent_name
66
+ break parent_const.configure if parent_const.respond_to? :configure
67
+ namespace.pop
68
+ end
69
+ default_config = Client::Configuration.new parent_config
70
+
71
+ default_config.rpcs.process_document.timeout = 120.0
72
+ default_config.rpcs.process_document.retry_policy = {
73
+ initial_delay: 0.1,
74
+ max_delay: 60.0,
75
+ multiplier: 1.3,
76
+ retry_codes: [4, 14]
77
+ }
78
+
79
+ default_config.rpcs.batch_process_documents.timeout = 120.0
80
+ default_config.rpcs.batch_process_documents.retry_policy = {
81
+ initial_delay: 0.1,
82
+ max_delay: 60.0,
83
+ multiplier: 1.3,
84
+ retry_codes: [4, 14]
85
+ }
86
+
87
+ default_config.rpcs.review_document.timeout = 120.0
88
+ default_config.rpcs.review_document.retry_policy = {
89
+ initial_delay: 0.1,
90
+ max_delay: 60.0,
91
+ multiplier: 1.3,
92
+ retry_codes: [4, 14]
93
+ }
94
+
95
+ default_config
96
+ end
97
+ yield @configure if block_given?
98
+ @configure
99
+ end
100
+
101
+ ##
102
+ # Configure the DocumentProcessorService Client instance.
103
+ #
104
+ # The configuration is set to the derived mode, meaning that values can be changed,
105
+ # but structural changes (adding new fields, etc.) are not allowed. Structural changes
106
+ # should be made on {Client.configure}.
107
+ #
108
+ # See {::Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client::Configuration}
109
+ # for a description of the configuration fields.
110
+ #
111
+ # @yield [config] Configure the Client client.
112
+ # @yieldparam config [Client::Configuration]
113
+ #
114
+ # @return [Client::Configuration]
115
+ #
116
+ def configure
117
+ yield @config if block_given?
118
+ @config
119
+ end
120
+
121
+ ##
122
+ # Create a new DocumentProcessorService client object.
123
+ #
124
+ # ## Examples
125
+ #
126
+ # To create a new DocumentProcessorService client with the default
127
+ # configuration:
128
+ #
129
+ # client = ::Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client.new
130
+ #
131
+ # To create a new DocumentProcessorService client with a custom
132
+ # configuration:
133
+ #
134
+ # client = ::Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client.new do |config|
135
+ # config.timeout = 10.0
136
+ # end
137
+ #
138
+ # @yield [config] Configure the DocumentProcessorService client.
139
+ # @yieldparam config [Client::Configuration]
140
+ #
141
+ def initialize
142
+ # These require statements are intentionally placed here to initialize
143
+ # the gRPC module only when it's required.
144
+ # See https://github.com/googleapis/toolkit/issues/446
145
+ require "gapic/grpc"
146
+ require "google/cloud/documentai/v1/document_processor_service_services_pb"
147
+
148
+ # Create the configuration object
149
+ @config = Configuration.new Client.configure
150
+
151
+ # Yield the configuration if needed
152
+ yield @config if block_given?
153
+
154
+ # Create credentials
155
+ credentials = @config.credentials
156
+ # Use self-signed JWT if the scope and endpoint are unchanged from default,
157
+ # but only if the default endpoint does not have a region prefix.
158
+ enable_self_signed_jwt = @config.scope == Client.configure.scope &&
159
+ @config.endpoint == Client.configure.endpoint &&
160
+ !@config.endpoint.split(".").first.include?("-")
161
+ credentials ||= Credentials.default scope: @config.scope,
162
+ enable_self_signed_jwt: enable_self_signed_jwt
163
+ if credentials.is_a?(String) || credentials.is_a?(Hash)
164
+ credentials = Credentials.new credentials, scope: @config.scope
165
+ end
166
+ @quota_project_id = @config.quota_project
167
+ @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id
168
+
169
+ @operations_client = Operations.new do |config|
170
+ config.credentials = credentials
171
+ config.endpoint = @config.endpoint
172
+ end
173
+
174
+ @document_processor_service_stub = ::Gapic::ServiceStub.new(
175
+ ::Google::Cloud::DocumentAI::V1::DocumentProcessorService::Stub,
176
+ credentials: credentials,
177
+ endpoint: @config.endpoint,
178
+ channel_args: @config.channel_args,
179
+ interceptors: @config.interceptors
180
+ )
181
+ end
182
+
183
+ ##
184
+ # Get the associated client for long-running operations.
185
+ #
186
+ # @return [::Google::Cloud::DocumentAI::V1::DocumentProcessorService::Operations]
187
+ #
188
+ attr_reader :operations_client
189
+
190
+ # Service calls
191
+
192
+ ##
193
+ # Processes a single document.
194
+ #
195
+ # @overload process_document(request, options = nil)
196
+ # Pass arguments to `process_document` via a request object, either of type
197
+ # {::Google::Cloud::DocumentAI::V1::ProcessRequest} or an equivalent Hash.
198
+ #
199
+ # @param request [::Google::Cloud::DocumentAI::V1::ProcessRequest, ::Hash]
200
+ # A request object representing the call parameters. Required. To specify no
201
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
202
+ # @param options [::Gapic::CallOptions, ::Hash]
203
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
204
+ #
205
+ # @overload process_document(inline_document: nil, raw_document: nil, name: nil, skip_human_review: nil)
206
+ # Pass arguments to `process_document` via keyword arguments. Note that at
207
+ # least one keyword argument is required. To specify no parameters, or to keep all
208
+ # the default parameter values, pass an empty Hash as a request object (see above).
209
+ #
210
+ # @param inline_document [::Google::Cloud::DocumentAI::V1::Document, ::Hash]
211
+ # An inline document proto.
212
+ # @param raw_document [::Google::Cloud::DocumentAI::V1::RawDocument, ::Hash]
213
+ # A raw document content (bytes).
214
+ # @param name [::String]
215
+ # Required. The processor resource name.
216
+ # @param skip_human_review [::Boolean]
217
+ # Whether Human Review feature should be skipped for this request. Default to
218
+ # false.
219
+ #
220
+ # @yield [response, operation] Access the result along with the RPC operation
221
+ # @yieldparam response [::Google::Cloud::DocumentAI::V1::ProcessResponse]
222
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
223
+ #
224
+ # @return [::Google::Cloud::DocumentAI::V1::ProcessResponse]
225
+ #
226
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
227
+ #
228
+ def process_document request, options = nil
229
+ raise ::ArgumentError, "request must be provided" if request.nil?
230
+
231
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::DocumentAI::V1::ProcessRequest
232
+
233
+ # Converts hash and nil to an options object
234
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
235
+
236
+ # Customize the options with defaults
237
+ metadata = @config.rpcs.process_document.metadata.to_h
238
+
239
+ # Set x-goog-api-client and x-goog-user-project headers
240
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
241
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
242
+ gapic_version: ::Google::Cloud::DocumentAI::V1::VERSION
243
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
244
+
245
+ header_params = {
246
+ "name" => request.name
247
+ }
248
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
249
+ metadata[:"x-goog-request-params"] ||= request_params_header
250
+
251
+ options.apply_defaults timeout: @config.rpcs.process_document.timeout,
252
+ metadata: metadata,
253
+ retry_policy: @config.rpcs.process_document.retry_policy
254
+ options.apply_defaults metadata: @config.metadata,
255
+ retry_policy: @config.retry_policy
256
+
257
+ @document_processor_service_stub.call_rpc :process_document, request, options: options do |response, operation|
258
+ yield response, operation if block_given?
259
+ return response
260
+ end
261
+ rescue ::GRPC::BadStatus => e
262
+ raise ::Google::Cloud::Error.from_error(e)
263
+ end
264
+
265
+ ##
266
+ # LRO endpoint to batch process many documents. The output is written
267
+ # to Cloud Storage as JSON in the [Document] format.
268
+ #
269
+ # @overload batch_process_documents(request, options = nil)
270
+ # Pass arguments to `batch_process_documents` via a request object, either of type
271
+ # {::Google::Cloud::DocumentAI::V1::BatchProcessRequest} or an equivalent Hash.
272
+ #
273
+ # @param request [::Google::Cloud::DocumentAI::V1::BatchProcessRequest, ::Hash]
274
+ # A request object representing the call parameters. Required. To specify no
275
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
276
+ # @param options [::Gapic::CallOptions, ::Hash]
277
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
278
+ #
279
+ # @overload batch_process_documents(name: nil, input_documents: nil, document_output_config: nil, skip_human_review: nil)
280
+ # Pass arguments to `batch_process_documents` via keyword arguments. Note that at
281
+ # least one keyword argument is required. To specify no parameters, or to keep all
282
+ # the default parameter values, pass an empty Hash as a request object (see above).
283
+ #
284
+ # @param name [::String]
285
+ # Required. The processor resource name.
286
+ # @param input_documents [::Google::Cloud::DocumentAI::V1::BatchDocumentsInputConfig, ::Hash]
287
+ # The input documents for batch process.
288
+ # @param document_output_config [::Google::Cloud::DocumentAI::V1::DocumentOutputConfig, ::Hash]
289
+ # The overall output config for batch process.
290
+ # @param skip_human_review [::Boolean]
291
+ # Whether Human Review feature should be skipped for this request. Default to
292
+ # false.
293
+ #
294
+ # @yield [response, operation] Access the result along with the RPC operation
295
+ # @yieldparam response [::Gapic::Operation]
296
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
297
+ #
298
+ # @return [::Gapic::Operation]
299
+ #
300
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
301
+ #
302
+ def batch_process_documents request, options = nil
303
+ raise ::ArgumentError, "request must be provided" if request.nil?
304
+
305
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::DocumentAI::V1::BatchProcessRequest
306
+
307
+ # Converts hash and nil to an options object
308
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
309
+
310
+ # Customize the options with defaults
311
+ metadata = @config.rpcs.batch_process_documents.metadata.to_h
312
+
313
+ # Set x-goog-api-client and x-goog-user-project headers
314
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
315
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
316
+ gapic_version: ::Google::Cloud::DocumentAI::V1::VERSION
317
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
318
+
319
+ header_params = {
320
+ "name" => request.name
321
+ }
322
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
323
+ metadata[:"x-goog-request-params"] ||= request_params_header
324
+
325
+ options.apply_defaults timeout: @config.rpcs.batch_process_documents.timeout,
326
+ metadata: metadata,
327
+ retry_policy: @config.rpcs.batch_process_documents.retry_policy
328
+ options.apply_defaults metadata: @config.metadata,
329
+ retry_policy: @config.retry_policy
330
+
331
+ @document_processor_service_stub.call_rpc :batch_process_documents, request, options: options do |response, operation|
332
+ response = ::Gapic::Operation.new response, @operations_client, options: options
333
+ yield response, operation if block_given?
334
+ return response
335
+ end
336
+ rescue ::GRPC::BadStatus => e
337
+ raise ::Google::Cloud::Error.from_error(e)
338
+ end
339
+
340
+ ##
341
+ # Send a document for Human Review. The input document should be processed by
342
+ # the specified processor.
343
+ #
344
+ # @overload review_document(request, options = nil)
345
+ # Pass arguments to `review_document` via a request object, either of type
346
+ # {::Google::Cloud::DocumentAI::V1::ReviewDocumentRequest} or an equivalent Hash.
347
+ #
348
+ # @param request [::Google::Cloud::DocumentAI::V1::ReviewDocumentRequest, ::Hash]
349
+ # A request object representing the call parameters. Required. To specify no
350
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
351
+ # @param options [::Gapic::CallOptions, ::Hash]
352
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
353
+ #
354
+ # @overload review_document(inline_document: nil, human_review_config: nil)
355
+ # Pass arguments to `review_document` via keyword arguments. Note that at
356
+ # least one keyword argument is required. To specify no parameters, or to keep all
357
+ # the default parameter values, pass an empty Hash as a request object (see above).
358
+ #
359
+ # @param inline_document [::Google::Cloud::DocumentAI::V1::Document, ::Hash]
360
+ # An inline document proto.
361
+ # @param human_review_config [::String]
362
+ # Required. The resource name of the HumanReviewConfig that the document will be
363
+ # reviewed with.
364
+ #
365
+ # @yield [response, operation] Access the result along with the RPC operation
366
+ # @yieldparam response [::Gapic::Operation]
367
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
368
+ #
369
+ # @return [::Gapic::Operation]
370
+ #
371
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
372
+ #
373
+ def review_document request, options = nil
374
+ raise ::ArgumentError, "request must be provided" if request.nil?
375
+
376
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::DocumentAI::V1::ReviewDocumentRequest
377
+
378
+ # Converts hash and nil to an options object
379
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
380
+
381
+ # Customize the options with defaults
382
+ metadata = @config.rpcs.review_document.metadata.to_h
383
+
384
+ # Set x-goog-api-client and x-goog-user-project headers
385
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
386
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
387
+ gapic_version: ::Google::Cloud::DocumentAI::V1::VERSION
388
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
389
+
390
+ header_params = {
391
+ "human_review_config" => request.human_review_config
392
+ }
393
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
394
+ metadata[:"x-goog-request-params"] ||= request_params_header
395
+
396
+ options.apply_defaults timeout: @config.rpcs.review_document.timeout,
397
+ metadata: metadata,
398
+ retry_policy: @config.rpcs.review_document.retry_policy
399
+ options.apply_defaults metadata: @config.metadata,
400
+ retry_policy: @config.retry_policy
401
+
402
+ @document_processor_service_stub.call_rpc :review_document, request, options: options do |response, operation|
403
+ response = ::Gapic::Operation.new response, @operations_client, options: options
404
+ yield response, operation if block_given?
405
+ return response
406
+ end
407
+ rescue ::GRPC::BadStatus => e
408
+ raise ::Google::Cloud::Error.from_error(e)
409
+ end
410
+
411
+ ##
412
+ # Configuration class for the DocumentProcessorService API.
413
+ #
414
+ # This class represents the configuration for DocumentProcessorService,
415
+ # providing control over timeouts, retry behavior, logging, transport
416
+ # parameters, and other low-level controls. Certain parameters can also be
417
+ # applied individually to specific RPCs. See
418
+ # {::Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client::Configuration::Rpcs}
419
+ # for a list of RPCs that can be configured independently.
420
+ #
421
+ # Configuration can be applied globally to all clients, or to a single client
422
+ # on construction.
423
+ #
424
+ # # Examples
425
+ #
426
+ # To modify the global config, setting the timeout for process_document
427
+ # to 20 seconds, and all remaining timeouts to 10 seconds:
428
+ #
429
+ # ::Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client.configure do |config|
430
+ # config.timeout = 10.0
431
+ # config.rpcs.process_document.timeout = 20.0
432
+ # end
433
+ #
434
+ # To apply the above configuration only to a new client:
435
+ #
436
+ # client = ::Google::Cloud::DocumentAI::V1::DocumentProcessorService::Client.new do |config|
437
+ # config.timeout = 10.0
438
+ # config.rpcs.process_document.timeout = 20.0
439
+ # end
440
+ #
441
+ # @!attribute [rw] endpoint
442
+ # The hostname or hostname:port of the service endpoint.
443
+ # Defaults to `"documentai.googleapis.com"`.
444
+ # @return [::String]
445
+ # @!attribute [rw] credentials
446
+ # Credentials to send with calls. You may provide any of the following types:
447
+ # * (`String`) The path to a service account key file in JSON format
448
+ # * (`Hash`) A service account key as a Hash
449
+ # * (`Google::Auth::Credentials`) A googleauth credentials object
450
+ # (see the [googleauth docs](https://googleapis.dev/ruby/googleauth/latest/index.html))
451
+ # * (`Signet::OAuth2::Client`) A signet oauth2 client object
452
+ # (see the [signet docs](https://googleapis.dev/ruby/signet/latest/Signet/OAuth2/Client.html))
453
+ # * (`GRPC::Core::Channel`) a gRPC channel with included credentials
454
+ # * (`GRPC::Core::ChannelCredentials`) a gRPC credentails object
455
+ # * (`nil`) indicating no credentials
456
+ # @return [::Object]
457
+ # @!attribute [rw] scope
458
+ # The OAuth scopes
459
+ # @return [::Array<::String>]
460
+ # @!attribute [rw] lib_name
461
+ # The library name as recorded in instrumentation and logging
462
+ # @return [::String]
463
+ # @!attribute [rw] lib_version
464
+ # The library version as recorded in instrumentation and logging
465
+ # @return [::String]
466
+ # @!attribute [rw] channel_args
467
+ # Extra parameters passed to the gRPC channel. Note: this is ignored if a
468
+ # `GRPC::Core::Channel` object is provided as the credential.
469
+ # @return [::Hash]
470
+ # @!attribute [rw] interceptors
471
+ # An array of interceptors that are run before calls are executed.
472
+ # @return [::Array<::GRPC::ClientInterceptor>]
473
+ # @!attribute [rw] timeout
474
+ # The call timeout in seconds.
475
+ # @return [::Numeric]
476
+ # @!attribute [rw] metadata
477
+ # Additional gRPC headers to be sent with the call.
478
+ # @return [::Hash{::Symbol=>::String}]
479
+ # @!attribute [rw] retry_policy
480
+ # The retry policy. The value is a hash with the following keys:
481
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
482
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
483
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
484
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
485
+ # trigger a retry.
486
+ # @return [::Hash]
487
+ # @!attribute [rw] quota_project
488
+ # A separate project against which to charge quota.
489
+ # @return [::String]
490
+ #
491
+ class Configuration
492
+ extend ::Gapic::Config
493
+
494
+ config_attr :endpoint, "documentai.googleapis.com", ::String
495
+ config_attr :credentials, nil do |value|
496
+ allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
497
+ allowed += [::GRPC::Core::Channel, ::GRPC::Core::ChannelCredentials] if defined? ::GRPC
498
+ allowed.any? { |klass| klass === value }
499
+ end
500
+ config_attr :scope, nil, ::String, ::Array, nil
501
+ config_attr :lib_name, nil, ::String, nil
502
+ config_attr :lib_version, nil, ::String, nil
503
+ config_attr(:channel_args, { "grpc.service_config_disable_resolution" => 1 }, ::Hash, nil)
504
+ config_attr :interceptors, nil, ::Array, nil
505
+ config_attr :timeout, nil, ::Numeric, nil
506
+ config_attr :metadata, nil, ::Hash, nil
507
+ config_attr :retry_policy, nil, ::Hash, ::Proc, nil
508
+ config_attr :quota_project, nil, ::String, nil
509
+
510
+ # @private
511
+ def initialize parent_config = nil
512
+ @parent_config = parent_config unless parent_config.nil?
513
+
514
+ yield self if block_given?
515
+ end
516
+
517
+ ##
518
+ # Configurations for individual RPCs
519
+ # @return [Rpcs]
520
+ #
521
+ def rpcs
522
+ @rpcs ||= begin
523
+ parent_rpcs = nil
524
+ parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs)
525
+ Rpcs.new parent_rpcs
526
+ end
527
+ end
528
+
529
+ ##
530
+ # Configuration RPC class for the DocumentProcessorService API.
531
+ #
532
+ # Includes fields providing the configuration for each RPC in this service.
533
+ # Each configuration object is of type `Gapic::Config::Method` and includes
534
+ # the following configuration fields:
535
+ #
536
+ # * `timeout` (*type:* `Numeric`) - The call timeout in seconds
537
+ # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional gRPC headers
538
+ # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields
539
+ # include the following keys:
540
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
541
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
542
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
543
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
544
+ # trigger a retry.
545
+ #
546
+ class Rpcs
547
+ ##
548
+ # RPC-specific configuration for `process_document`
549
+ # @return [::Gapic::Config::Method]
550
+ #
551
+ attr_reader :process_document
552
+ ##
553
+ # RPC-specific configuration for `batch_process_documents`
554
+ # @return [::Gapic::Config::Method]
555
+ #
556
+ attr_reader :batch_process_documents
557
+ ##
558
+ # RPC-specific configuration for `review_document`
559
+ # @return [::Gapic::Config::Method]
560
+ #
561
+ attr_reader :review_document
562
+
563
+ # @private
564
+ def initialize parent_rpcs = nil
565
+ process_document_config = parent_rpcs.process_document if parent_rpcs.respond_to? :process_document
566
+ @process_document = ::Gapic::Config::Method.new process_document_config
567
+ batch_process_documents_config = parent_rpcs.batch_process_documents if parent_rpcs.respond_to? :batch_process_documents
568
+ @batch_process_documents = ::Gapic::Config::Method.new batch_process_documents_config
569
+ review_document_config = parent_rpcs.review_document if parent_rpcs.respond_to? :review_document
570
+ @review_document = ::Gapic::Config::Method.new review_document_config
571
+
572
+ yield self if block_given?
573
+ end
574
+ end
575
+ end
576
+ end
577
+ end
578
+ end
579
+ end
580
+ end
581
+ end