-
Notifications
You must be signed in to change notification settings - Fork 0
/
includeMessagingPostman.html
139 lines (127 loc) · 6.14 KB
/
includeMessagingPostman.html
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
<div class="inline-wrap">
<div class="form-input clearfix blocks half-block required">
<label for="input-text">Dashboard Username:</label>
<input class="postman-env" type="text" value="" id="db_user" />
<div class="help">Your username to signin to Bandwidth Dashboard</div>
</div>
<div class="form-input clearfix blocks half-block required">
<label for="input-text">Dashboard Password:</label>
<input class="postman-env" type="password" value="" id="db_password" />
<div class="help">Your Password to signin to Bandwidth Dashboard</div>
</div>
</div>
<div class="inline-wrap">
<div class="form-input clearfix blocks half-block required">
<label for="input-text">Dashboard Account Id:</label>
<input class="postman-env" type="text" value="" id="db_account_id" />
<div class="help">Your Bandwidth Dashboard Accound ID</div>
</div>
<div class="form-input clearfix blocks half-block required">
<label for="input-text">Dashboard Sub-account Id:</label>
<input class="postman-env" type="text" value="" id="db_subaccount_id" />
<div class="help">Your Bandwidth Dashboard Sub-account Id</div>
</div>
</div>
<div class="inline-wrap">
<div class="form-input clearfix blocks medium-block required">
<label for="input-text">Messaging API User Id:</label>
<input class="postman-env" type="text" value="" id="messaging_user_id" />
<div class="help">Your Messaging API User Id</div>
</div>
<div class="form-input clearfix blocks medium-block required">
<label for="input-text">Messaging API Token:</label>
<input class="postman-env" type="text" value="" id="messaging_api_token" />
<div class="help">Your Messaging API Token</div>
</div>
<div class="form-input clearfix blocks medium-block required">
<label for="input-text">Messaging API Secret:</label>
<input class="postman-env" type="password" value="" id="messaging_api_secret" />
<div class="help">Your Messaging API Secret</div>
</div>
</div>
<div id="postman-container" style="pointer-events: none; opacity: 0.5;">
<div class="postman-run-button"
data-postman-action="collection/import"
data-postman-var-1="e22838c8453c71551be4"
data-postman-param="env%5BBandwidth%20API%20Keys%5D=W3sia2V5IjoidXNlciIsInZhbHVlIjoiIiwiZGVzY3JpcHRpb24iOiIiLCJ0eXBlIjoidGV4dCIsImVuYWJsZWQiOnRydWV9LHsia2V5IjoicGFzc3dvcmQiLCJ2YWx1ZSI6IiIsImRlc2NyaXB0aW9uIjoiIiwidHlwZSI6InRleHQiLCJlbmFibGVkIjp0cnVlfSx7ImtleSI6InVzZXJJZCIsInZhbHVlIjoiIiwiZGVzY3JpcHRpb24iOiIiLCJ0eXBlIjoidGV4dCIsImVuYWJsZWQiOnRydWV9LHsia2V5IjoidG9rZW4iLCJ2YWx1ZSI6IiIsImRlc2NyaXB0aW9uIjoiIiwidHlwZSI6InRleHQiLCJlbmFibGVkIjp0cnVlfSx7ImtleSI6InNlY3JldCIsInZhbHVlIjoiIiwiZGVzY3JpcHRpb24iOiIiLCJ0eXBlIjoidGV4dCIsImVuYWJsZWQiOnRydWV9LHsia2V5Ijoic3ViYWNjb3VudCIsInZhbHVlIjoiIiwiZGVzY3JpcHRpb24iOiIiLCJ0eXBlIjoidGV4dCIsImVuYWJsZWQiOnRydWV9XQ=="></div></div>
</div>
<script type="text/javascript">
function messaging2Page () {
function enableOnChange (functionName) {
console.log('Enabling On Change for elements');
const elements = document.getElementsByClassName("postman-env");
for (let element of elements) {
element.addEventListener("change", functionName, false);
element.addEventListener("keyup", functionName, false);
element.addEventListener("paste", functionName, false);
}
}
function loadPostman () {
console.log('loading postman');
try {
document.getElementById("_pmPostmanRunObject").outerHTML="";
document.getElementById("pm-oip-overlay").outerHTML="";
}
catch (e) {
console.log('Postman was not loaded');
}
(function (p,o,s,t,m,a,n) {
!p[s] && (p[s] = function () { (p[t] || (p[t] = [])).push(arguments); });
!o.getElementById(s+t) && o.getElementsByTagName("head")[0].appendChild((
(n = o.createElement("script")),
(n.id = s+t), (n.async = 1), (n.src = m), n
));
}(window, document, "_pm", "PostmanRunObject", "https://run.pstmn.io/button.js"));
}
function checkAllVal (obj) {
var result = true;
for (var i in obj) {
if (obj[i] === '') {
result = false;
break;
}
}
return result;
}
function updatePostmanEnv (data) {
const success = _pm("env.replace", "Bandwidth API Keys", data);
if (!success) {
_pm("env.create", "Bandwidth API Keys", data);
}
}
function updateMessaging20Env () {
//instead of triggering on button, do onchange (keyup, paste, enter, tab, bbrown will send all this fun stuff)
const user = document.getElementById("db_user").value;
const password = document.getElementById("db_password").value;
const account = document.getElementById("db_account_id").value;
const userId = document.getElementById("messaging_user_id").value;
const token = document.getElementById("messaging_api_token").value;
const secret = document.getElementById("messaging_api_secret").value;
const subaccount = document.getElementById("db_subaccount_id").value;
const envData = {
user : user,
password : password,
account : account,
userId : userId,
token : token,
secret : secret,
subaccount : subaccount
};
console.log(envData);
//INstead of creating, replace. will need update collection to contain default empty enviornment
if (checkAllVal(envData)) {
console.log('All set, updating postman');
updatePostmanEnv(envData);
document.getElementById("postman-container").removeAttribute("style");
}
else {
console.log('Nothing yet');
updatePostmanEnv(envData);
document.getElementById("postman-container").setAttribute("style", "pointer-events: none; opacity: 0.5;");
}
}
loadPostman();
enableOnChange(updateMessaging20Env);
};
messaging2Page();
</script>