This repository has been archived by the owner on Aug 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
57 lines (52 loc) · 1.87 KB
/
node_helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var NodeHelper = require("node_helper");
var fetcher = require('./fetcher');
module.exports = NodeHelper.create({
socketNotificationReceived: function (notification, payload) {
if (notification === "INIT") {
this.initialize(payload);
} else if (notification === "FETCH_RELEASE") {
this.fetchRelease(payload);
} else if (notification === "FETCH_COLLECTION") {
this.fetchCollection(payload);
} else if (notification === "FETCH_RELEASE") {
this.fetchRelease(payload);
}else if(notification === "FETCH_COLLECTION"){
this.fetchCollection(payload);
}
},
init: function (config) {
var self = this;
if(typeof config != "undefined") {
fetcher.init(config.apiToken, config.username, function (result) {
if (!result) {
self.sendSocketNotification("ERROR", "noCredentialsError");
}
});
}
},
initialize: function (config) {
var self = this;
fetcher.init(config.apiToken, config.username, function (result) {
if (!result) {
self.sendSocketNotification("ERROR", "noCredentialsError");
} else {
self.sendSocketNotification("INIT_COMPLETE");
}
});
},
fetchCollection: function () {
var self = this;
fetcher.fetchCollection(function (ids) {
self.sendSocketNotification("NEW_DATA_IDS", ids);
});
},
fetchRelease: function (id) {
var self = this;
fetcher.fetchDetails(id, function (data) {
if (typeof data === "string" && data.indexOf("error") != -1) {
self.sendSocketNotification("ERROR", "fetchingError");
}
self.sendSocketNotification("NEW_DATA_RELEASE", data);
});
}
});