fetch nav categories from Medium

This commit is contained in:
Matthias Kretschmann 2019-06-05 23:19:05 +02:00
parent 493366cca6
commit 6ba91ed109
Signed by: m
GPG Key ID: 606EEEF3C479A91F
3 changed files with 61 additions and 1 deletions

View File

@ -13,6 +13,7 @@
- [Medium](#medium)
- [Get Latest Posts](#get-latest-posts)
- [Get Followers Count](#get-followers-count)
- [Get Categories](#get-categories)
- [YouTube](#youtube)
- [MailChimp](#mailchimp)
- [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
**`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.

View File

@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"scripts": {
"start": "wt serve webtask-youtube.js",
"start": "wt serve webtask-medium.js",
"test": "eslint ./*.js"
},
"dependencies": {

View File

@ -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)