google-cloud-optimization-v1 0.2.1 → 0.3.0

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