mirror of
https://github.com/oceanprotocol/webtasks
synced 2025-01-08 21:04:03 +01:00
fetch nav categories from Medium
This commit is contained in:
parent
493366cca6
commit
6ba91ed109
38
README.md
38
README.md
@ -13,6 +13,7 @@
|
|||||||
- [Medium](#medium)
|
- [Medium](#medium)
|
||||||
- [Get Latest Posts](#get-latest-posts)
|
- [Get Latest Posts](#get-latest-posts)
|
||||||
- [Get Followers Count](#get-followers-count)
|
- [Get Followers Count](#get-followers-count)
|
||||||
|
- [Get Categories](#get-categories)
|
||||||
- [YouTube](#youtube)
|
- [YouTube](#youtube)
|
||||||
- [MailChimp](#mailchimp)
|
- [MailChimp](#mailchimp)
|
||||||
- [Zoho](#zoho)
|
- [Zoho](#zoho)
|
||||||
@ -59,6 +60,43 @@ https://TASK_URL/TASK_NAME/:medium_username/followers
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
#### Get Categories
|
||||||
|
|
||||||
|
Reflecting the navigation categories used in the blog.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
http://localhost:8080/:medium_username/categories
|
||||||
|
|
||||||
|
# when published on webtask.io
|
||||||
|
https://TASK_URL/TASK_NAME/:medium_username/categories
|
||||||
|
```
|
||||||
|
|
||||||
|
**Response**
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"title": "Product",
|
||||||
|
"url": "https://blog.oceanprotocol.com/product/home"
|
||||||
|
}, {
|
||||||
|
"title": "Community",
|
||||||
|
"url": "https://blog.oceanprotocol.com/community/home"
|
||||||
|
}, {
|
||||||
|
"title": "Deep Tech",
|
||||||
|
"url": "https://blog.oceanprotocol.com/deep-tech/home"
|
||||||
|
}, {
|
||||||
|
"title": "People",
|
||||||
|
"url": "https://blog.oceanprotocol.com/people/home"
|
||||||
|
}, {
|
||||||
|
"title": "Token Launch",
|
||||||
|
"url": "https://blog.oceanprotocol.com/token/home"
|
||||||
|
}, {
|
||||||
|
"title": "Use Cases",
|
||||||
|
"url": "https://blog.oceanprotocol.com/usecases/home"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
### YouTube
|
### YouTube
|
||||||
|
|
||||||
**`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.
|
**`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.
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "wt serve webtask-youtube.js",
|
"start": "wt serve webtask-medium.js",
|
||||||
"test": "eslint ./*.js"
|
"test": "eslint ./*.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -63,4 +63,26 @@ app.get('/:username/followers', (req, res) => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.get('/:username/categories', (req, res) => {
|
||||||
|
const url = `https://medium.com/${req.params.username}?format=json`
|
||||||
|
|
||||||
|
request(url, (error, response) => {
|
||||||
|
const json = JSON.parse(response.body.replace('])}while(1);</x>', ''))
|
||||||
|
const { navItems } = json.payload.collection
|
||||||
|
const parsedCategories = []
|
||||||
|
let holder = {}
|
||||||
|
|
||||||
|
if (error) return
|
||||||
|
|
||||||
|
for (let i = 0; i < navItems.length; i++) {
|
||||||
|
holder.title = navItems[i].title
|
||||||
|
holder.url = navItems[i].url
|
||||||
|
parsedCategories.push(holder)
|
||||||
|
holder = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
res.send(parsedCategories)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
module.exports = webtask.fromExpress(app)
|
module.exports = webtask.fromExpress(app)
|
||||||
|
Loading…
Reference in New Issue
Block a user