google-shopping-merchant-reports-v1 0.a → 0.1.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.
@@ -0,0 +1,487 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2025 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/shopping/merchant/reports/v1/reports_pb"
21
+
22
+ module Google
23
+ module Shopping
24
+ module Merchant
25
+ module Reports
26
+ module V1
27
+ module ReportService
28
+ ##
29
+ # Client for the ReportService service.
30
+ #
31
+ # Service for retrieving reports and insights about your products, their
32
+ # performance, and their competitive environment on Google.
33
+ #
34
+ class Client
35
+ # @private
36
+ API_VERSION = ""
37
+
38
+ # @private
39
+ DEFAULT_ENDPOINT_TEMPLATE = "merchantapi.$UNIVERSE_DOMAIN$"
40
+
41
+ # @private
42
+ attr_reader :report_service_stub
43
+
44
+ ##
45
+ # Configure the ReportService Client class.
46
+ #
47
+ # See {::Google::Shopping::Merchant::Reports::V1::ReportService::Client::Configuration}
48
+ # for a description of the configuration fields.
49
+ #
50
+ # @example
51
+ #
52
+ # # Modify the configuration for all ReportService clients
53
+ # ::Google::Shopping::Merchant::Reports::V1::ReportService::Client.configure do |config|
54
+ # config.timeout = 10.0
55
+ # end
56
+ #
57
+ # @yield [config] Configure the Client client.
58
+ # @yieldparam config [Client::Configuration]
59
+ #
60
+ # @return [Client::Configuration]
61
+ #
62
+ def self.configure
63
+ @configure ||= begin
64
+ namespace = ["Google", "Shopping", "Merchant", "Reports", "V1"]
65
+ parent_config = while namespace.any?
66
+ parent_name = namespace.join "::"
67
+ parent_const = const_get parent_name
68
+ break parent_const.configure if parent_const.respond_to? :configure
69
+ namespace.pop
70
+ end
71
+ default_config = Client::Configuration.new parent_config
72
+
73
+ default_config.timeout = 60.0
74
+ default_config.retry_policy = {
75
+ initial_delay: 1.0, max_delay: 10.0, multiplier: 1.3, retry_codes: [14]
76
+ }
77
+
78
+ default_config
79
+ end
80
+ yield @configure if block_given?
81
+ @configure
82
+ end
83
+
84
+ ##
85
+ # Configure the ReportService Client instance.
86
+ #
87
+ # The configuration is set to the derived mode, meaning that values can be changed,
88
+ # but structural changes (adding new fields, etc.) are not allowed. Structural changes
89
+ # should be made on {Client.configure}.
90
+ #
91
+ # See {::Google::Shopping::Merchant::Reports::V1::ReportService::Client::Configuration}
92
+ # for a description of the configuration fields.
93
+ #
94
+ # @yield [config] Configure the Client client.
95
+ # @yieldparam config [Client::Configuration]
96
+ #
97
+ # @return [Client::Configuration]
98
+ #
99
+ def configure
100
+ yield @config if block_given?
101
+ @config
102
+ end
103
+
104
+ ##
105
+ # The effective universe domain
106
+ #
107
+ # @return [String]
108
+ #
109
+ def universe_domain
110
+ @report_service_stub.universe_domain
111
+ end
112
+
113
+ ##
114
+ # Create a new ReportService client object.
115
+ #
116
+ # @example
117
+ #
118
+ # # Create a client using the default configuration
119
+ # client = ::Google::Shopping::Merchant::Reports::V1::ReportService::Client.new
120
+ #
121
+ # # Create a client using a custom configuration
122
+ # client = ::Google::Shopping::Merchant::Reports::V1::ReportService::Client.new do |config|
123
+ # config.timeout = 10.0
124
+ # end
125
+ #
126
+ # @yield [config] Configure the ReportService client.
127
+ # @yieldparam config [Client::Configuration]
128
+ #
129
+ def initialize
130
+ # These require statements are intentionally placed here to initialize
131
+ # the gRPC module only when it's required.
132
+ # See https://github.com/googleapis/toolkit/issues/446
133
+ require "gapic/grpc"
134
+ require "google/shopping/merchant/reports/v1/reports_services_pb"
135
+
136
+ # Create the configuration object
137
+ @config = Configuration.new Client.configure
138
+
139
+ # Yield the configuration if needed
140
+ yield @config if block_given?
141
+
142
+ # Create credentials
143
+ credentials = @config.credentials
144
+ # Use self-signed JWT if the endpoint is unchanged from default,
145
+ # but only if the default endpoint does not have a region prefix.
146
+ enable_self_signed_jwt = @config.endpoint.nil? ||
147
+ (@config.endpoint == Configuration::DEFAULT_ENDPOINT &&
148
+ !@config.endpoint.split(".").first.include?("-"))
149
+ credentials ||= Credentials.default scope: @config.scope,
150
+ enable_self_signed_jwt: enable_self_signed_jwt
151
+ if credentials.is_a?(::String) || credentials.is_a?(::Hash)
152
+ credentials = Credentials.new credentials, scope: @config.scope
153
+ end
154
+ @quota_project_id = @config.quota_project
155
+ @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id
156
+
157
+ @report_service_stub = ::Gapic::ServiceStub.new(
158
+ ::Google::Shopping::Merchant::Reports::V1::ReportService::Stub,
159
+ credentials: credentials,
160
+ endpoint: @config.endpoint,
161
+ endpoint_template: DEFAULT_ENDPOINT_TEMPLATE,
162
+ universe_domain: @config.universe_domain,
163
+ channel_args: @config.channel_args,
164
+ interceptors: @config.interceptors,
165
+ channel_pool_config: @config.channel_pool,
166
+ logger: @config.logger
167
+ )
168
+
169
+ @report_service_stub.stub_logger&.info do |entry|
170
+ entry.set_system_name
171
+ entry.set_service
172
+ entry.message = "Created client for #{entry.service}"
173
+ entry.set_credentials_fields credentials
174
+ entry.set "customEndpoint", @config.endpoint if @config.endpoint
175
+ entry.set "defaultTimeout", @config.timeout if @config.timeout
176
+ entry.set "quotaProject", @quota_project_id if @quota_project_id
177
+ end
178
+ end
179
+
180
+ ##
181
+ # The logger used for request/response debug logging.
182
+ #
183
+ # @return [Logger]
184
+ #
185
+ def logger
186
+ @report_service_stub.logger
187
+ end
188
+
189
+ # Service calls
190
+
191
+ ##
192
+ # Retrieves a report defined by a search query. The response might contain
193
+ # fewer rows than specified by `page_size`. Rely on `next_page_token` to
194
+ # determine if there are more rows to be requested.
195
+ #
196
+ # @overload search(request, options = nil)
197
+ # Pass arguments to `search` via a request object, either of type
198
+ # {::Google::Shopping::Merchant::Reports::V1::SearchRequest} or an equivalent Hash.
199
+ #
200
+ # @param request [::Google::Shopping::Merchant::Reports::V1::SearchRequest, ::Hash]
201
+ # A request object representing the call parameters. Required. To specify no
202
+ # parameters, or to keep all the default parameter values, pass an empty Hash.
203
+ # @param options [::Gapic::CallOptions, ::Hash]
204
+ # Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
205
+ #
206
+ # @overload search(parent: nil, query: nil, page_size: nil, page_token: nil)
207
+ # Pass arguments to `search` via keyword arguments. Note that at
208
+ # least one keyword argument is required. To specify no parameters, or to keep all
209
+ # the default parameter values, pass an empty Hash as a request object (see above).
210
+ #
211
+ # @param parent [::String]
212
+ # Required. Id of the account making the call. Must be a standalone account
213
+ # or an MCA subaccount. Format: accounts/\\{account}
214
+ # @param query [::String]
215
+ # Required. Query that defines a report to be retrieved.
216
+ #
217
+ # For details on how to construct your query, see the [Query Language
218
+ # guide](/merchant/api/guides/reports/query-language). For the full list of
219
+ # available tables and fields, see the [Available
220
+ # fields](/merchant/api/reference/rest/reports_v1/accounts.reports).
221
+ # @param page_size [::Integer]
222
+ # Optional. Number of `ReportRows` to retrieve in a single page. Defaults to
223
+ # 1000. Values above 5000 are coerced to 5000.
224
+ # @param page_token [::String]
225
+ # Optional. Token of the page to retrieve. If not specified, the first page
226
+ # of results is returned. In order to request the next page of results, the
227
+ # value obtained from `next_page_token` in the previous response should be
228
+ # used.
229
+ #
230
+ # @yield [response, operation] Access the result along with the RPC operation
231
+ # @yieldparam response [::Gapic::PagedEnumerable<::Google::Shopping::Merchant::Reports::V1::ReportRow>]
232
+ # @yieldparam operation [::GRPC::ActiveCall::Operation]
233
+ #
234
+ # @return [::Gapic::PagedEnumerable<::Google::Shopping::Merchant::Reports::V1::ReportRow>]
235
+ #
236
+ # @raise [::Google::Cloud::Error] if the RPC is aborted.
237
+ #
238
+ # @example Basic example
239
+ # require "google/shopping/merchant/reports/v1"
240
+ #
241
+ # # Create a client object. The client can be reused for multiple calls.
242
+ # client = Google::Shopping::Merchant::Reports::V1::ReportService::Client.new
243
+ #
244
+ # # Create a request. To set request fields, pass in keyword arguments.
245
+ # request = Google::Shopping::Merchant::Reports::V1::SearchRequest.new
246
+ #
247
+ # # Call the search method.
248
+ # result = client.search request
249
+ #
250
+ # # The returned object is of type Gapic::PagedEnumerable. You can iterate
251
+ # # over elements, and API calls will be issued to fetch pages as needed.
252
+ # result.each do |item|
253
+ # # Each element is of type ::Google::Shopping::Merchant::Reports::V1::ReportRow.
254
+ # p item
255
+ # end
256
+ #
257
+ def search request, options = nil
258
+ raise ::ArgumentError, "request must be provided" if request.nil?
259
+
260
+ request = ::Gapic::Protobuf.coerce request, to: ::Google::Shopping::Merchant::Reports::V1::SearchRequest
261
+
262
+ # Converts hash and nil to an options object
263
+ options = ::Gapic::CallOptions.new(**options.to_h) if options.respond_to? :to_h
264
+
265
+ # Customize the options with defaults
266
+ metadata = @config.rpcs.search.metadata.to_h
267
+
268
+ # Set x-goog-api-client, x-goog-user-project and x-goog-api-version headers
269
+ metadata[:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \
270
+ lib_name: @config.lib_name, lib_version: @config.lib_version,
271
+ gapic_version: ::Google::Shopping::Merchant::Reports::V1::VERSION
272
+ metadata[:"x-goog-api-version"] = API_VERSION unless API_VERSION.empty?
273
+ metadata[:"x-goog-user-project"] = @quota_project_id if @quota_project_id
274
+
275
+ header_params = {}
276
+ if request.parent
277
+ header_params["parent"] = request.parent
278
+ end
279
+
280
+ request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&")
281
+ metadata[:"x-goog-request-params"] ||= request_params_header
282
+
283
+ options.apply_defaults timeout: @config.rpcs.search.timeout,
284
+ metadata: metadata,
285
+ retry_policy: @config.rpcs.search.retry_policy
286
+
287
+ options.apply_defaults timeout: @config.timeout,
288
+ metadata: @config.metadata,
289
+ retry_policy: @config.retry_policy
290
+
291
+ @report_service_stub.call_rpc :search, request, options: options do |response, operation|
292
+ response = ::Gapic::PagedEnumerable.new @report_service_stub, :search, request, response, operation, options
293
+ yield response, operation if block_given?
294
+ throw :response, response
295
+ end
296
+ rescue ::GRPC::BadStatus => e
297
+ raise ::Google::Cloud::Error.from_error(e)
298
+ end
299
+
300
+ ##
301
+ # Configuration class for the ReportService API.
302
+ #
303
+ # This class represents the configuration for ReportService,
304
+ # providing control over timeouts, retry behavior, logging, transport
305
+ # parameters, and other low-level controls. Certain parameters can also be
306
+ # applied individually to specific RPCs. See
307
+ # {::Google::Shopping::Merchant::Reports::V1::ReportService::Client::Configuration::Rpcs}
308
+ # for a list of RPCs that can be configured independently.
309
+ #
310
+ # Configuration can be applied globally to all clients, or to a single client
311
+ # on construction.
312
+ #
313
+ # @example
314
+ #
315
+ # # Modify the global config, setting the timeout for
316
+ # # search to 20 seconds,
317
+ # # and all remaining timeouts to 10 seconds.
318
+ # ::Google::Shopping::Merchant::Reports::V1::ReportService::Client.configure do |config|
319
+ # config.timeout = 10.0
320
+ # config.rpcs.search.timeout = 20.0
321
+ # end
322
+ #
323
+ # # Apply the above configuration only to a new client.
324
+ # client = ::Google::Shopping::Merchant::Reports::V1::ReportService::Client.new do |config|
325
+ # config.timeout = 10.0
326
+ # config.rpcs.search.timeout = 20.0
327
+ # end
328
+ #
329
+ # @!attribute [rw] endpoint
330
+ # A custom service endpoint, as a hostname or hostname:port. The default is
331
+ # nil, indicating to use the default endpoint in the current universe domain.
332
+ # @return [::String,nil]
333
+ # @!attribute [rw] credentials
334
+ # Credentials to send with calls. You may provide any of the following types:
335
+ # * (`String`) The path to a service account key file in JSON format
336
+ # * (`Hash`) A service account key as a Hash
337
+ # * (`Google::Auth::Credentials`) A googleauth credentials object
338
+ # (see the [googleauth docs](https://rubydoc.info/gems/googleauth/Google/Auth/Credentials))
339
+ # * (`Signet::OAuth2::Client`) A signet oauth2 client object
340
+ # (see the [signet docs](https://rubydoc.info/gems/signet/Signet/OAuth2/Client))
341
+ # * (`GRPC::Core::Channel`) a gRPC channel with included credentials
342
+ # * (`GRPC::Core::ChannelCredentials`) a gRPC credentails object
343
+ # * (`nil`) indicating no credentials
344
+ #
345
+ # Warning: If you accept a credential configuration (JSON file or Hash) from an
346
+ # external source for authentication to Google Cloud, you must validate it before
347
+ # providing it to a Google API client library. Providing an unvalidated credential
348
+ # configuration to Google APIs can compromise the security of your systems and data.
349
+ # For more information, refer to [Validate credential configurations from external
350
+ # sources](https://cloud.google.com/docs/authentication/external/externally-sourced-credentials).
351
+ # @return [::Object]
352
+ # @!attribute [rw] scope
353
+ # The OAuth scopes
354
+ # @return [::Array<::String>]
355
+ # @!attribute [rw] lib_name
356
+ # The library name as recorded in instrumentation and logging
357
+ # @return [::String]
358
+ # @!attribute [rw] lib_version
359
+ # The library version as recorded in instrumentation and logging
360
+ # @return [::String]
361
+ # @!attribute [rw] channel_args
362
+ # Extra parameters passed to the gRPC channel. Note: this is ignored if a
363
+ # `GRPC::Core::Channel` object is provided as the credential.
364
+ # @return [::Hash]
365
+ # @!attribute [rw] interceptors
366
+ # An array of interceptors that are run before calls are executed.
367
+ # @return [::Array<::GRPC::ClientInterceptor>]
368
+ # @!attribute [rw] timeout
369
+ # The call timeout in seconds.
370
+ # @return [::Numeric]
371
+ # @!attribute [rw] metadata
372
+ # Additional gRPC headers to be sent with the call.
373
+ # @return [::Hash{::Symbol=>::String}]
374
+ # @!attribute [rw] retry_policy
375
+ # The retry policy. The value is a hash with the following keys:
376
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
377
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
378
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
379
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
380
+ # trigger a retry.
381
+ # @return [::Hash]
382
+ # @!attribute [rw] quota_project
383
+ # A separate project against which to charge quota.
384
+ # @return [::String]
385
+ # @!attribute [rw] universe_domain
386
+ # The universe domain within which to make requests. This determines the
387
+ # default endpoint URL. The default value of nil uses the environment
388
+ # universe (usually the default "googleapis.com" universe).
389
+ # @return [::String,nil]
390
+ # @!attribute [rw] logger
391
+ # A custom logger to use for request/response debug logging, or the value
392
+ # `:default` (the default) to construct a default logger, or `nil` to
393
+ # explicitly disable logging.
394
+ # @return [::Logger,:default,nil]
395
+ #
396
+ class Configuration
397
+ extend ::Gapic::Config
398
+
399
+ # @private
400
+ # The endpoint specific to the default "googleapis.com" universe. Deprecated.
401
+ DEFAULT_ENDPOINT = "merchantapi.googleapis.com"
402
+
403
+ config_attr :endpoint, nil, ::String, nil
404
+ config_attr :credentials, nil do |value|
405
+ allowed = [::String, ::Hash, ::Proc, ::Symbol, ::Google::Auth::Credentials, ::Google::Auth::BaseClient, ::Signet::OAuth2::Client, nil]
406
+ allowed += [::GRPC::Core::Channel, ::GRPC::Core::ChannelCredentials] if defined? ::GRPC::Core::Channel
407
+ allowed.any? { |klass| klass === value }
408
+ end
409
+ config_attr :scope, nil, ::String, ::Array, nil
410
+ config_attr :lib_name, nil, ::String, nil
411
+ config_attr :lib_version, nil, ::String, nil
412
+ config_attr(:channel_args, { "grpc.service_config_disable_resolution" => 1 }, ::Hash, nil)
413
+ config_attr :interceptors, nil, ::Array, nil
414
+ config_attr :timeout, nil, ::Numeric, nil
415
+ config_attr :metadata, nil, ::Hash, nil
416
+ config_attr :retry_policy, nil, ::Hash, ::Proc, nil
417
+ config_attr :quota_project, nil, ::String, nil
418
+ config_attr :universe_domain, nil, ::String, nil
419
+ config_attr :logger, :default, ::Logger, nil, :default
420
+
421
+ # @private
422
+ def initialize parent_config = nil
423
+ @parent_config = parent_config unless parent_config.nil?
424
+
425
+ yield self if block_given?
426
+ end
427
+
428
+ ##
429
+ # Configurations for individual RPCs
430
+ # @return [Rpcs]
431
+ #
432
+ def rpcs
433
+ @rpcs ||= begin
434
+ parent_rpcs = nil
435
+ parent_rpcs = @parent_config.rpcs if defined?(@parent_config) && @parent_config.respond_to?(:rpcs)
436
+ Rpcs.new parent_rpcs
437
+ end
438
+ end
439
+
440
+ ##
441
+ # Configuration for the channel pool
442
+ # @return [::Gapic::ServiceStub::ChannelPool::Configuration]
443
+ #
444
+ def channel_pool
445
+ @channel_pool ||= ::Gapic::ServiceStub::ChannelPool::Configuration.new
446
+ end
447
+
448
+ ##
449
+ # Configuration RPC class for the ReportService API.
450
+ #
451
+ # Includes fields providing the configuration for each RPC in this service.
452
+ # Each configuration object is of type `Gapic::Config::Method` and includes
453
+ # the following configuration fields:
454
+ #
455
+ # * `timeout` (*type:* `Numeric`) - The call timeout in seconds
456
+ # * `metadata` (*type:* `Hash{Symbol=>String}`) - Additional gRPC headers
457
+ # * `retry_policy (*type:* `Hash`) - The retry policy. The policy fields
458
+ # include the following keys:
459
+ # * `:initial_delay` (*type:* `Numeric`) - The initial delay in seconds.
460
+ # * `:max_delay` (*type:* `Numeric`) - The max delay in seconds.
461
+ # * `:multiplier` (*type:* `Numeric`) - The incremental backoff multiplier.
462
+ # * `:retry_codes` (*type:* `Array<String>`) - The error codes that should
463
+ # trigger a retry.
464
+ #
465
+ class Rpcs
466
+ ##
467
+ # RPC-specific configuration for `search`
468
+ # @return [::Gapic::Config::Method]
469
+ #
470
+ attr_reader :search
471
+
472
+ # @private
473
+ def initialize parent_rpcs = nil
474
+ search_config = parent_rpcs.search if parent_rpcs.respond_to? :search
475
+ @search = ::Gapic::Config::Method.new search_config
476
+
477
+ yield self if block_given?
478
+ end
479
+ end
480
+ end
481
+ end
482
+ end
483
+ end
484
+ end
485
+ end
486
+ end
487
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2025 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 "googleauth"
20
+
21
+ module Google
22
+ module Shopping
23
+ module Merchant
24
+ module Reports
25
+ module V1
26
+ module ReportService
27
+ # Credentials for the ReportService API.
28
+ class Credentials < ::Google::Auth::Credentials
29
+ self.scope = [
30
+ "https://www.googleapis.com/auth/content"
31
+ ]
32
+ self.env_vars = [
33
+ "GOOGLE_CLOUD_CREDENTIALS",
34
+ "GOOGLE_CLOUD_KEYFILE",
35
+ "GCLOUD_KEYFILE",
36
+ "GOOGLE_CLOUD_CREDENTIALS_JSON",
37
+ "GOOGLE_CLOUD_KEYFILE_JSON",
38
+ "GCLOUD_KEYFILE_JSON"
39
+ ]
40
+ self.paths = [
41
+ "~/.config/google_cloud/application_default_credentials.json"
42
+ ]
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end