new endpoint for Medium followers count

This commit is contained in:
Matthias Kretschmann 2018-12-23 15:56:45 +01:00
parent fc226ba570
commit 6bafc615e4
Signed by: m
GPG Key ID: 606EEEF3C479A91F
2 changed files with 34 additions and 0 deletions

View File

@ -11,6 +11,8 @@
- [Tasks](#tasks)
- [Medium](#medium)
- [Get Latest Posts](#get-latest-posts)
- [Get Followers Count](#get-followers-count)
- [YouTube](#youtube)
- [Bounties](#bounties)
- [MailChimp](#mailchimp)
@ -30,6 +32,8 @@
**`webtask-medium.js`**: Generic task to fetch and reconstruct items from any medium publication.
#### Get Latest Posts
Requires the Medium username appended at the end of the url:
```bash
@ -39,6 +43,23 @@ http://localhost:8080/:medium_username
https://TASK_URL/TASK_NAME/:medium_username
```
#### Get Followers Count
```bash
http://localhost:8080/:medium_username/followers
# when published on webtask.io
https://TASK_URL/TASK_NAME/:medium_username/followers
```
**Response**
```json
{
"followers": 2528
}
```
### 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

@ -50,4 +50,17 @@ app.get('/:username/raw', (req, res) => {
})
})
app.get('/:username/followers', (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 { collection } = json.payload
if (error) return
res.send(`{ "followers": ${collection.metadata.followerCount} }`)
})
})
module.exports = webtask.fromExpress(app)