From 5e9bc5a70043e7c7a33bf47b4bc1fbac46d4a805 Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Wed, 5 Jun 2019 09:58:59 -0700 Subject: [PATCH] feat: support apiEndpoint override in client constructor (#256) --- .../src/v1/language_service_client.js | 14 ++++++++++- .../src/v1beta2/language_service_client.js | 14 ++++++++++- packages/google-cloud-language/synth.metadata | 10 ++++---- .../google-cloud-language/test/gapic-v1.js | 21 +++++++++++++++++ .../test/gapic-v1beta2.js | 23 +++++++++++++++++++ 5 files changed, 75 insertions(+), 7 deletions(-) diff --git a/packages/google-cloud-language/src/v1/language_service_client.js b/packages/google-cloud-language/src/v1/language_service_client.js index 367879c8fca..dbd900faafb 100644 --- a/packages/google-cloud-language/src/v1/language_service_client.js +++ b/packages/google-cloud-language/src/v1/language_service_client.js @@ -56,14 +56,18 @@ class LanguageServiceClient { * API remote host. */ constructor(opts) { + opts = opts || {}; this._descriptors = {}; + const servicePath = + opts.servicePath || opts.apiEndpoint || this.constructor.servicePath; + // Ensure that options include the service address and port. opts = Object.assign( { clientConfig: {}, port: this.constructor.port, - servicePath: this.constructor.servicePath, + servicePath, }, opts ); @@ -149,6 +153,14 @@ class LanguageServiceClient { return 'language.googleapis.com'; } + /** + * The DNS address for this API service - same as servicePath(), + * exists for compatibility reasons. + */ + static get apiEndpoint() { + return 'language.googleapis.com'; + } + /** * The port for this API service. */ diff --git a/packages/google-cloud-language/src/v1beta2/language_service_client.js b/packages/google-cloud-language/src/v1beta2/language_service_client.js index 9f31bc9e298..868dfe172f2 100644 --- a/packages/google-cloud-language/src/v1beta2/language_service_client.js +++ b/packages/google-cloud-language/src/v1beta2/language_service_client.js @@ -56,14 +56,18 @@ class LanguageServiceClient { * API remote host. */ constructor(opts) { + opts = opts || {}; this._descriptors = {}; + const servicePath = + opts.servicePath || opts.apiEndpoint || this.constructor.servicePath; + // Ensure that options include the service address and port. opts = Object.assign( { clientConfig: {}, port: this.constructor.port, - servicePath: this.constructor.servicePath, + servicePath, }, opts ); @@ -149,6 +153,14 @@ class LanguageServiceClient { return 'language.googleapis.com'; } + /** + * The DNS address for this API service - same as servicePath(), + * exists for compatibility reasons. + */ + static get apiEndpoint() { + return 'language.googleapis.com'; + } + /** * The port for this API service. */ diff --git a/packages/google-cloud-language/synth.metadata b/packages/google-cloud-language/synth.metadata index b1a477caaf3..2ff517d8b8c 100644 --- a/packages/google-cloud-language/synth.metadata +++ b/packages/google-cloud-language/synth.metadata @@ -1,19 +1,19 @@ { - "updateTime": "2019-05-21T11:17:54.880717Z", + "updateTime": "2019-06-05T14:20:03.832982Z", "sources": [ { "generator": { "name": "artman", - "version": "0.20.0", - "dockerImage": "googleapis/artman@sha256:3246adac900f4bdbd62920e80de2e5877380e44036b3feae13667ec255ebf5ec" + "version": "0.23.1", + "dockerImage": "googleapis/artman@sha256:9d5cae1454da64ac3a87028f8ef486b04889e351c83bb95e83b8fab3959faed0" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "32a10f69e2c9ce15bba13ab1ff928bacebb25160", - "internalRef": "249058354" + "sha": "47c142a7cecc6efc9f6f8af804b8be55392b795b", + "internalRef": "251635729" } }, { diff --git a/packages/google-cloud-language/test/gapic-v1.js b/packages/google-cloud-language/test/gapic-v1.js index 853c9753c6e..d2d93821669 100644 --- a/packages/google-cloud-language/test/gapic-v1.js +++ b/packages/google-cloud-language/test/gapic-v1.js @@ -23,6 +23,27 @@ const error = new Error(); error.code = FAKE_STATUS_CODE; describe('LanguageServiceClient', () => { + it('has servicePath', () => { + const servicePath = languageModule.v1.LanguageServiceClient.servicePath; + assert(servicePath); + }); + + it('has apiEndpoint', () => { + const apiEndpoint = languageModule.v1.LanguageServiceClient.apiEndpoint; + assert(apiEndpoint); + }); + + it('has port', () => { + const port = languageModule.v1.LanguageServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no options', () => { + const client = new languageModule.v1.LanguageServiceClient(); + assert(client); + }); + describe('analyzeSentiment', () => { it('invokes analyzeSentiment without error', done => { const client = new languageModule.v1.LanguageServiceClient({ diff --git a/packages/google-cloud-language/test/gapic-v1beta2.js b/packages/google-cloud-language/test/gapic-v1beta2.js index d6ab5151c4a..bab852198bc 100644 --- a/packages/google-cloud-language/test/gapic-v1beta2.js +++ b/packages/google-cloud-language/test/gapic-v1beta2.js @@ -23,6 +23,29 @@ const error = new Error(); error.code = FAKE_STATUS_CODE; describe('LanguageServiceClient', () => { + it('has servicePath', () => { + const servicePath = + languageModule.v1beta2.LanguageServiceClient.servicePath; + assert(servicePath); + }); + + it('has apiEndpoint', () => { + const apiEndpoint = + languageModule.v1beta2.LanguageServiceClient.apiEndpoint; + assert(apiEndpoint); + }); + + it('has port', () => { + const port = languageModule.v1beta2.LanguageServiceClient.port; + assert(port); + assert(typeof port === 'number'); + }); + + it('should create a client with no options', () => { + const client = new languageModule.v1beta2.LanguageServiceClient(); + assert(client); + }); + describe('analyzeSentiment', () => { it('invokes analyzeSentiment without error', done => { const client = new languageModule.v1beta2.LanguageServiceClient({