From 670105f579342e93ba8c189fada688eb178046df Mon Sep 17 00:00:00 2001 From: ray Date: Fri, 13 Mar 2015 15:13:35 +0100 Subject: [PATCH 1/3] improve image search use object instead of a string for the imagefilters --- README.md | 8 +++++++- lib/bing.js | 18 +++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index afc93b2..fd3cc38 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,13 @@ Adding filter(s) for the Image Search ```js Bing.images("Ninja Turtles", function(error, res, body){ console.log(body); -}, {imagefilters: 'Size:Small+Color:Monochrome'}); + }, + { + imagefilters: { + size: 'small', + color: 'monochrome' + } + }); ``` Accepted filter values: * Size:\ diff --git a/lib/bing.js b/lib/bing.js index 04052a5..df26386 100644 --- a/lib/bing.js +++ b/lib/bing.js @@ -139,13 +139,29 @@ Bing.prototype.search = Bing.prototype.web; * * @param {Object} options Options to command, allows overriding of * rootUri, accKey (Bing API key), - * userAgent, reqTimeout, top, skip + * userAgent, reqTimeout, top, skip, + * imagefilters * @function */ Bing.prototype.images = function(query, callback, options) { + if (options.imagefilters) { + var filterQuery = ''; + var filters = Object.keys(options.imagefilters); + filters.map(function(key, i) { + filterQuery += capitalizeFirstLetter(key) + ':'; + filterQuery += capitalizeFirstLetter(options.imagefilters[key]); + if (i < filters.length - 1) + filterQuery += '+'; + }); + options.imagefilters = filterQuery; + } this.searchVertical(query, "Image", callback, options); }; +function capitalizeFirstLetter(s) { + return s.charAt(0).toUpperCase() + s.slice(1); +} + module.exports = Bing; From b752fcd12e8b9f04358b0fda03d2f3fbc4e0106d Mon Sep 17 00:00:00 2001 From: ray Date: Fri, 13 Mar 2015 15:22:08 +0100 Subject: [PATCH 2/3] fix missing options bug --- lib/bing.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/bing.js b/lib/bing.js index df26386..41ce18f 100644 --- a/lib/bing.js +++ b/lib/bing.js @@ -144,7 +144,7 @@ Bing.prototype.search = Bing.prototype.web; * @function */ Bing.prototype.images = function(query, callback, options) { - if (options.imagefilters) { + if (options && options.imagefilters) { var filterQuery = ''; var filters = Object.keys(options.imagefilters); filters.map(function(key, i) { @@ -162,6 +162,5 @@ function capitalizeFirstLetter(s) { return s.charAt(0).toUpperCase() + s.slice(1); } - module.exports = Bing; From f4675b5d54b2af5e476bf505542f457cb6d1dbbe Mon Sep 17 00:00:00 2001 From: ray Date: Fri, 13 Mar 2015 15:31:44 +0100 Subject: [PATCH 3/3] dont break older versions --- lib/bing.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/bing.js b/lib/bing.js index 41ce18f..d543c4f 100644 --- a/lib/bing.js +++ b/lib/bing.js @@ -144,7 +144,9 @@ Bing.prototype.search = Bing.prototype.web; * @function */ Bing.prototype.images = function(query, callback, options) { - if (options && options.imagefilters) { + if (options + && options.imagefilters + && typeof options.imagefilters === 'object') { var filterQuery = ''; var filters = Object.keys(options.imagefilters); filters.map(function(key, i) {