google-cloud-document_ai-v1 1.1.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -78,17 +78,17 @@ module Google
78
78
 
79
79
  default_config.rpcs.process_document.timeout = 300.0
80
80
  default_config.rpcs.process_document.retry_policy = {
81
- initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [4, 14]
81
+ initial_delay: 1.0, max_delay: 90.0, multiplier: 9.0, retry_codes: [4, 14, 8]
82
82
  }
83
83
 
84
84
  default_config.rpcs.batch_process_documents.timeout = 120.0
85
85
  default_config.rpcs.batch_process_documents.retry_policy = {
86
- initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [4, 14]
86
+ initial_delay: 1.0, max_delay: 60.0, multiplier: 1.5, retry_codes: [4, 14]
87
87
  }
88
88
 
89
89
  default_config.rpcs.review_document.timeout = 120.0
90
90
  default_config.rpcs.review_document.retry_policy = {
91
- initial_delay: 0.1, max_delay: 60.0, multiplier: 1.3, retry_codes: [4, 14]
91
+ initial_delay: 1.0, max_delay: 60.0, multiplier: 1.5, retry_codes: [4, 14]
92
92
  }
93
93
 
94
94
  default_config
@@ -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
  ##
@@ -311,7 +332,6 @@ module Google
311
332
 
312
333
  @document_processor_service_stub.process_document request, options do |result, operation|
313
334
  yield result, operation if block_given?
314
- return result
315
335
  end
316
336
  rescue ::Gapic::Rest::Error => e
317
337
  raise ::Google::Cloud::Error.from_error(e)
@@ -424,7 +444,7 @@ module Google
424
444
  @document_processor_service_stub.batch_process_documents request, options do |result, operation|
425
445
  result = ::Gapic::Operation.new result, @operations_client, options: options
426
446
  yield result, operation if block_given?
427
- return result
447
+ throw :response, result
428
448
  end
429
449
  rescue ::Gapic::Rest::Error => e
430
450
  raise ::Google::Cloud::Error.from_error(e)
@@ -506,7 +526,6 @@ module Google
506
526
 
507
527
  @document_processor_service_stub.fetch_processor_types request, options do |result, operation|
508
528
  yield result, operation if block_given?
509
- return result
510
529
  end
511
530
  rescue ::Gapic::Rest::Error => e
512
531
  raise ::Google::Cloud::Error.from_error(e)
@@ -597,7 +616,7 @@ module Google
597
616
  @document_processor_service_stub.list_processor_types request, options do |result, operation|
598
617
  result = ::Gapic::Rest::PagedEnumerable.new @document_processor_service_stub, :list_processor_types, "processor_types", request, result, options
599
618
  yield result, operation if block_given?
600
- return result
619
+ throw :response, result
601
620
  end
602
621
  rescue ::Gapic::Rest::Error => e
603
622
  raise ::Google::Cloud::Error.from_error(e)
@@ -676,7 +695,6 @@ module Google
676
695
 
677
696
  @document_processor_service_stub.get_processor_type request, options do |result, operation|
678
697
  yield result, operation if block_given?
679
- return result
680
698
  end
681
699
  rescue ::Gapic::Rest::Error => e
682
700
  raise ::Google::Cloud::Error.from_error(e)
@@ -768,7 +786,7 @@ module Google
768
786
  @document_processor_service_stub.list_processors request, options do |result, operation|
769
787
  result = ::Gapic::Rest::PagedEnumerable.new @document_processor_service_stub, :list_processors, "processors", request, result, options
770
788
  yield result, operation if block_given?
771
- return result
789
+ throw :response, result
772
790
  end
773
791
  rescue ::Gapic::Rest::Error => e
774
792
  raise ::Google::Cloud::Error.from_error(e)
@@ -847,7 +865,6 @@ module Google
847
865
 
848
866
  @document_processor_service_stub.get_processor request, options do |result, operation|
849
867
  yield result, operation if block_given?
850
- return result
851
868
  end
852
869
  rescue ::Gapic::Rest::Error => e
853
870
  raise ::Google::Cloud::Error.from_error(e)
