1
0
mirror of https://github.com/oceanprotocol/webtasks synced 2024-06-26 03:06:46 +02:00
webtasks/webtask-bounties.js

53 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-10-24 07:50:21 +02:00
'use latest'
2018-10-16 13:38:08 +02:00
const express = require('express')
2018-10-24 07:50:21 +02:00
const axios = require('axios')
2018-10-16 13:38:08 +02:00
const webtask = require('webtask-tools')
2018-10-24 07:50:21 +02:00
const regeneratorRuntime = require('regenerator-runtime') // eslint-disable-line
2018-10-16 13:38:08 +02:00
2018-10-24 07:50:21 +02:00
const server = express()
2018-10-16 13:38:08 +02:00
2018-10-24 07:50:21 +02:00
async function getGitcoin() {
try {
const response = await axios.get('https://gitcoin.co/api/v0.1/bounties/')
2018-10-17 14:40:14 +02:00
2018-10-24 07:50:21 +02:00
const gitcoinBody = response.data // returns only open bounties by default
2018-10-16 13:38:08 +02:00
const gitcoin = gitcoinBody.filter(
2018-10-24 07:50:21 +02:00
// filter the response manually, no way atm to do that as API query
2018-10-16 13:38:08 +02:00
item => item.funding_organisation.includes('Ocean Protocol')
)
2018-10-24 07:50:21 +02:00
const data = { gitcoin: gitcoin.length }
2018-10-16 13:52:28 +02:00
2018-10-24 07:50:21 +02:00
return data
} catch (error) {
console.error(`Error: ${error.reason}`) // eslint-disable-line no-console
}
}
2018-10-16 13:38:08 +02:00
2018-10-24 07:50:21 +02:00
async function getBountiesNetwork() {
try {
const response = await axios.get('https://api.bounties.network/bounty/?search=ocean%20protocol&bountyStage=1&platform=bounties-network')
2018-10-17 14:40:14 +02:00
2018-10-24 07:50:21 +02:00
const bountiesNetwork = response.data
const data = { bountiesNetwork: bountiesNetwork.results.length }
return data
} catch (error) {
console.error(`Error: ${error.reason}`) // eslint-disable-line no-console
}
2018-10-17 14:40:14 +02:00
}
2018-10-24 07:50:21 +02:00
server.get('/', async (req, res) => {
try {
const dataGitcoin = await getGitcoin()
const dataBountiesNetwork = await getBountiesNetwork()
const data = Object.assign(dataGitcoin, dataBountiesNetwork)
res.send(data)
} catch (error) {
res.send(error)
2018-10-17 14:40:14 +02:00
}
2018-10-16 13:38:08 +02:00
})
2018-10-24 07:50:21 +02:00
module.exports = webtask.fromExpress(server)