mirror of
https://github.com/oceanprotocol/webtasks
synced 2025-01-08 21:04:03 +01:00
rewrite bounty task
This commit is contained in:
parent
2719ced69f
commit
4c95bd4fad
10
README.md
10
README.md
@ -69,16 +69,12 @@ https://TASK_URL/TASK_NAME/
|
|||||||
|
|
||||||
**Response**
|
**Response**
|
||||||
|
|
||||||
Response is structured by network and fills it with whatever comes back from respective API:
|
Response is structured by network and returns the count of open bounties:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"gitcoin": [
|
"gitcoin": 1,
|
||||||
{...}
|
"bountiesNetwork": 2
|
||||||
],
|
|
||||||
"bountiesNetwork": [
|
|
||||||
{...}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -3,13 +3,15 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "wt serve webtask-mailchimp.js",
|
"start": "wt serve webtask-bounties.js",
|
||||||
"test": "eslint ./*.js"
|
"test": "eslint ./*.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"axios": "^0.18.0",
|
||||||
"body-parser": "^1.18.3",
|
"body-parser": "^1.18.3",
|
||||||
"cors": "^2.8.4",
|
"cors": "^2.8.4",
|
||||||
"express": "^4.16.4",
|
"express": "^4.16.4",
|
||||||
|
"ms": "^2.1.1",
|
||||||
"request": "^2.88.0",
|
"request": "^2.88.0",
|
||||||
"webtask-tools": "^3.4.0"
|
"webtask-tools": "^3.4.0"
|
||||||
},
|
},
|
||||||
|
@ -1,50 +1,52 @@
|
|||||||
'use strict' // eslint-disable-line
|
'use latest'
|
||||||
|
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
const request = require('request')
|
const axios = require('axios')
|
||||||
const webtask = require('webtask-tools')
|
const webtask = require('webtask-tools')
|
||||||
|
const regeneratorRuntime = require('regenerator-runtime') // eslint-disable-line
|
||||||
|
|
||||||
const app = express()
|
const server = express()
|
||||||
|
|
||||||
let cached
|
async function getGitcoin() {
|
||||||
|
try {
|
||||||
|
const response = await axios.get('https://gitcoin.co/api/v0.1/bounties/')
|
||||||
|
|
||||||
const getData = res => {
|
const gitcoinBody = response.data // returns only open bounties by default
|
||||||
// Just chained callbacks in lack of proper async/await support on webtask.io
|
|
||||||
// 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(
|
const gitcoin = gitcoinBody.filter(
|
||||||
// filter the response manually, no way atm to do that as API query
|
// filter the response manually, no way atm to do that as API query
|
||||||
item => item.funding_organisation.includes('Ocean Protocol')
|
item => item.funding_organisation.includes('Ocean Protocol')
|
||||||
)
|
)
|
||||||
|
|
||||||
let holder = {}
|
const data = { gitcoin: gitcoin.length }
|
||||||
|
|
||||||
holder.gitcoin = gitcoin
|
return data
|
||||||
|
} catch (error) {
|
||||||
// Bounties.network bounties
|
console.error(`Error: ${error.reason}`) // eslint-disable-line no-console
|
||||||
request('https://new.api.bounties.network/bounty/?search=ocean%20protocol&bountyStage=1&platform=bounties-network', (error, response, body) => {
|
}
|
||||||
if (error) return
|
|
||||||
|
|
||||||
const bountiesNetwork = JSON.parse(body)
|
|
||||||
holder.bountiesNetwork = bountiesNetwork.results
|
|
||||||
|
|
||||||
cached = holder
|
|
||||||
|
|
||||||
// Send final response
|
|
||||||
res.send(holder)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app.get('/', (req, res) => {
|
async function getBountiesNetwork() {
|
||||||
if (cached) {
|
try {
|
||||||
res.send(cached)
|
const response = await axios.get('https://api.bounties.network/bounty/?search=ocean%20protocol&bountyStage=1&platform=bounties-network')
|
||||||
} else {
|
|
||||||
getData(res)
|
const bountiesNetwork = response.data
|
||||||
|
const data = { bountiesNetwork: bountiesNetwork.results.length }
|
||||||
|
return data
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Error: ${error.reason}`) // eslint-disable-line no-console
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
module.exports = webtask.fromExpress(app)
|
module.exports = webtask.fromExpress(server)
|
||||||
|
Loading…
Reference in New Issue
Block a user