@@ -953,7 +970,7 @@ module Google
953
970
  @document_processor_service_stub.train_processor_version request, options do |result, operation|
954
971
  result = ::Gapic::Operation.new result, @operations_client, options: options
955
972
  yield result, operation if block_given?
956
- return result
973
+ throw :response, result
957
974
  end
958
975
  rescue ::Gapic::Rest::Error => e
959
976
  raise ::Google::Cloud::Error.from_error(e)
@@ -1032,7 +1049,6 @@ module Google
1032
1049
 
1033
1050
  @document_processor_service_stub.get_processor_version request, options do |result, operation|
1034
1051
  yield result, operation if block_given?
1035
- return result
1036
1052
  end
1037
1053
  rescue ::Gapic::Rest::Error => e
1038
1054
  raise ::Google::Cloud::Error.from_error(e)
@@ -1125,7 +1141,7 @@ module Google
1125
1141
  @document_processor_service_stub.list_processor_versions request, options do |result, operation|
1126
1142
  result = ::Gapic::Rest::PagedEnumerable.new @document_processor_service_stub, :list_processor_versions, "processor_versions", request, result, options
1127
1143
  yield result, operation if block_given?
1128
- return result
1144
+ throw :response, result
1129
1145
  end
1130
1146
  rescue ::Gapic::Rest::Error => e
1131
1147
  raise ::Google::Cloud::Error.from_error(e)
@@ -1213,7 +1229,7 @@ module Google
1213
1229
  @document_processor_service_stub.delete_processor_version request, options do |result, operation|
1214
1230
  result = ::Gapic::Operation.new result, @operations_client, options: options
1215
1231
  yield result, operation if block_given?
1216
- return result
1232
+ throw :response, result
1217
1233
  end
1218
1234
  rescue ::Gapic::Rest::Error => e
1219
1235
  raise ::Google::Cloud::Error.from_error(e)
@@ -1300,7 +1316,7 @@ module Google
1300
1316
  @document_processor_service_stub.deploy_processor_version request, options do |result, operation|
1301
1317
  result = ::Gapic::Operation.new result, @operations_client, options: options
1302
1318
  yield result, operation if block_given?
1303
- return result
1319
+ throw :response, result
1304
1320
  end
1305
1321
  rescue ::Gapic::Rest::Error => e
1306
1322
  raise ::Google::Cloud::Error.from_error(e)
@@ -1387,7 +1403,7 @@ module Google
1387
1403
  @document_processor_service_stub.undeploy_processor_version request, options do |result, operation|
1388
1404
  result = ::Gapic::Operation.new result, @operations_client, options: options
1389
1405
  yield result, operation if block_given?
1390
- return result
1406
+ throw :response, result
1391
1407
  end
1392
1408
  rescue ::Gapic::Rest::Error => e
1393
1409
  raise ::Google::Cloud::Error.from_error(e)
@@ -1480,7 +1496,6 @@ module Google
1480
1496
 
1481
1497
  @document_processor_service_stub.create_processor request, options do |result, operation|
1482
1498
  yield result, operation if block_given?
1483
- return result
1484
1499
  end
1485
1500
  rescue ::Gapic::Rest::Error => e
1486
1501
  raise ::Google::Cloud::Error.from_error(e)
@@ -1568,7 +1583,7 @@ module Google
1568
1583
  @document_processor_service_stub.delete_processor request, options do |result, operation|
1569
1584
  result = ::Gapic::Operation.new result, @operations_client, options: options
1570
1585
  yield result, operation if block_given?
1571
- return result
1586
+ throw :response, result
1572
1587
  end
1573
1588
  rescue ::Gapic::Rest::Error => e
1574
1589
  raise ::Google::Cloud::Error.from_error(e)
@@ -1655,7 +1670,7 @@ module Google
1655
1670
  @document_processor_service_stub.enable_processor request, options do |result, operation|
1656
1671
  result = ::Gapic::Operation.new result, @operations_client, options: options
1657
1672
  yield result, operation if block_given?
1658
- return result
1673
+ throw :response, result
1659
1674
  end
