-
Notifications
You must be signed in to change notification settings - Fork 3
/
info-api.js
67 lines (60 loc) · 2.15 KB
/
info-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
var request = require('request');
var auth = require('./auth');
var helper = require('./helpers');
var c = require('./config.json');
var api = {};
api.createUser = function () {
return new Promise(function (resolve, reject) {
request.post({
'url': c.url + '/users/',
headers: {
'authentication': auth.getAuth()
}
}, helper.handleResponse(resolve, reject));
});
};
api.getLocationDetails = function (city, zipcode, street) {
return new Promise(function (resolve, reject) {
request.get({
'url': `${c.url}/locations/?city=${city}&zipcode=${zipcode}&street=${street}`,
headers: {
'authentication': auth.getAuth()
}
}, helper.handleResponse(resolve, reject));
});
};
api.getRestaurants = function (lat, lon, offset, limit) {
offset = offset === undefined ? 0 : offset;
limit = limit === undefined ? 10000 : limit;
return new Promise(function (resolve, reject) {
request.get({
'url': `${c.url}/restaurants/?lat=${lat}&lon=${lon}&offset=${offset}&limit=${limit}&fields=general%2Crating%2Caddress%2Cavailability%2Cdistance%2Cpayment_methods`,
headers: {
'authentication': auth.getAuth()
}
}, helper.handleResponse(resolve, reject));
});
};
api.getRestaurantDetails = function (id) {
return new Promise(function (resolve, reject) {
request.get({
'url': `${c.url}/restaurants/${id}/`,
headers: {
'authentication': auth.getAuth()
}
}, helper.handleResponse(resolve, reject));
});
};
api.getRestaurantComments = function (id, offset, limit) {
offset = offset === undefined ? 0 : offset;
limit = limit === undefined ? 10000 : limit;
return new Promise(function (resolve, reject) {
request.get({
'url': `${c.url}/restaurants/${id}/comments/?fields=comment&offset=${offset}&limit=${limit}`,
headers: {
'authentication': auth.getAuth()
}
}, helper.handleResponse(resolve, reject));
});
};
module.exports = api;