Skip to content

Commit 808eb16

Browse files
authored
Switch to individual API packages. (GoogleCloudPlatform#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

+13-10
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

+3-3
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

+4-9
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

+10-5
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

+1-1
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

+10-8
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

+2-2
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

+7-7
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

+7-6
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

+7-7
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]

bigquery/list_datasets_and_projects.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@
2323

2424
// [START all]
2525
// [START auth]
26-
// By default, gcloud will authenticate using the service account file specified
27-
// by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use the
28-
// project specified by the GCLOUD_PROJECT environment variable. See
29-
// https://googlecloudplatform.github.io/gcloud-node/#/docs/guides/authentication
30-
var gcloud = require('gcloud');
26+
// By default, the client will authenticate using the service account file
27+
// specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable and use
28+
// the project specified by the GCLOUD_PROJECT environment variable. See
29+
// https://googlecloudplatform.github.io/gcloud-node/#/docs/google-cloud/latest/guides/authentication
30+
var BigQuery = require('@google-cloud/bigquery');
31+
32+
var Resource = require('@google-cloud/resource');
33+
34+
// Instantiate a resource client
35+
var resource = Resource();
3136
// [END auth]
3237

3338
// [START list_tables]
@@ -41,7 +46,9 @@ function listDatasets (projectId, callback) {
4146
if (!projectId) {
4247
return callback(new Error('projectId is required!'));
4348
}
44-
var bigquery = gcloud.bigquery({
49+
50+
// Instantiate a bigquery client
51+
var bigquery = BigQuery({
4552
projectId: projectId
4653
});
4754

@@ -63,8 +70,6 @@ function listDatasets (projectId, callback) {
6370
* @param {Function} callback Callback function.
6471
*/
6572
function listProjects (callback) {
66-
var resource = gcloud.resource();
67-
6873
resource.getProjects(function (err, projects) {
6974
if (err) {
7075
return callback(err);

bigquery/load_data_from_csv.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
var fs = require('fs');
1818
var path = require('path');
1919

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

26-
// Get a reference to the bigquery component
27-
var bigquery = gcloud.bigquery();
26+
// Instantiate a bigquery client
27+
var bigquery = BigQuery();
2828

2929
/**
3030
* Wait for the provided job to complete.

bigquery/load_data_from_gcs.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616

1717
var request = require('request');
1818

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

25-
// Get a reference to the bigquery component
26-
var bigquery = gcloud.bigquery();
25+
// Instantiate a bigquery client
26+
var bigquery = BigQuery();
2727

2828
/**
2929
* Wait for the provided job to complete.

bigquery/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
},
1111
"dependencies": {
1212
"@google-cloud/bigquery": "^0.1.1",
13-
"async": "^1.5.2",
14-
"gcloud": "^0.37.0",
13+
"@google-cloud/resource": "^0.1.1",
14+
"async": "^2.0.1",
1515
"request": "^2.72.0"
1616
},
1717
"devDependencies": {
18-
"mocha": "^2.5.3"
18+
"mocha": "^3.0.2"
1919
}
2020
}

bigquery/test/list_datasets_and_projects.test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ function getSample () {
3232
var resourceMock = {
3333
getProjects: sinon.stub().callsArgWith(0, null, projectsMock)
3434
};
35-
var gcloudMock = {
36-
bigquery: sinon.stub().returns(bigqueryMock),
37-
resource: sinon.stub().returns(resourceMock)
38-
};
35+
var BigQueryMock = sinon.stub().returns(bigqueryMock);
36+
var ResourceMock = sinon.stub().returns(resourceMock);
3937
return {
4038
program: proxyquire('../list_datasets_and_projects', {
41-
gcloud: gcloudMock
39+
'@google-cloud/bigquery': BigQueryMock,
40+
'@google-cloud/resource': ResourceMock
4241
}),
4342
mocks: {
44-
gcloud: gcloudMock,
43+
BigQuery: BigQueryMock,
44+
Resource: ResourceMock,
4545
bigquery: bigqueryMock,
4646
resource: resourceMock,
4747
datasets: datasetsMock,

computeengine/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
"system-test": "mocha -R spec -t 120000 --require intelli-espower-loader ../system-test/_setup.js system-test/*.test.js"
1010
},
1111
"dependencies": {
12-
"gcloud": "^0.37.0",
13-
"googleapis": "^12.0.0",
12+
"@google-cloud/compute": "^0.1.1",
13+
"googleapis": "^12.2.0",
1414
"nodemailer": "^2.4.1",
1515
"nodemailer-smtp-transport": "^2.5.0",
1616
"sendgrid": "^2.0.0"
1717
},
1818
"devDependencies": {
19-
"mocha": "^2.5.3"
19+
"mocha": "^3.0.2"
2020
}
2121
}

0 commit comments

Comments
 (0)