google-cloud-retail-v2 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/google/cloud/retail/v2/catalog_service/rest/client.rb +1220 -0
  4. data/lib/google/cloud/retail/v2/catalog_service/rest/service_stub.rb +704 -0
  5. data/lib/google/cloud/retail/v2/catalog_service/rest.rb +52 -0
  6. data/lib/google/cloud/retail/v2/catalog_service.rb +6 -0
  7. data/lib/google/cloud/retail/v2/completion_service/rest/client.rb +533 -0
  8. data/lib/google/cloud/retail/v2/completion_service/rest/operations.rb +828 -0
  9. data/lib/google/cloud/retail/v2/completion_service/rest/service_stub.rb +167 -0
  10. data/lib/google/cloud/retail/v2/completion_service/rest.rb +56 -0
  11. data/lib/google/cloud/retail/v2/completion_service.rb +6 -0
  12. data/lib/google/cloud/retail/v2/control_service/rest/client.rb +680 -0
  13. data/lib/google/cloud/retail/v2/control_service/rest/service_stub.rb +345 -0
  14. data/lib/google/cloud/retail/v2/control_service/rest.rb +52 -0
  15. data/lib/google/cloud/retail/v2/control_service.rb +6 -0
  16. data/lib/google/cloud/retail/v2/prediction_service/rest/client.rb +486 -0
  17. data/lib/google/cloud/retail/v2/prediction_service/rest/service_stub.rb +116 -0
  18. data/lib/google/cloud/retail/v2/prediction_service/rest.rb +52 -0
  19. data/lib/google/cloud/retail/v2/prediction_service.rb +6 -0
  20. data/lib/google/cloud/retail/v2/product_service/rest/client.rb +1649 -0
  21. data/lib/google/cloud/retail/v2/product_service/rest/operations.rb +828 -0
  22. data/lib/google/cloud/retail/v2/product_service/rest/service_stub.rb +705 -0
  23. data/lib/google/cloud/retail/v2/product_service/rest.rb +54 -0
  24. data/lib/google/cloud/retail/v2/product_service.rb +6 -0
  25. data/lib/google/cloud/retail/v2/rest.rb +44 -0
  26. data/lib/google/cloud/retail/v2/search_service/rest/client.rb +598 -0
  27. data/lib/google/cloud/retail/v2/search_service/rest/service_stub.rb +116 -0
  28. data/lib/google/cloud/retail/v2/search_service/rest.rb +55 -0
  29. data/lib/google/cloud/retail/v2/search_service.rb +6 -0
  30. data/lib/google/cloud/retail/v2/serving_config_service/rest/client.rb +825 -0
  31. data/lib/google/cloud/retail/v2/serving_config_service/rest/service_stub.rb +465 -0
  32. data/lib/google/cloud/retail/v2/serving_config_service/rest.rb +52 -0
  33. data/lib/google/cloud/retail/v2/serving_config_service.rb +6 -0
  34. data/lib/google/cloud/retail/v2/user_event_service/rest/client.rb +755 -0
  35. data/lib/google/cloud/retail/v2/user_event_service/rest/operations.rb +828 -0
  36. data/lib/google/cloud/retail/v2/user_event_service/rest/service_stub.rb +347 -0
  37. data/lib/google/cloud/retail/v2/user_event_service/rest.rb +53 -0
  38. data/lib/google/cloud/retail/v2/user_event_service.rb +6 -0
  39. data/lib/google/cloud/retail/v2/version.rb +1 -1
  40. data/lib/google/cloud/retail/v2.rb +5 -0
  41. metadata +35 -5
