Skip to content

Commit

Permalink
Added the ability to specify HTTP proxies in the Node.js API.
Browse files Browse the repository at this point in the history
  • Loading branch information
GrabzIt committed Jan 17, 2018
1 parent dbbbe29 commit bb6c6b3
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 34 deletions.
43 changes: 27 additions & 16 deletions nodejs/grabzIt/lib/grabzit.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ function GrabzItClient(applicationKey, applicationSecret)
PARAMETER_INVALID_WAIT_FOR_VALUE: 169,
PARAMETER_INVALID_TRANSPARENT_VALUE: 170,
PARAMETER_INVALID_ENCRYPTION_KEY: 171,
PARAMETER_INVALID_NO_ADS: 172,
PARAMETER_INVALID_NO_ADS: 172,
PARAMETER_INVALID_PROXY: 173,
NETWORK_SERVER_OFFLINE: 200,
NETWORK_GENERAL_ERROR: 201,
NETWORK_DDOS_ATTACK: 202,
Expand Down Expand Up @@ -386,7 +387,8 @@ function _getDOCXRequestObject(applicationKey, applicationSecret, url, options,
'browserWidth': '',
'templateVariables': '',
'pageWidth': 0,
'pageHeight': 0
'pageHeight': 0,
'proxy': ''
};

context = _extend(defaults, options);
Expand Down Expand Up @@ -437,7 +439,8 @@ function _getDOCXRequestObject(applicationKey, applicationSecret, url, options,
'target': context['targetElement'],
'tvars': context['templateVariables'],
'width': context['pageWidth'],
'height': context['pageHeight']
'height': context['pageHeight'],
'proxy': context['proxy']
};

requestParams = _addTargetToRequest(requestParams, isPost, target);
Expand All @@ -448,7 +451,7 @@ function _getDOCXRequestObject(applicationKey, applicationSecret, url, options,
+ '|' + parseInt(context['requestAs']) + '|' + context['country'] + '|' + parseInt(context['quality']) + '|' + context['hideElement']
+ '|' + context['exportUrl'] + '|' + context['waitForElement'] + '|' + context['encryptionKey'] + '|' + _toInt(context['noAds'])
+ '|' + context['postData'] + '|' + context['targetElement'] + '|' + context['templateId'] + '|' + context['templateVariables']
+ '|' + context['pageHeight'] + '|' + context['pageWidth'] + '|' + context['browserWidth'];
+ '|' + context['pageHeight'] + '|' + context['pageWidth'] + '|' + context['browserWidth'] + '|' + context['proxy'];

return new Request(url, requestParams, _createFirstSignature(applicationSecret, target, isPost), signaturePartTwo, isPost, startDelay, target);
}
Expand Down Expand Up @@ -483,7 +486,8 @@ function _getPDFRequestObject(applicationKey, applicationSecret, url, options, i
'browserWidth': '',
'templateVariables': '',
'pageWidth': 0,
'pageHeight': 0
'pageHeight': 0,
'proxy': ''
};

context = _extend(defaults, options);
Expand Down Expand Up @@ -536,7 +540,8 @@ function _getPDFRequestObject(applicationKey, applicationSecret, url, options, i
'post': context['postData'],
'tvars': context['templateVariables'],
'width': context['pageWidth'],
'height': context['pageHeight']
'height': context['pageHeight'],
'proxy': context['proxy']
};

requestParams = _addTargetToRequest(requestParams, isPost, target);
Expand All @@ -547,7 +552,7 @@ function _getPDFRequestObject(applicationKey, applicationSecret, url, options, i
+ '|' + parseInt(context['marginRight']) + '|' + context['delay'] + '|' + parseInt(context['requestAs']) + '|' + context['country']
+ '|' + parseInt(context['quality']) + '|' + context['templateId'] + '|' + context['hideElement'] + '|' + context['targetElement']
+ '|' + context['exportUrl'] + '|' + context['waitForElement'] + '|' + context['encryptionKey'] + '|' + _toInt(context['noAds'])
+ '|' + context['postData']+ '|' + context['browserWidth']+ '|' + context['pageHeight']+ '|' + context['pageWidth']+ '|' + context['templateVariables'];
+ '|' + context['postData']+ '|' + context['browserWidth']+ '|' + context['pageHeight']+ '|' + context['pageWidth']+ '|' + context['templateVariables'] + '|' + context['proxy'];

return new Request(url, requestParams, _createFirstSignature(applicationSecret, target, isPost), signaturePartTwo, isPost, startDelay, target);
}
Expand All @@ -564,7 +569,8 @@ function _getTableRequestObject(applicationKey, applicationSecret, url, options,
'country': '',
'exportUrl': '',
'encryptionKey': '',
'postData':''
'postData':'',
'proxy': ''
};

context = _extend(defaults, options);
Expand All @@ -583,15 +589,16 @@ function _getTableRequestObject(applicationKey, applicationSecret, url, options,
'country': context['country'],
'export': context['exportUrl'],
'encryption': context['encryptionKey'],
'post': context['postData']
'post': context['postData'],
'proxy': context['proxy']
};

