Skip to content

Commit

Permalink
docs(samples): modernize the samples, tests, and README (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored May 2, 2019
1 parent 0dbdbaa commit 7a121eb
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 109 deletions.
16 changes: 0 additions & 16 deletions packages/google-cloud-dns/.cloud-repo-tools.json

This file was deleted.

1 change: 1 addition & 0 deletions packages/google-cloud-dns/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ system-test/*key.json
*.lock
package-lock.json
build/
__pycache__
13 changes: 13 additions & 0 deletions packages/google-cloud-dns/.repo-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "dns",
"name_pretty": "Cloud DNS",
"product_documentation": "https://cloud.google.com/dns",
"client_documentation": "https://cloud.google.com/nodejs/docs/reference/dns/latest/",
"issue_tracker": "https://issuetracker.google.com/savedsearches/559772",
"release_level": "alpha",
"language": "nodejs",
"repo": "googleapis/nodejs-dns",
"distribution_name": "@google-cloud/dns",
"api_id": "dns.googleapis.com",
"requires_billing": true
}
89 changes: 43 additions & 46 deletions packages/google-cloud-dns/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
[//]: # "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 DNS: Node.js Client](https://github.com/googleapis/nodejs-dns)
# [Cloud DNS: Node.js Client](https://github.com/googleapis/nodejs-dns)

[![release level](https://img.shields.io/badge/release%20level-alpha-orange.svg?style&#x3D;flat)](https://cloud.google.com/terms/launch-stages)
[![release level](https://img.shields.io/badge/release%20level-alpha-orange.svg?style=flat)](https://cloud.google.com/terms/launch-stages)
[![npm version](https://img.shields.io/npm/v/@google-cloud/dns.svg)](https://www.npmjs.org/package/@google-cloud/dns)
[![codecov](https://img.shields.io/codecov/c/github/googleapis/nodejs-dns/master.svg?style=flat)](https://codecov.io/gh/googleapis/nodejs-dns)

> Node.js idiomatic client for [Cloud DNS][product-docs].

[Cloud DNS](https://cloud.google.com/dns/docs/) allows you to publish your domain names using Google&#x27;s infrastructure for production-quality, high-volume DNS services. Google&#x27;s global network of anycast name servers provide reliable, low-latency authoritative name lookups for your domains from anywhere in the world.


Cloud DNS Client Library for Node.js


* [Cloud DNS Node.js Client API Reference][client-docs]
* [github.com/googleapis/nodejs-dns](https://github.com/googleapis/nodejs-dns)
* [Cloud DNS Documentation][product-docs]
* [github.com/googleapis/nodejs-dns](https://github.com/googleapis/nodejs-dns)

Read more about the client libraries for Cloud APIs, including the older
Google APIs Client Libraries, in [Client Libraries Explained][explained].
Expand All @@ -22,6 +25,7 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained].

**Table of contents:**


* [Quickstart](#quickstart)
* [Before you begin](#before-you-begin)
* [Installing the client library](#installing-the-client-library)
Expand All @@ -35,66 +39,51 @@ Google APIs Client Libraries, in [Client Libraries Explained][explained].

### Before you begin

1. Select or create a Cloud Platform project.

[Go to the projects page][projects]

1. Enable billing for your project.

[Enable billing][billing]

1. Enable the Google Cloud DNS API.

[Enable the API][enable_api]

1. [Select or create a Cloud Platform project][projects].
1. [Enable billing for your project][billing].
1. [Enable the Cloud DNS API][enable_api].
1. [Set up authentication with a service account][auth] so you can access the
API from your local workstation.

[projects]: https://console.cloud.google.com/project
[billing]: https://support.google.com/cloud/answer/6293499#enable-billing
[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=dns.googleapis.com
[auth]: https://cloud.google.com/docs/authentication/getting-started

### Installing the client library

npm install --save @google-cloud/dns
```bash
npm install @google-cloud/dns
```


### Using the client library

```javascript
// Imports the Google Cloud client library
const {DNS} = require('@google-cloud/dns');
// Imports the Google Cloud client library
const {DNS} = require('@google-cloud/dns');

// Your Google Cloud Platform project ID
const projectId = 'YOUR_PROJECT_ID';

// Creates a client
const dns = new DNS({
projectId: projectId,
});

// Lists all zones in the current project
dns
.getZones()
.then(results => {
const zones = results[0];
// Creates a client
const dns = new DNS();

async function quickstart() {
// Lists all zones in the current project
const [zones] = await dns.getZones();
console.log('Zones:');
zones.forEach(zone => console.log(zone.name));
})
.catch(err => {
console.error('ERROR:', err);
});
}
quickstart();

```



## Samples

Samples are in the [`samples/`](https://github.com/googleapis/nodejs-dns/tree/master/samples) directory. The samples' `README.md`
has instructions for running the samples.

| Sample | Source Code | Try it |
| --------------------------- | --------------------------------- | ------ |
| Zones | [source code](https://github.com/googleapis/nodejs-dns/blob/master/samples/zones.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dns&page=editor&open_in_editor=samples/zones.js,samples/README.md) |
| List Zones | [source code](https://github.com/googleapis/nodejs-dns/blob/master/samples/listZones.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-dns&page=editor&open_in_editor=samples/listZones.js,samples/README.md) |
| Quickstart | [source code](https://github.com/googleapis/nodejs-dns/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-dns&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) |



The [Cloud DNS Node.js Client API Reference][client-docs] documentation
also contains samples.
Expand All @@ -103,10 +92,15 @@ also contains samples.

This library follows [Semantic Versioning](http://semver.org/).




This library is considered to be in **alpha**. This means it is still a
work-in-progress and under active development. Any release is subject to
backwards-incompatible changes at any time.



More Information: [Google Cloud Platform Launch Stages][launch_stages]

[launch_stages]: https://cloud.google.com/terms/launch-stages
Expand All @@ -122,6 +116,9 @@ Apache Version 2.0
See [LICENSE](https://github.com/googleapis/nodejs-dns/blob/master/LICENSE)

[client-docs]: https://cloud.google.com/nodejs/docs/reference/dns/latest/
[product-docs]: https://cloud.google.com/dns/docs/
[shell_img]: //gstatic.com/cloudssh/images/open-btn.png

[product-docs]: https://cloud.google.com/dns
[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png
[projects]: https://console.cloud.google.com/project
[billing]: https://support.google.com/cloud/answer/6293499#enable-billing
[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=dns.googleapis.com
[auth]: https://cloud.google.com/docs/authentication/getting-started
2 changes: 0 additions & 2 deletions packages/google-cloud-dns/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
],
"scripts": {
"docs": "jsdoc -c .jsdoc.js",
"generate-scaffolding": "repo-tools generate all && repo-tools generate lib_samples_readme -l samples/ --config ../.cloud-repo-tools.json",
"lint": "gts check && eslint '**/*.js'",
"test": "nyc mocha build/test",
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
Expand All @@ -52,7 +51,6 @@
"string-format-obj": "^1.1.1"
},
"devDependencies": {
"@google-cloud/nodejs-repo-tools": "^3.0.0",
"@types/lodash.groupby": "^4.6.4",
"@types/mocha": "^5.2.5",
"@types/node": "^10.9.4",
Expand Down
1 change: 0 additions & 1 deletion packages/google-cloud-dns/samples/.eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
rules:
no-console: off
node/no-missing-require: off
63 changes: 39 additions & 24 deletions packages/google-cloud-dns/samples/README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,66 @@
[//]: # "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 DNS: Node.js Samples
# [Cloud DNS: Node.js Samples](https://github.com/googleapis/nodejs-dns)

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

[Cloud DNS](https://cloud.google.com/dns/docs/) allows you to publish your domain names using Google&#x27;s infrastructure for production-quality, high-volume DNS services. Google&#x27;s global network of anycast name servers provide reliable, low-latency authoritative name lookups for your domains from anywhere in the world.


## Table of Contents

* [Before you begin](#before-you-begin)
* [Samples](#samples)
* [Zones](#zones)
* [List Zones](#list-zones)
* [Quickstart](#quickstart)

## Before you begin

Before running the samples, make sure you've followed the steps in the
[Before you begin section](../README.md#before-you-begin) of the client
library's README.
Before running the samples, make sure you've followed the steps outlined in
[Using the client library](https://github.com/googleapis/nodejs-dns#using-the-client-library).

## Samples

### Zones

View the [source code][zones_0_code].

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

Lists all zones in the current project.

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

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

__Usage:__


`node listZones`


-----




### Quickstart

Fetches a list of all available zones.

View the [source code](https://github.com/googleapis/nodejs-dns/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-dns&page=editor&open_in_editor=samples/quickstart.js,samples/README.md)

__Usage:__

__Usage:__ `node zones.js --help`

```
zones.js <command>
`node quickstart`

Commands:
zones.js list Lists all zones in the current project.

Options:
--version Show version number [boolean]
--help Show help [boolean]

Examples:
node zones.js list Lists all zones in the current project.

For more information, see https://cloud.google.com/dns/docs
```

[zones_0_docs]: https://cloud.google.com/dns/docs
[zones_0_code]: zones.js

[shell_img]: //gstatic.com/cloudssh/images/open-btn.png
[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-dns&page=editor&open_in_editor=samples/README.md
[product-docs]: https://cloud.google.com/dns
6 changes: 2 additions & 4 deletions packages/google-cloud-dns/samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
"*.js"
],
"scripts": {
"test": "mocha system-test --timeout 600000"
"test": "mocha --timeout 600000"
},
"dependencies": {
"@google-cloud/dns": "^0.9.2",
"yargs": "^13.0.0"
"@google-cloud/dns": "^0.9.2"
},
"devDependencies": {
"chai": "^4.2.0",
"execa": "^1.0.0",
"mocha": "^6.0.0",
"uuid": "^3.3.0"
}
Expand Down
29 changes: 17 additions & 12 deletions packages/google-cloud-dns/samples/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,27 @@

'use strict';

// [START dns_quickstart]
async function quickstart(
projectId = 'YOUR_PROJECT_ID' // Your GCP project Id
) {
// sample-metadata:
// name: Quickstart
// description: Fetches a list of all available zones.
// usage: node quickstart

async function main() {
// [START dns_quickstart]
// Imports the Google Cloud client library
const {DNS} = require('@google-cloud/dns');

// Creates a client
const dns = new DNS({projectId});
const dns = new DNS();

// Lists all zones in the current project
const [zones] = await dns.getZones();
console.log('Zones:');
zones.forEach(zone => console.log(zone.name));
async function quickstart() {
// Lists all zones in the current project
const [zones] = await dns.getZones();
console.log('Zones:');
zones.forEach(zone => console.log(zone.name));
}
quickstart();
// [END dns_quickstart]
}
// [END dns_quickstart]

const args = process.argv.slice(2);
quickstart(...args).catch(console.error);
main();
3 changes: 2 additions & 1 deletion packages/google-cloud-dns/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ class DNS extends Service {
callback!(err, null, null, resp);
return;
}
const zones = arrify(resp.managedZones).map(zone => {
// tslint:disable-next-line no-any
const zones = arrify(resp.managedZones).map((zone: any) => {
const zoneInstance = this.zone(zone.name);
zoneInstance.metadata = zone;
return zoneInstance;
Expand Down
3 changes: 2 additions & 1 deletion packages/google-cloud-dns/src/zone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,8 @@ import(localPath: string, callback?: CreateChangeCallback): void|Promise<CreateC
const recordsToCreate: Record[] = [];
recordTypes.forEach(recordType => {
const recordTypeSet = arrify(parsedZonefile[recordType]);
recordTypeSet.forEach(record => {
// tslint:disable-next-line no-any
recordTypeSet.forEach((record: any) => {
record.ttl = record.ttl || defaultTTL;
recordsToCreate.push(Record.fromZoneRecord_(this, recordType, record));
});
Expand Down
4 changes: 2 additions & 2 deletions packages/google-cloud-dns/synth.metadata
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"updateTime": "2019-03-08T00:45:37.531320Z",
"updateTime": "2019-05-01T19:31:02.875460Z",
"sources": [
{
"template": {
"name": "node_library",
"origin": "synthtool.gcp",
"version": "2019.1.16"
"version": "2019.4.10"
}
}
]
Expand Down

0 comments on commit 7a121eb

Please sign in to comment.