google-cloud-document_ai-v1 1.2.0 → 1.4.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.
@@ -176,15 +176,27 @@ module Google
176
176
  endpoint: @config.endpoint,
177
177
  endpoint_template: DEFAULT_ENDPOINT_TEMPLATE,
178
178
  universe_domain: @config.universe_domain,
179
- credentials: credentials
179
+ credentials: credentials,
180
+ logger: @config.logger
180
181
  )
181
182
 
183
+ @document_processor_service_stub.logger(stub: true)&.info do |entry|
184
+ entry.set_system_name
185
+ entry.set_service
186
+ entry.message = "Created client for #{entry.service}"
187
+ entry.set_credentials_fields credentials
188
+ entry.set "customEndpoint", @config.endpoint if @config.endpoint
189
+ entry.set "defaultTimeout", @config.timeout if @config.timeout
190
+ entry.set "quotaProject", @quota_project_id if @quota_project_id
191
+ end
192
+
182
193
  @location_client = Google::Cloud::Location::Locations::Rest::Client.new do |config|
183
194
  config.credentials = credentials
184
195
  config.quota_project = @quota_project_id
185
196
  config.endpoint = @document_processor_service_stub.endpoint
186
197
  config.universe_domain = @document_processor_service_stub.universe_domain
187
198
  config.bindings_override = @config.bindings_override
199
+ config.logger = @document_processor_service_stub.logger if config.respond_to? :logger=
188
200
  end
189
201
  end
190
202
 
@@ -202,6 +214,15 @@ module Google
202
214
  #
203
215
  attr_reader :location_client
204
216
 
217
+ ##
218
+ # The logger used for request/response debug logging.
219
+ #
220
+ # @return [Logger]
221
+ #
222
+ def logger
223
+ @document_processor_service_stub.logger
224
+ end
225
+
205
226
  # Service calls
206
227
 
207
228
  ##
@@ -224,10 +245,16 @@ module Google
224
245
  #
225
246
  # @param inline_document [::Google::Cloud::DocumentAI::V1::Document, ::Hash]
226
247
  # An inline document proto.
248
+ #
249
+ # Note: The following fields are mutually exclusive: `inline_document`, `raw_document`, `gcs_document`. If a field in that set is populated, all other fields in the set will automatically be cleared.
227
250
  # @param raw_document [::Google::Cloud::DocumentAI::V1::RawDocument, ::Hash]
228
251
  # A raw document content (bytes).
252
+ #
253
+ # Note: The following fields are mutually exclusive: `raw_document`, `inline_document`, `gcs_document`. If a field in that set is populated, all other fields in the set will automatically be cleared.
229
254
  # @param gcs_document [::Google::Cloud::DocumentAI::V1::GcsDocument, ::Hash]
230
255
  # A raw document on Google Cloud Storage.
256
+ #
257
+ # Note: The following fields are mutually exclusive: `gcs_document`, `inline_document`, `raw_document`. If a field in that set is populated, all other fields in the set will automatically be cleared.
231
258
  # @param name [::String]
232
259
  # Required. The resource name of the
233
260
  # {::Google::Cloud::DocumentAI::V1::Processor Processor} or
@@ -311,7 +338,6 @@ module Google
311
338
 
312
339
  @document_processor_service_stub.process_document request, options do |result, operation|
313
340
  yield result, operation if block_given?
314
- return result
315
341
  end
316
342
  rescue ::Gapic::Rest::Error => e
317
343
  raise ::Google::Cloud::Error.from_error(e)
@@ -424,7 +450,7 @@ module Google
424
450
  @document_processor_service_stub.batch_process_documents request, options do |result, operation|
425
451
  result = ::Gapic::Operation.new result, @operations_client, options: options
426
452
  yield result, operation if block_given?
427
- return result
453
+ throw :response, result
428
454
  end
429
455
  rescue ::Gapic::Rest::Error => e
430
456
  raise ::Google::Cloud::Error.from_error(e)
@@ -506,7 +532,6 @@ module Google
506
532
 
507
533
  @document_processor_service_stub.fetch_processor_types request, options do |result, operation|
