Skip to content

Instantly share code, notes, and snippets.

@robertcoopercode
Created September 1, 2017 04:21
Show Gist options
  • Save robertcoopercode/fbbfa4ff9c9d26a6e557cdc3ef2e1fbb to your computer and use it in GitHub Desktop.
Save robertcoopercode/fbbfa4ff9c9d26a6e557cdc3ef2e1fbb to your computer and use it in GitHub Desktop.
function getMediumData(callback) {
let mediumData = {};
https.get( {
host: 'medium.com',
path: '/@jaltucher/latest',
headers: {
Accept: 'application/json'
}
}, (response) => {
let rawData = '';
response.on('data', (chunk) => { rawData += chunk; });
response.on('end', () => {
rawData = rawData.replace('])}while(1);</x>', '');
const parsedData = JSON.parse(rawData);
const posts = parsedData['payload']['references']['Post']
for (let i = 1; i <= 3; i++) {
let post = posts[Object.keys(posts)[i-1]];
mediumData['mediumTitle' + i] = post['title'];
mediumData['mediumExcerpt' + i] = post['content']['subtitle'];
mediumData['mediumUrl' + i] = 'https://medium.com/@jaltucher/' + post['uniqueSlug']
}
callback(mediumData);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment