commit
80967c205a
2 changed files with 25 additions and 2 deletions
|
@ -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:\<Small | Medium | Large\>
|
||||
|
|
19
lib/bing.js
19
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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue