From 92d80ab42ffaa8b382dc6268e0642c8c75af1b52 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Tue, 16 Oct 2018 13:38:08 +0200 Subject: [PATCH] add bounties webtask --- README.md | 27 +++++++++++++++++++++++++++ package.json | 10 +++++----- webtask-bounties.js | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 webtask-bounties.js diff --git a/README.md b/README.md index 3734317..6515bc4 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ - [Tasks](#tasks) - [Medium](#medium) - [YouTube](#youtube) + - [Bounties](#Bounties) - [Zoho](#zoho) - [Campaigns API](#campaigns-api) - [CRM API](#crm-api) @@ -52,6 +53,32 @@ http://localhost:8080/:youtube_playlist_id https://TASK_URL/TASK_NAME/:youtube_playlist_id ``` +### Bounties + +**`webtask-bounties.js`**: Task to fetch open bounties on Gitcoin and Bounties.network in one request. Task creates a unified response from fetching both networks. + +Construct your `/` request url like so, e.g. locally: + +```bash +http://localhost:8080/ + +# when published on webtask.io +https://TASK_URL/TASK_NAME/ +``` + +Response is structured by network and fills it with whatever comes back from respective API: + +```json +{ + "gitcoin": [ + {...} + ], + "bountiesNetwork": [ + {...} + ] +} +``` + ### Zoho **`webtask-zoho.js`**: Generic task to subscribe users into lists on Zoho Campaigns & Zoho CRM. diff --git a/package.json b/package.json index 1780933..6ca0ed9 100644 --- a/package.json +++ b/package.json @@ -3,23 +3,23 @@ "version": "0.1.0", "private": true, "scripts": { - "start": "wt serve webtask-zoho.js", + "start": "wt serve webtask-bounties.js", "test": "eslint ./*.js" }, "dependencies": { "body-parser": "^1.18.3", "cors": "^2.8.4", - "express": "^4.16.3", + "express": "^4.16.4", "request": "^2.88.0", "webtask-tools": "^3.4.0" }, "devDependencies": { - "eslint": "^5.4.0", - "eslint-config-oceanprotocol": "^1.1.1", + "eslint": "^5.7.0", + "eslint-config-oceanprotocol": "^1.2.0", "eslint-config-standard": "^12.0.0", "eslint-plugin-import": "^2.14.0", "eslint-plugin-node": "^7.0.1", - "eslint-plugin-promise": "^4.0.0", + "eslint-plugin-promise": "^4.0.1", "eslint-plugin-security": "^1.4.0", "eslint-plugin-standard": "^4.0.0" } diff --git a/webtask-bounties.js b/webtask-bounties.js new file mode 100644 index 0000000..77d66ec --- /dev/null +++ b/webtask-bounties.js @@ -0,0 +1,39 @@ +'use strict' // eslint-disable-line + +const express = require('express') +const request = require('request') +const webtask = require('webtask-tools') + +const app = express() + +// Just chained callbacks in lack of proper async/await support on webtask.io +app.get('/', (req, res) => { + + // 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( + // filter the response manually, no way atm to do that as API query + item => item.funding_organisation.includes('Ocean Protocol') + ) + + let holder = {} + + holder.gitcoin = gitcoin + + // Bounties.network bounties + request('https://new.api.bounties.network/bounty/?search=ocean%20protocol&bountyStage=1', (error, response, body) => { + if (error) return + + const bountiesNetwork = JSON.parse(body) + holder.bountiesNetwork = bountiesNetwork.results + + // Send final response + res.send(holder) + }) + }) +}) + +module.exports = webtask.fromExpress(app)