-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-interface.html
139 lines (128 loc) · 4.38 KB
/
test-interface.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
<html>
<!-- NOTE: THIS FILE ONLY WORKS FROM A ZESTY.IO DOMAIN DUE TO CORS RESTRICTIONS ON THE REST API -->
<head>
<title>Zesty.io Rest API Fetch Wrapper</title>
<script type="text/javascript" src="/dist/index.js"></script>
<script>
var ZestyAPI = {}
// cookie things
function setCookie(cname, cvalue, exdays) {
var d = new Date()
d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000)
var expires = "expires=" + d.toUTCString()
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"
}
function getCookie(cname) {
var name = cname + "="
var ca = document.cookie.split(";")
for (var i = 0; i < ca.length; i++) {
var c = ca[i]
while (c.charAt(0) == " ") {
c = c.substring(1)
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length)
}
}
return ""
}
function checkCookie() {
var user = getCookie("username")
if (user != "") {
alert("Welcome again " + user)
} else {
user = prompt("Please enter your name:", "")
if (user != "" && user != null) {
setCookie("username", user, 365)
}
}
}
function updateToken(name, value) {
setCookie(name, value)
window.location.reload()
}
if (getCookie("APP_SID") != "") {
console.log("API Instantiated")
ZestyAPI = new Zesty.FetchWrapper(
getCookie("INSTANCE_ZUID"),
getCookie("APP_SID"),
)
console.log(ZestyAPI)
}
async function testMethod(func, resultsID = "results") {
let results = await func
console.log(results)
document.querySelector(`#${resultsID}`).innerText = JSON.stringify(results)
}
function clearResults(resultsID = "results") {
document.querySelector(`#${resultsID}`).innerText = ""
}
</script>
<style>
body,
html {
font-family: Verdana, Geneva, Tahoma, sans-serif;
background: black;
}
</style>
</head>
<body>
<div
style="
padding: 5px 10px;
border-radius: 5px;
background: lightgrey;
display: flex;
"
>
<div style="flex: 5">
<h3>Start testing by setting up an auth cookie!</h3>
<label>Enter your Zesty.io auth token (APP_SID):</label>
<input
type="text"
placeholder="APP SID"
value=""
value=""
onChange="updateToken('APP_SID',this.value)"
/>
<label>Enter your INSTANCE ZUID:</label>
<input
type="text"
placeholder="Instance Zuid"
value=""
onChange="updateToken('INSTANCE_ZUID',this.value)"
/>
<p>
You will find this by logging into accounts.zesty.io, then look at browser
cookies under APP_SID.
</p>
</div>
<div style="flex: 1; padding: 20px; max-width: 100px">
<img src="https://brand.zesty.io/zesty-io-logo.png" width="100%" />
</div>
</div>
<button onclick="testMethod(ZestyAPI.verify())">Verify User</button>
<button onclick="testMethod(ZestyAPI.getInstances())">Get Instance</button>
<button onclick="testMethod(ZestyAPI.getModels())">Get Models</button>
<button onclick="testMethod(ZestyAPI.getViews())">Get Views</button>
<button onclick="testMethod(ZestyAPI.createView('hello-world','mycode'))">
Make View
</button>
<button onclick="testMethod(ZestyAPI.updateView('11-c6a8b7f8ed-wn3gn1','foo bar'))">
Update View
</button>
<button onclick="clearResults()">Clear Results</button>
<pre
id="results"
style="
background: #eee;
padding: 20px;
margin: 10px;
white-space: pre;
overflow: scroll;
font-size: 10px;
font-family: mono;
"
></pre>
</body>
</html>