508
534
  yield result, operation if block_given?
509
- return result
510
535
  end
511
536
  rescue ::Gapic::Rest::Error => e
512
537
  raise ::Google::Cloud::Error.from_error(e)
@@ -597,7 +622,7 @@ module Google
597
622
  @document_processor_service_stub.list_processor_types request, options do |result, operation|
598
623
  result = ::Gapic::Rest::PagedEnumerable.new @document_processor_service_stub, :list_processor_types, "processor_types", request, result, options
599
624
  yield result, operation if block_given?
600
- return result
625
+ throw :response, result
601
626
  end
602
627
  rescue ::Gapic::Rest::Error => e
603
628
  raise ::Google::Cloud::Error.from_error(e)
@@ -676,7 +701,6 @@ module Google
676
701
 
677
702
  @document_processor_service_stub.get_processor_type request, options do |result, operation|
678
703
  yield result, operation if block_given?
679
- return result
680
704
  end
681
705
  rescue ::Gapic::Rest::Error => e
682
706
  raise ::Google::Cloud::Error.from_error(e)
@@ -768,7 +792,7 @@ module Google
768
792
  @document_processor_service_stub.list_processors request, options do |result, operation|
769
793
  result = ::Gapic::Rest::PagedEnumerable.new @document_processor_service_stub, :list_processors, "processors", request, result, options
770
794
  yield result, operation if block_given?
771
- return result
795
+ throw :response, result
772
796
  end
773
797
  rescue ::Gapic::Rest::Error => e
774
798
  raise ::Google::Cloud::Error.from_error(e)
@@ -847,7 +871,6 @@ module Google
847
871
 
848
872
  @document_processor_service_stub.get_processor request, options do |result, operation|
849
873
  yield result, operation if block_given?
850
- return result
851
874
  end
852
875
  rescue ::Gapic::Rest::Error => e
853
876
  raise ::Google::Cloud::Error.from_error(e)
@@ -875,8 +898,12 @@ module Google
875
898
  #
876
899
  # @param custom_document_extraction_options [::Google::Cloud::DocumentAI::V1::TrainProcessorVersionRequest::CustomDocumentExtractionOptions, ::Hash]
877
900
  # Options to control Custom Document Extraction (CDE) Processor.
901
+ #
902
+ # Note: The following fields are mutually exclusive: `custom_document_extraction_options`, `foundation_model_tuning_options`. If a field in that set is populated, all other fields in the set will automatically be cleared.
878
903
  # @param foundation_model_tuning_options [::Google::Cloud::DocumentAI::V1::TrainProcessorVersionRequest::FoundationModelTuningOptions, ::Hash]
879
904
  # Options to control foundation model tuning of a processor.
905
+ #
906
+ # Note: The following fields are mutually exclusive: `foundation_model_tuning_options`, `custom_document_extraction_options`. If a field in that set is populated, all other fields in the set will automatically be cleared.
880
907
  # @param parent [::String]
881
908
  # Required. The parent (project, location and processor) to create the new
882
909
  # version for. Format:
@@ -953,7 +980,7 @@ module Google
953
980
  @document_processor_service_stub.train_processor_version request, options do |result, operation|
954
981
  result = ::Gapic::Operation.new result, @operations_client, options: options
955
982
  yield result, operation if block_given?
956
- return result
983
+ throw :response, result
957
984
  end
958
985
  rescue ::Gapic::Rest::Error => e
959
986
  raise ::Google::Cloud::Error.from_error(e)
@@ -1032,7 +1059,6 @@ module Google
1032
1059
 
1033
1060
  @document_processor_service_stub.get_processor_version request, options do |result, operation|
1034
1061
  yield result, operation if block_given?
1035
- return result
1036
1062
  end
1037
1063
  rescue ::Gapic::Rest::Error => e
1038
1064
  raise ::Google::Cloud::Error.from_error(e)
@@ -1125,7 +1151,7 @@ module Google
1125
1151
  @document_processor_service_stub.list_processor_versions request, options do |result, operation|
