aboutsummaryrefslogtreecommitdiffstats
path: root/lib/main.js
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2010-06-30 01:13:19 +0200
committerMatěj Cepl <mcepl@redhat.com>2010-06-30 01:13:19 +0200
commit10ba5aaadd5c4f4bc5a769c2778ef26f952bb5a7 (patch)
tree09761465da097e065c398d2805332d8b7447dcae /lib/main.js
parent984c66b9db41ccb8d338df993cf16cde2ff68068 (diff)
downloadbugzilla-triage-10ba5aaadd5c4f4bc5a769c2778ef26f952bb5a7.tar.gz
Use 'request' module instead of home brewed load{Text,JSON} and httpPOST
Diffstat (limited to 'lib/main.js')
-rw-r--r--lib/main.js71
1 files changed, 38 insertions, 33 deletions
diff --git a/lib/main.js b/lib/main.js
index 3d59d6e..71e4dee 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -17,6 +17,7 @@ var myStorage = require("simple-storage").storage;
var browser = require("tab-browser");
var urlMod = require("url");
var selfMod = require("self");
+var Request = require("request").Request;
var preferences = require("preferences-service");
var BSTPrefNS = require("bzpage").BSTPrefNS;
// Use my JSON for now before it is fixed for general public
@@ -32,7 +33,6 @@ var config = {};
config.matches = matchesAll.matches;
config.skipMatches = matchesAll.skipMatches;
})();
-console.log("config.matches = " + config.matches.toSource());
// ==============================================================
// https://wiki.mozilla.org/Labs/Jetpack/JEP/24
var WillBemanifest = {
@@ -76,7 +76,6 @@ function skipThisPage(doc) {
var hostname = urlMod.URL(doc.location.href).host;
if (REArr) {
var bugNo = REArr[1];
- console.log("bugNo = " + bugNo + ", hostname = " + hostname);
var emailsSent = doc.
querySelector("#bugzilla-body > dl:nth-of-type(1)").textContent;
emailsSent = emailsSent.replace(/^(\s*)$/mg,"");
@@ -87,48 +86,54 @@ function skipThisPage(doc) {
function initialize(callback) {
var prefName = BSTPrefNS+"JSONURL";
- var url = "";
+ var urlStr = "";
if (preferences.isSet(prefName)) {
- url = preferences.get(prefName);
+ urlStr = preferences.get(prefName);
} else {
- url = JSONURLDefault;
+ urlStr = JSONURLDefault;
preferences.set(prefName, JSONURLDefault);
}
- util.loadJSON(url, function(parsedData) {
- config.gJSONData = parsedData;
+ Request({
+ url: urlStr,
+ onComplete: function () {
+ config.gJSONData = this.response.json;
- var keys = "", key = "";
- for (key in config.gJSONData) {
- keys += key + " ";
- }
- console.log("loaded JSON object keys: " + keys);
-
- // Get card translation table
- if ("downloadJSON" in config.gJSONData.configData) {
- var URLsList = config.gJSONData.configData.downloadJSON;
- for (var dwnldObj in URLsList) {
- console.log("Downloading " +
- dwnldObj + " from URL " +
- URLsList[dwnldObj] + ".");
- util.loadJSON(URLsList[dwnldObj],function(response){
- config[dwnldObj] = response;
- });
+ var keys = "", key = "";
+ for (key in config.gJSONData) {
+ keys += key + " ";
}
- };
+ console.log("loaded JSON object keys: " + keys);
- if (!myStorage.logs) {
- console.log("myStorage.logs empty!");
- myStorage.logs = {};
- }
+ // Get additional tables
+ if ("downloadJSON" in config.gJSONData.configData) {
+ var URLsList = config.gJSONData.configData.downloadJSON;
+ for (var dwnldObj in URLsList) {
+ console.log("Downloading " +
+ dwnldObj + " from URL " +
+ URLsList[dwnldObj] + ".");
+ Request({
+ url: URLsList[dwnldObj],
+ onComplete: function() {
+ config[dwnldObj] = this.response.json;
+ }
+ }).get();
+ }
+ };
- var logConstructor = logger.Logger;
- config.logger = new logConstructor(myStorage.logs,
- JSON.parse(selfMod.data.load("bugzillalabelAbbreviations.json")));
+ if (!myStorage.logs) {
+ console.log("myStorage.logs empty!");
+ myStorage.logs = {};
+ }
+
+ var logConstructor = logger.Logger;
+ config.logger = new logConstructor(myStorage.logs,
+ JSON.parse(selfMod.data.load("bugzillalabelAbbreviations.json")));
- callback(config);
- }, this);
+ callback(config);
+ }
+ }).get();
}
exports.main = function main(options, callbacks) {