Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added default protocol for buildUrl method #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ var screenshotStream = url2png.readURL(url, options);
<td>protocol</td>
<td>string</td>
<td>-</td>
<td>The protocol to use, can be 'https' or 'http' (blank to use protocol relative urls).</td>
<td>The protocol to use, can be 'https' or 'http'. Default 'https'.</td>
</tr>
</tbody>
</table>
Expand Down
18 changes: 9 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ function url2png(apiKey, privateKey) {

function buildURL(url, options) {
options = options || {};
if(typeof url !== 'string') throw new Error('url should be of type string (something like www.google.com)');
if(options.viewport && (typeof options.viewport !== 'string' || !options.viewport.match(/\d+x\d+/))) throw new Error('viewport should be a string with the format "{width}x{height}"');
if(options.fullpage && typeof options.fullpage !== 'boolean') throw new Error('fullpage should be a boolean');
if(options.thumbnail_max_width && typeof options.thumbnail_max_width !== 'number') throw new Error('thumbnail_max_width should be a number in pixels');
if(options.delay && typeof options.delay !== 'number') throw new Error('delay should be a number in seconds');
if(options.force && typeof options.force !== 'boolean') throw new Error('force should be a boolean');
if(options.protocol && options.protocol != 'https' && options.protocol != 'http') throw new Error('protocol should either be "https" or "http"');
options.protocol = options.protocol || '';
if (typeof url !== 'string') throw new Error('url should be of type string (something like www.google.com)');
if (options.viewport && (typeof options.viewport !== 'string' || !options.viewport.match(/\d+x\d+/))) throw new Error('viewport should be a string with the format "{width}x{height}"');
if (options.fullpage && typeof options.fullpage !== 'boolean') throw new Error('fullpage should be a boolean');
if (options.thumbnail_max_width && typeof options.thumbnail_max_width !== 'number') throw new Error('thumbnail_max_width should be a number in pixels');
if (options.delay && typeof options.delay !== 'number') throw new Error('delay should be a number in seconds');
if (options.force && typeof options.force !== 'boolean') throw new Error('force should be a boolean');
if (options.protocol && options.protocol != 'https' && options.protocol != 'http') throw new Error('protocol should either be "https" or "http"');
options.protocol = options.protocol || 'https';

url = 'url=' + encodeURIComponent(url);
var optionsQuery = '';
for(var option in options) {
for (var option in options) {
if (option != 'protocol')
optionsQuery += "&" + [option, options[option]].join('=');
}
Expand Down
64 changes: 30 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
{
"name": "url2png",
"version": "6.0.2",
"description": "node.js API for the URL2PNG online service",
"main": "index.js",
"dependencies": {
"request": ">=2.53.0 <3.0.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/ForbesLindesay/url2png.git"
},
"keywords": [
"url2png",
"url",
"png",
"websnapr",
"shrinktheweb",
"thumbalizr",
"webthumb",
"browsershots",
"cutycapt"
],
"author": {
"name": "Forbes Lindesay"
},
"contributors": [
{ "name": "Pato Jutard", "email": "[email protected]" },
{ "name": "Johnny Halife", "email": "[email protected]" }
],
"license": "BSD"
"name": "@mpurusottamc/url2png",
"version": "6.0.3",
"description": "node.js API for the URL2PNG online service",
"main": "index.js",
"dependencies": {
"request": ">=2.53.0 <3.0.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/mpurusottamc/url2png.git"
},
"keywords": [
"url2png",
"url",
"png",
"websnapr",
"shrinktheweb",
"thumbalizr",
"webthumb",
"browsershots",
"cutycapt"
],
"author": {
"name": "Purusottam Mupunu"
},
"license": "BSD"
}