1126
1152
  result = ::Gapic::Rest::PagedEnumerable.new @document_processor_service_stub, :list_processor_versions, "processor_versions", request, result, options
1127
1153
  yield result, operation if block_given?
1128
- return result
1154
+ throw :response, result
1129
1155
  end
1130
1156
  rescue ::Gapic::Rest::Error => e
1131
1157
  raise ::Google::Cloud::Error.from_error(e)
@@ -1213,7 +1239,7 @@ module Google
1213
1239
  @document_processor_service_stub.delete_processor_version request, options do |result, operation|
1214
1240
  result = ::Gapic::Operation.new result, @operations_client, options: options
1215
1241
  yield result, operation if block_given?
1216
- return result
1242
+ throw :response, result
1217
1243
  end
1218
1244
  rescue ::Gapic::Rest::Error => e
1219
1245
  raise ::Google::Cloud::Error.from_error(e)
@@ -1300,7 +1326,7 @@ module Google
1300
1326
  @document_processor_service_stub.deploy_processor_version request, options do |result, operation|
1301
1327
  result = ::Gapic::Operation.new result, @operations_client, options: options
1302
1328
  yield result, operation if block_given?
1303
- return result
1329
+ throw :response, result
1304
1330
  end
1305
1331
  rescue ::Gapic::Rest::Error => e
1306
1332
  raise ::Google::Cloud::Error.from_error(e)
@@ -1387,7 +1413,7 @@ module Google
1387
1413
  @document_processor_service_stub.undeploy_processor_version request, options do |result, operation|
1388
1414
  result = ::Gapic::Operation.new result, @operations_client, options: options
1389
1415
  yield result, operation if block_given?
1390
- return result
1416
+ throw :response, result
1391
1417
  end
1392
1418
  rescue ::Gapic::Rest::Error => e
1393
1419
  raise ::Google::Cloud::Error.from_error(e)
@@ -1480,7 +1506,6 @@ module Google
1480
1506
 
1481
1507
  @document_processor_service_stub.create_processor request, options do |result, operation|
1482
1508
  yield result, operation if block_given?
1483
- return result
1484
1509
  end
1485
1510
  rescue ::Gapic::Rest::Error => e
1486
1511
  raise ::Google::Cloud::Error.from_error(e)
@@ -1568,7 +1593,7 @@ module Google
1568
1593
  @document_processor_service_stub.delete_processor request, options do |result, operation|
1569
1594
  result = ::Gapic::Operation.new result, @operations_client, options: options
1570
1595
  yield result, operation if block_given?
1571
- return result
1596
+ throw :response, result
1572
1597
  end
1573
1598
  rescue ::Gapic::Rest::Error => e
1574
1599
  raise ::Google::Cloud::Error.from_error(e)
@@ -1655,7 +1680,7 @@ module Google
1655
1680
  @document_processor_service_stub.enable_processor request, options do |result, operation|
1656
1681
  result = ::Gapic::Operation.new result, @operations_client, options: options
1657
1682
  yield result, operation if block_given?
1658
- return result
1683
+ throw :response, result
1659
1684
  end
1660
1685
  rescue ::Gapic::Rest::Error => e
1661
1686
  raise ::Google::Cloud::Error.from_error(e)
@@ -1742,7 +1767,7 @@ module Google
1742
1767
  @document_processor_service_stub.disable_processor request, options do |result, operation|
1743
1768
  result = ::Gapic::Operation.new result, @operations_client, options: options
1744
1769
  yield result, operation if block_given?
1745
- return result
1770
+ throw :response, result
1746
1771
  end
1747
1772
  rescue ::Gapic::Rest::Error => e
1748
1773
  raise ::Google::Cloud::Error.from_error(e)
@@ -1840,7 +1865,7 @@ module Google
1840
1865
  @document_processor_service_stub.set_default_processor_version request, options do |result, operation|
1841
1866
  result = ::Gapic::Operation.new result, @operations_client, options: options
1842
1867
  yield result, operation if block_given?
1843
- return result
1868
+ throw :response, result
1844
1869
  end
1845
1870
  rescue ::Gapic::Rest::Error => e
