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
|
@ -35,7 +35,13 @@ Adding filter(s) for the Image Search
|
||||||
```js
|
```js
|
||||||
Bing.images("Ninja Turtles", function(error, res, body){
|
Bing.images("Ninja Turtles", function(error, res, body){
|
||||||
console.log(body);
|
console.log(body);
|
||||||
}, {imagefilters: 'Size:Small+Color:Monochrome'});
|
},
|
||||||
|
{
|
||||||
|
imagefilters: {
|
||||||
|
size: 'small',
|
||||||
|
color: 'monochrome'
|
||||||
|
}
|
||||||
|
});
|
||||||
```
|
```
|
||||||
Accepted filter values:
|
Accepted filter values:
|
||||||
* Size:\<Small | Medium | Large\>
|
* Size:\<Small | Medium | Large\>
|
||||||
|
|
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
|
* @param {Object} options Options to command, allows overriding of
|
||||||
* rootUri, accKey (Bing API key),
|
* rootUri, accKey (Bing API key),
|
||||||
* userAgent, reqTimeout, top, skip
|
* userAgent, reqTimeout, top, skip,
|
||||||
|
* imagefilters
|
||||||
* @function
|
* @function
|
||||||
*/
|
*/
|
||||||
Bing.prototype.images = function(query, callback, options) {
|
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);
|
this.searchVertical(query, "Image", callback, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function capitalizeFirstLetter(s) {
|
||||||
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports = Bing;
|
module.exports = Bing;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue