Skip to content

Commit 7b3ccf4

Browse files
yoshi-automationJustinBeckwith
authored andcommitted
feat: support apiEndpoint override in client constructor (#393)
1 parent 5c1ae7b commit 7b3ccf4

14 files changed

+277
-13
lines changed

packages/google-cloud-vision/src/v1/image_annotator_client.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,18 @@ class ImageAnnotatorClient {
5858
* API remote host.
5959
*/
6060
constructor(opts) {
61+
opts = opts || {};
6162
this._descriptors = {};
6263

64+
const servicePath =
65+
opts.servicePath || opts.apiEndpoint || this.constructor.servicePath;
66+
6367
// Ensure that options include the service address and port.
6468
opts = Object.assign(
6569
{
6670
clientConfig: {},
6771
port: this.constructor.port,
68-
servicePath: this.constructor.servicePath,
72+
servicePath,
6973
},
7074
opts
7175
);
@@ -202,6 +206,14 @@ class ImageAnnotatorClient {
202206
return 'vision.googleapis.com';
203207
}
204208

209+
/**
210+
* The DNS address for this API service - same as servicePath(),
211+
* exists for compatibility reasons.
212+
*/
213+
static get apiEndpoint() {
214+
return 'vision.googleapis.com';
215+
}
216+
205217
/**
206218
* The port for this API service.
207219
*/

packages/google-cloud-vision/src/v1/product_search_client.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,18 @@ class ProductSearchClient {
7171
* API remote host.
7272
*/
7373
constructor(opts) {
74+
opts = opts || {};
7475
this._descriptors = {};
7576

77+
const servicePath =
78+
opts.servicePath || opts.apiEndpoint || this.constructor.servicePath;
79+
7680
// Ensure that options include the service address and port.
7781
opts = Object.assign(
7882
{
7983
clientConfig: {},
8084
port: this.constructor.port,
81-
servicePath: this.constructor.servicePath,
85+
servicePath,
8286
},
8387
opts
8488
);
@@ -255,6 +259,14 @@ class ProductSearchClient {
255259
return 'vision.googleapis.com';
256260
}
257261

262+
/**
263+
* The DNS address for this API service - same as servicePath(),
264+
* exists for compatibility reasons.
265+
*/
266+
static get apiEndpoint() {
267+
return 'vision.googleapis.com';
268+
}
269+
258270
/**
259271
* The port for this API service.
260272
*/

packages/google-cloud-vision/src/v1p1beta1/image_annotator_client.js

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

63+
const servicePath =
64+
opts.servicePath || opts.apiEndpoint || this.constructor.servicePath;
65+
6266
// Ensure that options include the service address and port.
6367
opts = Object.assign(
6468
{
6569
clientConfig: {},
6670
port: this.constructor.port,
67-
servicePath: this.constructor.servicePath,
71+
servicePath,
6872
},
6973
opts
7074
);
@@ -143,6 +147,14 @@ class ImageAnnotatorClient {
143147
return 'vision.googleapis.com';
144148
}
145149

150+
/**
151+
* The DNS address for this API service - same as servicePath(),
152+
* exists for compatibility reasons.
153+
*/
154+
static get apiEndpoint() {
155+
return 'vision.googleapis.com';
156+
}
157+
146158
/**
147159
* The port for this API service.
148160
*/

packages/google-cloud-vision/src/v1p2beta1/image_annotator_client.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,18 @@ class ImageAnnotatorClient {
5858
* API remote host.
5959
*/
6060
constructor(opts) {
61+
opts = opts || {};
6162
this._descriptors = {};
6263

64+
const servicePath =
65+
opts.servicePath || opts.apiEndpoint || this.constructor.servicePath;
66+
6367
// Ensure that options include the service address and port.
6468
opts = Object.assign(
6569
{
6670
clientConfig: {},
6771
port: this.constructor.port,
68-
servicePath: this.constructor.servicePath,
72+
servicePath,
6973
},
7074
opts
7175
);
@@ -185,6 +189,14 @@ class ImageAnnotatorClient {
185189
return 'vision.googleapis.com';
186190
}
187191

192+
/**
193+
* The DNS address for this API service - same as servicePath(),
194+
* exists for compatibility reasons.
195+
*/
196+
static get apiEndpoint() {
197+
return 'vision.googleapis.com';
198+
}
199+
188200
/**
189201
* The port for this API service.
190202
*/

packages/google-cloud-vision/src/v1p3beta1/image_annotator_client.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,18 @@ class ImageAnnotatorClient {
5858
* API remote host.
5959
*/
6060
constructor(opts) {
61+
opts = opts || {};
6162
this._descriptors = {};
6263

64+
const servicePath =
65+
opts.servicePath || opts.apiEndpoint || this.constructor.servicePath;
66+
6367
// Ensure that options include the service address and port.
6468
opts = Object.assign(
6569
{
6670
clientConfig: {},
6771
port: this.constructor.port,
68-
servicePath: this.constructor.servicePath,
72+
servicePath,
6973
},
7074
opts
7175
);
@@ -185,6 +189,14 @@ class ImageAnnotatorClient {
185189
return 'vision.googleapis.com';
186190
}
187191

192+
/**
193+
* The DNS address for this API service - same as servicePath(),
194+
* exists for compatibility reasons.
195+
*/
196+
static get apiEndpoint() {
197+
return 'vision.googleapis.com';
198+
}
199+
188200
/**
189201
* The port for this API service.
190202
*/

packages/google-cloud-vision/src/v1p3beta1/product_search_client.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,18 @@ class ProductSearchClient {
7373
* API remote host.
7474
*/
7575
constructor(opts) {
76+
opts = opts || {};
7677
this._descriptors = {};
7778

79+
const servicePath =
80+
opts.servicePath || opts.apiEndpoint || this.constructor.servicePath;
81+
7882
// Ensure that options include the service address and port.
7983
opts = Object.assign(
8084
{
8185
clientConfig: {},
8286
port: this.constructor.port,
83-
servicePath: this.constructor.servicePath,
87+
servicePath,
8488
},
8589
opts
8690
);
@@ -257,6 +261,14 @@ class ProductSearchClient {
257261
return 'vision.googleapis.com';
258262
}
259263

264+
/**
265+
* The DNS address for this API service - same as servicePath(),
266+
* exists for compatibility reasons.
267+
*/
268+
static get apiEndpoint() {
269+
return 'vision.googleapis.com';
270+
}
271+
260272
/**
261273
* The port for this API service.
262274
*/

packages/google-cloud-vision/src/v1p4beta1/image_annotator_client.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,18 @@ class ImageAnnotatorClient {
5858
* API remote host.
5959
*/
6060
constructor(opts) {
61+
opts = opts || {};
6162
this._descriptors = {};
6263

64+
const servicePath =
65+
opts.servicePath || opts.apiEndpoint || this.constructor.servicePath;
66+
6367
// Ensure that options include the service address and port.
6468
opts = Object.assign(
6569
{
6670
clientConfig: {},
6771
port: this.constructor.port,
68-
servicePath: this.constructor.servicePath,
72+
servicePath,
6973
},
7074
opts
7175
);
@@ -202,6 +206,14 @@ class ImageAnnotatorClient {
202206
return 'vision.googleapis.com';
203207
}
204208

209+
/**
210+
* The DNS address for this API service - same as servicePath(),
211+
* exists for compatibility reasons.
212+
*/
213+
static get apiEndpoint() {
214+
return 'vision.googleapis.com';
215+
}
216+
205217
/**
206218
* The port for this API service.
207219
*/

packages/google-cloud-vision/src/v1p4beta1/product_search_client.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,18 @@ class ProductSearchClient {
7373
* API remote host.
7474
*/
7575
constructor(opts) {
76+
opts = opts || {};
7677
this._descriptors = {};
7778

79+
const servicePath =
80+
opts.servicePath || opts.apiEndpoint || this.constructor.servicePath;
81+
7882
// Ensure that options include the service address and port.
7983
opts = Object.assign(
8084
{
8185
clientConfig: {},
8286
port: this.constructor.port,
83-
servicePath: this.constructor.servicePath,
87+
servicePath,
8488
},
8589
opts
8690
);
@@ -257,6 +261,14 @@ class ProductSearchClient {
257261
return 'vision.googleapis.com';
258262
}
259263

264+
/**
265+
* The DNS address for this API service - same as servicePath(),
266+
* exists for compatibility reasons.
267+
*/
268+
static get apiEndpoint() {
269+
return 'vision.googleapis.com';
270+
}
271+
260272
/**
261273
* The port for this API service.
262274
*/

packages/google-cloud-vision/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-28T23:46:31.467800Z",
2+
"updateTime": "2019-06-05T14:31:18.354995Z",
33
"sources": [
44
{
55
"generator": {
66
"name": "artman",
7-
"version": "0.21.0",
8-
"dockerImage": "googleapis/artman@sha256:28d4271586772b275cd3bc95cb46bd227a24d3c9048de45dccdb7f3afb0bfba9"
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": "8f6588f68e1f3fc2f6cbb47d12565f9b81926d42",
16-
"internalRef": "250373427"
15+
"sha": "47c142a7cecc6efc9f6f8af804b8be55392b795b",
16+
"internalRef": "251635729"
1717
}
1818
},
1919
{

packages/google-cloud-vision/test/gapic-v1.js

Lines changed: 42 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('ImageAnnotatorClient', () => {
26+
it('has servicePath', () => {
27+
const servicePath = visionModule.v1.ImageAnnotatorClient.servicePath;
28+
assert(servicePath);
29+
});
30+
31+
it('has apiEndpoint', () => {
32+
const apiEndpoint = visionModule.v1.ImageAnnotatorClient.apiEndpoint;
33+
assert(apiEndpoint);
34+
});
35+
36+
it('has port', () => {
37+
const port = visionModule.v1.ImageAnnotatorClient.port;
38+
assert(port);
39+
assert(typeof port === 'number');
40+
});
41+
42+
it('should create a client with no options', () => {
43+
const client = new visionModule.v1.ImageAnnotatorClient();
44+
assert(client);
45+
});
46+
2647
describe('batchAnnotateImages', () => {
2748
it('invokes batchAnnotateImages without error', done => {
2849
const client = new visionModule.v1.ImageAnnotatorClient({
@@ -318,6 +339,27 @@ describe('ImageAnnotatorClient', () => {
318339
});
319340
});
320341
describe('ProductSearchClient', () => {
342+
it('has servicePath', () => {
343+
const servicePath = visionModule.v1.ProductSearchClient.servicePath;
344+
assert(servicePath);
345+
});
346+
347+
it('has apiEndpoint', () => {
348+
const apiEndpoint = visionModule.v1.ProductSearchClient.apiEndpoint;
349+
assert(apiEndpoint);
350+
});
351+
352+
it('has port', () => {
353+
const port = visionModule.v1.ProductSearchClient.port;
354+
assert(port);
355+
assert(typeof port === 'number');
356+
});
357+
358+
it('should create a client with no options', () => {
359+
const client = new visionModule.v1.ProductSearchClient();
360+
assert(client);
361+
});
362+
321363
describe('createProductSet', () => {
322364
it('invokes createProductSet without error', done => {
323365
const client = new visionModule.v1.ProductSearchClient({

0 commit comments

Comments
 (0)