Last active
December 11, 2015 02:10
-
-
Save oztune/4f0d209d313e094974ea to your computer and use it in GitHub Desktop.
Node.js script for generating Link Peek urls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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