1
0
mirror of https://github.com/oceanprotocol/webtasks synced 2025-01-08 21:04:03 +01:00
webtasks/webtask-bounties.js

51 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-10-16 13:38:08 +02:00
'use strict' // eslint-disable-line
const express = require('express')
const request = require('request')
const webtask = require('webtask-tools')
const app = express()
2018-10-17 14:40:14 +02:00
let cached
const getData = res => {
// Just chained callbacks in lack of proper async/await support on webtask.io
2018-10-16 13:38:08 +02:00
// Gitcoin bounties
request('https://gitcoin.co/api/v0.1/bounties/', (error, response, body) => {
if (error) return error
const gitcoinBody = JSON.parse(body) // returns only open bounties by default
const gitcoin = gitcoinBody.filter(
2018-10-17 14:40:14 +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')
)
let holder = {}
holder.gitcoin = gitcoin
2018-10-16 13:52:28 +02:00
2018-10-16 13:38:08 +02:00
// Bounties.network bounties
2018-10-16 17:06:01 +02:00
request('https://new.api.bounties.network/bounty/?search=ocean%20protocol&bountyStage=1&platform=bounties-network', (error, response, body) => {
2018-10-16 13:38:08 +02:00
if (error) return
const bountiesNetwork = JSON.parse(body)
holder.bountiesNetwork = bountiesNetwork.results
2018-10-17 14:40:14 +02:00
cached = holder
2018-10-16 13:38:08 +02:00
// Send final response
res.send(holder)
})
})
2018-10-17 14:40:14 +02:00
}
app.get('/', (req, res) => {
if (cached) {
res.send(cached)
} else {
getData(res)
}
2018-10-16 13:38:08 +02:00
})
module.exports = webtask.fromExpress(app)