Added News,Video search support
This commit is contained in:
parent
352f36d7c9
commit
98fec2aa0f
2 changed files with 82 additions and 4 deletions
58
lib/bing.js
58
lib/bing.js
|
@ -64,11 +64,16 @@ var Bing = function( options ) {
|
|||
+ "&$skip=" + opts.skip
|
||||
+ (opts.sources ? "&Sources=%27" + opts.sources + "%27" : '')
|
||||
+ (opts.newssortby ? "&NewsSortBy=%27" + opts.newssortby + "%27" : '')
|
||||
+ (opts.newscategory ? "&NewsCategory=%27" + opts.newscategory + "%27" : '')
|
||||
+ (opts.newslocationoverride ? "&NewsLocationOverride=%27" + opts.newslocationoverride + "%27" : '')
|
||||
+ (opts.market ? "&Market=%27" + opts.market + "%27" : '')
|
||||
+ (opts.adult ? "&Adult=%27" + opts.adult + "%27" : '')
|
||||
+ (opts.imagefilters
|
||||
? '&' + qs.stringify({ "ImageFilters": "'" + opts.imagefilters + "'" })
|
||||
: '');
|
||||
: '')
|
||||
+ (opts.videofilters
|
||||
? '&' + qs.stringify({ "VideoFilters": "'" + opts.videofilters + "'" })
|
||||
: '');
|
||||
|
||||
request({
|
||||
uri: reqUri,
|
||||
|
@ -148,9 +153,54 @@ Bing.prototype.composite = function(query, callback, options) {
|
|||
this.searchVertical(query, "Composite", callback, options);
|
||||
};
|
||||
|
||||
// Alias Bing.search to Bing.web
|
||||
// Note: Keep this for compatibility with older versions
|
||||
Bing.prototype.search = Bing.prototype.composite;
|
||||
/**
|
||||
* Performs a Bing search in the News vertical.
|
||||
*
|
||||
* @param {String} query Query term to search for.
|
||||
*
|
||||
* @param {requestCallback} callback Callback called with (potentially
|
||||
* json-parsed) response.
|
||||
*
|
||||
* @param {Object} options Options to command, allows overriding
|
||||
* of rootUri, accKey (Bing API key),
|
||||
* userAgent, reqTimeout, top, skip,
|
||||
* @function
|
||||
*/
|
||||
Bing.prototype.news = function(query, callback, options) {
|
||||
this.searchVertical(query, "News", callback, options);
|
||||
};
|
||||
|
||||
/**
|
||||
* Performs a Bing search in the Video vertical.
|
||||
*
|
||||
* @param {String} query Query term to search for.
|
||||
*
|
||||
* @param {requestCallback} callback Callback called with (potentially
|
||||
* json-parsed) response.
|
||||
*
|
||||
* @param {Object} options Options to command, allows overriding
|
||||
* of rootUri, accKey (Bing API key),
|
||||
* userAgent, reqTimeout, top, skip,
|
||||
* @function
|
||||
*/
|
||||
Bing.prototype.video = function(query, callback, options) {
|
||||
if (options
|
||||
&& options.videofilters
|
||||
&& typeof options.videofilters === 'object') {
|
||||
var filterQuery = '';
|
||||
var filters = Object.keys(options.videofilters);
|
||||
filters.map(function(key, i) {
|
||||
filterQuery += capitalizeFirstLetter(key) + ':';
|
||||
filterQuery += capitalizeFirstLetter(options.videofilters[key]);
|
||||
if (i < filters.length - 1)
|
||||
filterQuery += '+';
|
||||
});
|
||||
options.videofilters = filterQuery;
|
||||
}
|
||||
this.searchVertical(query, "Video", callback, options);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Performs a Bing search in the Images vertical.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue