Upgrading to API v5
This commit is contained in:
parent
d6b6b06a4b
commit
56b2e8b088
4 changed files with 64 additions and 121 deletions
52
lib/bing.js
52
lib/bing.js
|
@ -59,41 +59,23 @@ 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
|
||||
+ "&Options=%27" + (opts.options || []).join('%2B') + "%27"
|
||||
+ (vertical == 'spellcheck' ? "?text=" : "?q=") + query
|
||||
+ (opts.top ? "&count=" + opts.top : "")
|
||||
+ (opts.offset ? "&offset=" + opts.skip : "")
|
||||
+ (opts.preContextText ? "&preContextText=" + opts.preContextText : "")
|
||||
+ (opts.mode ? "&mode=" + opts.mode : "")
|
||||
+ (opts.postContextText ? "&postContextText=" + opts.postContextText : "")
|
||||
// + "&Options='" + (opts.options || []).join('%2B') + "'"
|
||||
+ (opts.sources
|
||||
? "&Sources=%27" + encodeURIComponent(opts.sources) + "%27"
|
||||
? "&Sources='" + encodeURIComponent(opts.sources) + "'"
|
||||
: '')
|
||||
+ (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.videoSortBy ? "&VideoSortBy=%27" + opts.videoSortBy + "%27" : '')
|
||||
+ (opts.videoFilters
|
||||
? '&' + qs.stringify({ "VideoFilters": "'" + opts.videoFilters + "'" })
|
||||
: '');
|
||||
+ (opts.market ? "&mkt='" + opts.market + "'" : '')
|
||||
+ (opts.adult ? "&safesearch=" + opts.adult : '')
|
||||
|
||||
request({
|
||||
uri: reqUri,
|
||||
|
@ -144,7 +126,7 @@ var Bing = function (options) {
|
|||
* @function
|
||||
*/
|
||||
Bing.prototype.web = function (query, options, callback) {
|
||||
this.searchVertical(query, "Web", options, callback);
|
||||
this.searchVertical(query, "search", options, callback);
|
||||
};
|
||||
|
||||
// Alias Bing.search to Bing.web
|
||||
|
@ -166,7 +148,7 @@ Bing.prototype.search = Bing.prototype.web;
|
|||
* @function
|
||||
*/
|
||||
Bing.prototype.composite = function (query, options, callback) {
|
||||
this.searchVertical(query, "Composite", options, callback);
|
||||
this.searchVertical(query, "search", options, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -183,7 +165,7 @@ Bing.prototype.composite = function (query, options, callback) {
|
|||
* @function
|
||||
*/
|
||||
Bing.prototype.news = function (query, options, callback) {
|
||||
this.searchVertical(query, "News", options, callback);
|
||||
this.searchVertical(query, "news/search", options, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -217,7 +199,7 @@ Bing.prototype.video = function (query, options, callback) {
|
|||
options.videoFilters = filterQuery;
|
||||
}
|
||||
}
|
||||
this.searchVertical(query, "Video", options, callback);
|
||||
this.searchVertical(query, "videos/search", options, callback);
|
||||
};
|
||||
|
||||
|
||||
|
@ -254,7 +236,7 @@ Bing.prototype.images = function (query, options, callback) {
|
|||
options.imageFilters = filterQuery;
|
||||
}
|
||||
}
|
||||
this.searchVertical(query, "Image", options, callback);
|
||||
this.searchVertical(query, "images/search", options, callback);
|
||||
};
|
||||
|
||||
|
||||
|
@ -272,7 +254,7 @@ Bing.prototype.images = function (query, options, callback) {
|
|||
* @function
|
||||
*/
|
||||
Bing.prototype.relatedSearch = function (query, options, callback) {
|
||||
this.searchVertical(query, "RelatedSearch", options, callback);
|
||||
this.searchVertical(query, "search", options, callback);
|
||||
};
|
||||
|
||||
|
||||
|
@ -290,7 +272,7 @@ Bing.prototype.relatedSearch = function (query, options, callback) {
|
|||
* @function
|
||||
*/
|
||||
Bing.prototype.spelling = function (query, options, callback) {
|
||||
this.searchVertical(query, "SpellingSuggestions", options, callback);
|
||||
this.searchVertical(query, "spellcheck", options, callback);
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue