improve image search
use object instead of a string for the imagefilters
This commit is contained in:
parent
5fc630c004
commit
670105f579
2 changed files with 24 additions and 2 deletions
18
lib/bing.js
18
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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue