forked from olin/maraudersmap-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
75 lines (59 loc) · 1.78 KB
/
api.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
;(function () {
function callback(call, cb) {
call.success(function (json) { cb(0, json); }).error(function (err) { cb(err, null); });
}
// API object
var Api = window.Api = {};
Api.getUser = function (username, cb) {
callback($.get('/api/users/' + username), cb);
};
Api.getBind = function (id, cb) {
callback($.get('/api/binds/' + id), cb);
};
Api.getPlace = function (id, cb) {
callback($.get('/api/places/' + id), cb);
};
Api.getBinds = function (cb) {
callback($.get('/api/binds/'), cb);
};
// If extended == true, will expand place and bind in request's return
Api.getPositions = function (extended, cb) {
if (cb == null) {
cb = extended;
extended = false;
}
if (extended) {
callback($.get('/api/positions/?extended'), cb);
} else {
callback($.get('/api/positions/'), cb);
}
};
Api.getPlaces = function (criteria, cb) {
// criteria is optional
if (cb == null) {
cb = criteria;
callback($.get('/api/places/'), cb);
} else {
callback($.get('/api/places/', criteria), cb);
}
};
/* posting */
Api.putUser = function (name, alias, cb) {
var args = {name: name, alias: alias || ''};
callback($.put('/api/users/' + name, args), cb);
};
Api.postPlace = function (floor, name, alias, cb) {
var args = {floor: floor, name: name, alias: alias || ''};
callback($.post('/api/places/', args), cb);
};
Api.postBind = function (username, place_id, x, y, signals, cb) {
var args = {username: username, place: place_id, x: x, y: y};
for (var k in signals)
args['signals[' + k + ']'] = signals[k];
callback($.post('/api/binds/', args), cb);
};
Api.postPosition = function (username, bind_id, cb) {
var args = {username: username, bind: bind_id};
callback($.post('/api/positions/', args), cb);
};
})();