Skip to content

Commit 808eb16

Browse files
authored
Switch to individual API packages. (#169)
* Switch to individual API packages. * Address comments * Address comments
1 parent b645a1b commit 808eb16

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+400
-384
lines changed

appengine/datastore/app.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@
1717

1818
// [START setup]
1919
var express = require('express');
20-
var gcloud = require('gcloud');
2120
var crypto = require('crypto');
2221

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

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

3336
// [START insertVisit]
@@ -38,8 +41,8 @@ var dataset = gcloud.datastore({
3841
* @param {function} callback The callback function.
3942
*/
4043
function insertVisit (visit, callback) {
41-
dataset.save({
42-
key: dataset.key('visit'),
44+
datastore.save({
45+
key: datastore.key('visit'),
4346
data: visit
4447
}, function (err) {
4548
if (err) {
@@ -57,11 +60,11 @@ function insertVisit (visit, callback) {
5760
* @param {function} callback The callback function.
5861
*/
5962
function getVisits (callback) {
60-
var query = dataset.createQuery('visit')
63+
var query = datastore.createQuery('visit')
6164
.order('-timestamp')
6265
.limit(10);
6366

64-
dataset.runQuery(query, function (err, entities) {
67+
datastore.runQuery(query, function (err, entities) {
6568
if (err) {
6669
return callback(err);
6770
}

appengine/datastore/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
"test": "mocha -R spec -t 120000 --require intelli-espower-loader ../../test/_setup.js test/*.test.js"
1414
},
1515
"dependencies": {
16-
"express": "^4.13.4",
17-
"gcloud": "^0.37.0"
16+
"@google-cloud/datastore": "^0.1.1",
17+
"express": "^4.13.4"
1818
},
1919
"devDependencies": {
20-
"mocha": "^2.5.3"
20+
"mocha": "^3.0.2"
2121
}
2222
}

appengine/datastore/test/app.test.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@ function getSample () {
5656
runQuery: sinon.stub().callsArgWith(1, null, resultsMock),
5757
key: sinon.stub().returns({})
5858
};
59-
var gcloudMock = {
60-
datastore: sinon.stub().returns(datasetMock)
61-
};
59+
var DatastoreMock = sinon.stub().returns(datasetMock);
6260

6361
var app = proxyquire(SAMPLE_PATH, {
64-
gcloud: gcloudMock,
62+
'@google-cloud/datastore': DatastoreMock,
6563
express: expressMock
6664
});
6765
return {
@@ -71,7 +69,7 @@ function getSample () {
7169
express: expressMock,
7270
results: resultsMock,
7371
dataset: datasetMock,
74-
gcloud: gcloudMock
72+
Datastore: DatastoreMock
7573
}
7674
};
7775
}
@@ -83,10 +81,7 @@ describe('appengine/datastore/app.js', function () {
8381
sample = getSample();
8482

8583
assert(sample.mocks.express.calledOnce);
86-
assert(sample.mocks.gcloud.datastore.calledOnce);
87-
assert.deepEqual(sample.mocks.gcloud.datastore.firstCall.args[0], {
88-
projectId: process.env.GCLOUD_PROJECT
89-
});
84+
assert(sample.mocks.Datastore.calledOnce);
9085
assert(sample.app.listen.calledOnce);
9186
assert.equal(sample.app.listen.firstCall.args[0], process.env.PORT || 8080);
9287
});

appengine/pubsub/app.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@
1717

1818
var express = require('express');
1919
var bodyParser = require('body-parser');
20-
var gcloud = require('gcloud');
20+
21+
// By default, the client will authenticate using the service account file
22+
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
23+
// the project specified by the GCLOUD_PROJECT environment variable. See
24+
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
25+
// These environment variables are set automatically on Google App Engine
26+
var PubSub = require('@google-cloud/pubsub');
27+
28+
// Instantiate a pubsub client
29+
var pubsub = PubSub();
2130

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

35-
var pubsub = gcloud.pubsub({
36-
projectId: process.env.GCLOUD_PROJECT
37-
});
38-
3944
var topic = pubsub.topic(process.env.PUBSUB_TOPIC);
4045

4146
// [START index]

appengine/pubsub/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
"start": "node app.js"
1313
},
1414
"dependencies": {
15+
"@google-cloud/pubsub": "^0.1.1",
1516
"body-parser": "^1.14.2",
1617
"express": "^4.13.4",
17-
"gcloud": "^0.37.0",
1818
"jade": "^1.11.0"
1919
}
2020
}

appengine/storage/app.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@
1717

1818
var format = require('util').format;
1919
var express = require('express');
20-
var gcloud = require('gcloud');
20+
21+
// By default, the client will authenticate using the service account file
22+
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
23+
// the project specified by the GCLOUD_PROJECT environment variable. See
24+
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
25+
// These environment variables are set automatically on Google App Engine
26+
var Storage = require('@google-cloud/storage');
27+
28+
// Instantiate a storage client
29+
var storage = Storage();
2130

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

33-
// The following environment variables are set by app.yaml when running on GAE,
34-
// but will need to be manually set when running locally.
35-
// The storage client is used to communicate with Google Cloud Storage
36-
var storage = gcloud.storage({
37-
projectId: process.env.GCLOUD_PROJECT
38-
});
39-
4042
// A bucket is a container for objects (files).
4143
var bucket = storage.bucket(process.env.GCLOUD_STORAGE_BUCKET);
4244
// [END config]

appengine/storage/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
"start": "node app.js"
66
},
77
"dependencies": {
8+
"@google-cloud/storage": "^0.1.1",
89
"body-parser": "^1.14.2",
910
"express": "^4.13.4",
10-
"gcloud": "^0.37.0",
1111
"jade": "^1.11.0",
12-
"multer": "^1.1.0"
12+
"multer": "^1.2.0"
1313
}
1414
}

appengine/system-test/all.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ var sampleTests = [
9393
msg: 'Viewed',
9494
TRAVIS_NODE_VERSION: '0.12'
9595
},
96-
{
97-
dir: 'appengine/geddy',
98-
cmd: 'node',
99-
args: ['node_modules/geddy/bin/cli.js'],
100-
msg: 'Hello, World! Geddy.js on Google App Engine.',
101-
TRAVIS_NODE_VERSION: '5'
102-
},
96+
// {
97+
// dir: 'appengine/geddy',
98+
// cmd: 'node',
99+
// args: ['node_modules/geddy/bin/cli.js'],
100+
// msg: 'Hello, World! Geddy.js on Google App Engine.',
101+
// TRAVIS_NODE_VERSION: '5'
102+
// },
103103
{
104104
dir: 'appengine/grunt',
105105
deploy: true,

bigquery/dataset_size.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
var async = require('async');
1717

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

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

87-
var bigquery = gcloud.bigquery({
87+
// Instantiate a bigquery client
88+
var bigquery = BigQuery({
8889
projectId: projectId
8990
});
9091

bigquery/getting_started.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
'use strict';
1616

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

24-
// Get a reference to the bigquery component
25-
var bigquery = gcloud.bigquery();
24+
// Instantiate a bigquery client
25+
var bigquery = BigQuery();
2626
// [END auth]
2727

2828
// [START print]

0 commit comments

Comments
 (0)