Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change quickstart style. #221

Merged
merged 2 commits into from
Sep 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions bigquery/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
23 changes: 17 additions & 6 deletions datastore/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions datastore/test/quickstart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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])]);
});
});
23 changes: 18 additions & 5 deletions logging/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
19 changes: 14 additions & 5 deletions pubsub/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
19 changes: 14 additions & 5 deletions storage/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
19 changes: 15 additions & 4 deletions translate/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down