From 4d29ab08149c5e985d2c5ee240e6031cf3e8482a Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Wed, 13 Apr 2016 19:07:57 -0400 Subject: [PATCH] vision: support maxResults --- lib/vision/index.js | 20 ++++++++++++++------ test/vision/index.js | 23 +++++++++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/lib/vision/index.js b/lib/vision/index.js index bf9d6c308bf..1132828de32 100644 --- a/lib/vision/index.js +++ b/lib/vision/index.js @@ -184,12 +184,14 @@ Vision.prototype.annotate = function(requests, callback) { * @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 or a gcloud File object. - * @param {string[]|object} config - An array of types or a configuration + * @param {string[]|object=} options - An array of types or a configuration * object. - * @param {string[]} config.types - An array of feature types to detect from the - * provided images. Acceptable values: `faces`, `landmarks`, `labels`, + * @param {number} options.maxResults - The maximum number of results, per type, + * to return in the response. + * @param {string[]} options.types - An array of feature types to detect from + * the provided images. Acceptable values: `faces`, `landmarks`, `labels`, * `logos`, `properties`, `safeSearch`, `text`. - * @param {boolean=} config.verbose - Use verbose mode, which returns a less- + * @param {boolean=} options.verbose - Use verbose mode, which returns a less- * simplistic representation of the annotation (default: `false`). * @param {function} callback - The callback function. * @param {?error} callback.err - An error returned while making this request. @@ -292,12 +294,18 @@ Vision.prototype.detect = function(images, options, callback) { throw new Error('Requested detection feature not found: ' + type); } - config.push({ + var cfg = { image: image, features: { type: typeName } - }); + }; + + if (is.number(options.maxResults)) { + cfg.features.maxResults = options.maxResults; + } + + config.push(cfg); }); }); diff --git a/test/vision/index.js b/test/vision/index.js index f0cee5c7e08..7bb2b13400f 100644 --- a/test/vision/index.js +++ b/test/vision/index.js @@ -303,6 +303,29 @@ describe('Vision', function() { async.each(shortNames, checkConfig, done); }); + it('should allow setting maxResults', function(done) { + var maxResults = 10; + + vision.annotate = function(config) { + assert.deepEqual(config, [ + { + image: IMAGES[0], + features: { + type: 'FACE_DETECTION', + maxResults: 10 + } + } + ]); + + done(); + }; + + vision.detect(IMAGE, { + types: ['face'], + maxResults: maxResults + }, assert.ifError); + }); + it('should not return detections when none were found', function(done) { vision.annotate = function(config, callback) { callback(null, []);