Skip to content

Instantly share code, notes, and snippets.

@oztune
Last active December 11, 2015 02:10
Show Gist options
  • Save oztune/4f0d209d313e094974ea to your computer and use it in GitHub Desktop.
Save oztune/4f0d209d313e094974ea to your computer and use it in GitHub Desktop.
Node.js script for generating Link Peek urls
function linkPeek(apiKey, secret) {
return function getUrl(uri, queryParams) {
queryParams = Object.assign({
size: 'original'
}, queryParams)
const token = md5(secret + uri + queryParams.size)
const extraParams = queryParams && Object.keys(queryParams).map(param => `${param}=${encodeURIComponent(queryParams[param])}`).join('&')
return `https://linkpeek.com/api/v1?uri=${encodeURIComponent(uri)}&apikey=${apiKey}&token=${token}${extraParams ? `&${extraParams}` : ''}`
}
function md5(string) {
return require('crypto').createHash('md5').update(string).digest("hex")
}
}
// Usage:
// linkPeek('apikey', 'secret')('http://url.com', { size: '100x100' })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment