commit
b6c49f47bb
3 changed files with 59 additions and 11 deletions
44
README.md
44
README.md
|
@ -1,12 +1,12 @@
|
|||
# Node Bing API
|
||||
Node.js lib for the Azure Bing Web Search API
|
||||
|
||||
### Installation
|
||||
## Installation
|
||||
````
|
||||
npm install node-bing-api
|
||||
````
|
||||
|
||||
### Usage
|
||||
## Usage
|
||||
|
||||
Require the library and initialialize it with your account key:
|
||||
|
||||
|
@ -14,9 +14,9 @@ Require the library and initialialize it with your account key:
|
|||
var Bing = require('node-bing-api')({ accKey: "your-account-key" });
|
||||
```
|
||||
|
||||
##### Web Search:
|
||||
#### Web Search:
|
||||
```js
|
||||
Bing.search("Pizza", function(error, res, body){
|
||||
Bing.web("Pizza", function(error, res, body){
|
||||
console.log(body);
|
||||
},
|
||||
{
|
||||
|
@ -25,7 +25,7 @@ Bing.search("Pizza", function(error, res, body){
|
|||
});
|
||||
```
|
||||
|
||||
##### Images Search:
|
||||
#### Images Search:
|
||||
```js
|
||||
Bing.images("Ninja Turtles", function(error, res, body){
|
||||
console.log(body);
|
||||
|
@ -35,18 +35,46 @@ 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\>
|
||||
* Size:Height:\<*Height*\>
|
||||
* Size:Width:\<*Width*\>
|
||||
* Aspect:\<Square | Wide | Tall\>
|
||||
* Color:\<Color | Monochrome\>
|
||||
* Style:\<Photo | Graphics\>
|
||||
* Face:\<Face | Portrait | Other\>
|
||||
|
||||
##### Specify Market
|
||||
|
||||
#### Specify Market
|
||||
Getting spanish results:
|
||||
```js
|
||||
Bing.images("Ninja Turtles", function(error, res, body){
|
||||
console.log(body);
|
||||
}, {top: 5, market: 'es-ES'});
|
||||
```
|
||||
[List of Bing Markets](https://msdn.microsoft.com/en-us/library/dd251064.aspx)
|
||||
|
||||
|
||||
### License
|
||||
#### Adult Filter
|
||||
```js
|
||||
Bing.images('Kim Kardashian', function(error, res, body){
|
||||
console.log(body.d.results);
|
||||
}, { market: 'en-US', adult: 'Strict'});
|
||||
```
|
||||
Accepted values: "Off", "Moderate", "Strict".
|
||||
|
||||
*Moderate level should not include results with sexually explicit images
|
||||
or videos, but may include sexually explicit text.*
|
||||
|
||||
|
||||
## License
|
||||
MIT
|
||||
|
||||
|
|
24
lib/bing.js
24
lib/bing.js
|
@ -63,6 +63,7 @@ var Bing = function( options ) {
|
|||
+ "&$top=" + opts.top
|
||||
+ "&$skip=" + opts.skip
|
||||
+ (opts.market ? "&Market=%27" + opts.market + "%27" : '')
|
||||
+ (opts.adult ? "&Adult=%27" + opts.adult + "%27" : '')
|
||||
+ (opts.imagefilters
|
||||
? '&' + qs.stringify({ "ImageFilters": "'" + opts.imagefilters + "'" })
|
||||
: '');
|
||||
|
@ -119,10 +120,14 @@ var Bing = function( options ) {
|
|||
* userAgent, reqTimeout, top, skip
|
||||
* @function
|
||||
*/
|
||||
Bing.prototype.search = function(query, callback, options) {
|
||||
Bing.prototype.web = function(query, callback, options) {
|
||||
this.searchVertical(query, "Web", callback, options);
|
||||
};
|
||||
|
||||
// Alias Bing.search to Bing.web
|
||||
// Note: Keep this for compatibility with older versions
|
||||
Bing.prototype.search = Bing.prototype.web;
|
||||
|
||||
|
||||
/**
|
||||
* Performs a Bing search in the Images vertical.
|
||||
|
@ -134,13 +139,28 @@ Bing.prototype.search = function(query, callback, options) {
|
|||
*
|
||||
* @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) {
|
||||
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;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "node-bing-api",
|
||||
"version": "0.1.6",
|
||||
"version": "1.1.0",
|
||||
"description": "Node.js module for the Azure Bing Search API",
|
||||
"main": "index.js",
|
||||
"author": "Mr. Goferito",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue