Force camelCase for search options
This commit is contained in:
parent
2501d2a637
commit
346c7030a1
3 changed files with 50 additions and 31 deletions
64
lib/bing.js
64
lib/bing.js
|
@ -59,25 +59,37 @@ var Bing = function (options) {
|
|||
_.extend(opts, options);
|
||||
}
|
||||
|
||||
// Use camelCased options
|
||||
// Note: this translation is needed for compatibility with older versions.
|
||||
// At some point it could be deprecated and removed in a major version
|
||||
opts.newsSortBy = opts.newsSortBy || opts.newssortby || null;
|
||||
opts.newsCategory = opts.newsCategory || opts.newscategory || null;
|
||||
opts.newsLocationOverride = opts.newsLocationOverride
|
||||
|| opts.newslocationoverride
|
||||
|| null;
|
||||
opts.imageFilters = opts.imageFilters || opts.imagefilters || null;
|
||||
opts.videoSortBy = opts.videoSortBy || opts.videosortby || null;
|
||||
opts.videoFilters = opts.videoFilters || opts.videofilters || null;
|
||||
|
||||
var reqUri = opts.rootUri
|
||||
+ vertical
|
||||
+ "?$format=json&" + qs.stringify({ "Query": "'" + query + "'" })
|
||||
+ "&$top=" + opts.top
|
||||
+ "&$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.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.imageFilters
|
||||
? '&' + qs.stringify({ "ImageFilters": "'" + opts.imageFilters + "'" })
|
||||
: '')
|
||||
+ (opts.videoSortBy ? "&VideoSortBy=%27" + opts.videoSortBy + "%27" : '')
|
||||
+ (opts.videofilters
|
||||
? '&' + qs.stringify({ "VideoFilters": "'" + opts.videofilters + "'" })
|
||||
+ (opts.videoFilters
|
||||
? '&' + qs.stringify({ "VideoFilters": "'" + opts.videoFilters + "'" })
|
||||
: '');
|
||||
|
||||
request({
|
||||
|
@ -188,19 +200,22 @@ Bing.prototype.news = function (query, options, callback) {
|
|||
* @function
|
||||
*/
|
||||
Bing.prototype.video = function (query, options, callback) {
|
||||
if (options
|
||||
&& typeof options === 'object'
|
||||
&& options.videofilters
|
||||
&& typeof options.videofilters === 'object') {
|
||||
if (options && typeof options === 'object') {
|
||||
|
||||
var filterQuery = Object.keys(options.videofilters)
|
||||
//compatibility with older versions
|
||||
options.videoFilters = options.videoFilters || options.videofilters || '';
|
||||
|
||||
if (options.videoFilters && typeof options.videoFilters === 'object') {
|
||||
|
||||
var filterQuery = Object.keys(options.videoFilters)
|
||||
.map(function(key){
|
||||
return capitalise(key) + ':'
|
||||
+ capitalise(options.videofilters[key]);
|
||||
+ capitalise(options.videoFilters[key]);
|
||||
})
|
||||
.join('+');
|
||||
|
||||
options.videofilters = filterQuery;
|
||||
options.videoFilters = filterQuery;
|
||||
}
|
||||
}
|
||||
this.searchVertical(query, "Video", options, callback);
|
||||
};
|
||||
|
@ -215,26 +230,29 @@ Bing.prototype.video = function (query, options, callback) {
|
|||
* @param {Object} options Options to command, allows overriding of
|
||||
* rootUri, accKey (Bing API key),
|
||||
* userAgent, reqTimeout, top, skip,
|
||||
* imagefilters
|
||||
* imageFilters
|
||||
*
|
||||
* @param {requestCallback} callback Callback called with (potentially
|
||||
* json-parsed) response.
|
||||
* @function
|
||||
*/
|
||||
Bing.prototype.images = function (query, options, callback) {
|
||||
if (options
|
||||
&& typeof options === 'object'
|
||||
&& options.imagefilters
|
||||
&& typeof options.imagefilters === 'object') {
|
||||
if (options && typeof options === 'object') {
|
||||
|
||||
var filterQuery = Object.keys(options.imagefilters)
|
||||
//compatibility with older versions
|
||||
options.imageFilters = options.imageFilters || options.imagefilters || '';
|
||||
|
||||
if (options.imageFilters && typeof options.imageFilters === 'object') {
|
||||
|
||||
var filterQuery = Object.keys(options.imageFilters)
|
||||
.map(function(key){
|
||||
return capitalise(key) + ':'
|
||||
+ capitalise(options.imagefilters[key]);
|
||||
+ capitalise(options.imageFilters[key]);
|
||||
})
|
||||
.join('+');
|
||||
|
||||
options.imagefilters = filterQuery;
|
||||
options.imageFilters = filterQuery;
|
||||
}
|
||||
}
|
||||
this.searchVertical(query, "Image", options, callback);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue