curlrequest
Advanced tools
Comparing version 0.1.1 to 0.1.3
46
index.js
var child = require('child_process'); | ||
/** | ||
* Make curl opts friendlier. | ||
*/ | ||
var curl_map = { | ||
retries: 'retry' | ||
, timeout: 'max-time' | ||
, redirects: 'max-redirs' | ||
}; | ||
/** | ||
* Make a request with cURL. | ||
@@ -13,18 +23,17 @@ * | ||
if (arguments.length === 1) { | ||
if (typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} else { | ||
var defaults = options, prev = this; | ||
return function (options, callback) { | ||
if (typeof options === 'object') { | ||
for (var key in defaults) { | ||
if (typeof options[key] === 'undefined') { | ||
options[key] = defaults[key]; | ||
} | ||
} | ||
var defaults = options; | ||
return function (options, callback) { | ||
if (typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} else if (typeof options === 'string') { | ||
options = { url: options }; | ||
} | ||
for (var key in defaults) { | ||
if (typeof options[key] === 'undefined') { | ||
options[key] = defaults[key]; | ||
} | ||
prev.apply(prev, arguments); | ||
}; | ||
} | ||
} | ||
module.exports.call(this, options, callback); | ||
}; | ||
} | ||
@@ -36,2 +45,9 @@ | ||
for (var key in curl_map) { | ||
if (typeof options[key] !== 'undefined') { | ||
options[curl_map[key]] = options[key]; | ||
delete options[key]; | ||
} | ||
} | ||
var curl | ||
@@ -38,0 +54,0 @@ , args = ['--silent', '--show-error', '--no-buffer'] |
{ "name" : "curlrequest", | ||
"description" : "A curl wrapper for node", | ||
"version" : "0.1.1", | ||
"version" : "0.1.3", | ||
"homepage" : "https://github.com/chriso/curlrequest", | ||
@@ -5,0 +5,0 @@ "author" : "Chris O'Hara <cohara87@gmail.com>", |
5633
132