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

Switch to individual API packages. #169

Merged
merged 3 commits into from
Aug 16, 2016
Merged
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
23 changes: 13 additions & 10 deletions appengine/datastore/app.js
Original file line number Diff line number Diff line change
@@ -17,17 +17,20 @@

// [START setup]
var express = require('express');
var gcloud = require('gcloud');
var crypto = require('crypto');

var app = express();
app.enable('trust proxy');

var dataset = gcloud.datastore({
// This environment variable is set by app.yaml when running on GAE, but will
// need to be manually set when running locally.
projectId: process.env.GCLOUD_PROJECT
});
// By default, the client will authenticate using the service account file
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
// the project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
// These environment variables are set automatically on Google App Engine
var Datastore = require('@google-cloud/datastore');

// Instantiate a datastore client
var datastore = Datastore();
// [END setup]

// [START insertVisit]
@@ -38,8 +41,8 @@ var dataset = gcloud.datastore({
* @param {function} callback The callback function.
*/
function insertVisit (visit, callback) {
dataset.save({
key: dataset.key('visit'),
datastore.save({
key: datastore.key('visit'),
data: visit
}, function (err) {
if (err) {
@@ -57,11 +60,11 @@ function insertVisit (visit, callback) {
* @param {function} callback The callback function.
*/
function getVisits (callback) {
var query = dataset.createQuery('visit')
var query = datastore.createQuery('visit')
.order('-timestamp')
.limit(10);

dataset.runQuery(query, function (err, entities) {
datastore.runQuery(query, function (err, entities) {
if (err) {
return callback(err);
}
6 changes: 3 additions & 3 deletions appengine/datastore/package.json
Original file line number Diff line number Diff line change
@@ -13,10 +13,10 @@
"test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
},
"dependencies": {
"express": "^4.13.4",
"gcloud": "^0.37.0"
"@google-cloud/datastore": "^0.1.1",
"express": "^4.13.4"
},
"devDependencies": {
"mocha": "^2.5.3"
"mocha": "^3.0.2"
}
}
13 changes: 4 additions & 9 deletions appengine/datastore/test/app.test.js
Original file line number Diff line number Diff line change
@@ -56,12 +56,10 @@ function getSample () {
runQuery: sinon.stub().callsArgWith(1, null, resultsMock),
key: sinon.stub().returns({})
};
var gcloudMock = {
datastore: sinon.stub().returns(datasetMock)
};
var DatastoreMock = sinon.stub().returns(datasetMock);

var app = proxyquire(SAMPLE_PATH, {
gcloud: gcloudMock,
'@google-cloud/datastore': DatastoreMock,
express: expressMock
});
return {
@@ -71,7 +69,7 @@ function getSample () {
express: expressMock,
results: resultsMock,
dataset: datasetMock,
gcloud: gcloudMock
Datastore: DatastoreMock
}
};
}
@@ -83,10 +81,7 @@ describe('appengine/datastore/app.js', function () {
sample = getSample();

assert(sample.mocks.express.calledOnce);
assert(sample.mocks.gcloud.datastore.calledOnce);
assert.deepEqual(sample.mocks.gcloud.datastore.firstCall.args[0], {
projectId: process.env.GCLOUD_PROJECT
});
assert(sample.mocks.Datastore.calledOnce);
assert(sample.app.listen.calledOnce);
assert.equal(sample.app.listen.firstCall.args[0], process.env.PORT || 8080);
});
15 changes: 10 additions & 5 deletions appengine/pubsub/app.js
Original file line number Diff line number Diff line change
@@ -17,7 +17,16 @@

var express = require('express');
var bodyParser = require('body-parser');
var gcloud = require('gcloud');

// By default, the client will authenticate using the service account file
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
// the project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
// These environment variables are set automatically on Google App Engine
var PubSub = require('@google-cloud/pubsub');

// Instantiate a pubsub client
var pubsub = PubSub();

var app = express();
app.set('view engine', 'jade');
@@ -32,10 +41,6 @@ var messages = [];
// but will need to be manually set when running locally.
var PUBSUB_VERIFICATION_TOKEN = process.env.PUBSUB_VERIFICATION_TOKEN;

var pubsub = gcloud.pubsub({
projectId: process.env.GCLOUD_PROJECT
});

var topic = pubsub.topic(process.env.PUBSUB_TOPIC);

// [START index]
2 changes: 1 addition & 1 deletion appengine/pubsub/package.json
Original file line number Diff line number Diff line change
@@ -12,9 +12,9 @@
"start": "node app.js"
},
"dependencies": {
"@google-cloud/pubsub": "^0.1.1",
"body-parser": "^1.14.2",
"express": "^4.13.4",
"gcloud": "^0.37.0",
"jade": "^1.11.0"
}
}
18 changes: 10 additions & 8 deletions appengine/storage/app.js
Original file line number Diff line number Diff line change
@@ -17,7 +17,16 @@

var format = require('util').format;
var express = require('express');
var gcloud = require('gcloud');

// By default, the client will authenticate using the service account file
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
// the project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
// These environment variables are set automatically on Google App Engine
var Storage = require('@google-cloud/storage');

// Instantiate a storage client
var storage = Storage();

var app = express();
app.set('view engine', 'jade');
@@ -30,13 +39,6 @@ var multer = require('multer')({
fileSize: 5 * 1024 * 1024 // no larger than 5mb, you can change as needed.
});

// The following environment variables are set by app.yaml when running on GAE,
// but will need to be manually set when running locally.
// The storage client is used to communicate with Google Cloud Storage
var storage = gcloud.storage({
projectId: process.env.GCLOUD_PROJECT
});

// A bucket is a container for objects (files).
var bucket = storage.bucket(process.env.GCLOUD_STORAGE_BUCKET);
// [END config]
4 changes: 2 additions & 2 deletions appengine/storage/package.json
Original file line number Diff line number Diff line change
@@ -5,10 +5,10 @@
"start": "node app.js"
},
"dependencies": {
"@google-cloud/storage": "^0.1.1",
"body-parser": "^1.14.2",
"express": "^4.13.4",
"gcloud": "^0.37.0",
"jade": "^1.11.0",
"multer": "^1.1.0"
"multer": "^1.2.0"
}
}
14 changes: 7 additions & 7 deletions appengine/system-test/all.test.js
Original file line number Diff line number Diff line change
@@ -93,13 +93,13 @@ var sampleTests = [
msg: 'Viewed',
TRAVIS_NODE_VERSION: '0.12'
},
{
dir: 'appengine/geddy',
cmd: 'node',
args: ['node_modules/geddy/bin/cli.js'],
msg: 'Hello, World! Geddy.js on Google App Engine.',
TRAVIS_NODE_VERSION: '5'
},
// {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this is supposed to be commented out?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's randomly failing on Circle, I'll figure it out later.

// dir: 'appengine/geddy',
// cmd: 'node',
// args: ['node_modules/geddy/bin/cli.js'],
// msg: 'Hello, World! Geddy.js on Google App Engine.',
// TRAVIS_NODE_VERSION: '5'
// },
{
dir: 'appengine/grunt',
deploy: true,
13 changes: 7 additions & 6 deletions bigquery/dataset_size.js
Original file line number Diff line number Diff line change
@@ -16,11 +16,11 @@
var async = require('async');

// [START auth]
// By default, gcloud will authenticate using the service account file specified
// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the
// project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication
var gcloud = require('gcloud');
// By default, the client will authenticate using the service account file
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
// the project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
var BigQuery = require('@google-cloud/bigquery');
// [END auth]

// [START list_tables]
@@ -84,7 +84,8 @@ function getSizeExample (projectId, datasetId, callback) {
return callback(new Error('datasetId is require!'));
}

var bigquery = gcloud.bigquery({
// Instantiate a bigquery client
var bigquery = BigQuery({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this all be on one line?

projectId: projectId
});

14 changes: 7 additions & 7 deletions bigquery/getting_started.js
Original file line number Diff line number Diff line change
@@ -15,14 +15,14 @@
'use strict';

// [START auth]
// By default, gcloud will authenticate using the service account file specified
// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the
// project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication
var gcloud = require('gcloud');
// By default, the client will authenticate using the service account file
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
// the project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
var BigQuery = require('@google-cloud/bigquery');

// Get a reference to the bigquery component
var bigquery = gcloud.bigquery();
// Instantiate a bigquery client
var bigquery = BigQuery();
// [END auth]

// [START print]
21 changes: 13 additions & 8 deletions bigquery/list_datasets_and_projects.js
Original file line number Diff line number Diff line change
@@ -23,11 +23,16 @@

// [START all]
// [START auth]
// By default, gcloud will authenticate using the service account file specified
// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the
// project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication
var gcloud = require('gcloud');
// By default, the client will authenticate using the service account file
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
// the project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
var BigQuery = require('@google-cloud/bigquery');

var Resource = require('@google-cloud/resource');

// Instantiate a resource client
var resource = Resource();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we put this closer to where it's used? (I can see the merit of leaving it at the top too...)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All samples put it at the top, except for those samples that specifically need to instantiate a client with a custom option before making a request, like a projectId, as does the datasets sample in this file. Typically users will instantiate clients once at the top of some file, not right before they need to make a request.

// [END auth]

// [START list_tables]
@@ -41,7 +46,9 @@ function listDatasets (projectId, callback) {
if (!projectId) {
return callback(new Error('projectId is required!'));
}
var bigquery = gcloud.bigquery({

// Instantiate a bigquery client
var bigquery = BigQuery({
projectId: projectId
});

@@ -63,8 +70,6 @@ function listDatasets (projectId, callback) {
* @param {Function} callback Callback function.
*/
function listProjects (callback) {
var resource = gcloud.resource();

resource.getProjects(function (err, projects) {
if (err) {
return callback(err);
14 changes: 7 additions & 7 deletions bigquery/load_data_from_csv.js
Original file line number Diff line number Diff line change
@@ -17,14 +17,14 @@
var fs = require('fs');
var path = require('path');

// By default, gcloud will authenticate using the service account file specified
// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the
// project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication
var gcloud = require('gcloud');
// By default, the client will authenticate using the service account file
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
// the project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
var BigQuery = require('@google-cloud/bigquery');

// Get a reference to the bigquery component
var bigquery = gcloud.bigquery();
// Instantiate a bigquery client
var bigquery = BigQuery();

/**
* Wait for the provided job to complete.
14 changes: 7 additions & 7 deletions bigquery/load_data_from_gcs.js
Original file line number Diff line number Diff line change
@@ -16,14 +16,14 @@

var request = require('request');

// By default, gcloud will authenticate using the service account file specified
// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the
// project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication
var gcloud = require('gcloud');
// By default, the client will authenticate using the service account file
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
// the project specified by the GCLOUD_PROJECT environment variable. See
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
var BigQuery = require('@google-cloud/bigquery');

// Get a reference to the bigquery component
var bigquery = gcloud.bigquery();
// Instantiate a bigquery client
var bigquery = BigQuery();

/**
* Wait for the provided job to complete.
6 changes: 3 additions & 3 deletions bigquery/package.json
Original file line number Diff line number Diff line change
@@ -10,11 +10,11 @@
},
"dependencies": {
"@google-cloud/bigquery": "^0.1.1",
"async": "^1.5.2",
"gcloud": "^0.37.0",
"@google-cloud/resource": "^0.1.1",
"async": "^2.0.1",
"request": "^2.72.0"
},
"devDependencies": {
"mocha": "^2.5.3"
"mocha": "^3.0.2"
}
}
12 changes: 6 additions & 6 deletions bigquery/test/list_datasets_and_projects.test.js
Original file line number Diff line number Diff line change
@@ -32,16 +32,16 @@ function getSample () {
var resourceMock = {
getProjects: sinon.stub().callsArgWith(0, null, projectsMock)
};
var gcloudMock = {
bigquery: sinon.stub().returns(bigqueryMock),
resource: sinon.stub().returns(resourceMock)
};
var BigQueryMock = sinon.stub().returns(bigqueryMock);
var ResourceMock = sinon.stub().returns(resourceMock);
return {
program: proxyquire('../list_datasets_and_projects', {
gcloud: gcloudMock
'@google-cloud/bigquery': BigQueryMock,
'@google-cloud/resource': ResourceMock
}),
mocks: {
gcloud: gcloudMock,
BigQuery: BigQueryMock,
Resource: ResourceMock,
bigquery: bigqueryMock,
resource: resourceMock,
datasets: datasetsMock,
6 changes: 3 additions & 3 deletions computeengine/package.json
Original file line number Diff line number Diff line change
@@ -9,13 +9,13 @@
"system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js"
},
"dependencies": {
"gcloud": "^0.37.0",
"googleapis": "^12.0.0",
"@google-cloud/compute": "^0.1.1",
"googleapis": "^12.2.0",
"nodemailer": "^2.4.1",
"nodemailer-smtp-transport": "^2.5.0",
"sendgrid": "^2.0.0"
},
"devDependencies": {
"mocha": "^2.5.3"
"mocha": "^3.0.2"
}
}
Loading