1846
1871
  raise ::Google::Cloud::Error.from_error(e)
@@ -1938,7 +1963,7 @@ module Google
1938
1963
  @document_processor_service_stub.review_document request, options do |result, operation|
1939
1964
  result = ::Gapic::Operation.new result, @operations_client, options: options
1940
1965
  yield result, operation if block_given?
1941
- return result
1966
+ throw :response, result
1942
1967
  end
1943
1968
  rescue ::Gapic::Rest::Error => e
1944
1969
  raise ::Google::Cloud::Error.from_error(e)
@@ -2032,7 +2057,7 @@ module Google
2032
2057
  @document_processor_service_stub.evaluate_processor_version request, options do |result, operation|
2033
2058
  result = ::Gapic::Operation.new result, @operations_client, options: options
2034
2059
  yield result, operation if block_given?
2035
- return result
2060
+ throw :response, result
2036
2061
  end
2037
2062
  rescue ::Gapic::Rest::Error => e
2038
2063
  raise ::Google::Cloud::Error.from_error(e)
@@ -2113,7 +2138,6 @@ module Google
2113
2138
 
2114
2139
  @document_processor_service_stub.get_evaluation request, options do |result, operation|
2115
2140
  yield result, operation if block_given?
2116
- return result
2117
2141
  end
2118
2142
  rescue ::Gapic::Rest::Error => e
2119
2143
  raise ::Google::Cloud::Error.from_error(e)
@@ -2207,7 +2231,7 @@ module Google
2207
2231
  @document_processor_service_stub.list_evaluations request, options do |result, operation|
2208
2232
  result = ::Gapic::Rest::PagedEnumerable.new @document_processor_service_stub, :list_evaluations, "evaluations", request, result, options
2209
2233
  yield result, operation if block_given?
2210
- return result
2234
+ throw :response, result
2211
2235
  end
2212
2236
  rescue ::Gapic::Rest::Error => e
2213
2237
  raise ::Google::Cloud::Error.from_error(e)
@@ -2255,6 +2279,13 @@ module Google
2255
2279
  # * (`Signet::OAuth2::Client`) A signet oauth2 client object
2256
2280
  # (see the [signet docs](https://rubydoc.info/gems/signet/Signet/OAuth2/Client))
2257
2281
  # * (`nil`) indicating no credentials
2282
+ #
2283
+ # Warning: If you accept a credential configuration (JSON file or Hash) from an
2284
+ # external source for authentication to Google Cloud, you must validate it before
2285
+ # providing it to a Google API client library. Providing an unvalidated credential
2286
+ # configuration to Google APIs can compromise the security of your systems and data.
2287
+ # For more information, refer to [Validate credential configurations from external
2288
+ # sources](https://cloud.google.com/docs/authentication/external/externally-sourced-credentials).
2258
2289
  # @return [::Object]
2259
2290
  # @!attribute [rw] scope
2260
2291
  # The OAuth scopes
@@ -2287,6 +2318,11 @@ module Google
2287
2318
  # default endpoint URL. The default value of nil uses the environment
2288
2319
  # universe (usually the default "googleapis.com" universe).
2289
2320
  # @return [::String,nil]
2321
+ # @!attribute [rw] logger
2322
+ # A custom logger to use for request/response debug logging, or the value
2323
+ # `:default` (the default) to construct a default logger, or `nil` to
2324
+ # explicitly disable logging.
2325
+ # @return [::Logger,:default,nil]
2290
2326
  #
2291
2327
  class Configuration
2292
2328
  extend ::Gapic::Config
@@ -2315,6 +2351,7 @@ module Google
2315
2351
  # by the host service.
2316
2352
  # @return [::Hash{::Symbol=>::Array<::Gapic::Rest::GrpcTranscoder::HttpBinding>}]
2317
2353
  config_attr :bindings_override, {}, ::Hash, nil
2354
+ config_attr :logger, :default, ::Logger, nil, :default
2318
2355
 
2319
2356
  # @private
2320
2357
  def initialize parent_config = nil
@@ -115,14 +115,6 @@ module Google
115
115
  # Lists operations that match the specified filter in the request. If the
