lib/google/cloud/speech/v1/speech_client.rb in google-cloud-speech-0.27.0 vs lib/google/cloud/speech/v1/speech_client.rb in google-cloud-speech-0.28.0

- old
+ new

@@ -1,12 +1,12 @@ -# Copyright 2017, Google Inc. All rights reserved. +# Copyright 2017 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and @@ -55,10 +55,14 @@ # this service. ALL_SCOPES = [ "https://www.googleapis.com/auth/cloud-platform" ].freeze + class OperationsClient < Google::Longrunning::OperationsClient + SERVICE_ADDRESS = SERVICE_ADDRESS + end + # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc] # Provides the means for authenticating requests made by the client. This parameter can # be many types. # A `Google::Auth::Credentials` uses a the properties of its represented keyfile for # authenticating requests made by this client. @@ -80,15 +84,10 @@ # this data. Falls back to the default config if not specified # or the specified config is missing data points. # @param timeout [Numeric] # The default timeout, in seconds, for calls made through this client. def initialize \ - service_path: SERVICE_ADDRESS, - port: DEFAULT_SERVICE_PORT, - channel: nil, - chan_creds: nil, - updater_proc: nil, credentials: nil, scopes: ALL_SCOPES, client_config: {}, timeout: DEFAULT_TIMEOUT, lib_name: nil, @@ -97,25 +96,13 @@ # the gRPC module only when it's required. # See https://github.com/googleapis/toolkit/issues/446 require "google/gax/grpc" require "google/cloud/speech/v1/cloud_speech_services_pb" - if channel || chan_creds || updater_proc - warn "The `channel`, `chan_creds`, and `updater_proc` parameters will be removed " \ - "on 2017/09/08" - credentials ||= channel - credentials ||= chan_creds - credentials ||= updater_proc - end - if service_path != SERVICE_ADDRESS || port != DEFAULT_SERVICE_PORT - warn "`service_path` and `port` parameters are deprecated and will be removed" - end - credentials ||= Google::Cloud::Speech::Credentials.default - @operations_client = Google::Longrunning::OperationsClient.new( - service_path: service_path, + @operations_client = OperationsClient.new( credentials: credentials, scopes: scopes, client_config: client_config, timeout: timeout, lib_name: lib_name, @@ -136,13 +123,15 @@ end if credentials.is_a?(Google::Auth::Credentials) updater_proc = credentials.updater_proc end + package_version = Gem.loaded_specs['google-cloud-speech'].version.version + google_api_client = "gl-ruby/#{RUBY_VERSION}" google_api_client << " #{lib_name}/#{lib_version}" if lib_name - google_api_client << " gapic/0.1.0 gax/#{Google::Gax::VERSION}" + google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}" google_api_client << " grpc/#{GRPC::VERSION}" google_api_client.freeze headers = { :"x-goog-api-client" => google_api_client } client_config_file = Pathname.new(__dir__).join( @@ -157,9 +146,13 @@ timeout, errors: Google::Gax::Grpc::API_ERRORS, kwargs: headers ) end + + # Allow overriding the service path/port in subclasses. + service_path = self.class::SERVICE_ADDRESS + port = self.class::DEFAULT_SERVICE_PORT @speech_stub = Google::Gax::Grpc.create_stub( service_path, port, chan_creds: chan_creds, channel: channel,