requestParams = _addTargetToRequest(requestParams, isPost, target);

this.signaturePartOne = applicationSecret + '|' + url + '|';
this.signaturePartTwo = '|' + context['customId'] + '|' + parseInt(context['tableNumberToInclude']) + '|' + _toInt(context['includeAllTables'])
+ '|' + _toInt(context['includeHeaderNames']) + '|' + context['targetElement'] + '|' + context['format'] + '|' + parseInt(context['requestAs'])
+ '|' + context['country'] + '|' + context['exportUrl'] + '|' + context['encryptionKey'] + '|' + context['postData'];
+ '|' + context['country'] + '|' + context['exportUrl'] + '|' + context['encryptionKey'] + '|' + context['postData'] + '|' + context['proxy'];

return new Request(url, requestParams, _createFirstSignature(applicationSecret, target, isPost), signaturePartTwo, isPost, startDelay, target);
}
Expand All @@ -611,7 +618,8 @@ function _getAnimationRequestObject(applicationKey, applicationSecret, url, opti
'quality': -1,
'country': '',
'exportUrl': '',
'encryptionKey': ''
'encryptionKey': '',
'proxy': ''
};

context = _extend(defaults, options);
Expand All @@ -633,13 +641,14 @@ function _getAnimationRequestObject(applicationKey, applicationSecret, url, opti
'country': context['country'],
'quality': parseInt(context['quality']),
'export': context['exportUrl'],
'encryption': context['encryptionKey']
'encryption': context['encryptionKey'],
'proxy': context['proxy']
};

requestParams = _addTargetToRequest(requestParams, isPost, target);

var signaturePartTwo = '|' + parseInt(context['height']) + '|' + parseInt(context['width']) + '|' + context['customId'] + '|' + parseFloat(context['framesPerSecond']) + '|' +parseFloat(context['speed'])
+ '|' + parseInt(context['duration']) + '|' + parseInt(context['repeat']) + '|' + _toInt(context['reverse']) + '|' + parseInt(context['start']) + '|' + context['customWaterMarkId'] + '|' + context['country'] + '|' + parseInt(context['quality']) + '|' + context['exportUrl'] + '|' + context['encryptionKey'];
+ '|' + parseInt(context['duration']) + '|' + parseInt(context['repeat']) + '|' + _toInt(context['reverse']) + '|' + parseInt(context['start']) + '|' + context['customWaterMarkId'] + '|' + context['country'] + '|' + parseInt(context['quality']) + '|' + context['exportUrl'] + '|' + context['encryptionKey'] + '|' + context['proxy'];

return new Request(url, requestParams, _createFirstSignature(applicationSecret, target, isPost), signaturePartTwo, isPost, startDelay, target);
}
Expand All @@ -664,7 +673,8 @@ function _getImageRequestObject(applicationKey, applicationSecret, url, options,
'transparent': 0,
'encryptionKey': '',
'noAds':false,
'postData':''
'postData':'',
'proxy': ''
};

context = _extend(defaults, options);
Expand Down Expand Up @@ -695,7 +705,8 @@ function _getImageRequestObject(applicationKey, applicationSecret, url, options,
'transparent': context['transparent'],
'encryption': context['encryptionKey'],
'noads': _toInt(context['noAds']),
'post': context['postData']
'post': context['postData'],
'proxy': context['proxy']
};

requestParams = _addTargetToRequest(requestParams, isPost, target);
Expand All @@ -704,7 +715,7 @@ function _getImageRequestObject(applicationKey, applicationSecret, url, options,
+ '|' + context['browserWidth'] + '|' + context['customId'] + '|' + context['delay'] + '|' + context['targetElement']
+ '|' + context['customWaterMarkId'] + '|' + _toInt(context['requestAs']) + '|' + context['country'] + '|' + context['quality']
+ '|' + context['hideElement'] + '|' + context['exportUrl'] + '|' + context['waitForElement'] + '|' + _toInt(context['transparent'])
+ '|' + context['encryptionKey'] + '|' + _toInt(context['noAds']) + '|' + context['postData'];
+ '|' + context['encryptionKey'] + '|' + _toInt(context['noAds']) + '|' + context['postData'] + '|' + context['proxy'];

return new Request(url, requestParams, _createFirstSignature(applicationSecret, target, isPost), signaturePartTwo, isPost, startDelay, target);
}
Expand Down
2 changes: 1 addition & 1 deletion nodejs/grabzIt/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grabzit",
"description": "Automatically convert HTML or URL's into images, DOCX or PDF documents. Additionally convert online videos into animated GIF's or convert HTML tables to CSV.",
"version": "3.2.6",
"version": "3.2.8",
"main": "./lib/grabzit",
"keywords": [
"screenshots",
Expand Down
43 changes: 27 additions & 16 deletions nodejs/grabzitdemo/node_modules/grabzit/lib/grabzit.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nodejs/grabzitdemo/node_modules/grabzit/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bb6c6b3

Please sign in to comment.