-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadobe-api-helpers.js
157 lines (147 loc) · 4.04 KB
/
adobe-api-helpers.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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
"use strict";
var currentTokenWSSE = '';
var wsse = require('wsse');
var request = require('browser-request');
let username = '';
let password = '';
function setCredentials (userInput, passInput){
username = userInput;
password = passInput;
}
function getCredentials (){
return {username, password};
}
function getNewAuthToken () {
var token = wsse(getCredentials());
currentTokenWSSE = token.getWSSEHeader({ nonceBase64: true });
return currentTokenWSSE;
}
function getHeaders (){
let currentTokenWSSE = getNewAuthToken();
return {
'Content-Type': 'application/x-www-form-urlencoded',
'X-WSSE': currentTokenWSSE
};
}
function constructRequestBodyRSID (report_suites) {
//posting this over AJAX makes things picky for some reason.
//this function manually constructs the POST body to make Adobe happy
//because all my earlier attempts to use querystring or other methods failed.
window.rsid_list = {
"rsid_list": []
};
var stringList = '{"rsid_list":[';
for (var i = 0; i < report_suites.length; i++) {
stringList = stringList + '"' + report_suites[i] + '"';
if (i < report_suites.length - 1) {
stringList = stringList + ",";
}
}
stringList = stringList + ']}';
return stringList;
}
function getListOfReportSuites (callback) {
var options = {
headers: getHeaders(),
uri: 'https://api.omniture.com/admin/1.4/rest/?method=Company.GetReportSuites',
body: "search=&types=standard",
method: 'POST',
json: true
};
request(options, function (err, res, body) {
if (!err) {
report_suites = body.report_suites;
callback(report_suites);
}
else {
console.log(res.statusCode);
displayError(err);
}
});
}
function getListOfEvars (form, callback) {
getNewAuthToken();
request({
headers: getHeaders(),
uri: 'https://api.omniture.com/admin/1.4/rest/?method=ReportSuite.GetEvars',
body: form,
method: 'POST'
}, function (err, res, body) {
if (!err) {
var evarsRaw = body;
let evars = JSON.parse(evarsRaw);
callback(evars, form);
}
else {
console.log(res.statusCode);
displayError(err);
console.log(body);
}
});
}
function getListOfProps (form, callback) {
getNewAuthToken();
request({
headers: getHeaders(),
uri: 'https://api.omniture.com/admin/1.4/rest/?method=ReportSuite.GetProps',
body: form,
method: 'POST'
}, function (err, res, body) {
if (!err) {
var propsRaw = body;
let props = JSON.parse(propsRaw);
callback(props, form);
}
else {
console.log(res.statusCode);
displayError(err);
console.log(body);
}
});
}
function getListOfEvents (form, callback) {
request({
headers: getHeaders(),
uri: 'https://api.omniture.com/admin/1.4/rest/?method=ReportSuite.GetEvents',
body: form,
method: 'POST'
}, function (err, res, body) {
if (!err) {
var eventsRaw = body;
let events = JSON.parse(eventsRaw);
callback(events, form);
}
else {
console.log(res.statusCode);
displayError(err);
console.log(body);
}
});
}
function mapToNameValuePairs(array, nameofVarSlot){
var rsid_mapping = {};
for (let i=0; i<array.length; i++){
var reportSuiteInfo = array[i];
var rsid = reportSuiteInfo.rsid;
var vars = reportSuiteInfo[nameofVarSlot];
var nvp = {};
for (var j=0; j<vars.length; j++){
var presentVariable = vars[j];
nvp[presentVariable.id] = presentVariable;
}
rsid_mapping[rsid] = nvp;
}
return rsid_mapping;
}
var exports = module.exports = {
constructRequestBodyRSID,
setCredentials,
getHeaders,
getNewAuthToken,
getListOfReportSuites,
getListOfEvents,
getListOfEvars,
getListOfProps,
_currentTokenWSSE : function(){return currentTokenWSSE;},
mapToNameValuePairs
};