-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb-jsonbin.js
46 lines (42 loc) · 1.33 KB
/
db-jsonbin.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
class DBJsonBin extends DB {
saveSelectedStocks(data) {
console.log("Saving");
$.ajax({
url: 'https://api.jsonbin.io/b/' + jsonbin_selected_stocks_bin_id,
type: 'PUT',
contentType: 'application/json',
headers: {
'secret-key': jsonbin_key
},
data: JSON.stringify({'selectedStocks': data}),
success: (data) => {
console.log(data);
},
error: (err) => {
console.log(err.responseJSON);
}
});
}
loadSelectedStocks(callback) {
$.ajax({
url: 'https://api.jsonbin.io/b/' + jsonbin_selected_stocks_bin_id + '/latest',
type: 'GET',
headers: {
'secret-key': jsonbin_key
},
success: (data) => {
console.log(data);
callback(data.selectedStocks);
},
error: (err) => {
if (err.status == 422) {
alert("There is no bin for selected stocks. Will not be able to persist them");
callback({});
}
else
alert("An error occured loading selected stocks");
console.log(err.responseJSON);
}
});
}
}