@@ -0,0 +1,486 @@
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 "google/cloud/errors"
20
+ require "google/cloud/retail/v2/prediction_service_pb"
21
+ require "google/cloud/retail/v2/prediction_service/rest/service_stub"
22
+ require "google/cloud/location/rest"
23
+
24
+ module Google
25
+ module Cloud
26
+ module Retail
27
+ module V2
28
+ module PredictionService
29
+ module Rest
30
+ ##
31
+ # REST client for the PredictionService service.
32
+ #
33
+ # Service for making recommendation prediction.
34
+ #
35
+ class Client
36
+ include Paths
37
+
38
+ # @private
39
+ attr_reader :prediction_service_stub
40
+
41
+ ##
42
+ # Configure the PredictionService Client class.
43
+ #
44
+ # See {::Google::Cloud::Retail::V2::PredictionService::Rest::Client::Configuration}
45
+ # for a description of the configuration fields.
46
+ #
47
+ # @example
48
+ #
49
+ # # Modify the configuration for all PredictionService clients
50
+ # ::Google::Cloud::Retail::V2::PredictionService::Rest::Client.configure do |config|
51
+ # config.timeout = 10.0
52
+ # end
53
+ #
54
+ # @yield [config] Configure the Client client.
55
+ # @yieldparam config [Client::Configuration]
56
+ #
57
+ # @return [Client::Configuration]
58
+ #
59
+ def self.configure
60
+ @configure ||= begin
61
+ namespace = ["Google", "Cloud", "Retail", "V2"]
62
+ parent_config = while namespace.any?
63
+ parent_name = namespace.join "::"
64
+ parent_const = const_get parent_name
65
+ break parent_const.configure if parent_const.respond_to? :configure
66
+ namespace.pop
67
+ end
68
+ default_config = Client::Configuration.new parent_config
69
+
70
+ default_config.timeout = 5.0
71
+ default_config.retry_policy = {
72
+ initial_delay: 0.1, max_delay: 5.0, multiplier: 1.3, retry_codes: [14, 4]
73
+ }
74
+
75
+ default_config
76
+ end
77
+ yield @configure if block_given?
78
+ @configure
79
+ end
80
+
81
+ ##
82
+ # Configure the PredictionService Client instance.
83
+ #
84
+ # The configuration is set to the derived mode, meaning that values can be changed,
85
+ # but structural changes (adding new fields, etc.) are not allowed. Structural changes
86
+ # should be made on {Client.configure}.
87
+ #
88
+ # See {::Google::Cloud::Retail::V2::PredictionService::Rest::Client::Configuration}
89
+ # for a description of the configuration fields.
90
+ #
91
+ # @yield [config] Configure the Client client.
92
+ # @yieldparam config [Client::Configuration]
93
+ #
94
+ # @return [Client::Configuration]
95
+ #
96
+ def configure
97
+ yield @config if block_given?
98
+ @config
99
+ end
100
+
101
+ ##
102
+ # Create a new PredictionService REST client object.
103
+ #
104
+ # @example
105
+ #
106
+ # # Create a client using the default configuration
107
+ # client = ::Google::Cloud::Retail::V2::PredictionService::Rest::Client.new
108
+ #
109
+ # # Create a client using a custom configuration
110
+ # client = ::Google::Cloud::Retail::V2::PredictionService::Rest::Client.new do |config|
111
+ # config.timeout = 10.0
112
+ # end
113
+ #
114
+ # @yield [config] Configure the PredictionService client.
115
+ # @yieldparam config [Client::Configuration]
116
+ #
117
+ def initialize
118
+ # Create the configuration object
119
+ @config = Configuration.new Client.configure
120
+
121
+ # Yield the configuration if needed
122
+ yield @config if block_given?
123
+
124
+ # Create credentials
125
+ credentials = @config.credentials
126
+ # Use self-signed JWT if the endpoint is unchanged from default,
127
+ # but only if the default endpoint does not have a region prefix.
128
+ enable_self_signed_jwt = @config.endpoint == Client.configure.endpoint &&
129
+ !@config.endpoint.split(".").first.include?("-")
130
+ credentials ||= Credentials.default scope: @config.scope,
131
+ enable_self_signed_jwt: enable_self_signed_jwt
132
+ if credentials.is_a?(::String) || credentials.is_a?(::Hash)
133
+ credentials = Credentials.new credentials, scope: @config.scope
134
+ end
135
+
136
+ @quota_project_id = @config.quota_project
137
+ @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id
138
+
139
+ @location_client = Google::Cloud::Location::Locations::Rest::Client.new do |config|
140
+ config.credentials = credentials
141
+ config.quota_project = @quota_project_id
142
+ config.endpoint = @config.endpoint
143
+ end
144
+
145
+ @prediction_service_stub = ::Google::Cloud::Retail::V2::PredictionService::Rest::ServiceStub.new endpoint: @config.endpoint, credentials: credentials
146
+ end
147
+
148
+ ##
149
+ # Get the associated client for mix-in of the Locations.
150
+ #
151
+ # @return [Google::Cloud::Location::Locations::Rest::Client]
152
+ #
153
+ attr_reader :location_client
154
+
155
+ # Service calls
156
+
157
+ ##
158
+ # Makes a recommendation prediction.
159
+ #
160
+ # @overload predict(request, options = nil)
161
+ # Pass arguments to `predict` via a request object, either of type
162
+ # {::Google::Cloud::Retail::V2::PredictRequest} or an equivalent Hash.
163
+ #
164
+ # @param request [::Google::Cloud::Retail::V2::PredictRequest, ::Hash]
165
+ # A request object representing the call parameters. Required. To specify no
166
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
167
+ # @param options [::Gapic::CallOptions, ::Hash]
168
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
169
+ #
170
+ # @overload predict(placement: nil, user_event: nil, page_size: nil, page_token: nil, filter: nil, validate_only: nil, params: nil, labels: nil)
171
+ # Pass arguments to `predict` via keyword arguments. Note that at
172
+ # least one keyword argument is required. To specify no parameters, or to keep all
173
+ # the default parameter values, pass an empty Hash as a request object (see above).
174
+ #
175
+ # @param placement [::String]
176
+ # Required. Full resource name of the format:
177
+ # `{placement=projects/*/locations/global/catalogs/default_catalog/servingConfigs/*}`
178
+ # or
179
+ # `{placement=projects/*/locations/global/catalogs/default_catalog/placements/*}`.
180
+ # We recommend using the `servingConfigs` resource. `placements` is a legacy
181
+ # resource.
182
+ # The ID of the Recommendations AI serving config or placement.
183
+ # Before you can request predictions from your model, you must create at
184
+ # least one serving config or placement for it. For more information, see
185
+ # [Manage serving configs]
186
+ # (https://cloud.google.com/retail/docs/manage-configs).
187
+ #
188
+ # The full list of available serving configs can be seen at
189
+ # https://console.cloud.google.com/ai/retail/catalogs/default_catalog/configs
190
+ # @param user_event [::Google::Cloud::Retail::V2::UserEvent, ::Hash]
191
+ # Required. Context about the user, what they are looking at and what action
192
+ # they took to trigger the predict request. Note that this user event detail
193
+ # won't be ingested to userEvent logs. Thus, a separate userEvent write
194
+ # request is required for event logging.
195
+ #
196
+ # Don't set
197
+ # {::Google::Cloud::Retail::V2::UserEvent#visitor_id UserEvent.visitor_id} or
198
+ # {::Google::Cloud::Retail::V2::UserInfo#user_id UserInfo.user_id} to the same
199
+ # fixed ID for different users. If you are trying to receive non-personalized
200
+ # recommendations (not recommended; this can negatively impact model
201
+ # performance), instead set
202
+ # {::Google::Cloud::Retail::V2::UserEvent#visitor_id UserEvent.visitor_id} to a
203
+ # random unique ID and leave
204
+ # {::Google::Cloud::Retail::V2::UserInfo#user_id UserInfo.user_id} unset.
205
+ # @param page_size [::Integer]
206
+ # Maximum number of results to return. Set this property to the number of
207
+ # prediction results needed. If zero, the service will choose a reasonable
208
+ # default. The maximum allowed value is 100. Values above 100 will be coerced
209
+ # to 100.
210
+ # @param page_token [::String]
211
+ # This field is not used; leave it unset.
212
+ # @param filter [::String]
213
+ # Filter for restricting prediction results with a length limit of 5,000
214
+ # characters. Accepts values for tags and the `filterOutOfStockItems` flag.
215
+ #
216
+ # * Tag expressions. Restricts predictions to products that match all of the
217
+ # specified tags. Boolean operators `OR` and `NOT` are supported if the
218
+ # expression is enclosed in parentheses, and must be separated from the
219
+ # tag values by a space. `-"tagA"` is also supported and is equivalent to
220
+ # `NOT "tagA"`. Tag values must be double quoted UTF-8 encoded strings
221
+ # with a size limit of 1,000 characters.
222
+ #
223
+ # Note: "Recently viewed" models don't support tag filtering at the
224
+ # moment.
225
+ #
226
+ # * filterOutOfStockItems. Restricts predictions to products that do not
227
+ # have a
228
+ # stockState value of OUT_OF_STOCK.
229
+ #
230
+ # Examples:
231
+ #
232
+ # * tag=("Red" OR "Blue") tag="New-Arrival" tag=(NOT "promotional")
233
+ # * filterOutOfStockItems tag=(-"promotional")
234
+ # * filterOutOfStockItems
235
+ #
236
+ # If your filter blocks all prediction results, the API will return *no*
237
+ # results. If instead you want empty result sets to return generic
238
+ # (unfiltered) popular products, set `strictFiltering` to False in
239
+ # `PredictRequest.params`. Note that the API will never return items with
240
+ # storageStatus of "EXPIRED" or "DELETED" regardless of filter choices.
241
+ #
242
+ # If `filterSyntaxV2` is set to true under the `params` field, then
243
+ # attribute-based expressions are expected instead of the above described
244
+ # tag-based syntax. Examples:
245
+ #
246
+ # * (colors: ANY("Red", "Blue")) AND NOT (categories: ANY("Phones"))
247
+ # * (availability: ANY("IN_STOCK")) AND
248
+ # (colors: ANY("Red") OR categories: ANY("Phones"))
249
+ # @param validate_only [::Boolean]
250
+ # Use validate only mode for this prediction query. If set to true, a
251
+ # dummy model will be used that returns arbitrary products.
252
+ # Note that the validate only mode should only be used for testing the API,
253
+ # or if the model is not ready.
254
+ # @param params [::Hash{::String => ::Google::Protobuf::Value, ::Hash}]
255
+ # Additional domain specific parameters for the predictions.
256
+ #
257
+ # Allowed values:
258
+ #
259
+ # * `returnProduct`: Boolean. If set to true, the associated product
260
+ # object will be returned in the `results.metadata` field in the
261
+ # prediction response.
262
+ # * `returnScore`: Boolean. If set to true, the prediction 'score'
263
+ # corresponding to each returned product will be set in the
264
+ # `results.metadata` field in the prediction response. The given
265
+ # 'score' indicates the probability of a product being clicked/purchased
266
+ # given the user's context and history.
267
+ # * `strictFiltering`: Boolean. True by default. If set to false, the service
268
+ # will return generic (unfiltered) popular products instead of empty if
269
+ # your filter blocks all prediction results.
270
+ # * `priceRerankLevel`: String. Default empty. If set to be non-empty, then
271
+ # it needs to be one of {'no-price-reranking', 'low-price-reranking',
272
+ # 'medium-price-reranking', 'high-price-reranking'}. This gives
273
+ # request-level control and adjusts prediction results based on product
274
+ # price.
275
+ # * `diversityLevel`: String. Default empty. If set to be non-empty, then
276
+ # it needs to be one of {'no-diversity', 'low-diversity',
277
+ # 'medium-diversity', 'high-diversity', 'auto-diversity'}. This gives
278
+ # request-level control and adjusts prediction results based on product
279
+ # category.
280
+ # * `filterSyntaxV2`: Boolean. False by default. If set to true, the `filter`
281
+ # field is interpreteted according to the new, attribute-based syntax.
282
+ # @param labels [::Hash{::String => ::String}]
283
+ # The labels applied to a resource must meet the following requirements:
284
+ #
285
+ # * Each resource can have multiple labels, up to a maximum of 64.
286
+ # * Each label must be a key-value pair.
287
+ # * Keys have a minimum length of 1 character and a maximum length of 63
288
+ # characters and cannot be empty. Values can be empty and have a maximum
289
+ # length of 63 characters.
290
+ # * Keys and values can contain only lowercase letters, numeric characters,
291
+ # underscores, and dashes. All characters must use UTF-8 encoding, and
292
+ # international characters are allowed.
293
+ # * The key portion of a label must be unique. However, you can use the same
294
+ # key with multiple resources.
295
+ # * Keys must start with a lowercase letter or international character.
296
+ #
297
+ # See [Google Cloud
298
+ # Document](https://cloud.google.com/resource-manager/docs/creating-managing-labels#requirements)
299
+ # for more details.
300
+ # @yield [result, operation] Access the result along with the TransportOperation object
301
+ # @yieldparam result [::Google::Cloud::Retail::V2::PredictResponse]
302
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
303
+ #
304
+ # @return [::Google::Cloud::Retail::V2::PredictResponse]
305
+ #
306
+ # @raise [::Google::Cloud::Error] if the REST call is aborted.
307
+ def predict request, options = nil
308
+ raise ::ArgumentError, "request must be provided" if request.nil?
309
+
310
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Retail::V2::PredictRequest
311
+
312
+ # Converts hash and nil to an options object
313
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
314
+
315
+ # Customize the options with defaults
316
+ call_metadata = @config.rpcs.predict.metadata.to_h
317
+
318
+ # Set x-goog-api-client and x-goog-user-project headers
319
+ call_metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
320
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
321
+ gapic_version: ::Google::Cloud::Retail::V2::VERSION,
322
+ transports_version_send: [:rest]
323
+
324
+ call_metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
325
+
326
+ options.apply_defaults timeout: @config.rpcs.predict.timeout,
327
+ metadata: call_metadata,
328
+ retry_policy: @config.rpcs.predict.retry_policy
329
+
330
+ options.apply_defaults timeout: @config.timeout,
331
+ metadata: @config.metadata,
332
+ retry_policy: @config.retry_policy
333
+
334
+ @prediction_service_stub.predict request, options do |result, operation|
335
+ yield result, operation if block_given?
336
+ return result
337
+ end
338
+ rescue ::Gapic::Rest::Error => e
339
+ raise ::Google::Cloud::Error.from_error(e)
340
+ end
341
+
342
+ ##
343
+ # Configuration class for the PredictionService REST API.
344
+ #
345
+ # This class represents the configuration for PredictionService REST,
346
+ # providing control over timeouts, retry behavior, logging, transport
347
+ # parameters, and other low-level controls. Certain parameters can also be
348
+ # applied individually to specific RPCs. See
349
+ # {::Google::Cloud::Retail::V2::PredictionService::Rest::Client::Configuration::Rpcs}
350
+ # for a list of RPCs that can be configured independently.
351
+ #
352
+ # Configuration can be applied globally to all clients, or to a single client
353
+ # on construction.
354
+ #
355
+ # @example
356
+ #
357
+ # # Modify the global config, setting the timeout for
358
+ # # predict to 20 seconds,
359
+ # # and all remaining timeouts to 10 seconds.
360
+ # ::Google::Cloud::Retail::V2::PredictionService::Rest::Client.configure do |config|
361
+ # config.timeout = 10.0
362
+ # config.rpcs.predict.timeout = 20.0
363
+ # end
364
+ #
365
+ # # Apply the above configuration only to a new client.
366
+ # client = ::Google::Cloud::Retail::V2::PredictionService::Rest::Client.new do |config|
367
+ # config.timeout = 10.0
368
+ # config.rpcs.predict.timeout = 20.0
369
+ # end
370
+ #
371
+ # @!attribute [rw] endpoint
372
+ # The hostname or hostname:port of the service endpoint.
373
+ # Defaults to `"retail.googleapis.com"`.
374
+ # @return [::String]
375
+ # @!attribute [rw] credentials
376
+ # Credentials to send with calls. You may provide any of the following types:
377
+ # * (`String`) The path to a service account key file in JSON format
378
+ # * (`Hash`) A service account key as a Hash
379
+ # * (`Google::Auth::Credentials`) A googleauth credentials object
380
+ # (see the [googleauth docs](https://googleapis.dev/ruby/googleauth/latest/index.html))
381
+ # * (`Signet::OAuth2::Client`) A signet oauth2 client object
382
+ # (see the [signet docs](https://googleapis.dev/ruby/signet/latest/Signet/OAuth2/Client.html))
383
+ # * (`nil`) indicating no credentials
384
+ # @return [::Object]
385
+ # @!attribute [rw] scope
386
+ # The OAuth scopes
387
+ # @return [::Array<::String>]
388
+ # @!attribute [rw] lib_name
389
+ # The library name as recorded in instrumentation and logging
390
+ # @return [::String]
391
+ # @!attribute [rw] lib_version
392
+ # The library version as recorded in instrumentation and logging
393
+ # @return [::String]
394
+ # @!attribute [rw] timeout
395
+ # The call timeout in seconds.
396
+ # @return [::Numeric]
397
+ # @!attribute [rw] metadata
398
+ # Additional headers to be sent with the call.
399
+ # @return [::Hash{::Symbol=>::String}]
400
+ # @!attribute [rw] retry_policy
401
+ # The retry policy. The value is a hash with the following keys:
402
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
403
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
404
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
405
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
406
+ # trigger a retry.
407
+ # @return [::Hash]
408
+ # @!attribute [rw] quota_project
409
+ # A separate project against which to charge quota.
410
+ # @return [::String]
411
+ #
412
+ class Configuration
413
+ extend ::Gapic::Config
414
+
415
+ config_attr :endpoint, "retail.googleapis.com", ::String
416
+ config_attr :credentials, nil do |value|
417
+ allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Signet::OAuth2::Client, nil]
418
+ allowed.any? { |klass| klass === value }
419
+ end
420
+ config_attr :scope, nil, ::String, ::Array, nil
421
+ config_attr :lib_name, nil, ::String, nil
422
+ config_attr :lib_version, nil, ::String, nil
423
+ config_attr :timeout, nil, ::Numeric, nil
424
+ config_attr :metadata, nil, ::Hash, nil
425
+ config_attr :retry_policy, nil, ::Hash, ::Proc, nil
426
+ config_attr :quota_project, nil, ::String, nil
427
+
428
+ # @private
429
+ def initialize parent_config = nil
430
+ @parent_config = parent_config unless parent_config.nil?
431
+
432
+ yield self if block_given?
433
+ end
434
+
435
+ ##
436
+ # Configurations for individual RPCs
437
+ # @return [Rpcs]
438
+ #
439
+ def rpcs
440
+ @rpcs ||= begin
441
+ parent_rpcs = nil
442
+ parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs)
443
+ Rpcs.new parent_rpcs
444
+ end
445
+ end
446
+
447
+ ##
448
+ # Configuration RPC class for the PredictionService API.
449
+ #
450
+ # Includes fields providing the configuration for each RPC in this service.
451
+ # Each configuration object is of type `Gapic::Config::Method` and includes
452
+ # the following configuration fields:
453
+ #
454
+ # * `timeout` (*type:* `Numeric`) - The call timeout in seconds
455
+ # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional headers
456
+ # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields
457
+ # include the following keys:
458
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
459
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
460
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
461
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
462
+ # trigger a retry.
463
+ #
464
+ class Rpcs
465
+ ##
466
+ # RPC-specific configuration for `predict`
467
+ # @return [::Gapic::Config::Method]
468
+ #
469
+ attr_reader :predict
470
+
471
+ # @private
472
+ def initialize parent_rpcs = nil
473
+ predict_config = parent_rpcs.predict if parent_rpcs.respond_to? :predict
474
+ @predict = ::Gapic::Config::Method.new predict_config
475
+
476
+ yield self if block_given?
477
+ end
478
+ end
479
+ end
480
+ end
481
+ end
482
+ end
483
+ end
484
+ end
485
+ end
486
+ end
@@ -0,0 +1,116 @@
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 "google/cloud/retail/v2/prediction_service_pb"
20
+
21
+ module Google
22
+ module Cloud
23
+ module Retail
24
+ module V2
25
+ module PredictionService
26
+ module Rest
27
+ ##
28
+ # REST service stub for the PredictionService service.
29
+ # Service stub contains baseline method implementations
30
+ # including transcoding, making the REST call, and deserialing the response.
31
+ #
32
+ class ServiceStub
33
+ def initialize endpoint:, credentials:
34
+ # These require statements are intentionally placed here to initialize
35
+ # the REST modules only when it's required.
36
+ require "gapic/rest"
37
+
38
+ @client_stub = ::Gapic::Rest::ClientStub.new endpoint: endpoint, credentials: credentials,
39
+ numeric_enums: true,
40
+ raise_faraday_errors: false
41
+ end
42
+
43
+ ##
44
+ # Baseline implementation for the predict REST call
45
+ #
46
+ # @param request_pb [::Google::Cloud::Retail::V2::PredictRequest]
47
+ # A request object representing the call parameters. Required.
48
+ # @param options [::Gapic::CallOptions]
49
+ # Overrides the default settings for this call, e.g, timeout, retries etc. Optional.
50
+ #
51
+ # @yield [result, operation] Access the result along with the TransportOperation object
52
+ # @yieldparam result [::Google::Cloud::Retail::V2::PredictResponse]
53
+ # @yieldparam operation [::Gapic::Rest::TransportOperation]
54
+ #
55
+ # @return [::Google::Cloud::Retail::V2::PredictResponse]
56
+ # A result object deserialized from the server's reply
57
+ def predict request_pb, options = nil
58
+ raise ::ArgumentError, "request must be provided" if request_pb.nil?
59
+
60
+ verb, uri, query_string_params, body = ServiceStub.transcode_predict_request request_pb
61
+ query_string_params = if query_string_params.any?
62
+ query_string_params.to_h { |p| p.split("=", 2) }
63
+ else
64
+ {}
65
+ end
66
+
67
+ response = @client_stub.make_http_request(
68
+ verb,
69
+ uri: uri,
70
+ body: body || "",
71
+ params: query_string_params,
72
+ options: options
73
+ )
74
+ operation = ::Gapic::Rest::TransportOperation.new response
75
+ result = ::Google::Cloud::Retail::V2::PredictResponse.decode_json response.body, ignore_unknown_fields: true
76
+
77
+ yield result, operation if block_given?
78
+ result
79
+ end
80
+
81
+ ##
82
+ # @private
83
+ #
84
+ # GRPC transcoding helper method for the predict REST call
85
+ #
86
+ # @param request_pb [::Google::Cloud::Retail::V2::PredictRequest]
87
+ # A request object representing the call parameters. Required.
88
+ # @return [Array(String, [String, nil], Hash{String => String})]
89
+ # Uri, Body, Query string parameters
90
+ def self.transcode_predict_request request_pb
91
+ transcoder = Gapic::Rest::GrpcTranscoder.new
92
+ .with_bindings(
93
+ uri_method: :post,
94
+ uri_template: "/v2/{placement}:predict",
95
+ body: "*",
96
+ matches: [
97
+ ["placement", %r{^projects/[^/]+/locations/[^/]+/catalogs/[^/]+/placements/[^/]+/?$}, false]
98
+ ]
99
+ )
100
+ .with_bindings(
101
+ uri_method: :post,
102
+ uri_template: "/v2/{placement}:predict",
103
+ body: "*",
104
+ matches: [
105
+ ["placement", %r{^projects/[^/]+/locations/[^/]+/catalogs/[^/]+/servingConfigs/[^/]+/?$}, false]
106
+ ]
107
+ )
108
+ transcoder.transcode request_pb
109
+ end
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,52 @@
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/rest"
20
+ require "gapic/config"
21
+ require "gapic/config/method"
22
+
23
+ require "google/cloud/retail/v2/version"
24
+
25
+ require "google/cloud/retail/v2/prediction_service/credentials"
26
+ require "google/cloud/retail/v2/prediction_service/paths"
27
+ require "google/cloud/retail/v2/prediction_service/rest/client"
28
+
29
+ module Google
30
+ module Cloud
31
+ module Retail
32
+ module V2
33
+ ##
34
+ # Service for making recommendation prediction.
35
+ #
36
+ # To load this service and instantiate a REST client:
37
+ #
38
+ # require "google/cloud/retail/v2/prediction_service/rest"
39
+ # client = ::Google::Cloud::Retail::V2::PredictionService::Rest::Client.new
40
+ #
41
+ module PredictionService
42
+ # Client for the REST transport
43
+ module Rest
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ helper_path = ::File.join __dir__, "rest", "helpers.rb"
52
+ require "google/cloud/retail/v2/prediction_service/rest/helpers" if ::File.file? helper_path
@@ -25,6 +25,7 @@ require "google/cloud/retail/v2/version"
25
25
  require "google/cloud/retail/v2/prediction_service/credentials"
26
26
  require "google/cloud/retail/v2/prediction_service/paths"
27
27
  require "google/cloud/retail/v2/prediction_service/client"
28
+ require "google/cloud/retail/v2/prediction_service/rest"
28
29
 
29
30
  module Google
30
31
  module Cloud
@@ -38,6 +39,11 @@ module Google
38
39
  # require "google/cloud/retail/v2/prediction_service"
39
40
  # client = ::Google::Cloud::Retail::V2::PredictionService::Client.new
40
41
  #
42
+ # @example Load this service and instantiate a REST client
43
+ #
44
+ # require "google/cloud/retail/v2/prediction_service/rest"
45
+ # client = ::Google::Cloud::Retail::V2::PredictionService::Rest::Client.new
46
+ #
41
47
  module PredictionService
42
48
  end
43
49
  end