forked from 0xtableau/tableau-flipside-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.js
More file actions
56 lines (45 loc) · 1.55 KB
/
sample.js
File metadata and controls
56 lines (45 loc) · 1.55 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
(function () {
var myConnector = tableau.makeConnector();
myConnector.getSchema = function(schemaCallback) {
var cols = [{
id: "symbol",
dataType: tableau.dataTypeEnum.string
}, {
id: "hour",
dataType: tableau.dataTypeEnum.string
}, {
id: "price",
dataType: tableau.dataTypeEnum.float
}];
var tableSchema = {
id: "tokenFeed",
alias: "defi tokens",
columns: cols
};
schemaCallback([tableSchema]);
};
myConnector.getData = function(table, doneCallback) {
var apiCall = "https://api.flipsidecrypto.com/api/v2/queries/77a363ca-4096-4414-82e3-9c5c7f7e6b56/data/latest";
$.getJSON(apiCall, function(resp) {
var response = JSON.parse(JSON.stringify(resp)),
tableData = [];
// Iterate over the JSON object
for (var i = 0, len = response.length; i < len; i++) {
tableData.push({
"symbol": response[i].symbol,
"hour": response[i].hour,
"price": response[i].price
});
}
table.appendRows(tableData);
doneCallback();
});
};
tableau.registerConnector(myConnector);
$(document).ready(function () {
$("#submitButton").click(function () {
tableau.connectionName = "Token Price Feed";
tableau.submit();
});
});
})();