-
Notifications
You must be signed in to change notification settings - Fork 0
/
endpoints.js
46 lines (44 loc) · 1.46 KB
/
endpoints.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
const { get } = require('axios')
module.exports = (app) => {
app.get('/pancakeswap/:token', async (request, response) => {
/*
#swagger.tags = ['GET']
#swagger.description = 'Endpoint to get the informations about coin to scrap.'
#swagger.produces = ["application/json"]
#swagger.parameters['token'] = {
description: 'Coin token (e.g. for cryptomines the token should be: 0xD44FD09d74cd13838F137B590497595d6b3FEeA4).',
type: 'string'
}
*/
const retrive = async () => {
try {
const url = `https://api.pancakeswap.info/api/v2/tokens/${request.params.token}`
const fetch = await get(url)
console.log(fetch);
return {
succeed: true,
status: fetch.status,
message: fetch.statusText,
update: fetch.data.updated_at,
content: {
name: fetch.data.data.name,
symbol: fetch.data.data.symbol,
price: fetch.data.data.price
}
}
} catch (error) {
return {
succeed: false,
status: error.response.status,
message: error.response.statusText
}
}
}
const data = await retrive()
if (data.succeed) {
return response.status(200).send(data) // #swagger.responses[200] = { description: 'Success.' }
} else {
return response.status(400).send(data) // #swagger.responses[400] = { description: 'Failure.' }
}
});
}