Skip to content

Commit

Permalink
docs(samples): add a quickstart (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored and grayside committed Nov 8, 2022
1 parent 97e6604 commit f909d35
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 6 deletions.
46 changes: 46 additions & 0 deletions datalabeling/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[//]: # "This README.md file is auto-generated, all changes to this file will be lost."
[//]: # "To regenerate it, use `python -m synthtool`."
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>

# [Google Cloud Data Labeling: Node.js Samples](https://github.com/googleapis/nodejs-datalabeling)

[![Open in Cloud Shell][shell_img]][shell_link]



## Table of Contents

* [Before you begin](#before-you-begin)
* [Samples](#samples)
* [Get Datasets](#get-datasets)

## Before you begin

Before running the samples, make sure you've followed the steps outlined in
[Using the client library](https://github.com/googleapis/nodejs-datalabeling#using-the-client-library).

## Samples



### Get Datasets

Gets all available Datasets.

View the [source code](https://github.com/googleapis/nodejs-datalabeling/blob/master/samples/quickstart.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-datalabeling&page=editor&open_in_editor=samples/quickstart.js,samples/README.md)

__Usage:__


`node quickstart.js`






[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png
[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-datalabeling&page=editor&open_in_editor=samples/README.md
[product-docs]: https://cloud.google.com/data-labeling/docs/
8 changes: 6 additions & 2 deletions datalabeling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@
"node": ">=8"
},
"files": [
"*.js"
"*.js",
"!test/"
],
"scripts": {
"test": "mocha --timeout 600000"
},
"dependencies": {
"@google-cloud/datalabeling": "^1.3.2"
},
"devDependencies": {}
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^6.2.2"
}
}
24 changes: 24 additions & 0 deletions datalabeling/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,27 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

// sample-metadata:
// title: Get Datasets
// description: Gets all available Datasets.
// usage: node quickstart.js

function main() {
// [START datalabeling_quickstart]
const {DataLabelingServiceClient} = require('@google-cloud/datalabeling');
const client = new DataLabelingServiceClient();

async function quickstart() {
const projectId = await client.getProjectId();
const parent = client.projectPath(projectId);
const [result] = await client.listDatasets({parent});
console.log('Datasets:');
console.log(result);
}
quickstart();
// [END datalabeling_quickstart]
}
main(...process.argv.slice(2));
5 changes: 2 additions & 3 deletions datalabeling/test/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
rules:
node/no-unpublished-require: off
no-empty: off
env:
mocha: true
1 change: 0 additions & 1 deletion datalabeling/test/no-test.js

This file was deleted.

27 changes: 27 additions & 0 deletions datalabeling/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const {assert} = require('chai');
const {execSync} = require('child_process');

const exec = cmd => execSync(cmd, {encoding: 'utf8'});

describe('quickstart', () => {
it('should run the quickstart', () => {
const stdout = exec('node quickstart.js');
assert.include(stdout, 'Datasets:');
});
});

0 comments on commit f909d35

Please sign in to comment.