116
116
  # server doesn't support this method, it returns `UNIMPLEMENTED`.
117
117
  #
118
- # NOTE: the `name` binding allows API services to override the binding
119
- # to use different resource name schemes, such as `users/*/operations`. To
120
- # override the binding, API services can add a binding such as
121
- # `"/v1/{name=users/*}/operations"` to their service configuration.
122
- # For backwards compatibility, the default name includes the operations
123
- # collection id, however overriding users must ensure the name binding
124
- # is the parent resource, without the operations collection id.
125
- #
126
118
  # @overload list_operations(request, options = nil)
127
119
  # Pass arguments to `list_operations` via a request object, either of type
128
120
  # {::Google::Longrunning::ListOperationsRequest} or an equivalent Hash.
@@ -204,7 +196,7 @@ module Google
204
196
  @operations_stub.list_operations request, options do |result, operation|
205
197
  result = ::Gapic::Rest::PagedEnumerable.new @operations_stub, :list_operations, "operations", request, result, options
206
198
  yield result, operation if block_given?
207
- return result
199
+ throw :response, result
208
200
  end
209
201
  rescue ::Gapic::Rest::Error => e
210
202
  raise ::Google::Cloud::Error.from_error(e)
@@ -293,7 +285,7 @@ module Google
293
285
  @operations_stub.get_operation request, options do |result, operation|
294
286
  result = ::Gapic::Operation.new result, @operations_client, options: options
295
287
  yield result, operation if block_given?
296
- return result
288
+ throw :response, result
297
289
  end
298
290
  rescue ::Gapic::Rest::Error => e
299
291
  raise ::Google::Cloud::Error.from_error(e)
@@ -375,7 +367,6 @@ module Google
375
367
 
376
368
  @operations_stub.delete_operation request, options do |result, operation|
377
369
  yield result, operation if block_given?
378
- return result
379
370
  end
380
371
  rescue ::Gapic::Rest::Error => e
381
372
  raise ::Google::Cloud::Error.from_error(e)
@@ -390,8 +381,9 @@ module Google
390
381
  # other methods to check whether the cancellation succeeded or whether the
391
382
  # operation completed despite cancellation. On successful cancellation,
392
383
  # the operation is not deleted; instead, it becomes an operation with
393
- # an {::Google::Longrunning::Operation#error Operation.error} value with a {::Google::Rpc::Status#code google.rpc.Status.code} of 1,
394
- # corresponding to `Code.CANCELLED`.
384
+ # an {::Google::Longrunning::Operation#error Operation.error} value with a
385
+ # {::Google::Rpc::Status#code google.rpc.Status.code} of `1`, corresponding to
386
+ # `Code.CANCELLED`.
395
387
  #
396
388
  # @overload cancel_operation(request, options = nil)
397
389
  # Pass arguments to `cancel_operation` via a request object, either of type
@@ -463,7 +455,6 @@ module Google
463
455
 
464
456
  @operations_stub.cancel_operation request, options do |result, operation|
465
457
  yield result, operation if block_given?
466
- return result
467
458
  end
468
459
  rescue ::Gapic::Rest::Error => e
469
460
  raise ::Google::Cloud::Error.from_error(e)
@@ -511,6 +502,13 @@ module Google
511
502
  # * (`Signet::OAuth2::Client`) A signet oauth2 client object
512
503
  # (see the [signet docs](https://rubydoc.info/gems/signet/Signet/OAuth2/Client))
513
504
  # * (`nil`) indicating no credentials
505
+ #
506
+ # Warning: If you accept a credential configuration (JSON file or Hash) from an
507
+ # external source for authentication to Google Cloud, you must validate it before
508
+ # providing it to a Google API client library. Providing an unvalidated credential
509
+ # configuration to Google APIs can compromise the security of your systems and data.
510
+ # For more information, refer to [Validate credential configurations from external
511
+ # sources](https://cloud.google.com/docs/authentication/external/externally-sourced-credentials).
514
512
  # @return [::Object]
515
513
  # @!attribute [rw] scope
516
514
  # The OAuth scopes
