Skip to content
This repository was archived by the owner on Jul 13, 2023. It is now read-only.

Commit 48ac8fd

Browse files
yoshi-automationJustinBeckwith
authored andcommitted
feat: support apiEndpoint override in client constructor (#256)
1 parent 477c231 commit 48ac8fd

5 files changed

Lines changed: 75 additions & 7 deletions

File tree

src/v1/language_service_client.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,18 @@ class LanguageServiceClient {
5656
* API remote host.
5757
*/
5858
constructor(opts) {
59+
opts = opts || {};
5960
this._descriptors = {};
6061

62+
const servicePath =
63+
opts.servicePath || opts.apiEndpoint || this.constructor.servicePath;
64+
6165
// Ensure that options include the service address and port.
6266
opts = Object.assign(
6367
{
6468
clientConfig: {},
6569
port: this.constructor.port,
66-
servicePath: this.constructor.servicePath,
70+
servicePath,
6771
},
6872
opts
6973
);
@@ -149,6 +153,14 @@ class LanguageServiceClient {
149153
return 'language.googleapis.com';
150154
}
151155

156+
/**
157+
* The DNS address for this API service - same as servicePath(),
158+
* exists for compatibility reasons.
159+
*/
160+
static get apiEndpoint() {
161+
return 'language.googleapis.com';
162+
}
163+
152164
/**
153165
* The port for this API service.
154166
*/

src/v1beta2/language_service_client.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,18 @@ class LanguageServiceClient {
5656
* API remote host.
5757
*/
5858
constructor(opts) {
59+
opts = opts || {};
5960
this._descriptors = {};
6061

62+
const servicePath =
63+
opts.servicePath || opts.apiEndpoint || this.constructor.servicePath;
64+
6165
// Ensure that options include the service address and port.
6266
opts = Object.assign(
6367
{
6468
clientConfig: {},
6569
port: this.constructor.port,
66-
servicePath: this.constructor.servicePath,
70+
servicePath,
6771
},
6872
opts
6973
);
@@ -149,6 +153,14 @@ class LanguageServiceClient {
149153
return 'language.googleapis.com';
150154
}
151155

156+
/**
157+
* The DNS address for this API service - same as servicePath(),
158+
* exists for compatibility reasons.
159+
*/
160+
static get apiEndpoint() {
161+
return 'language.googleapis.com';
162+
}
163+
152164
/**
153165
* The port for this API service.
154166
*/

synth.metadata

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
2-
"updateTime": "2019-05-21T11:17:54.880717Z",
2+
"updateTime": "2019-06-05T14:20:03.832982Z",
33
"sources": [
44
{
55
"generator": {
66
"name": "artman",
7-
"version": "0.20.0",
8-
"dockerImage": "googleapis/artman@sha256:3246adac900f4bdbd62920e80de2e5877380e44036b3feae13667ec255ebf5ec"
7+
"version": "0.23.1",
8+
"dockerImage": "googleapis/artman@sha256:9d5cae1454da64ac3a87028f8ef486b04889e351c83bb95e83b8fab3959faed0"
99
}
1010
},
1111
{
1212
"git": {
1313
"name": "googleapis",
1414
"remote": "https://github.com/googleapis/googleapis.git",
15-
"sha": "32a10f69e2c9ce15bba13ab1ff928bacebb25160",
16-
"internalRef": "249058354"
15+
"sha": "47c142a7cecc6efc9f6f8af804b8be55392b795b",
16+
"internalRef": "251635729"
1717
}
1818
},
1919
{

test/gapic-v1.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@ const error = new Error();
2323
error.code = FAKE_STATUS_CODE;
2424

2525
describe('LanguageServiceClient', () => {
26+
it('has servicePath', () => {
27+
const servicePath = languageModule.v1.LanguageServiceClient.servicePath;
28+
assert(servicePath);
29+
});
30+
31+
it('has apiEndpoint', () => {
32+
const apiEndpoint = languageModule.v1.LanguageServiceClient.apiEndpoint;
33+
assert(apiEndpoint);
34+
});
35+
36+
it('has port', () => {
37+
const port = languageModule.v1.LanguageServiceClient.port;
38+
assert(port);
39+
assert(typeof port === 'number');
40+
});
41+
42+
it('should create a client with no options', () => {
43+
const client = new languageModule.v1.LanguageServiceClient();
44+
assert(client);
45+
});
46+
2647
describe('analyzeSentiment', () => {
2748
it('invokes analyzeSentiment without error', done => {
2849
const client = new languageModule.v1.LanguageServiceClient({

test/gapic-v1beta2.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,29 @@ const error = new Error();
2323
error.code = FAKE_STATUS_CODE;
2424

2525
describe('LanguageServiceClient', () => {
26+
it('has servicePath', () => {
27+
const servicePath =
28+
languageModule.v1beta2.LanguageServiceClient.servicePath;
29+
assert(servicePath);
30+
});
31+
32+
it('has apiEndpoint', () => {
33+
const apiEndpoint =
34+
languageModule.v1beta2.LanguageServiceClient.apiEndpoint;
35+
assert(apiEndpoint);
36+
});
37+
38+
it('has port', () => {
39+
const port = languageModule.v1beta2.LanguageServiceClient.port;
40+
assert(port);
41+
assert(typeof port === 'number');
42+
});
43+
44+
it('should create a client with no options', () => {
45+
const client = new languageModule.v1beta2.LanguageServiceClient();
46+
assert(client);
47+
});
48+
2649
describe('analyzeSentiment', () => {
2750
it('invokes analyzeSentiment without error', done => {
2851
const client = new languageModule.v1beta2.LanguageServiceClient({

0 commit comments

Comments
 (0)