-
Notifications
You must be signed in to change notification settings - Fork 0
/
amiiboapi.js
116 lines (108 loc) · 3.59 KB
/
amiiboapi.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
(function() {
// Create the connector object
var myConnector = tableau.makeConnector();
// Define the schema
myConnector.getSchema = function(schemaCallback) {
var cols = [
{
id: "head",
alias: "Head",
dataType: tableau.dataTypeEnum.string
},
{
id: "tail",
alias: "Tail",
dataType: tableau.dataTypeEnum.string
},
{
id: "amiiboSeries",
alias: "Amiibo Series",
dataType: tableau.dataTypeEnum.string
},
{
id: "character",
alias: "Character",
dataType: tableau.dataTypeEnum.string
},
{
id: "gameSeries",
alias: "Game Series",
dataType: tableau.dataTypeEnum.string
},
{
id: "name",
alias: "Amiibo Name",
dataType: tableau.dataTypeEnum.string
}, {
id: "release_na",
alias: "NA Release Date",
dataType: tableau.dataTypeEnum.date
},
{
id: "release_eu",
alias: "EU Release Date",
dataType: tableau.dataTypeEnum.date
},
{
id: "release_au",
alias: "AU Release Date",
dataType: tableau.dataTypeEnum.date
},
{
id: "release_jp",
alias: "JP Release Date",
dataType: tableau.dataTypeEnum.date
},
{
id: "image",
alias: "Image",
dataType: tableau.dataTypeEnum.string
},
{
id: "type",
alias: "Type",
dataType: tableau.dataTypeEnum.string
}
];
var tableSchema = { // Create tableSchema obj
id: "amiiboapi",
alias: "Amiibo API",
columns: cols
};
schemaCallback([tableSchema]); // Callback function to report the table
};
// Download the data
myConnector.getData = function(table, doneCallback) {
$.getJSON("https://www.amiiboapi.com/api/amiibo/", function(resp) { //GET HTTP request to load data from Amiibo API
var feat = resp.amiibo,
tableData = [];
// Iterate over the JSON object
for (var i = 0, len = feat.length; i < len; i++) {
tableData.push({ // Add to tableData array
"head": feat[i].head,
"tail": feat[i].tail,
"amiiboSeries": feat[i].amiiboSeries,
"character": feat[i].character,
"name": feat[i].name,
"gameSeries": feat[i].gameSeries,
"release_na": feat[i].release.na,
"release_eu": feat[i].release.eu,
"release_au": feat[i].release.au,
"release_jp": feat[i].release.jp,
"image": feat[i].image,
"type": feat[i].type
});
}
table.appendRows(tableData);
doneCallback(); // To indicate data has been gathered
});
};
tableau.registerConnector(myConnector); // Registers the connecter with Tableau
// Create event listeners for when the user clicks the Get Amiibo Data! button
$(document).ready(function() {
$("#submitButton").click(function() {
tableau.connectionName = "Amiibo API"; // Data source name in Tableau
tableau.submit(); // This sends the connector object to Tableau
});
});
})();