Comparing version 0.8.3 to 0.9.0
{ | ||
"name": "sajari", | ||
"version": "0.8.3", | ||
"version": "0.9.0", | ||
"description": "JavaScript SDK for access to the Sajari search API", | ||
@@ -5,0 +5,0 @@ "author": { |
/* | ||
* api.js - The Sajari JavaScript API SDK | ||
* Sajari Search API SDK | ||
* https://www.sajari.com/ | ||
*/ | ||
@@ -9,8 +10,7 @@ | ||
var request = require('superagent'); | ||
var jsonp = require('superagent-jsonp'); // To use jsonp chain: .use(jsonp) | ||
var log = require('loglevel'); | ||
var searchSeq = 1; | ||
/* | ||
* Sajari Search API SDK | ||
* https://www.sajari.com/ | ||
* | ||
@@ -420,8 +420,8 @@ * @param {string} company - Your company ID, see your dashboard | ||
if (this.jsonp) { | ||
req.use(jsonp); | ||
} else { | ||
req.send(data); | ||
this.jsonpSend(path, data, opts.success, opts.failure); | ||
return; | ||
} | ||
// Send the request and handle the response | ||
req.send(data); | ||
req.end(function(err, res) { | ||
@@ -434,2 +434,33 @@ if (err) { | ||
}); | ||
}, | ||
/** | ||
* Performs a JSONP request. Asynchronsely either calls success() (with response), or failure(). | ||
*/ | ||
jsonpSend : function(path, args, success, failure) { | ||
var uri = url.augmentUri(path, args); | ||
var seq = '_jsonp_' + (searchSeq++); | ||
var script = document.createElement('script'); | ||
window['__SJ'+seq] = function(response) { | ||
success(response); | ||
try { | ||
delete window['__SJ'+seq]; | ||
} catch (e) { | ||
window['__SJ'+seq] = undefined; | ||
} | ||
script.parentNode.removeChild(script); | ||
}; | ||
script.onerror = function() { | ||
failure(); | ||
try { | ||
delete window['__SJ'+seq]; | ||
} catch (e) { | ||
window['__SJ'+seq] = undefined; | ||
} | ||
script.parentNode.removeChild(script); | ||
}; | ||
script.src = url.augmentUri(uri, { jsoncallback: '__SJ'+seq }); | ||
document.getElementsByTagName('head')[0].appendChild(script); | ||
} | ||
@@ -436,0 +467,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38276
1083