-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
48 lines (46 loc) · 1.59 KB
/
index.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
const request = require("./services/_request");
const nutritionix = {
header: {},
base_url: 'https://trackapi.nutritionix.com/v2/',
init: function(app_id,key){
this.header = {
'x-app-key': key,
'x-app-id': app_id,
}
},
natural:{
search: async function(query) {
return request.ajax("POST", `${nutritionix.base_url}natural/nutrients`, { query: query}, nutritionix.header).then(result => {
return result.response;
}).catch(error => {
return { error: error.error }
})
}
},
utils:{
nutrients: async function() {
return request.ajax("GET", `${nutritionix.base_url}utils/nutrients`, { }, nutritionix.header).then(result => {
return result.response;
}).catch(error => {
return { error: error.error }
})
}
},
item:{
byUpc: async function(upc){
return request.ajax("GET", `${nutritionix.base_url}search/item?upc=${upc}`, {}, nutritionix.header).then(result => {
return result.response;
}).catch(error => {
return {error: error.error }
})
},
byId: async function (nix_item_id){
return request.ajax("GET", `${nutritionix.base_url}search/item?nix_item_id=${nix_item_id}`, {}, nutritionix.header).then(result => {
return result.response;
}).catch(error => {
return {error: error.error }
})
}
}
}
module.exports = nutritionix;