1660
1675
  rescue ::Gapic::Rest::Error => e
1661
1676
  raise ::Google::Cloud::Error.from_error(e)
@@ -1742,7 +1757,7 @@ module Google
1742
1757
  @document_processor_service_stub.disable_processor request, options do |result, operation|
1743
1758
  result = ::Gapic::Operation.new result, @operations_client, options: options
1744
1759
  yield result, operation if block_given?
1745
- return result
1760
+ throw :response, result
1746
1761
  end
1747
1762
  rescue ::Gapic::Rest::Error => e
1748
1763
  raise ::Google::Cloud::Error.from_error(e)
@@ -1840,7 +1855,7 @@ module Google
1840
1855
  @document_processor_service_stub.set_default_processor_version request, options do |result, operation|
1841
1856
  result = ::Gapic::Operation.new result, @operations_client, options: options
1842
1857
  yield result, operation if block_given?
1843
- return result
1858
+ throw :response, result
1844
1859
  end
1845
1860
  rescue ::Gapic::Rest::Error => e
1846
1861
  raise ::Google::Cloud::Error.from_error(e)
@@ -1938,7 +1953,7 @@ module Google
1938
1953
  @document_processor_service_stub.review_document request, options do |result, operation|
1939
1954
  result = ::Gapic::Operation.new result, @operations_client, options: options
1940
1955
  yield result, operation if block_given?
1941
- return result
1956
+ throw :response, result
1942
1957
  end
1943
1958
  rescue ::Gapic::Rest::Error => e
1944
1959
  raise ::Google::Cloud::Error.from_error(e)
@@ -2032,7 +2047,7 @@ module Google
2032
2047
  @document_processor_service_stub.evaluate_processor_version request, options do |result, operation|
2033
2048
  result = ::Gapic::Operation.new result, @operations_client, options: options
2034
2049
  yield result, operation if block_given?
2035
- return result
2050
+ throw :response, result
2036
2051
  end
2037
2052
  rescue ::Gapic::Rest::Error => e
2038
2053
  raise ::Google::Cloud::Error.from_error(e)
@@ -2113,7 +2128,6 @@ module Google
2113
2128
 
2114
2129
  @document_processor_service_stub.get_evaluation request, options do |result, operation|
2115
2130
  yield result, operation if block_given?
2116
- return result
2117
2131
  end
2118
2132
  rescue ::Gapic::Rest::Error => e
2119
2133
  raise ::Google::Cloud::Error.from_error(e)
@@ -2207,7 +2221,7 @@ module Google
2207
2221
  @document_processor_service_stub.list_evaluations request, options do |result, operation|
2208
2222
  result = ::Gapic::Rest::PagedEnumerable.new @document_processor_service_stub, :list_evaluations, "evaluations", request, result, options
2209
2223
  yield result, operation if block_given?
2210
- return result
2224
+ throw :response, result
2211
2225
  end
2212
2226
  rescue ::Gapic::Rest::Error => e
2213
2227
  raise ::Google::Cloud::Error.from_error(e)
@@ -2287,6 +2301,11 @@ module Google
2287
2301
  # default endpoint URL. The default value of nil uses the environment
2288
2302
  # universe (usually the default "googleapis.com" universe).
2289
2303
  # @return [::String,nil]
2304
+ # @!attribute [rw] logger
2305
+ # A custom logger to use for request/response debug logging, or the value
2306
+ # `:default` (the default) to construct a default logger, or `nil` to
2307
+ # explicitly disable logging.
2308
+ # @return [::Logger,:default,nil]
2290
2309
  #
2291
2310
  class Configuration
2292
2311
  extend ::Gapic::Config
@@ -2315,6 +2334,7 @@ module Google
2315
2334
  # by the host service.
2316
2335
  # @return [::Hash{::Symbol=>::Array<::Gapic::Rest::GrpcTranscoder::HttpBinding>}]
2317
2336
  config_attr :bindings_override, {}, ::Hash, nil
2337
+ config_attr :logger, :default, ::Logger, nil, :default
2318
2338
 
2319
2339
  # @private
2320
2340
  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)
