google-cloud-optimization-v1 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,767 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2022 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/operation"
20
+ require "google/longrunning/operations_pb"
21
+
22
+ module Google
23
+ module Cloud
24
+ module Optimization
25
+ module V1
26
+ module FleetRouting
27
+ # Service that implements Longrunning Operations API.
28
+ class Operations
29
+ # @private
30
+ attr_reader :operations_stub
31
+
32
+ ##
33
+ # Configuration for the FleetRouting Operations API.
34
+ #
35
+ # @yield [config] Configure the Operations client.
36
+ # @yieldparam config [Operations::Configuration]
37
+ #
38
+ # @return [Operations::Configuration]
39
+ #
40
+ def self.configure
41
+ @configure ||= Operations::Configuration.new
42
+ yield @configure if block_given?
43
+ @configure
44
+ end
45
+
46
+ ##
47
+ # Configure the FleetRouting Operations instance.
48
+ #
49
+ # The configuration is set to the derived mode, meaning that values can be changed,
50
+ # but structural changes (adding new fields, etc.) are not allowed. Structural changes
51
+ # should be made on {Operations.configure}.
52
+ #
53
+ # @yield [config] Configure the Operations client.
54
+ # @yieldparam config [Operations::Configuration]
55
+ #
56
+ # @return [Operations::Configuration]
57
+ #
58
+ def configure
59
+ yield @config if block_given?
60
+ @config
61
+ end
62
+
63
+ ##
64
+ # Create a new Operations client object.
65
+ #
66
+ # @yield [config] Configure the Client client.
67
+ # @yieldparam config [Operations::Configuration]
68
+ #
69
+ def initialize
70
+ # These require statements are intentionally placed here to initialize
71
+ # the gRPC module only when it's required.
72
+ # See https://github.com/googleapis/toolkit/issues/446
73
+ require "gapic/grpc"
74
+ require "google/longrunning/operations_services_pb"
75
+
76
+ # Create the configuration object
77
+ @config = Configuration.new Operations.configure
78
+
79
+ # Yield the configuration if needed
80
+ yield @config if block_given?
81
+
82
+ # Create credentials
83
+ credentials = @config.credentials
84
+ credentials ||= Credentials.default scope: @config.scope
85
+ if credentials.is_a?(::String) || credentials.is_a?(::Hash)
86
+ credentials = Credentials.new credentials, scope: @config.scope
87
+ end
88
+ @quota_project_id = @config.quota_project
89
+ @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id
90
+
91
+ @operations_stub = ::Gapic::ServiceStub.new(
92
+ ::Google::Longrunning::Operations::Stub,
93
+ credentials: credentials,
94
+ endpoint: @config.endpoint,
95
+ channel_args: @config.channel_args,
96
+ interceptors: @config.interceptors
97
+ )
98
+ end
99
+
100
+ # Service calls
101
+
102
+ ##
103
+ # Lists operations that match the specified filter in the request. If the
104
+ # server doesn't support this method, it returns `UNIMPLEMENTED`.
105
+ #
106
+ # NOTE: the `name` binding allows API services to override the binding
107
+ # to use different resource name schemes, such as `users/*/operations`. To
108
+ # override the binding, API services can add a binding such as
109
+ # `"/v1/{name=users/*}/operations"` to their service configuration.
110
+ # For backwards compatibility, the default name includes the operations
111
+ # collection id, however overriding users must ensure the name binding
112
+ # is the parent resource, without the operations collection id.
113
+ #
114
+ # @overload list_operations(request, options = nil)
115
+ # Pass arguments to `list_operations` via a request object, either of type
116
+ # {::Google::Longrunning::ListOperationsRequest} or an equivalent Hash.
117
+ #
118
+ # @param request [::Google::Longrunning::ListOperationsRequest, ::Hash]
119
+ # A request object representing the call parameters. Required. To specify no
120
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
121
+ # @param options [::Gapic::CallOptions, ::Hash]
122
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
123
+ #
124
+ # @overload list_operations(name: nil, filter: nil, page_size: nil, page_token: nil)
125
+ # Pass arguments to `list_operations` via keyword arguments. Note that at
126
+ # least one keyword argument is required. To specify no parameters, or to keep all
127
+ # the default parameter values, pass an empty Hash as a request object (see above).
128
+ #
129
+ # @param name [::String]
130
+ # The name of the operation's parent resource.
131
+ # @param filter [::String]
132
+ # The standard list filter.
133
+ # @param page_size [::Integer]
134
+ # The standard list page size.
135
+ # @param page_token [::String]
136
+ # The standard list page token.
137
+ #
138
+ # @yield [response, operation] Access the result along with the RPC operation
139
+ # @yieldparam response [::Gapic::PagedEnumerable<::Gapic::Operation>]
140
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
141
+ #
142
+ # @return [::Gapic::PagedEnumerable<::Gapic::Operation>]
143
+ #
144
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
145
+ #
146
+ # @example Basic example
147
+ # require "google/longrunning"
148
+ #
149
+ # # Create a client object. The client can be reused for multiple calls.
150
+ # client = Google::Longrunning::Operations::Client.new
151
+ #
152
+ # # Create a request. To set request fields, pass in keyword arguments.
153
+ # request = Google::Longrunning::ListOperationsRequest.new
154
+ #
155
+ # # Call the list_operations method.
156
+ # result = client.list_operations request
157
+ #
158
+ # # The returned object is of type Gapic::PagedEnumerable. You can
159
+ # # iterate over all elements by calling #each, and the enumerable
160
+ # # will lazily make API calls to fetch subsequent pages. Other
161
+ # # methods are also available for managing paging directly.
162
+ # result.each do |response|
163
+ # # Each element is of type ::Google::Longrunning::Operation.
164
+ # p response
165
+ # end
166
+ #
167
+ def list_operations request, options = nil
168
+ raise ::ArgumentError, "request must be provided" if request.nil?
169
+
170
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Longrunning::ListOperationsRequest
171
+
172
+ # Converts hash and nil to an options object
173
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
174
+
175
+ # Customize the options with defaults
176
+ metadata = @config.rpcs.list_operations.metadata.to_h
177
+
178
+ # Set x-goog-api-client and x-goog-user-project headers
179
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
180
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
181
+ gapic_version: ::Google::Cloud::Optimization::V1::VERSION
182
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
183
+
184
+ header_params = {}
185
+ if request.name
186
+ header_params["name"] = request.name
187
+ end
188
+
189
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
190
+ metadata[:"x-goog-request-params"] ||= request_params_header
191
+
192
+ options.apply_defaults timeout: @config.rpcs.list_operations.timeout,
193
+ metadata: metadata,
194
+ retry_policy: @config.rpcs.list_operations.retry_policy
195
+
196
+ options.apply_defaults timeout: @config.timeout,
197
+ metadata: @config.metadata,
198
+ retry_policy: @config.retry_policy
199
+
200
+ @operations_stub.call_rpc :list_operations, request, options: options do |response, operation|
201
+ wrap_lro_operation = ->(op_response) { ::Gapic::Operation.new op_response, @operations_client }
202
+ response = ::Gapic::PagedEnumerable.new @operations_stub, :list_operations, request, response, operation, options, format_resource: wrap_lro_operation
203
+ yield response, operation if block_given?
204
+ return response
205
+ end
206
+ rescue ::GRPC::BadStatus => e
207
+ raise ::Google::Cloud::Error.from_error(e)
208
+ end
209
+
210
+ ##
211
+ # Gets the latest state of a long-running operation. Clients can use this
212
+ # method to poll the operation result at intervals as recommended by the API
213
+ # service.
214
+ #
215
+ # @overload get_operation(request, options = nil)
216
+ # Pass arguments to `get_operation` via a request object, either of type
217
+ # {::Google::Longrunning::GetOperationRequest} or an equivalent Hash.
218
+ #
219
+ # @param request [::Google::Longrunning::GetOperationRequest, ::Hash]
220
+ # A request object representing the call parameters. Required. To specify no
221
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
222
+ # @param options [::Gapic::CallOptions, ::Hash]
223
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
224
+ #
225
+ # @overload get_operation(name: nil)
226
+ # Pass arguments to `get_operation` via keyword arguments. Note that at
227
+ # least one keyword argument is required. To specify no parameters, or to keep all
228
+ # the default parameter values, pass an empty Hash as a request object (see above).
229
+ #
230
+ # @param name [::String]
231
+ # The name of the operation resource.
232
+ #
233
+ # @yield [response, operation] Access the result along with the RPC operation
234
+ # @yieldparam response [::Gapic::Operation]
235
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
236
+ #
237
+ # @return [::Gapic::Operation]
238
+ #
239
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
240
+ #
241
+ # @example Basic example
242
+ # require "google/longrunning"
243
+ #
244
+ # # Create a client object. The client can be reused for multiple calls.
245
+ # client = Google::Longrunning::Operations::Client.new
246
+ #
247
+ # # Create a request. To set request fields, pass in keyword arguments.
248
+ # request = Google::Longrunning::GetOperationRequest.new
249
+ #
250
+ # # Call the get_operation method.
251
+ # result = client.get_operation request
252
+ #
253
+ # # The returned object is of type Gapic::Operation. You can use this
254
+ # # object to check the status of an operation, cancel it, or wait
255
+ # # for results. Here is how to block until completion:
256
+ # result.wait_until_done! timeout: 60
257
+ # if result.response?
258
+ # p result.response
259
+ # else
260
+ # puts "Error!"
261
+ # end
262
+ #
263
+ def get_operation request, options = nil
264
+ raise ::ArgumentError, "request must be provided" if request.nil?
265
+
266
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Longrunning::GetOperationRequest
267
+
268
+ # Converts hash and nil to an options object
269
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
270
+
271
+ # Customize the options with defaults
272
+ metadata = @config.rpcs.get_operation.metadata.to_h
273
+
274
+ # Set x-goog-api-client and x-goog-user-project headers
275
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
276
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
277
+ gapic_version: ::Google::Cloud::Optimization::V1::VERSION
278
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
279
+
280
+ header_params = {}
281
+ if request.name
282
+ header_params["name"] = request.name
283
+ end
284
+
285
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
286
+ metadata[:"x-goog-request-params"] ||= request_params_header
287
+
288
+ options.apply_defaults timeout: @config.rpcs.get_operation.timeout,
289
+ metadata: metadata,
290
+ retry_policy: @config.rpcs.get_operation.retry_policy
291
+
292
+ options.apply_defaults timeout: @config.timeout,
293
+ metadata: @config.metadata,
294
+ retry_policy: @config.retry_policy
295
+
296
+ @operations_stub.call_rpc :get_operation, request, options: options do |response, operation|
297
+ response = ::Gapic::Operation.new response, @operations_client, options: options
298
+ yield response, operation if block_given?
299
+ return response
300
+ end
301
+ rescue ::GRPC::BadStatus => e
302
+ raise ::Google::Cloud::Error.from_error(e)
303
+ end
304
+
305
+ ##
306
+ # Deletes a long-running operation. This method indicates that the client is
307
+ # no longer interested in the operation result. It does not cancel the
308
+ # operation. If the server doesn't support this method, it returns
309
+ # `google.rpc.Code.UNIMPLEMENTED`.
310
+ #
311
+ # @overload delete_operation(request, options = nil)
312
+ # Pass arguments to `delete_operation` via a request object, either of type
313
+ # {::Google::Longrunning::DeleteOperationRequest} or an equivalent Hash.
314
+ #
315
+ # @param request [::Google::Longrunning::DeleteOperationRequest, ::Hash]
316
+ # A request object representing the call parameters. Required. To specify no
317
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
318
+ # @param options [::Gapic::CallOptions, ::Hash]
319
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
320
+ #
321
+ # @overload delete_operation(name: nil)
322
+ # Pass arguments to `delete_operation` via keyword arguments. Note that at
323
+ # least one keyword argument is required. To specify no parameters, or to keep all
324
+ # the default parameter values, pass an empty Hash as a request object (see above).
325
+ #
326
+ # @param name [::String]
327
+ # The name of the operation resource to be deleted.
328
+ #
329
+ # @yield [response, operation] Access the result along with the RPC operation
330
+ # @yieldparam response [::Google::Protobuf::Empty]
331
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
332
+ #
333
+ # @return [::Google::Protobuf::Empty]
334
+ #
335
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
336
+ #
337
+ # @example Basic example
338
+ # require "google/longrunning"
339
+ #
340
+ # # Create a client object. The client can be reused for multiple calls.
341
+ # client = Google::Longrunning::Operations::Client.new
342
+ #
343
+ # # Create a request. To set request fields, pass in keyword arguments.
344
+ # request = Google::Longrunning::DeleteOperationRequest.new
345
+ #
346
+ # # Call the delete_operation method.
347
+ # result = client.delete_operation request
348
+ #
349
+ # # The returned object is of type Google::Protobuf::Empty.
350
+ # p result
351
+ #
352
+ def delete_operation request, options = nil
353
+ raise ::ArgumentError, "request must be provided" if request.nil?
354
+
355
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Longrunning::DeleteOperationRequest
356
+
357
+ # Converts hash and nil to an options object
358
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
359
+
360
+ # Customize the options with defaults
361
+ metadata = @config.rpcs.delete_operation.metadata.to_h
362
+
363
+ # Set x-goog-api-client and x-goog-user-project headers
364
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
365
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
366
+ gapic_version: ::Google::Cloud::Optimization::V1::VERSION
367
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
368
+
369
+ header_params = {}
370
+ if request.name
371
+ header_params["name"] = request.name
372
+ end
373
+
374
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
375
+ metadata[:"x-goog-request-params"] ||= request_params_header
376
+
377
+ options.apply_defaults timeout: @config.rpcs.delete_operation.timeout,
378
+ metadata: metadata,
379
+ retry_policy: @config.rpcs.delete_operation.retry_policy
380
+
381
+ options.apply_defaults timeout: @config.timeout,
382
+ metadata: @config.metadata,
383
+ retry_policy: @config.retry_policy
384
+
385
+ @operations_stub.call_rpc :delete_operation, request, options: options do |response, operation|
386
+ yield response, operation if block_given?
387
+ return response
388
+ end
389
+ rescue ::GRPC::BadStatus => e
390
+ raise ::Google::Cloud::Error.from_error(e)
391
+ end
392
+
393
+ ##
394
+ # Starts asynchronous cancellation on a long-running operation. The server
395
+ # makes a best effort to cancel the operation, but success is not
396
+ # guaranteed. If the server doesn't support this method, it returns
397
+ # `google.rpc.Code.UNIMPLEMENTED`. Clients can use
398
+ # Operations.GetOperation or
399
+ # other methods to check whether the cancellation succeeded or whether the
400
+ # operation completed despite cancellation. On successful cancellation,
401
+ # the operation is not deleted; instead, it becomes an operation with
402
+ # an {::Google::Longrunning::Operation#error Operation.error} value with a {::Google::Rpc::Status#code google.rpc.Status.code} of 1,
403
+ # corresponding to `Code.CANCELLED`.
404
+ #
405
+ # @overload cancel_operation(request, options = nil)
406
+ # Pass arguments to `cancel_operation` via a request object, either of type
407
+ # {::Google::Longrunning::CancelOperationRequest} or an equivalent Hash.
408
+ #
409
+ # @param request [::Google::Longrunning::CancelOperationRequest, ::Hash]
410
+ # A request object representing the call parameters. Required. To specify no
411
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
412
+ # @param options [::Gapic::CallOptions, ::Hash]
413
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
414
+ #
415
+ # @overload cancel_operation(name: nil)
416
+ # Pass arguments to `cancel_operation` via keyword arguments. Note that at
417
+ # least one keyword argument is required. To specify no parameters, or to keep all
418
+ # the default parameter values, pass an empty Hash as a request object (see above).
419
+ #
420
+ # @param name [::String]
421
+ # The name of the operation resource to be cancelled.
422
+ #
423
+ # @yield [response, operation] Access the result along with the RPC operation
424
+ # @yieldparam response [::Google::Protobuf::Empty]
425
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
426
+ #
427
+ # @return [::Google::Protobuf::Empty]
428
+ #
429
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
430
+ #
431
+ # @example Basic example
432
+ # require "google/longrunning"
433
+ #
434
+ # # Create a client object. The client can be reused for multiple calls.
435
+ # client = Google::Longrunning::Operations::Client.new
436
+ #
437
+ # # Create a request. To set request fields, pass in keyword arguments.
438
+ # request = Google::Longrunning::CancelOperationRequest.new
439
+ #
440
+ # # Call the cancel_operation method.
441
+ # result = client.cancel_operation request
442
+ #
443
+ # # The returned object is of type Google::Protobuf::Empty.
444
+ # p result
445
+ #
446
+ def cancel_operation request, options = nil
447
+ raise ::ArgumentError, "request must be provided" if request.nil?
448
+
449
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Longrunning::CancelOperationRequest
450
+
451
+ # Converts hash and nil to an options object
452
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
453
+
454
+ # Customize the options with defaults
455
+ metadata = @config.rpcs.cancel_operation.metadata.to_h
456
+
457
+ # Set x-goog-api-client and x-goog-user-project headers
458
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
459
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
460
+ gapic_version: ::Google::Cloud::Optimization::V1::VERSION
461
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
462
+
463
+ header_params = {}
464
+ if request.name
465
+ header_params["name"] = request.name
466
+ end
467
+
468
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
469
+ metadata[:"x-goog-request-params"] ||= request_params_header
470
+
471
+ options.apply_defaults timeout: @config.rpcs.cancel_operation.timeout,
472
+ metadata: metadata,
473
+ retry_policy: @config.rpcs.cancel_operation.retry_policy
474
+
475
+ options.apply_defaults timeout: @config.timeout,
476
+ metadata: @config.metadata,
477
+ retry_policy: @config.retry_policy
478
+
479
+ @operations_stub.call_rpc :cancel_operation, request, options: options do |response, operation|
480
+ yield response, operation if block_given?
481
+ return response
482
+ end
483
+ rescue ::GRPC::BadStatus => e
484
+ raise ::Google::Cloud::Error.from_error(e)
485
+ end
486
+
487
+ ##
488
+ # Waits until the specified long-running operation is done or reaches at most
489
+ # a specified timeout, returning the latest state. If the operation is
490
+ # already done, the latest state is immediately returned. If the timeout
491
+ # specified is greater than the default HTTP/RPC timeout, the HTTP/RPC
492
+ # timeout is used. If the server does not support this method, it returns
493
+ # `google.rpc.Code.UNIMPLEMENTED`.
494
+ # Note that this method is on a best-effort basis. It may return the latest
495
+ # state before the specified timeout (including immediately), meaning even an
496
+ # immediate response is no guarantee that the operation is done.
497
+ #
498
+ # @overload wait_operation(request, options = nil)
499
+ # Pass arguments to `wait_operation` via a request object, either of type
500
+ # {::Google::Longrunning::WaitOperationRequest} or an equivalent Hash.
501
+ #
502
+ # @param request [::Google::Longrunning::WaitOperationRequest, ::Hash]
503
+ # A request object representing the call parameters. Required. To specify no
504
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
505
+ # @param options [::Gapic::CallOptions, ::Hash]
506
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
507
+ #
508
+ # @overload wait_operation(name: nil, timeout: nil)
509
+ # Pass arguments to `wait_operation` via keyword arguments. Note that at
510
+ # least one keyword argument is required. To specify no parameters, or to keep all
511
+ # the default parameter values, pass an empty Hash as a request object (see above).
512
+ #
513
+ # @param name [::String]
514
+ # The name of the operation resource to wait on.
515
+ # @param timeout [::Google::Protobuf::Duration, ::Hash]
516
+ # The maximum duration to wait before timing out. If left blank, the wait
517
+ # will be at most the time permitted by the underlying HTTP/RPC protocol.
518
+ # If RPC context deadline is also specified, the shorter one will be used.
519
+ #
520
+ # @yield [response, operation] Access the result along with the RPC operation
521
+ # @yieldparam response [::Gapic::Operation]
522
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
523
+ #
524
+ # @return [::Gapic::Operation]
525
+ #
526
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
527
+ #
528
+ # @example Basic example
529
+ # require "google/longrunning"
530
+ #
531
+ # # Create a client object. The client can be reused for multiple calls.
532
+ # client = Google::Longrunning::Operations::Client.new
533
+ #
534
+ # # Create a request. To set request fields, pass in keyword arguments.
535
+ # request = Google::Longrunning::WaitOperationRequest.new
536
+ #
537
+ # # Call the wait_operation method.
538
+ # result = client.wait_operation request
539
+ #
540
+ # # The returned object is of type Gapic::Operation. You can use this
541
+ # # object to check the status of an operation, cancel it, or wait
542
+ # # for results. Here is how to block until completion:
543
+ # result.wait_until_done! timeout: 60
544
+ # if result.response?
545
+ # p result.response
546
+ # else
547
+ # puts "Error!"
548
+ # end
549
+ #
550
+ def wait_operation request, options = nil
551
+ raise ::ArgumentError, "request must be provided" if request.nil?
552
+
553
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Longrunning::WaitOperationRequest
554
+
555
+ # Converts hash and nil to an options object
556
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
557
+
558
+ # Customize the options with defaults
559
+ metadata = @config.rpcs.wait_operation.metadata.to_h
560
+
561
+ # Set x-goog-api-client and x-goog-user-project headers
562
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
563
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
564
+ gapic_version: ::Google::Cloud::Optimization::V1::VERSION
565
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
566
+
567
+ options.apply_defaults timeout: @config.rpcs.wait_operation.timeout,
568
+ metadata: metadata,
569
+ retry_policy: @config.rpcs.wait_operation.retry_policy
570
+
571
+ options.apply_defaults timeout: @config.timeout,
572
+ metadata: @config.metadata,
573
+ retry_policy: @config.retry_policy
574
+
575
+ @operations_stub.call_rpc :wait_operation, request, options: options do |response, operation|
576
+ response = ::Gapic::Operation.new response, @operations_client, options: options
577
+ yield response, operation if block_given?
578
+ return response
579
+ end
580
+ rescue ::GRPC::BadStatus => e
581
+ raise ::Google::Cloud::Error.from_error(e)
582
+ end
583
+
584
+ ##
585
+ # Configuration class for the Operations API.
586
+ #
587
+ # This class represents the configuration for Operations,
588
+ # providing control over timeouts, retry behavior, logging, transport
589
+ # parameters, and other low-level controls. Certain parameters can also be
590
+ # applied individually to specific RPCs. See
591
+ # {::Google::Longrunning::Operations::Client::Configuration::Rpcs}
592
+ # for a list of RPCs that can be configured independently.
593
+ #
594
+ # Configuration can be applied globally to all clients, or to a single client
595
+ # on construction.
596
+ #
597
+ # @example
598
+ #
599
+ # # Modify the global config, setting the timeout for
600
+ # # list_operations to 20 seconds,
601
+ # # and all remaining timeouts to 10 seconds.
602
+ # ::Google::Longrunning::Operations::Client.configure do |config|
603
+ # config.timeout = 10.0
604
+ # config.rpcs.list_operations.timeout = 20.0
605
+ # end
606
+ #
607
+ # # Apply the above configuration only to a new client.
608
+ # client = ::Google::Longrunning::Operations::Client.new do |config|
609
+ # config.timeout = 10.0
610
+ # config.rpcs.list_operations.timeout = 20.0
611
+ # end
612
+ #
613
+ # @!attribute [rw] endpoint
614
+ # The hostname or hostname:port of the service endpoint.
615
+ # Defaults to `"cloudoptimization.googleapis.com"`.
616
+ # @return [::String]
617
+ # @!attribute [rw] credentials
618
+ # Credentials to send with calls. You may provide any of the following types:
619
+ # * (`String`) The path to a service account key file in JSON format
620
+ # * (`Hash`) A service account key as a Hash
621
+ # * (`Google::Auth::Credentials`) A googleauth credentials object
622
+ # (see the [googleauth docs](https://googleapis.dev/ruby/googleauth/latest/index.html))
623
+ # * (`Signet::OAuth2::Client`) A signet oauth2 client object
624
+ # (see the [signet docs](https://googleapis.dev/ruby/signet/latest/Signet/OAuth2/Client.html))
625
+ # * (`GRPC::Core::Channel`) a gRPC channel with included credentials
626
+ # * (`GRPC::Core::ChannelCredentials`) a gRPC credentails object
627
+ # * (`nil`) indicating no credentials
628
+ # @return [::Object]
629
+ # @!attribute [rw] scope
630
+ # The OAuth scopes
631
+ # @return [::Array<::String>]
632
+ # @!attribute [rw] lib_name
633
+ # The library name as recorded in instrumentation and logging
634
+ # @return [::String]
635
+ # @!attribute [rw] lib_version
636
+ # The library version as recorded in instrumentation and logging
637
+ # @return [::String]
638
+ # @!attribute [rw] channel_args
639
+ # Extra parameters passed to the gRPC channel. Note: this is ignored if a
640
+ # `GRPC::Core::Channel` object is provided as the credential.
641
+ # @return [::Hash]
642
+ # @!attribute [rw] interceptors
643
+ # An array of interceptors that are run before calls are executed.
644
+ # @return [::Array<::GRPC::ClientInterceptor>]
645
+ # @!attribute [rw] timeout
646
+ # The call timeout in seconds.
647
+ # @return [::Numeric]
648
+ # @!attribute [rw] metadata
649
+ # Additional gRPC headers to be sent with the call.
650
+ # @return [::Hash{::Symbol=>::String}]
651
+ # @!attribute [rw] retry_policy
652
+ # The retry policy. The value is a hash with the following keys:
653
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
654
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
655
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
656
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
657
+ # trigger a retry.
658
+ # @return [::Hash]
659
+ # @!attribute [rw] quota_project
660
+ # A separate project against which to charge quota.
661
+ # @return [::String]
662
+ #
663
+ class Configuration
664
+ extend ::Gapic::Config
665
+
666
+ config_attr :endpoint, "cloudoptimization.googleapis.com", ::String
667
+ config_attr :credentials, nil do |value|
668
+ allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
669
+ allowed += [::GRPC::Core::Channel, ::GRPC::Core::ChannelCredentials] if defined? ::GRPC
670
+ allowed.any? { |klass| klass === value }
671
+ end
672
+ config_attr :scope, nil, ::String, ::Array, nil
673
+ config_attr :lib_name, nil, ::String, nil
674
+ config_attr :lib_version, nil, ::String, nil
675
+ config_attr(:channel_args, { "grpc.service_config_disable_resolution" => 1 }, ::Hash, nil)
676
+ config_attr :interceptors, nil, ::Array, nil
677
+ config_attr :timeout, nil, ::Numeric, nil
678
+ config_attr :metadata, nil, ::Hash, nil
679
+ config_attr :retry_policy, nil, ::Hash, ::Proc, nil
680
+ config_attr :quota_project, nil, ::String, nil
681
+
682
+ # @private
683
+ def initialize parent_config = nil
684
+ @parent_config = parent_config unless parent_config.nil?
685
+
686
+ yield self if block_given?
687
+ end
688
+
689
+ ##
690
+ # Configurations for individual RPCs
691
+ # @return [Rpcs]
692
+ #
693
+ def rpcs
694
+ @rpcs ||= begin
695
+ parent_rpcs = nil
696
+ parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs)
697
+ Rpcs.new parent_rpcs
698
+ end
699
+ end
700
+
701
+ ##
702
+ # Configuration RPC class for the Operations API.
703
+ #
704
+ # Includes fields providing the configuration for each RPC in this service.
705
+ # Each configuration object is of type `Gapic::Config::Method` and includes
706
+ # the following configuration fields:
707
+ #
708
+ # * `timeout` (*type:* `Numeric`) - The call timeout in seconds
709
+ # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional gRPC headers
710
+ # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields
711
+ # include the following keys:
712
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
713
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
714
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
715
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
716
+ # trigger a retry.
717
+ #
718
+ class Rpcs
719
+ ##
720
+ # RPC-specific configuration for `list_operations`
721
+ # @return [::Gapic::Config::Method]
722
+ #
723
+ attr_reader :list_operations
724
+ ##
725
+ # RPC-specific configuration for `get_operation`
726
+ # @return [::Gapic::Config::Method]
727
+ #
728
+ attr_reader :get_operation
729
+ ##
730
+ # RPC-specific configuration for `delete_operation`
731
+ # @return [::Gapic::Config::Method]
732
+ #
733
+ attr_reader :delete_operation
734
+ ##
735
+ # RPC-specific configuration for `cancel_operation`
736
+ # @return [::Gapic::Config::Method]
737
+ #
738
+ attr_reader :cancel_operation
739
+ ##
740
+ # RPC-specific configuration for `wait_operation`
741
+ # @return [::Gapic::Config::Method]
742
+ #
743
+ attr_reader :wait_operation
744
+
745
+ # @private
746
+ def initialize parent_rpcs = nil
747
+ list_operations_config = parent_rpcs.list_operations if parent_rpcs.respond_to? :list_operations
748
+ @list_operations = ::Gapic::Config::Method.new list_operations_config
749
+ get_operation_config = parent_rpcs.get_operation if parent_rpcs.respond_to? :get_operation
750
+ @get_operation = ::Gapic::Config::Method.new get_operation_config
751
+ delete_operation_config = parent_rpcs.delete_operation if parent_rpcs.respond_to? :delete_operation
752
+ @delete_operation = ::Gapic::Config::Method.new delete_operation_config
753
+ cancel_operation_config = parent_rpcs.cancel_operation if parent_rpcs.respond_to? :cancel_operation
754
+ @cancel_operation = ::Gapic::Config::Method.new cancel_operation_config
755
+ wait_operation_config = parent_rpcs.wait_operation if parent_rpcs.respond_to? :wait_operation
756
+ @wait_operation = ::Gapic::Config::Method.new wait_operation_config
757
+
758
+ yield self if block_given?
759
+ end
760
+ end
761
+ end
762
+ end
763
+ end
764
+ end
765
+ end
766
+ end
767
+ end