Skip to content

Commit 7349855

Browse files
feat: introduce DataTransfer APIs (#30949)
* feat: introduce DataTransfer APIs PiperOrigin-RevId: 803093347 Source-Link: googleapis/googleapis@a195f5b Source-Link: googleapis/googleapis-gen@a4ce123 Copy-Tag: eyJwIjoiZ29vZ2xlLWNsb3VkLW5ldHdvcmtfY29ubmVjdGl2aXR5Ly5Pd2xCb3QueWFtbCIsImgiOiJhNGNlMTIzNTZiYjFkZjIxZTRkMWJhNzgzNmJmZGYwNGE2ZThjYzA3In0= * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent b2dde2e commit 7349855

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

google-cloud-network_connectivity/lib/google/cloud/network_connectivity.rb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,67 @@ def self.cross_network_automation_service_available? version: :v1
106106
false
107107
end
108108

109+
##
110+
# Create a new client object for DataTransferService.
111+
#
112+
# By default, this returns an instance of
113+
# [Google::Cloud::NetworkConnectivity::V1::DataTransferService::Client](https://cloud.google.com/ruby/docs/reference/google-cloud-network_connectivity-v1/latest/Google-Cloud-NetworkConnectivity-V1-DataTransferService-Client)
114+
# for a gRPC client for version V1 of the API.
115+
# However, you can specify a different API version by passing it in the
116+
# `version` parameter. If the DataTransferService service is
117+
# supported by that API version, and the corresponding gem is available, the
118+
# appropriate versioned client will be returned.
119+
#
120+
# Raises an exception if the currently installed versioned client gem for the
121+
# given API version does not support the DataTransferService service.
122+
# You can determine whether the method will succeed by calling
123+
# {Google::Cloud::NetworkConnectivity.data_transfer_service_available?}.
124+
#
125+
# ## About DataTransferService
126+
#
127+
# DataTransferService is the service for the Data Transfer API.
128+
#
129+
# @param version [::String, ::Symbol] The API version to connect to. Optional.
130+
# Defaults to `:v1`.
131+
# @return [::Object] A client object for the specified version.
132+
#
133+
def self.data_transfer_service version: :v1, &block
134+
require "google/cloud/network_connectivity/#{version.to_s.downcase}"
135+
136+
package_name = Google::Cloud::NetworkConnectivity
137+
.constants
138+
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
139+
.first
140+
service_module = Google::Cloud::NetworkConnectivity.const_get(package_name).const_get(:DataTransferService)
141+
service_module.const_get(:Client).new(&block)
142+
end
143+
144+
##
145+
# Determines whether the DataTransferService service is supported by the current client.
146+
# If true, you can retrieve a client object by calling {Google::Cloud::NetworkConnectivity.data_transfer_service}.
147+
# If false, that method will raise an exception. This could happen if the given
148+
# API version does not exist or does not support the DataTransferService service,
149+
# or if the versioned client gem needs an update to support the DataTransferService service.
150+
#
151+
# @param version [::String, ::Symbol] The API version to connect to. Optional.
152+
# Defaults to `:v1`.
153+
# @return [boolean] Whether the service is available.
154+
#
155+
def self.data_transfer_service_available? version: :v1
156+
require "google/cloud/network_connectivity/#{version.to_s.downcase}"
157+
package_name = Google::Cloud::NetworkConnectivity
158+
.constants
159+
.select { |sym| sym.to_s.downcase == version.to_s.downcase.tr("_", "") }
160+
.first
161+
return false unless package_name
162+
service_module = Google::Cloud::NetworkConnectivity.const_get package_name
163+
return false unless service_module.const_defined? :DataTransferService
164+
service_module = service_module.const_get :DataTransferService
165+
service_module.const_defined? :Client
166+
rescue ::LoadError
167+
false
168+
end
169+
109170
##
110171
# Create a new client object for HubService.
111172
#

google-cloud-network_connectivity/test/google/cloud/network_connectivity/client_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,17 @@ def test_cross_network_automation_service_grpc
5151
end
5252
end
5353

54+
def test_data_transfer_service_grpc
55+
skip unless Google::Cloud::NetworkConnectivity.data_transfer_service_available?
56+
Gapic::ServiceStub.stub :new, DummyStub.new do
57+
grpc_channel = GRPC::Core::Channel.new "localhost:8888", nil, :this_channel_is_insecure
58+
client = Google::Cloud::NetworkConnectivity.data_transfer_service do |config|
59+
config.credentials = grpc_channel
60+
end
61+
assert_kind_of Google::Cloud::NetworkConnectivity::V1::DataTransferService::Client, client
62+
end
63+
end
64+
5465
def test_hub_service_grpc
5566
skip unless Google::Cloud::NetworkConnectivity.hub_service_available?
5667
Gapic::ServiceStub.stub :new, DummyStub.new do

0 commit comments

Comments
 (0)