-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequestHelper.js
More file actions
118 lines (98 loc) · 2.44 KB
/
RequestHelper.js
File metadata and controls
118 lines (98 loc) · 2.44 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
var Request = require('./Request');
// Constants for accuracy mode
var Accuracy = {
LOW : 0,
NORMAL : 1,
HIGH : 2
};
// Constants for addressing mode
var Addressing = {
EXPLICIT_FROM : 0,
EXPLICIT_TO : 1,
OTHER : 2
};
function RequestHelper() {
// Default values
this.subject = "";
this.headerFrom = "";
this.headerTo = "";
this.headerCC = [];
this.date = new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '');
this.content = "";
this.analysisStrategy = "WTN_EVERYWHERE";
this.addressingMode = "OTHER";
this.attachedFiles = [];
}
RequestHelper.prototype.build = function() {
var postData = {
'Date' : this.date,
'Subject' : this.subject,
'HeaderFrom' : this.headerFrom,
'HeaderTo' : this.headerTo,
'HeaderCC' : this.headerCC,
'AddressingMode' : this.addressingMode,
'AttachedFiles' : this.attachedFiles,
'Content' : this.content,
'AnalysisStrategy' : this.analysisStrategy
};
return new Request(postData);
};
RequestHelper.prototype.withAccuracy = function(accuracy) {
switch(accuracy) {
case Accuracy.LOW:
this.analysisStrategy = "KWAGA_GADGET";
break;
case Accuracy.NORMAL:
this.analysisStrategy = "WTN_EVERYWHERE";
break;
case Accuracy.HIGH:
this.analysisStrategy = "KWAGA_CORE";
break;
}
return this;
};
RequestHelper.prototype.withDate = function(date) {
this.date = date;
return this;
};
RequestHelper.prototype.withSubject = function(subject) {
this.subject = subject;
return this;
};
RequestHelper.prototype.withContent = function(content) {
this.content = content;
return this;
};
RequestHelper.prototype.withHeaderFrom = function(headerFrom) {
this.headerFrom = headerFrom;
return this;
};
RequestHelper.prototype.withHeaderTo = function(headerTo) {
this.headerTo = headerTo;
return this;
};
RequestHelper.prototype.withHeaderCC = function(headerCC) {
this.headerCC.push(headerCC);
return this;
}
RequestHelper.prototype.withAddressingMode = function(mode) {
switch(mode) {
case Addressing.EXPLICIT_FROM:
this.addressingMode = "EXPLICIT_FROM";
break;
case Addressing.EXPLICIT_TO:
this.addressingMode = "EXPLICIT_TO";
break;
default:
this.addressingMode = "OTHER";
break;
}
return this;
}
RequestHelper.prototype.withAttachedFile = function(fileName) {
this.attachedFiles.push(fileName);
return this;
}
module.exports = RequestHelper;
module.exports.Accuracy = Accuracy;
module.exports.Addressing = Addressing;