-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.js
More file actions
140 lines (115 loc) · 3.56 KB
/
index.js
File metadata and controls
140 lines (115 loc) · 3.56 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* traitify
* https://github.com/brentertz/traitify
*
* Copyright (c) 2014 Brent Ertz
* Licensed under the MIT license.
*/
/**
* Escape special characters in the given string of html.
*
* @param {String} html
* @return {String}
*/
module.exports = {
host: "your host",
setHost: function(host){
this.host = host;
},
version: "version",
setVersion: function(version){
this.version = version;
},
secretKey: "secretKey",
setSecretKey: function(secretKey){
this.secretKey = secretKey;
this.privateKey = secretKey;
},
privateKey: "secretKey",
setPrivateKey: function(secretKey){
this.secretKey = secretKey;
this.privateKey = secretKey;
},
request: function(method, path, params, callBack){
var http = require('https');
var options = {
'hostname': this.host,
"path":"/" + this.version + path,
"method": method,
"json": true,
"headers": {
"Content-Type":"application/json",
"Accept": "application/json",
"Authorization":'Basic ' + this.secretKey + ':x'
}
}
var request = http.request(options, function (response) {
var responseData = String();
response.on('data', function (chunk) {
responseData += chunk
});
response.on('end', function () {
callBack(JSON.parse(responseData));
});
});
if(params){
params = JSON.stringify(params)
}
request.end(params);
},
get: function(path, params, callBack){
this.request("GET", path, params, callBack);
},
put: function(path, params, callBack){
this.request("PUT", path, params, callBack);
},
post: function(path, params, callBack){
this.request("POST", path, params, callBack);
},
createAssessment: function(deckId, callBack){
this.post("/assessments", {deck_id: deckId }, callBack);
},
getAssessment: function(assessmentId, callBack){
this.get("/assessments/" + assessmentId, String(), callBack);
},
getSlides: function(assessmentId, callBack){
this.get("/assessments/" + assessmentId + "/slides", String(), callBack);
},
addSlide: function(assessmentId, slideId, params, callBack){
this.put("/assessments/" + assessmentId + "/slides/" + slideId, params, callBack);
},
addSlides: function(assessmentId, params, callBack){
this.put("/assessments/" + assessmentId + "/slides", params, callBack);
},
getPersonalityTypes: function(assessmentId, callBack){
this.get("/assessments/" + assessmentId + "/personality_types", String(), callBack);
},
getPersonalityTraits: function(assessmentId, callBack){
this.get("/assessments/" + assessmentId + "/personality_traits/raw", String(), callBack);
},
getCareerMatches: function(assessmentId, params, callBack){
var url = "/assessments/" + assessmentId + "/matches/careers?x=1"
url = this.appendParams(url, params);
this.get(url, String(), callBack);
},
getResults: function(assessmentId, data, params, callBack){
var url = "/assessments/" + assessmentId + "?x=1"
if(data != undefined){
url += "&data=" + data.join(",");
}
url = this.appendParams(url, params);
this.get(url, String(), callBack);
},
appendParams: function(url, params){
if(params["imagePack"] != undefined){
url += "&image_pack=" + params["imagePack"];
}
if(params["numberOfMatches"] != undefined){
url += "&number_of_matches=" + params["numberOfMatches"];
}
if(params["experienceLevels"] != undefined){
url += "&experience_levels=" + params["experienceLevels"];
}
return url;
}
};