|
| 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 | +}); |
0 commit comments