@@ -543,6 +534,11 @@ module Google
543
534
  # default endpoint URL. The default value of nil uses the environment
544
535
  # universe (usually the default "googleapis.com" universe).
545
536
  # @return [::String,nil]
537
+ # @!attribute [rw] logger
538
+ # A custom logger to use for request/response debug logging, or the value
539
+ # `:default` (the default) to construct a default logger, or `nil` to
540
+ # explicitly disable logging.
541
+ # @return [::Logger,:default,nil]
546
542
  #
547
543
  class Configuration
548
544
  extend ::Gapic::Config
@@ -564,6 +560,7 @@ module Google
564
560
  config_attr :retry_policy, nil, ::Hash, ::Proc, nil
565
561
  config_attr :quota_project, nil, ::String, nil
566
562
  config_attr :universe_domain, nil, ::String, nil
563
+ config_attr :logger, :default, ::Logger, nil, :default
567
564
 
568
565
  # @private
569
566
  def initialize parent_config = nil
@@ -683,16 +680,18 @@ module Google
683
680
 
684
681
  response = @client_stub.make_http_request(
685
682
  verb,
686
- uri: uri,
687
- body: body || "",
688
- params: query_string_params,
683
+ uri: uri,
684
+ body: body || "",
685
+ params: query_string_params,
686
+ method_name: "list_operations",
689
687
  options: options
690
688
  )
691
689
  operation = ::Gapic::Rest::TransportOperation.new response
692
690
  result = ::Google::Longrunning::ListOperationsResponse.decode_json response.body, ignore_unknown_fields: true
693
-
694
- yield result, operation if block_given?
695
- result
691
+ catch :response do
692
+ yield result, operation if block_given?
693
+ result
694
+ end
696
695
  end
697
696
 
698
697
  ##
@@ -721,16 +720,18 @@ module Google
721
720
 
722
721
  response = @client_stub.make_http_request(
723
722
  verb,
724
- uri: uri,
725
- body: body || "",
726
- params: query_string_params,
723
+ uri: uri,
724
+ body: body || "",
725
+ params: query_string_params,
726
+ method_name: "get_operation",
727
727
  options: options
728
728
  )
729
729
  operation = ::Gapic::Rest::TransportOperation.new response
730
730
  result = ::Google::Longrunning::Operation.decode_json response.body, ignore_unknown_fields: true
731
-
732
- yield result, operation if block_given?
733
- result
731
+ catch :response do
732
+ yield result, operation if block_given?
733
+ result
734
+ end
734
735
  end
735
736
 
736
737
  ##
@@ -759,16 +760,18 @@ module Google
759
760
 
760
761
  response = @client_stub.make_http_request(
761
762
  verb,
762
- uri: uri,
763
- body: body || "",
764
- params: query_string_params,
763
+ uri: uri,
764
+ body: body || "",
765
+ params: query_string_params,
766
+ method_name: "delete_operation",
765
767
  options: options
766
768
  )
767
769
  operation = ::Gapic::Rest::TransportOperation.new response
768
770
  result = ::Google::Protobuf::Empty.decode_json response.body, ignore_unknown_fields: true
769
-
770
- yield result, operation if block_given?
771
- result
771
+ catch :response do
772
+ yield result, operation if block_given?
773
+ result
774
+ end
772
775
  end
773
776
 
774
777
  ##
@@ -797,16 +800,18 @@ module Google
797
800
 
798
801
  response = @client_stub.make_http_request(
799
802
  verb,
800
- uri: uri,
801
- body: body || "",
802
- params: query_string_params,
803
+ uri: uri,
804
+ body: body || "",
805
+ params: query_string_params,
806
+ method_name: "cancel_operation",
803
807
  options: options
804
808
  )
805
809
  operation = ::Gapic::Rest::TransportOperation.new response
806
810
  result = ::Google::Protobuf::Empty.decode_json response.body, ignore_unknown_fields: true
807
-
808
- yield result, operation if block_given?
809
- result
811
+ catch :response do
812
+ yield result, operation if block_given?
813
+ result
814
+ end
810
815
  end
811
816
 
812
817
  ##