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..d543c4f 100644 --- a/lib/bing.js +++ b/lib/bing.js @@ -139,13 +139,30 @@ 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 + && options.imagefilters + && typeof options.imagefilters === 'object') { + 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;