From 45ddedebd95170f98879b77e7ec71b3bfaf9c6a7 Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Wed, 28 Sep 2016 16:43:29 -0700 Subject: [PATCH 1/2] Change quickstart style. --- bigquery/quickstart.js | 19 ++++++++++++++----- datastore/quickstart.js | 23 +++++++++++++++++------ logging/quickstart.js | 23 ++++++++++++++++++----- pubsub/quickstart.js | 19 ++++++++++++++----- storage/quickstart.js | 19 ++++++++++++++----- translate/quickstart.js | 19 +++++++++++++++---- 6 files changed, 92 insertions(+), 30 deletions(-) diff --git a/bigquery/quickstart.js b/bigquery/quickstart.js index dae5b0c60f..134cd803fb 100644 --- a/bigquery/quickstart.js +++ b/bigquery/quickstart.js @@ -14,13 +14,22 @@ 'use strict'; // [START bigquery_quickstart] -// Imports and instantiates the Google Cloud client library -const bigquery = require('@google-cloud/bigquery')({ - projectId: 'YOUR_PROJECT_ID' +// Imports the Google Cloud client library +const BigQuery = require('@google-cloud/bigquery'); + +// Your Google Cloud Platform project ID +const projectId = 'YOUR_PROJECT_ID'; + +// Instantiates a client +const bigqueryClient = BigQuery({ + projectId: projectId }); -// Creates a new dataset -bigquery.createDataset('my_new_dataset', (err, dataset) => { +// The name for the new dataset +const datasetName = 'my_new_dataset'; + +// Creates the new dataset +bigqueryClient.createDataset(datasetName, (err, dataset) => { if (!err) { // The dataset was created successfully } diff --git a/datastore/quickstart.js b/datastore/quickstart.js index 60a2c40c04..01a8cf2582 100644 --- a/datastore/quickstart.js +++ b/datastore/quickstart.js @@ -14,15 +14,26 @@ 'use strict'; // [START datastore_quickstart] -// Imports and instantiates the Google Cloud client library -const datastore = require('@google-cloud/datastore')({ - projectId: 'YOUR_PROJECT_ID' +// Imports the Google Cloud client library +const Datastore = require('@google-cloud/datastore'); + +// Your Google Cloud Platform project ID +const projectId = 'YOUR_PROJECT_ID'; + +// Instantiates a client +const datastoreClient = Datastore({ + projectId: projectId }); -const taskKey = datastore.key(['Task', 1234]); +// The kind of the entity to retrieve +const kind = 'Task'; +// The id of the entity to retrieve +const id = 1234567890; +// The Datastore key for the entity +const taskKey = datastoreClient.key([kind, id]); -// Retrieves an entity -datastore.get(taskKey, (err, entity) => { +// Retrieves the entity +datastoreClient.get(taskKey, (err, entity) => { if (!err) { // The entity was retrieved successfully } diff --git a/logging/quickstart.js b/logging/quickstart.js index 7bf1c8da79..435aa28c04 100644 --- a/logging/quickstart.js +++ b/logging/quickstart.js @@ -14,15 +14,28 @@ 'use strict'; // [START logging_quickstart] -// Imports and instantiates the Google Cloud client library -const logging = require('@google-cloud/logging')({ - projectId: 'YOUR_PROJECT_ID' +// Imports the Google Cloud client library +const Logging = require('@google-cloud/logging'); + +// Your Google Cloud Platform project ID +const projectId = 'YOUR_PROJECT_ID'; + +// Instantiates a client +const loggingClient = Logging({ + projectId: projectId }); +// The name of the log to write to +const logName = 'my-log'; // Selects the log to write to -const log = logging.log('my-log'); +const log = loggingClient.log(logName); + +// The data to write to the log +const text = 'Hello, world!'; +// The resource associated with the data +const resource = { type: 'global' }; // Prepares a log entry -const entry = log.entry({ type: 'global' }, 'Hello, world!'); +const entry = log.entry(resource, text); // Writes the log entry log.write(entry, (err) => { diff --git a/pubsub/quickstart.js b/pubsub/quickstart.js index d8f72ef489..0ba215fb2d 100644 --- a/pubsub/quickstart.js +++ b/pubsub/quickstart.js @@ -14,13 +14,22 @@ 'use strict'; // [START pubsub_quickstart] -// Imports and instantiates the Google Cloud client library -const pubsub = require('@google-cloud/pubsub')({ - projectId: 'YOUR_PROJECT_ID' +// Imports the Google Cloud client library +const PubSub = require('@google-cloud/pubsub'); + +// Your Google Cloud Platform project ID +const projectId = 'YOUR_PROJECT_ID'; + +// Instantiates a client +const pubsubClient = PubSub({ + projectId: projectId }); -// Creates a new topic -pubsub.createTopic('my-new-topic', (err, topic) => { +// The name for the new topic +const topicName = 'my-new-topic'; + +// Creates the new topic +pubsubClient.createTopic(topicName, (err, topic) => { if (!err) { // The topic was created successfully } diff --git a/storage/quickstart.js b/storage/quickstart.js index 89c0b662cb..8a6633a331 100644 --- a/storage/quickstart.js +++ b/storage/quickstart.js @@ -14,13 +14,22 @@ 'use strict'; // [START storage_quickstart] -// Imports and instantiates the Google Cloud client library -const storage = require('@google-cloud/storage')({ - projectId: 'YOUR_PROJECT_ID' +// Imports the Google Cloud client library +const Storage = require('@google-cloud/storage'); + +// Your Google Cloud Platform project ID +const projectId = 'YOUR_PROJECT_ID'; + +// Instantiates a client +const storageClient = Storage({ + projectId: projectId }); -// Creates a new bucket -storage.createBucket('my-new-bucket', (err, bucket) => { +// The name for the new bucket +const bucketName = 'my-new-bucket'; + +// Creates the new bucket +storageClient.createBucket(bucketName, (err, bucket) => { if (!err) { // The bucket was created successfully } diff --git a/translate/quickstart.js b/translate/quickstart.js index 59c34f5248..e3f49aedf6 100644 --- a/translate/quickstart.js +++ b/translate/quickstart.js @@ -14,13 +14,24 @@ 'use strict'; // [START translate_quickstart] -// Imports and instantiates the Google Cloud client library -const translate = require('@google-cloud/translate')({ - key: 'YOUR_API_KEY' +// Imports the Google Cloud client library +const Translate = require('@google-cloud/translate'); + +// Your Translate API key +const apiKey = 'YOUR_API_KEY'; + +// Instantiates a client +const translateClient = Translate({ + key: apiKey }); +// The text to translate +const text = 'Hello, world!'; +// The target language +const target = 'ru'; + // Translates some text into Russian -translate.translate('Hello, world!', 'ru', (err, translation) => { +translateClient.translate(text, target, (err, translation) => { if (!err) { // The text was translated successfully } From c37d40945f1ae8fc44f083cfb0dbc8e8abee0dc2 Mon Sep 17 00:00:00 2001 From: Jason Dobry Date: Wed, 28 Sep 2016 20:42:53 -0700 Subject: [PATCH 2/2] Fix test. --- datastore/test/quickstart.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datastore/test/quickstart.test.js b/datastore/test/quickstart.test.js index e793399f1b..a48e12caa1 100644 --- a/datastore/test/quickstart.test.js +++ b/datastore/test/quickstart.test.js @@ -20,7 +20,7 @@ describe(`datastore:quickstart`, () => { before(() => { datastoreMock = { - get: sinon.stub().yields(null, { key: 1234 }), + get: sinon.stub().yields(null, { key: 1234567890 }), key: sinon.stub.returns(`task/1234`) }; DatastoreMock = sinon.stub().returns(datastoreMock); @@ -34,6 +34,6 @@ describe(`datastore:quickstart`, () => { assert.equal(DatastoreMock.calledOnce, true); assert.deepEqual(DatastoreMock.firstCall.args, [{ projectId: 'YOUR_PROJECT_ID' }]); assert.equal(datastoreMock.get.calledOnce, true); - assert.deepEqual(datastoreMock.get.firstCall.args.slice(0, -1), [datastoreMock.key(['Task', 1234])]); + assert.deepEqual(datastoreMock.get.firstCall.args.slice(0, -1), [datastoreMock.key(['Task', 1234567890])]); }); });