2020-06-16 11:12:27 +02:00
|
|
|
import fetch from 'node-fetch'
|
|
|
|
import { log, logError } from '../utils'
|
2019-05-14 20:52:48 +02:00
|
|
|
|
2020-06-16 11:12:27 +02:00
|
|
|
export default async function fetchMedium() {
|
2020-06-16 12:32:47 +02:00
|
|
|
const url = 'https://medium.com/oceanprotocol?format=json'
|
|
|
|
const start = Date.now()
|
|
|
|
const response = await fetch(url)
|
2019-05-14 20:52:48 +02:00
|
|
|
|
2020-06-16 12:32:47 +02:00
|
|
|
if (response.status !== 200) {
|
|
|
|
logError(`Non-200 response code from Medium: ${response.status}`)
|
|
|
|
return null
|
|
|
|
}
|
2019-05-14 20:52:48 +02:00
|
|
|
|
2020-06-16 12:32:47 +02:00
|
|
|
const responseText = await response.text()
|
|
|
|
const json = await JSON.parse(responseText.replace('])}while(1);</x>', ''))
|
|
|
|
const { collection } = json.payload
|
2019-05-14 20:52:48 +02:00
|
|
|
|
2020-06-16 12:32:47 +02:00
|
|
|
const followers = collection.metadata.followerCount
|
2019-05-14 20:52:48 +02:00
|
|
|
|
2020-06-16 12:32:47 +02:00
|
|
|
log(
|
2020-06-16 15:16:31 +02:00
|
|
|
'✓ Medium. ' +
|
2020-06-16 12:32:47 +02:00
|
|
|
`Total: ${followers} followers. ` +
|
|
|
|
`Elapsed: ${new Date() - start}ms`
|
|
|
|
)
|
2019-05-14 20:52:48 +02:00
|
|
|
|
2020-06-16 12:32:47 +02:00
|
|
|
return { followers }
|
2019-05-14 20:52:48 +02:00
|
|
|
}
|