1
0
mirror of https://github.com/oceanprotocol/webtasks synced 2024-11-24 02:55:13 +01:00
webtasks/README.md

241 lines
6.6 KiB
Markdown
Raw Normal View History

2018-06-22 12:46:38 +02:00
[![banner](https://raw.githubusercontent.com/oceanprotocol/art/master/github/repo-banner%402x.png)](https://oceanprotocol.com)
<h1 align="center">webtasks</h1>
2018-03-20 18:12:48 +01:00
2018-03-21 13:16:55 +01:00
> 🐬 Ocean Protocol's webtasks doing automatic things for us via webtask.io
2018-03-20 18:34:32 +01:00
![giphy](https://user-images.githubusercontent.com/90316/37671913-0eb2f70a-2c6d-11e8-809e-04d3b40ef1c9.gif)
2018-03-20 18:12:48 +01:00
[![Build Status](https://travis-ci.com/oceanprotocol/webtasks.svg?token=3psqw6c8KMDqfdGQ2x6d&branch=master)](https://travis-ci.com/oceanprotocol/webtasks)
2018-08-15 17:06:57 +02:00
[![js oceanprotocol](https://img.shields.io/badge/js-oceanprotocol-7b1173.svg)](https://github.com/oceanprotocol/eslint-config-oceanprotocol) [![Greenkeeper badge](https://badges.greenkeeper.io/oceanprotocol/webtasks.svg)](https://greenkeeper.io/)
2018-03-20 18:12:48 +01:00
2018-06-22 12:46:38 +02:00
## Table of Contents
- [Tasks](#tasks)
- [Medium](#medium)
- [YouTube](#youtube)
2018-10-20 03:19:36 +02:00
- [Bounties](#bounties)
- [MailChimp](#mailchimp)
2018-06-22 12:46:38 +02:00
- [Zoho](#zoho)
- [Campaigns API](#campaigns-api)
2018-06-26 13:57:39 +02:00
- [CRM API](#crm-api)
2018-06-22 12:46:38 +02:00
- [Development](#development)
- [Deployment](#deployment)
- [Authors](#authors)
- [License](#license)
---
2018-03-20 18:12:48 +01:00
## Tasks
### Medium
2018-03-20 18:34:32 +01:00
**`webtask-medium.js`**: Generic task to fetch and reconstruct items from any medium publication.
2018-06-22 12:46:38 +02:00
Requires the Medium username appended at the end of the url:
2018-03-20 18:34:32 +01:00
2018-06-22 12:46:38 +02:00
```bash
http://localhost:8080/:medium_username
2018-03-20 18:34:32 +01:00
2018-06-22 12:46:38 +02:00
# when published on webtask.io
https://TASK_URL/TASK_NAME/:medium_username
2018-03-21 12:43:05 +01:00
```
### YouTube
2018-03-21 12:43:05 +01:00
2018-10-31 13:07:48 +01:00
**`webtask-youtube.js`**: Generic task to fetch and reconstruct items from any YouTube account. YouTube API key is provided via [secret environment variable](https://webtask.io/docs/issue_parameters) `YOUTUBE_API_KEY` setup in web editor of webtask.io.
2018-03-21 12:43:05 +01:00
2018-10-31 13:07:48 +01:00
* `/playlist/:playlistId`: returns all videos in the given playlist.
* `/channel/:channelId`: returns latest 10 videos in the given channel, sorted by date.
Construct your `GET` request urls like so:
2018-03-21 12:43:05 +01:00
2018-06-22 12:46:38 +02:00
```bash
2018-10-31 13:07:48 +01:00
http://localhost:8080/playlist/:youtube_playlist_id
http://localhost:8080/channel/:youtube_channel_id
2018-03-21 12:43:05 +01:00
2018-06-22 12:46:38 +02:00
# when published on webtask.io
2018-10-31 13:07:48 +01:00
https://TASK_URL/TASK_NAME/playlist/:youtube_playlist_id
https://TASK_URL/TASK_NAME/channel/:youtube_channel_id
```
**Response**
For all endpoints, response is reconstructed in the same format:
```json
[{
"id": "8EMowpNlWPE",
"title": "Fang Gong, Researcher - Bringing Privacy to Ocean Protocol",
"description": "At Ocean Protocol, we unlock data for AI and use TCRs to maintain a registry of high-quality data sets through voting. Privacy is essential to protecting the ...",
"imageUrl": "https://i.ytimg.com/vi/8EMowpNlWPE/mqdefault.jpg",
"videoUrl": "https://www.youtube.com/watch?v=8EMowpNlWPE"
},
{
...
}]
2018-03-20 18:34:32 +01:00
```
2018-03-20 18:12:48 +01:00
2018-10-31 14:02:37 +01:00
If you want to get the original response returned from YouTube API, append `/raw` at the end of your request, e.g.:
```
https://TASK_URL/TASK_NAME/playlist/:youtube_playlist_id/raw
```
2018-10-16 13:38:08 +02:00
### 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/
```
2018-10-21 17:43:33 +02:00
**Response**
2018-10-24 07:50:21 +02:00
Response is structured by network and returns the count of open bounties:
2018-10-16 13:38:08 +02:00
```json
{
2018-10-24 07:50:21 +02:00
"gitcoin": 1,
"bountiesNetwork": 2
2018-10-16 13:38:08 +02:00
}
```
2018-10-20 03:19:36 +02:00
### MailChimp
**`webtask-mailchimp.js`**: Task to add a new newsletter subscriber.
2018-10-21 17:43:33 +02:00
Construct your `POST /newsletter` request url like so, e.g. locally:
2018-10-20 03:19:36 +02:00
```bash
http://localhost:8080/newsletter/jelly@mcjellyfish.com
# when published on webtask.io
https://TASK_URL/TASK_NAME/newsletter/jelly@mcjellyfish.com
```
2018-10-21 17:43:33 +02:00
**Response**
When subscription is successful:
```json
{ "status": "created" }
```
When subscriber already exists:
```json
{ "status": "exists" }
```
All errors from MailChimp (when `"status"` is a number) are simply passed through and follow the MailChimp API error responses, e.g.:
```json
{
"type": "http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/",
"title": "Forgotten Email Not Subscribed",
"status": 400,
"detail": "matthias@bigchaindb.com was permanently deleted and cannot be re-imported. The contact must re-subscribe to get back on the list.",
"instance": "06171156-4bca-4b6c-a84f-aa3690a82798"
}
```
### Zoho
2018-06-22 12:46:38 +02:00
**`webtask-zoho.js`**: Generic task to subscribe users into lists on Zoho Campaigns & Zoho CRM.
2018-06-22 12:46:38 +02:00
Credentials are provided via [secret environment variables](https://webtask.io/docs/issue_parameters), setup in web editor of webtask.io:
2018-06-22 12:46:38 +02:00
* `ZOHO_CAMPAIGNS_TOKEN`
* `ZOHO_CAMPAIGNS_LIST_KEY`
* `ZOHO_CRM_TOKEN`
#### Campaigns API
2018-06-22 12:46:38 +02:00
* `/newsletter/:data`: subscribes the given email address to the newsletter list on Zoho Campaigns.
The data needs to be in `json` format in the following pattern:
```
2018-06-22 12:46:38 +02:00
{Contact Email:info@oceanprotocol.com}
```
2018-06-22 12:46:38 +02:00
Construct your request url like so, e.g. locally:
```bash
http://localhost:8080/newsletter/:data
2018-06-22 12:46:38 +02:00
# when published on webtask.io
https://TASK_URL/TASK_NAME/newsletter/:data
```
2018-06-26 13:57:39 +02:00
#### CRM API
* `/crm/:data`: subscribes the given email address to the newsletter list on Zoho Campaigns.
The data needs to be in `json` format in the following pattern:
```
{First Name:Jellyfish, Last Name:McJellyfish, Contact Email:info@oceanprotocol.com}
```
Construct your request url like so, e.g. locally:
```bash
http://localhost:8080/crm/:data
# when published on webtask.io
https://TASK_URL/TASK_NAME/crm/:data
```
2018-03-20 18:12:48 +01:00
## Development
```bash
2018-03-21 12:43:05 +01:00
npm install wt-cli -g
2018-03-20 18:12:48 +01:00
npm start
```
2018-03-21 13:16:55 +01:00
And go to [localhost:8080](http://localhost:8080)
2018-03-20 18:12:48 +01:00
## Deployment
2018-03-20 18:34:32 +01:00
All tasks are running serverless on webtask.io where you can login with your GitHub account. Then interact with it locally with the `wt-cli`:
```bash
npm install wt-cli -g
wt init YOUR_GITHUB_EMAIL
2018-03-20 18:12:48 +01:00
2018-03-20 18:34:32 +01:00
wt create webtask-medium.js --name medium
# make sure it's there and get url
wt ls
```
2018-03-20 18:12:48 +01:00
2018-03-21 12:43:05 +01:00
## Authors
- Matthias Kretschmann ([@kremalicious](https://github.com/kremalicious)) - [BigchainDB](https://www.bigchaindb.com) & [Ocean Protocol](https://oceanprotocol.com)
2018-03-21 13:16:55 +01:00
- initial Medium web task by Pedro Gomes ([@pedrouid](https://github.com/pedrouid)) - [Balance](https://balance.io)
2018-03-21 12:43:05 +01:00
2018-03-20 18:12:48 +01:00
## License
```
Copyright 2018 Ocean Protocol Foundation Ltd.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```