diff --git a/google-cloud-dialogflow-cx/lib/google/cloud/dialogflow/cx.rb b/google-cloud-dialogflow-cx/lib/google/cloud/dialogflow/cx.rb index 34bb53abf90e..0ce977428a90 100644 --- a/google-cloud-dialogflow-cx/lib/google/cloud/dialogflow/cx.rb +++ b/google-cloud-dialogflow-cx/lib/google/cloud/dialogflow/cx.rb @@ -963,6 +963,76 @@ def self.environments_available? version: :v3, transport: :grpc false end + ## + # Create a new client object for Examples. + # + # By default, this returns an instance of + # [Google::Cloud::Dialogflow::CX::V3::Examples::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-dialogflow-cx-v3/latest/Google-Cloud-Dialogflow-CX-V3-Examples-Client) + # for a gRPC client for version V3 of the API. + # However, you can specify a different API version by passing it in the + # `version` parameter. If the Examples service is + # supported by that API version, and the corresponding gem is available, the + # appropriate versioned client will be returned. + # You can also specify a different transport by passing `:rest` or `:grpc` in + # the `transport` parameter. + # + # Raises an exception if the currently installed versioned client gem for the + # given API version does not support the given transport of the Examples service. + # You can determine whether the method will succeed by calling + # {Google::Cloud::Dialogflow::CX.examples_available?}. + # + # ## About Examples + # + # Service for managing Examples. + # + # @param version [::String, ::Symbol] The API version to connect to. Optional. + # Defaults to `:v3`. + # @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`. + # @return [::Object] A client object for the specified version. + # + def self.examples version: :v3, transport: :grpc, &block + require "google/cloud/dialogflow/cx/#{version.to_s.downcase}" + + package_name = Google::Cloud::Dialogflow::CX + .constants + .select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") } + .first + service_module = Google::Cloud::Dialogflow::CX.const_get(package_name).const_get(:Examples) + service_module = service_module.const_get(:Rest) if transport == :rest + service_module.const_get(:Client).new(&block) + end + + ## + # Determines whether the Examples service is supported by the current client. + # If true, you can retrieve a client object by calling {Google::Cloud::Dialogflow::CX.examples}. + # If false, that method will raise an exception. This could happen if the given + # API version does not exist or does not support the Examples service, + # or if the versioned client gem needs an update to support the Examples service. + # + # @param version [::String, ::Symbol] The API version to connect to. Optional. + # Defaults to `:v3`. + # @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`. + # @return [boolean] Whether the service is available. + # + def self.examples_available? version: :v3, transport: :grpc + require "google/cloud/dialogflow/cx/#{version.to_s.downcase}" + package_name = Google::Cloud::Dialogflow::CX + .constants + .select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") } + .first + return false unless package_name + service_module = Google::Cloud::Dialogflow::CX.const_get package_name + return false unless service_module.const_defined? :Examples + service_module = service_module.const_get :Examples + if transport == :rest + return false unless service_module.const_defined? :Rest + service_module = service_module.const_get :Rest + end + service_module.const_defined? :Client + rescue ::LoadError + false + end + ## # Create a new client object for Experiments. # @@ -1103,6 +1173,76 @@ def self.generators_available? version: :v3, transport: :grpc false end + ## + # Create a new client object for Playbooks. + # + # By default, this returns an instance of + # [Google::Cloud::Dialogflow::CX::V3::Playbooks::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-dialogflow-cx-v3/latest/Google-Cloud-Dialogflow-CX-V3-Playbooks-Client) + # for a gRPC client for version V3 of the API. + # However, you can specify a different API version by passing it in the + # `version` parameter. If the Playbooks service is + # supported by that API version, and the corresponding gem is available, the + # appropriate versioned client will be returned. + # You can also specify a different transport by passing `:rest` or `:grpc` in + # the `transport` parameter. + # + # Raises an exception if the currently installed versioned client gem for the + # given API version does not support the given transport of the Playbooks service. + # You can determine whether the method will succeed by calling + # {Google::Cloud::Dialogflow::CX.playbooks_available?}. + # + # ## About Playbooks + # + # Service for managing Playbooks. + # + # @param version [::String, ::Symbol] The API version to connect to. Optional. + # Defaults to `:v3`. + # @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`. + # @return [::Object] A client object for the specified version. + # + def self.playbooks version: :v3, transport: :grpc, &block + require "google/cloud/dialogflow/cx/#{version.to_s.downcase}" + + package_name = Google::Cloud::Dialogflow::CX + .constants + .select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") } + .first + service_module = Google::Cloud::Dialogflow::CX.const_get(package_name).const_get(:Playbooks) + service_module = service_module.const_get(:Rest) if transport == :rest + service_module.const_get(:Client).new(&block) + end + + ## + # Determines whether the Playbooks service is supported by the current client. + # If true, you can retrieve a client object by calling {Google::Cloud::Dialogflow::CX.playbooks}. + # If false, that method will raise an exception. This could happen if the given + # API version does not exist or does not support the Playbooks service, + # or if the versioned client gem needs an update to support the Playbooks service. + # + # @param version [::String, ::Symbol] The API version to connect to. Optional. + # Defaults to `:v3`. + # @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`. + # @return [boolean] Whether the service is available. + # + def self.playbooks_available? version: :v3, transport: :grpc + require "google/cloud/dialogflow/cx/#{version.to_s.downcase}" + package_name = Google::Cloud::Dialogflow::CX + .constants + .select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") } + .first + return false unless package_name + service_module = Google::Cloud::Dialogflow::CX.const_get package_name + return false unless service_module.const_defined? :Playbooks + service_module = service_module.const_get :Playbooks + if transport == :rest + return false unless service_module.const_defined? :Rest + service_module = service_module.const_get :Rest + end + service_module.const_defined? :Client + rescue ::LoadError + false + end + ## # Create a new client object for SecuritySettingsService. # @@ -1173,6 +1313,76 @@ def self.security_settings_service_available? version: :v3, transport: :grpc false end + ## + # Create a new client object for Tools. + # + # By default, this returns an instance of + # [Google::Cloud::Dialogflow::CX::V3::Tools::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-dialogflow-cx-v3/latest/Google-Cloud-Dialogflow-CX-V3-Tools-Client) + # for a gRPC client for version V3 of the API. + # However, you can specify a different API version by passing it in the + # `version` parameter. If the Tools service is + # supported by that API version, and the corresponding gem is available, the + # appropriate versioned client will be returned. + # You can also specify a different transport by passing `:rest` or `:grpc` in + # the `transport` parameter. + # + # Raises an exception if the currently installed versioned client gem for the + # given API version does not support the given transport of the Tools service. + # You can determine whether the method will succeed by calling + # {Google::Cloud::Dialogflow::CX.tools_available?}. + # + # ## About Tools + # + # Service for managing Tools. + # + # @param version [::String, ::Symbol] The API version to connect to. Optional. + # Defaults to `:v3`. + # @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`. + # @return [::Object] A client object for the specified version. + # + def self.tools version: :v3, transport: :grpc, &block + require "google/cloud/dialogflow/cx/#{version.to_s.downcase}" + + package_name = Google::Cloud::Dialogflow::CX + .constants + .select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") } + .first + service_module = Google::Cloud::Dialogflow::CX.const_get(package_name).const_get(:Tools) + service_module = service_module.const_get(:Rest) if transport == :rest + service_module.const_get(:Client).new(&block) + end + + ## + # Determines whether the Tools service is supported by the current client. + # If true, you can retrieve a client object by calling {Google::Cloud::Dialogflow::CX.tools}. + # If false, that method will raise an exception. This could happen if the given + # API version does not exist or does not support the Tools service, + # or if the versioned client gem needs an update to support the Tools service. + # + # @param version [::String, ::Symbol] The API version to connect to. Optional. + # Defaults to `:v3`. + # @param transport [:grpc, :rest] The transport to use. Defaults to `:grpc`. + # @return [boolean] Whether the service is available. + # + def self.tools_available? version: :v3, transport: :grpc + require "google/cloud/dialogflow/cx/#{version.to_s.downcase}" + package_name = Google::Cloud::Dialogflow::CX + .constants + .select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") } + .first + return false unless package_name + service_module = Google::Cloud::Dialogflow::CX.const_get package_name + return false unless service_module.const_defined? :Tools + service_module = service_module.const_get :Tools + if transport == :rest + return false unless service_module.const_defined? :Rest + service_module = service_module.const_get :Rest + end + service_module.const_defined? :Client + rescue ::LoadError + false + end + ## # Create a new client object for Versions. # diff --git a/google-cloud-dialogflow-cx/test/google/cloud/dialogflow/cx/client_test.rb b/google-cloud-dialogflow-cx/test/google/cloud/dialogflow/cx/client_test.rb index e0882aa3bebb..a883364d1fff 100644 --- a/google-cloud-dialogflow-cx/test/google/cloud/dialogflow/cx/client_test.rb +++ b/google-cloud-dialogflow-cx/test/google/cloud/dialogflow/cx/client_test.rb @@ -314,6 +314,27 @@ def test_environments_rest end end + def test_examples_grpc + skip unless Google::Cloud::Dialogflow::CX.examples_available? transport: :grpc + Gapic::ServiceStub.stub :new, DummyStub.new do + grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure + client = Google::Cloud::Dialogflow::CX.examples transport: :grpc do |config| + config.credentials = grpc_channel + end + assert_kind_of Google::Cloud::Dialogflow::CX::V3::Examples::Client, client + end + end + + def test_examples_rest + skip unless Google::Cloud::Dialogflow::CX.examples_available? transport: :rest + Gapic::Rest::ClientStub.stub :new, DummyStub.new do + client = Google::Cloud::Dialogflow::CX.examples transport: :rest do |config| + config.credentials = :dummy_credentials + end + assert_kind_of Google::Cloud::Dialogflow::CX::V3::Examples::Rest::Client, client + end + end + def test_experiments_grpc skip unless Google::Cloud::Dialogflow::CX.experiments_available? transport: :grpc Gapic::ServiceStub.stub :new, DummyStub.new do @@ -356,6 +377,27 @@ def test_generators_rest end end + def test_playbooks_grpc + skip unless Google::Cloud::Dialogflow::CX.playbooks_available? transport: :grpc + Gapic::ServiceStub.stub :new, DummyStub.new do + grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure + client = Google::Cloud::Dialogflow::CX.playbooks transport: :grpc do |config| + config.credentials = grpc_channel + end + assert_kind_of Google::Cloud::Dialogflow::CX::V3::Playbooks::Client, client + end + end + + def test_playbooks_rest + skip unless Google::Cloud::Dialogflow::CX.playbooks_available? transport: :rest + Gapic::Rest::ClientStub.stub :new, DummyStub.new do + client = Google::Cloud::Dialogflow::CX.playbooks transport: :rest do |config| + config.credentials = :dummy_credentials + end + assert_kind_of Google::Cloud::Dialogflow::CX::V3::Playbooks::Rest::Client, client + end + end + def test_security_settings_service_grpc skip unless Google::Cloud::Dialogflow::CX.security_settings_service_available? transport: :grpc Gapic::ServiceStub.stub :new, DummyStub.new do @@ -377,6 +419,27 @@ def test_security_settings_service_rest end end + def test_tools_grpc + skip unless Google::Cloud::Dialogflow::CX.tools_available? transport: :grpc + Gapic::ServiceStub.stub :new, DummyStub.new do + grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure + client = Google::Cloud::Dialogflow::CX.tools transport: :grpc do |config| + config.credentials = grpc_channel + end + assert_kind_of Google::Cloud::Dialogflow::CX::V3::Tools::Client, client + end + end + + def test_tools_rest + skip unless Google::Cloud::Dialogflow::CX.tools_available? transport: :rest + Gapic::Rest::ClientStub.stub :new, DummyStub.new do + client = Google::Cloud::Dialogflow::CX.tools transport: :rest do |config| + config.credentials = :dummy_credentials + end + assert_kind_of Google::Cloud::Dialogflow::CX::V3::Tools::Rest::Client, client + end + end + def test_versions_grpc skip unless Google::Cloud::Dialogflow::CX.versions_available? transport: :grpc Gapic::ServiceStub.stub :new, DummyStub.new do