Skip to content

Commit

Permalink
Switch to individual API packages. (#169)
Browse files Browse the repository at this point in the history
* Switch to individual API packages.

* Address comments

* Address comments
  • Loading branch information
jmdobry authored Aug 16, 2016
1 parent b645a1b commit 808eb16
Show file tree
Hide file tree
Showing 69 changed files with 400 additions and 384 deletions.
23 changes: 13 additions & 10 deletions appengine/datastore/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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) {
Expand All @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions appengine/datastore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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 {
Expand All @@ -71,7 +69,7 @@ function getSample () {
express: expressMock,
results: resultsMock,
dataset: datasetMock,
gcloud: gcloudMock
Datastore: DatastoreMock
}
};
}
Expand All @@ -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);
});
Expand Down
15 changes: 10 additions & 5 deletions appengine/pubsub/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion appengine/pubsub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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');
Expand All @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions appengine/storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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'
},
// {
// 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,
Expand Down
13 changes: 7 additions & 6 deletions bigquery/dataset_size.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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({
projectId: projectId
});

Expand Down
14 changes: 7 additions & 7 deletions bigquery/getting_started.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
21 changes: 13 additions & 8 deletions bigquery/list_datasets_and_projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
// [END auth]

// [START list_tables]
Expand All @@ -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
});

Expand All @@ -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);
Expand Down
14 changes: 7 additions & 7 deletions bigquery/load_data_from_csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions bigquery/load_data_from_gcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions bigquery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions computeengine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 808eb16

Please sign in to comment.