-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
27 lines (23 loc) · 1.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
var request = require('request'),
crypto = require('crypto');
var screenshotBaseUrl = 'https://api.screenshotmachine.com/?';
var pdfBaseUrl = 'https://pdfapi.screenshotmachine.com/?';
module.exports.generateScreenshotApiUrl = function(customerKey, secretPhrase, options) {
return generateUrl(screenshotBaseUrl, customerKey, secretPhrase, options);
}
module.exports.generatePdfApiUrl = function(customerKey, secretPhrase, options) {
return generateUrl(pdfBaseUrl, customerKey, secretPhrase, options);
}
function generateUrl(baseUrl, customerKey, secretPhrase, options) {
var apiUrl = baseUrl + 'key=' + customerKey;
if (secretPhrase != null && secretPhrase.trim().length > 0) {
apiUrl = apiUrl + '&hash=' + crypto.createHash('md5').update(options['url'] + secretPhrase).digest("hex");
}
for(var param in options) {
apiUrl = apiUrl + '&' + param + '=' + encodeURIComponent(options[param]);
}
return apiUrl;
}
module.exports.readScreenshot = function(url) {
return request(url);
}