Skip to content

Commit da8b213

Browse files
JustinBeckwithfhinkel
authored andcommitted
refactor: move createDataset sample to own file (GoogleCloudPlatform#1230)
1 parent 8d66bd4 commit da8b213

3 files changed

Lines changed: 53 additions & 34 deletions

File tree

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Copyright 2019, Google, LLC
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+
* http://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+
16+
'use strict';
17+
18+
function main(
19+
projectId = process.env.GCLOUD_PROJECT,
20+
cloudRegion = 'us-central1',
21+
datasetId
22+
) {
23+
// [START healthcare_create_dataset]
24+
const {google} = require('googleapis');
25+
const healthcare = google.healthcare('v1alpha2');
26+
27+
async function createDataset() {
28+
const auth = await google.auth.getClient({
29+
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
30+
});
31+
google.options({auth});
32+
33+
// TODO(developer): uncomment these lines before running the sample
34+
// const cloudRegion = 'us-central1';
35+
// const projectId = 'adjective-noun-123';
36+
// const datasetId = 'my-dataset';
37+
const parent = `projects/${projectId}/locations/${cloudRegion}`;
38+
const request = {parent, datasetId};
39+
40+
await healthcare.projects.locations.datasets.create(request);
41+
console.log(`Created dataset: ${datasetId}`);
42+
}
43+
44+
createDataset();
45+
// [END healthcare_create_dataset]
46+
}
47+
48+
// node createDataset.js <projectId> <cloudRegion> <datasetId>
49+
main(...process.argv.slice(2));

healthcare/datasets/datasets.js

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,6 @@
1717

1818
const {google} = require('googleapis');
1919

20-
// [START healthcare_create_dataset]
21-
function createDataset(client, projectId, cloudRegion, datasetId) {
22-
// Client retrieved in callback
23-
// getClient(serviceAccountJson, function(client) {...});
24-
// const cloudRegion = 'us-central1';
25-
// const projectId = 'adjective-noun-123';
26-
// const datasetId = 'my-dataset';
27-
const parentName = `projects/${projectId}/locations/${cloudRegion}`;
28-
29-
const request = {parent: parentName, datasetId: datasetId};
30-
31-
client.projects.locations.datasets
32-
.create(request)
33-
.then(() => {
34-
console.log(`Created dataset: ${datasetId}`);
35-
})
36-
.catch(err => {
37-
console.error(err);
38-
});
39-
}
40-
// [END healthcare_create_dataset]
41-
4220
// [START healthcare_delete_dataset]
4321
function deleteDataset(client, projectId, cloudRegion, datasetId) {
4422
// Client retrieved in callback
@@ -258,17 +236,6 @@ require(`yargs`) // eslint-disable-line
258236
type: 'string',
259237
},
260238
})
261-
.command(
262-
`createDataset <datasetId>`,
263-
`Creates a new health dataset.`,
264-
{},
265-
opts => {
266-
const cb = function(client) {
267-
createDataset(client, opts.projectId, opts.cloudRegion, opts.datasetId);
268-
};
269-
getClient(opts.apiKey, opts.serviceAccount, cb);
270-
}
271-
)
272239
.command(
273240
`deleteDataset <datasetId>`,
274241
`Deletes the specified health dataset and all data contained

healthcare/datasets/system-test/datasets.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ after(async () => {
3535
});
3636

3737
it('should create a dataset', async () => {
38-
const output = await tools.runAsync(`${cmd} createDataset ${datasetId}`, cwd);
38+
const output = await tools.runAsync(
39+
`$node createDataset.js ${datasetId}`,
40+
cwd
41+
);
3942
assert.strictEqual(output, `Created dataset: ${datasetId}`);
4043
});
4144

0 commit comments

Comments
 (0)