Skip to content

Commit c57c0bf

Browse files
authored
feat: added samples for api-endpoints (#259)
* Added samples for api-endpoints * Fixed license and function name * Fixed test case for setEndpoint and added file to linkinator until it lands
1 parent 98099ed commit c57c0bf

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

automl/beta/setEndpoint.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
async function setEndpoint(projectId) {
18+
// [START automl_set_endpoint]
19+
const automl = require('@google-cloud/automl').v1beta1;
20+
21+
// You must first create a dataset, using the `eu` endpoint, before you can
22+
// call other operations such as: list, get, import, delete, etc.
23+
const clientOptions = {apiEndpoint: 'eu-automl.googleapis.com'};
24+
25+
// Instantiates a client
26+
const client = new automl.AutoMlClient(clientOptions);
27+
28+
// A resource that represents Google Cloud Platform location.
29+
const projectLocation = client.locationPath(projectId, 'eu');
30+
// [END automl_set_endpoint]
31+
console.log(projectLocation);
32+
33+
// Grabs the list of datasets in a given project location.
34+
// Note: create a dataset in `eu` before calling `listDatasets`.
35+
const responses = await client.listDatasets({parent: projectLocation});
36+
37+
// Prints out each dataset.
38+
const datasets = responses[0];
39+
datasets.forEach(dataset => {
40+
console.log(dataset);
41+
});
42+
}
43+
44+
setEndpoint(...process.argv.slice(2)).catch(err => {
45+
console.error(err);
46+
process.exitCode = 1;
47+
});

automl/test/setEndpoint.test.js

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
const {assert} = require('chai');
18+
const cp = require('child_process');
19+
20+
const projectId = process.env.GCLOUD_PROJECT;
21+
22+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
23+
24+
describe('set endpoint for automl', () => {
25+
it('should list all datasets in `eu`', async () => {
26+
const stdout = execSync(`node beta/setEndpoint.js "${projectId}"`);
27+
assert.match(stdout, /do_not_delete_eu/);
28+
});
29+
});

0 commit comments

Comments
 (0)