@@ -543,6 +541,11 @@ module Google
543
541
  # default endpoint URL. The default value of nil uses the environment
544
542
  # universe (usually the default "googleapis.com" universe).
545
543
  # @return [::String,nil]
544
+ # @!attribute [rw] logger
545
+ # A custom logger to use for request/response debug logging, or the value
546
+ # `:default` (the default) to construct a default logger, or `nil` to
547
+ # explicitly disable logging.
548
+ # @return [::Logger,:default,nil]
546
549
  #
547
550
  class Configuration
548
551
  extend ::Gapic::Config
@@ -564,6 +567,7 @@ module Google
564
567
  config_attr :retry_policy, nil, ::Hash, ::Proc, nil
565
568
  config_attr :quota_project, nil, ::String, nil
566
569
  config_attr :universe_domain, nil, ::String, nil
570
+ config_attr :logger, :default, ::Logger, nil, :default
567
571
 
568
572
  # @private
569
573
  def initialize parent_config = nil
@@ -683,16 +687,18 @@ module Google
683
687
 
684
688
  response = @client_stub.make_http_request(
685
689
  verb,
686
- uri: uri,
687
- body: body || "",
688
- params: query_string_params,
690
+ uri: uri,
691
+ body: body || "",
692
+ params: query_string_params,
693
+ method_name: "list_operations",
689
694
  options: options
690
695
  )
691
696
  operation = ::Gapic::Rest::TransportOperation.new response
692
697
  result = ::Google::Longrunning::ListOperationsResponse.decode_json response.body, ignore_unknown_fields: true
693
-
694
- yield result, operation if block_given?
695
- result
698
+ catch :response do
699
+ yield result, operation if block_given?
700
+ result
701
+ end
696
702
  end
697
703
 
698
704
  ##
@@ -721,16 +727,18 @@ module Google
721
727
 
722
728
  response = @client_stub.make_http_request(
723
729
  verb,
724
- uri: uri,
725
- body: body || "",
726
- params: query_string_params,
730
+ uri: uri,
731
+ body: body || "",
732
+ params: query_string_params,
733
+ method_name: "get_operation",
727
734
  options: options
728
735
  )
729
736
  operation = ::Gapic::Rest::TransportOperation.new response
730
737
  result = ::Google::Longrunning::Operation.decode_json response.body, ignore_unknown_fields: true
731
-
732
- yield result, operation if block_given?
733
- result
738
+ catch :response do
739
+ yield result, operation if block_given?
740
+ result
741
+ end
734
742
  end
735
743
 
736
744
  ##
@@ -759,16 +767,18 @@ module Google
759
767
 
760
768
  response = @client_stub.make_http_request(
761
769
  verb,
762
- uri: uri,
763
- body: body || "",
764
- params: query_string_params,
770
+ uri: uri,
771
+ body: body || "",
772
+ params: query_string_params,
773
+ method_name: "delete_operation",
765
774
  options: options
766
775
  )
767
776
  operation = ::Gapic::Rest::TransportOperation.new response
768
777
  result = ::Google::Protobuf::Empty.decode_json response.body, ignore_unknown_fields: true
769
-
770
- yield result, operation if block_given?
771
- result
778
+ catch :response do
779
+ yield result, operation if block_given?
780
+ result
781
+ end
772
782
  end
773
783
 
774
784
  ##
@@ -797,16 +807,18 @@ module Google
797
807
 
798
808
  response = @client_stub.make_http_request(
799
809
  verb,
800
- uri: uri,
801
- body: body || "",
802
- params: query_string_params,
810
+ uri: uri,
811
+ body: body || "",
812
+ params: query_string_params,
813
+ method_name: "cancel_operation",
803
814
  options: options
804
815
  )
805
816
  operation = ::Gapic::Rest::TransportOperation.new response
806
817
  result = ::Google::Protobuf::Empty.decode_json response.body, ignore_unknown_fields: true
807
-
808
- yield result, operation if block_given?
809
- result
818
+ catch :response do
819
+ yield result, operation if block_given?
820
+ result
821
+ end
810
822
  end
811
823
 
812
824
  ##