From 3731ed5ca5bfb2f5d673adc7a45810f5107791a0 Mon Sep 17 00:00:00 2001 From: Dave Gramlich Date: Tue, 16 Aug 2016 16:31:47 -0400 Subject: [PATCH 1/2] docs: updated vision detect params/examples --- .jscsrc | 2 +- packages/vision/src/index.js | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.jscsrc b/.jscsrc index c9551063232..5da1775bb4e 100644 --- a/.jscsrc +++ b/.jscsrc @@ -17,7 +17,7 @@ "requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties", "maximumLineLength": { "value": 80, - "allowUrlComments": true + "allowComments": true }, "excludeFiles": [ "system-test/data/*", diff --git a/packages/vision/src/index.js b/packages/vision/src/index.js index 50f3dc0df28..422c45310b8 100644 --- a/packages/vision/src/index.js +++ b/packages/vision/src/index.js @@ -156,9 +156,10 @@ Vision.prototype.annotate = function(requests, callback) { * For the response in the original format, review the `apiResponse` argument * your callback receives. * - * @param {string|string[]|module:storage/file|module:storage/file[]} images - - * The source image(s) to run the detection on. It can be either a local - * image path, a remote image URL, or a @google-cloud/storage File object. + * @param {string|string[]|buffer|buffer[]|module:storage/file|module:storage/file[]} images - The + * source image(s) to run the detection on. It can be either a local image + * path, a remote image URL, a Buffer, or a @google-cloud/storage File + * object. * @param {string[]|object=} options - An array of types or a configuration * object. * @param {object=} options.imageContext - See an @@ -210,6 +211,19 @@ Vision.prototype.annotate = function(requests, callback) { * vision.detect(img, types, function(err, detection, apiResponse) {}); * * //- + * // Run feature detection over a Buffer. + * //- + * var fs = require('fs'); + * + * fs.readFile('image.jpg', function(err, contents) { + * if (err) { + * // Error handling omitted. + * } + * + * vision.detect(contents, types, function(err, detection, apiResponse) {}); + * }); + * + * //- * // Supply multiple images for feature detection. * //- * var images = [ From 518eaadf11410596092bdf49bcd0cd8105815d27 Mon Sep 17 00:00:00 2001 From: Dave Gramlich Date: Mon, 29 Aug 2016 17:19:58 -0400 Subject: [PATCH 2/2] updated buffer example --- .jscsrc | 2 +- packages/vision/src/index.js | 9 ++++++--- test/docs.js | 12 +++++++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.jscsrc b/.jscsrc index 5da1775bb4e..c9551063232 100644 --- a/.jscsrc +++ b/.jscsrc @@ -17,7 +17,7 @@ "requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties", "maximumLineLength": { "value": 80, - "allowComments": true + "allowUrlComments": true }, "excludeFiles": [ "system-test/data/*", diff --git a/packages/vision/src/index.js b/packages/vision/src/index.js index 422c45310b8..a4856e94ee4 100644 --- a/packages/vision/src/index.js +++ b/packages/vision/src/index.js @@ -133,6 +133,7 @@ Vision.prototype.annotate = function(requests, callback) { }); }; +// jscs:disable maximumLineLength /** * Detect properties from an image (or images) of one or more types. * @@ -213,14 +214,15 @@ Vision.prototype.annotate = function(requests, callback) { * //- * // Run feature detection over a Buffer. * //- - * var fs = require('fs'); + * var level = require('level'); + * var db = level('./users-database'); * - * fs.readFile('image.jpg', function(err, contents) { + * db.get('user-image', { encoding: 'binary' }, function(err, image) { * if (err) { * // Error handling omitted. * } * - * vision.detect(contents, types, function(err, detection, apiResponse) {}); + * vision.detect(image, function(err, detection, apiResponse) {}); * }); * * //- @@ -533,6 +535,7 @@ Vision.prototype.detect = function(images, options, callback) { }); }); }; +// jscs:enable maximumLineLength /** * Run face detection against an image. diff --git a/test/docs.js b/test/docs.js index ea2c701bbc1..e05760f7a0a 100644 --- a/test/docs.js +++ b/test/docs.js @@ -135,6 +135,15 @@ describe('documentation', function() { }; } + // For {module:vision} docs. + function FakeLevel() { + return { + get: function(key, options, callback) { + callback(null, 'image.jpg'); + } + }; + } + fileDocBlocks.methods.forEach(function(method) { var code = method.examples.map(prop('code')).join('\n'); var lowercaseId = method.id.toLowerCase(); @@ -171,7 +180,8 @@ describe('documentation', function() { /require\('(@google-cloud\/[^']*)/g, 'require(\'../packages/' + directory + '/node_modules/$1' ) - .replace('require(\'express\')', FakeExpress.toString()); + .replace('require(\'express\')', FakeExpress.toString()) + .replace('require(\'level\')', FakeLevel.toString()); var displayName = filename .replace('docs/json/master/', '')