Skip to content

Commit ca36e79

Browse files
feat(merchant-accounts): Support for Automatic Improvements (also requires an update to the google-shopping-merchant-accounts-v1beta gem) (googleapis#29346)
1 parent 892d74b commit ca36e79

2 files changed

Lines changed: 93 additions & 0 deletions

File tree

google-shopping-merchant-accounts/lib/google/shopping/merchant/accounts.rb

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,78 @@ def self.autofeed_settings_service_available? version: :v1beta, transport: :grpc
383383
false
384384
end
385385

386+
##
387+
# Create a new client object for AutomaticImprovementsService.
388+
#
389+
# By default, this returns an instance of
390+
# [Google::Shopping::Merchant::Accounts::V1beta::AutomaticImprovementsService::Client](https://rubydoc.info/gems/google-shopping-merchant-accounts-v1beta/Google/Shopping/Merchant/Accounts/V1beta/AutomaticImprovementsService/Client)
391+
# for a gRPC client for version V1beta of the API.
392+
# However, you can specify a different API version by passing it in the
393+
# `version` parameter. If the AutomaticImprovementsService service is
394+
# supported by that API version, and the corresponding gem is available, the
395+
# appropriate versioned client will be returned.
396+
# You can also specify a different transport by passing `:rest` or `:grpc` in
397+
# the `transport` parameter.
398+
#
399+
# Raises an exception if the currently installed versioned client gem for the
400+
# given API version does not support the given transport of the AutomaticImprovementsService service.
401+
# You can determine whether the method will succeed by calling
402+
# {Google::Shopping::Merchant::Accounts.automatic_improvements_service_available?}.
403+
#
404+
# ## About AutomaticImprovementsService
405+
#
406+
# Service to manage the automatic improvements of an account. The automatic
407+
# improvements of the account can be used to automatically update products,
408+
# improve images and shipping.
409+
#
410+
# @param version [::String, ::Symbol] The API version to connect to. Optional.
411+
# Defaults to `:v1beta`.
412+
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
413+
# @return [::Object] A client object for the specified version.
414+
#
415+
def self.automatic_improvements_service version: :v1beta, transport: :grpc, &block
416+
require "google/shopping/merchant/accounts/#{version.to_s.downcase}"
417+
418+
package_name = Google::Shopping::Merchant::Accounts
419+
.constants
420+
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
421+
.first
422+
service_module = Google::Shopping::Merchant::Accounts.const_get(package_name).const_get(:AutomaticImprovementsService)
423+
service_module = service_module.const_get(:Rest) if transport == :rest
424+
service_module.const_get(:Client).new(&block)
425+
end
426+
427+
##
428+
# Determines whether the AutomaticImprovementsService service is supported by the current client.
429+
# If true, you can retrieve a client object by calling {Google::Shopping::Merchant::Accounts.automatic_improvements_service}.
430+
# If false, that method will raise an exception. This could happen if the given
431+
# API version does not exist or does not support the AutomaticImprovementsService service,
432+
# or if the versioned client gem needs an update to support the AutomaticImprovementsService service.
433+
#
434+
# @param version [::String, ::Symbol] The API version to connect to. Optional.
435+
# Defaults to `:v1beta`.
436+
# @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`.
437+
# @return [boolean] Whether the service is available.
438+
#
439+
def self.automatic_improvements_service_available? version: :v1beta, transport: :grpc
440+
require "google/shopping/merchant/accounts/#{version.to_s.downcase}"
441+
package_name = Google::Shopping::Merchant::Accounts
442+
.constants
443+
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
444+
.first
445+
return false unless package_name
446+
service_module = Google::Shopping::Merchant::Accounts.const_get package_name
447+
return false unless service_module.const_defined? :AutomaticImprovementsService
448+
service_module = service_module.const_get :AutomaticImprovementsService
449+
if transport == :rest
450+
return false unless service_module.const_defined? :Rest
451+
service_module = service_module.const_get :Rest
452+
end
453+
service_module.const_defined? :Client
454+
rescue ::LoadError
455+
false
456+
end
457+
386458
##
387459
# Create a new client object for BusinessIdentityService.
388460
#

google-shopping-merchant-accounts/test/google/shopping/merchant/accounts/client_test.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,27 @@ def test_autofeed_settings_service_rest
146146
end
147147
end
148148

149+
def test_automatic_improvements_service_grpc
150+
skip unless Google::Shopping::Merchant::Accounts.automatic_improvements_service_available? transport: :grpc
151+
Gapic::ServiceStub.stub :new, DummyStub.new do
152+
grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
153+
client = Google::Shopping::Merchant::Accounts.automatic_improvements_service transport: :grpc do |config|
154+
config.credentials = grpc_channel
155+
end
156+
assert_kind_of Google::Shopping::Merchant::Accounts::V1beta::AutomaticImprovementsService::Client, client
157+
end
158+
end
159+
160+
def test_automatic_improvements_service_rest
161+
skip unless Google::Shopping::Merchant::Accounts.automatic_improvements_service_available? transport: :rest
162+
Gapic::Rest::ClientStub.stub :new, DummyStub.new do
163+
client = Google::Shopping::Merchant::Accounts.automatic_improvements_service transport: :rest do |config|
164+
config.credentials = :dummy_credentials
165+
end
166+
assert_kind_of Google::Shopping::Merchant::Accounts::V1beta::AutomaticImprovementsService::Rest::Client, client
167+
end
168+
end
169+
149170
def test_business_identity_service_grpc
150171
skip unless Google::Shopping::Merchant::Accounts.business_identity_service_available? transport: :grpc
151172
Gapic::ServiceStub.stub :new, DummyStub.new do

0 commit comments

Comments
 (0)