forked from paxful/api-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_test.htm
110 lines (99 loc) · 3.48 KB
/
api_test.htm
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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>PAXFUL API TESTER 5000</title>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/hmac-sha256.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
</head>
<body>
<div class="container">
<h1>PAXFUL API TESTER 5000</h1>
<div class="row">
<div class="col-md-4">
<div class="form">
<div class="form-group">
<label for="uri" class="control-label">URL</label>
<div class="input-group">
<span class="input-group-addon">https://paxful.com/api/</span>
<input type="text" name="uri" id="uri" class="form-control" value=""/>
</div>
</div>
<div class="form-group">
<label for="authentication" class="control-label">Authentication Required</label>
<input type="checkbox" value="1" name="require_authentication" id="authentication"/>
</div>
<div style="display: none" id="show-authentication">
<div class="form-group">
<label for="apikey" class="control-label">KEY</label>
<input type="text" name="apikey" id="apikey" class="form-control" />
</div>
<div class="form-group">
<label for="secret" class="control-label">Secret</label>
<input type="text" name="secret" id="secret" class="form-control"/>
</div>
</div>
<div class="form-group">
<label for="POST" class="control-label">PAYLOAD</label>
<textarea id="POST" rows="10" class="form-control"></textarea>
</div>
</div>
<div class="form-actions">
<button class="btn" id="dispatch">SEND</button>
</div>
<div id="generated_url" style="word-break: break-all;"></div>
</div>
<div class="col-md-8">
<h5>RESULT:</h5>
<div id="output" class="well"></div>
</div>
</div>
</div>
<script>
var button = document.getElementById('dispatch'),
authCheck = document.getElementById('authentication');
authCheck.addEventListener('change', function() {
if (this.checked) {
document.getElementById('show-authentication').style.display = 'block';
} else {
document.getElementById('show-authentication').style.display = 'none';
}
});
button.addEventListener('click', function(){
var xhr = new XMLHttpRequest(),
secret = document.getElementById('secret').value,
payload = document.getElementById('POST').value,
authentication = authCheck.checked,
body = 'apikey=' + document.getElementById('apikey').value + '&nonce=' + Date.now();
payload = payload.split("\n").map(Function.prototype.call, String.prototype.trim);
var tmp = [];
for (var i in payload) {
if (payload[i].length > 0) {
tmp.push(payload[i]);
}
}
payload = tmp;
delete tmp;
payload = payload.join('&');
if (payload.length) {
body += '&' + payload;
}
var seal = CryptoJS.HmacSHA256(body, secret);
document.getElementById('output').innerHTML = 'Loading bro, please wait.';
xhr.open('POST', 'https://paxful.com/api/' + document.getElementById('uri').value);
xhr.setRequestHeader('Content-Type', 'text/plain');
xhr.setRequestHeader('Accept', 'application/json');
xhr.onreadystatechange = function() {
document.getElementById('output').innerHTML = xhr.responseText;
}
var url = body + '&apiseal=' + seal;
document.getElementById('generated_url').innerHTML = url;
if (authentication) {
xhr.send(url);
} else {
xhr.send(payload);
}
});
</script>
</body>
</html>