diff options
author | Matěj Cepl <mcepl@redhat.com> | 2010-06-30 01:13:19 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2010-06-30 01:13:19 +0200 |
commit | 10ba5aaadd5c4f4bc5a769c2778ef26f952bb5a7 (patch) | |
tree | 09761465da097e065c398d2805332d8b7447dcae /lib/util.js | |
parent | 984c66b9db41ccb8d338df993cf16cde2ff68068 (diff) | |
download | bugzilla-triage-10ba5aaadd5c4f4bc5a769c2778ef26f952bb5a7.tar.gz |
Use 'request' module instead of home brewed load{Text,JSON} and httpPOST
Diffstat (limited to 'lib/util.js')
-rw-r--r-- | lib/util.js | 85 |
1 files changed, 1 insertions, 84 deletions
diff --git a/lib/util.js b/lib/util.js index b2a093c..6348598 100644 --- a/lib/util.js +++ b/lib/util.js @@ -215,87 +215,4 @@ var getPassword = exports.getPassword = function getPassword() { } else { return undefined; } -}; - -/** - * Load text from URL - * - * @param URL String - * @param cb_function Function to be called when the download happens with - * the downloaded body of the HTTP message as the only parameter - * @param what optional Object argument representing this for this call - * @return none - */ -var loadText = exports.loadText = function loadText(URL, cb_function, what) { - if (what === undefined) { // missing optional argument - what = this; - } - - var req = new xhrMod.XMLHttpRequest(); - req.open("GET", URL, true); - req.onreadystatechange = function (aEvt) { - if (req.readyState === 4) { - if (req.status === 200) { - cb_function.call(what, req.responseText); - } else { - throw "Getting " + URL + "failed!"; - } - } - }; - req.send(""); -}; - -/** - * Load JSON from URL - * - * @param URL String - * @param cb_function Function to be called when the download happens with - * the downloaded JSON as the only parameter - * @param what optional Object argument representing this for this call - * @return none - */ -exports.loadJSON = function loadJSON(URL, cb_function, what) { - if (what === undefined) { // missing optional argument - what = this; - } - - loadText(URL, function (text) { - var data = JSON.parse(text); - cb_function.call(what, data); - }, what); -}; - -/** - * run HTTP POST request - * - * @param URL String with URL; required - * @param data Object/String with data ; required - * @param cb_function Function called when the request succeeds, with - * the only parameter being request object ; required - * @param what Object which will represent this for the cb_function ; optional - * @param mimeData String with MIME type of data - * @param mimeGet String with MIME type expected on return - */ -exports.httpPOST = function httpPOST(URL, data, cb_function, what, mimeData, mimeGet) { - what = what === undefined ? this : what; - mimeData = mimeData === undefined ? "application/x-www-form-urlencoded" : mimeData; - mimeGet = mimeGet === undefined ? "text/plain" : mimeGet; - - var req = new xhrMod.XMLHttpRequest(); - console.log("req = " + req.toSource()); - req.open("POST", URL, true); - - req.overrideMimeType(mimeGet); - req.setRequestHeader("Content-type", mimeData); - req.onreadystatechange = function(aEvt) { - if (req.readyState === 4) { - if (req.status === 200) { - console.log("POST success!"); - cb_function.call(what, req); - } else { - console.error("POST failed!"); - } - } - }; - req.send(data); -}; +};
\ No newline at end of file |