Skip to content

Commit ef7495a

Browse files
jmdobryAce Nassri
authored and
Ace Nassri
committed
Change quickstart style. (#221)
* Change quickstart style. * Fix test.
1 parent ff7bda4 commit ef7495a

File tree

7 files changed

+94
-32
lines changed

7 files changed

+94
-32
lines changed

bigquery/quickstart.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,22 @@
1414
'use strict';
1515

1616
// [START bigquery_quickstart]
17-
// Imports and instantiates the Google Cloud client library
18-
const bigquery = require('@google-cloud/bigquery')({
19-
projectId: 'YOUR_PROJECT_ID'
17+
// Imports the Google Cloud client library
18+
const BigQuery = require('@google-cloud/bigquery');
19+
20+
// Your Google Cloud Platform project ID
21+
const projectId = 'YOUR_PROJECT_ID';
22+
23+
// Instantiates a client
24+
const bigqueryClient = BigQuery({
25+
projectId: projectId
2026
});
2127

22-
// Creates a new dataset
23-
bigquery.createDataset('my_new_dataset', (err, dataset) => {
28+
// The name for the new dataset
29+
const datasetName = 'my_new_dataset';
30+
31+
// Creates the new dataset
32+
bigqueryClient.createDataset(datasetName, (err, dataset) => {
2433
if (!err) {
2534
// The dataset was created successfully
2635
}

datastore/quickstart.js

+17-6
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,26 @@
1414
'use strict';
1515

1616
// [START datastore_quickstart]
17-
// Imports and instantiates the Google Cloud client library
18-
const datastore = require('@google-cloud/datastore')({
19-
projectId: 'YOUR_PROJECT_ID'
17+
// Imports the Google Cloud client library
18+
const Datastore = require('@google-cloud/datastore');
19+
20+
// Your Google Cloud Platform project ID
21+
const projectId = 'YOUR_PROJECT_ID';
22+
23+
// Instantiates a client
24+
const datastoreClient = Datastore({
25+
projectId: projectId
2026
});
2127

22-
const taskKey = datastore.key(['Task', 1234]);
28+
// The kind of the entity to retrieve
29+
const kind = 'Task';
30+
// The id of the entity to retrieve
31+
const id = 1234567890;
32+
// The Datastore key for the entity
33+
const taskKey = datastoreClient.key([kind, id]);
2334

24-
// Retrieves an entity
25-
datastore.get(taskKey, (err, entity) => {
35+
// Retrieves the entity
36+
datastoreClient.get(taskKey, (err, entity) => {
2637
if (!err) {
2738
// The entity was retrieved successfully
2839
}

datastore/test/quickstart.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe(`datastore:quickstart`, () => {
2020

2121
before(() => {
2222
datastoreMock = {
23-
get: sinon.stub().yields(null, { key: 1234 }),
23+
get: sinon.stub().yields(null, { key: 1234567890 }),
2424
key: sinon.stub.returns(`task/1234`)
2525
};
2626
DatastoreMock = sinon.stub().returns(datastoreMock);
@@ -34,6 +34,6 @@ describe(`datastore:quickstart`, () => {
3434
assert.equal(DatastoreMock.calledOnce, true);
3535
assert.deepEqual(DatastoreMock.firstCall.args, [{ projectId: 'YOUR_PROJECT_ID' }]);
3636
assert.equal(datastoreMock.get.calledOnce, true);
37-
assert.deepEqual(datastoreMock.get.firstCall.args.slice(0, -1), [datastoreMock.key(['Task', 1234])]);
37+
assert.deepEqual(datastoreMock.get.firstCall.args.slice(0, -1), [datastoreMock.key(['Task', 1234567890])]);
3838
});
3939
});

logging/quickstart.js

+18-5
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,28 @@
1414
'use strict';
1515

1616
// [START logging_quickstart]
17-
// Imports and instantiates the Google Cloud client library
18-
const logging = require('@google-cloud/logging')({
19-
projectId: 'YOUR_PROJECT_ID'
17+
// Imports the Google Cloud client library
18+
const Logging = require('@google-cloud/logging');
19+
20+
// Your Google Cloud Platform project ID
21+
const projectId = 'YOUR_PROJECT_ID';
22+
23+
// Instantiates a client
24+
const loggingClient = Logging({
25+
projectId: projectId
2026
});
2127

28+
// The name of the log to write to
29+
const logName = 'my-log';
2230
// Selects the log to write to
23-
const log = logging.log('my-log');
31+
const log = loggingClient.log(logName);
32+
33+
// The data to write to the log
34+
const text = 'Hello, world!';
35+
// The resource associated with the data
36+
const resource = { type: 'global' };
2437
// Prepares a log entry
25-
const entry = log.entry({ type: 'global' }, 'Hello, world!');
38+
const entry = log.entry(resource, text);
2639

2740
// Writes the log entry
2841
log.write(entry, (err) => {

pubsub/quickstart.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,22 @@
1414
'use strict';
1515

1616
// [START pubsub_quickstart]
17-
// Imports and instantiates the Google Cloud client library
18-
const pubsub = require('@google-cloud/pubsub')({
19-
projectId: 'YOUR_PROJECT_ID'
17+
// Imports the Google Cloud client library
18+
const PubSub = require('@google-cloud/pubsub');
19+
20+
// Your Google Cloud Platform project ID
21+
const projectId = 'YOUR_PROJECT_ID';
22+
23+
// Instantiates a client
24+
const pubsubClient = PubSub({
25+
projectId: projectId
2026
});
2127

22-
// Creates a new topic
23-
pubsub.createTopic('my-new-topic', (err, topic) => {
28+
// The name for the new topic
29+
const topicName = 'my-new-topic';
30+
31+
// Creates the new topic
32+
pubsubClient.createTopic(topicName, (err, topic) => {
2433
if (!err) {
2534
// The topic was created successfully
2635
}

storage/quickstart.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,22 @@
1414
'use strict';
1515

1616
// [START storage_quickstart]
17-
// Imports and instantiates the Google Cloud client library
18-
const storage = require('@google-cloud/storage')({
19-
projectId: 'YOUR_PROJECT_ID'
17+
// Imports the Google Cloud client library
18+
const Storage = require('@google-cloud/storage');
19+
20+
// Your Google Cloud Platform project ID
21+
const projectId = 'YOUR_PROJECT_ID';
22+
23+
// Instantiates a client
24+
const storageClient = Storage({
25+
projectId: projectId
2026
});
2127

22-
// Creates a new bucket
23-
storage.createBucket('my-new-bucket', (err, bucket) => {
28+
// The name for the new bucket
29+
const bucketName = 'my-new-bucket';
30+
31+
// Creates the new bucket
32+
storageClient.createBucket(bucketName, (err, bucket) => {
2433
if (!err) {
2534
// The bucket was created successfully
2635
}

translate/quickstart.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,24 @@
1414
'use strict';
1515

1616
// [START translate_quickstart]
17-
// Imports and instantiates the Google Cloud client library
18-
const translate = require('@google-cloud/translate')({
19-
key: 'YOUR_API_KEY'
17+
// Imports the Google Cloud client library
18+
const Translate = require('@google-cloud/translate');
19+
20+
// Your Translate API key
21+
const apiKey = 'YOUR_API_KEY';
22+
23+
// Instantiates a client
24+
const translateClient = Translate({
25+
key: apiKey
2026
});
2127

28+
// The text to translate
29+
const text = 'Hello, world!';
30+
// The target language
31+
const target = 'ru';
32+
2233
// Translates some text into Russian
23-
translate.translate('Hello, world!', 'ru', (err, translation) => {
34+
translateClient.translate(text, target, (err, translation) => {
2435
if (!err) {
2536
// The text was translated successfully
2637
}

0 commit comments

Comments
 (0)