Comparing version 0.0.8 to 0.1.0
@@ -6,20 +6,22 @@ var https = require('https'); | ||
function _request(path, params, fn) { | ||
var options = { | ||
host: 'www.dwolla.com' | ||
, path: API_PATH + path | ||
}; | ||
if (params) { | ||
options.path += '?' + qs.stringify(params); | ||
} | ||
var req = https.request(options, function(res) { | ||
function resHandler(fn) { | ||
return function (res) { | ||
var data = ''; | ||
res.on('data', function(chunk) { | ||
res.on('data', function (chunk) { | ||
data += chunk; | ||
}); | ||
res.on('end', function() { | ||
function onEnd() { | ||
res.removeListener('error', onError); | ||
try { | ||
data = JSON.parse(data); | ||
} catch (e) { | ||
fn('Error parsing response from Dwolla API.', data); | ||
var err = new Error('Error parsing response from Dwolla API.'); | ||
err.body = data; | ||
err.exception = e; | ||
fn(err); | ||
} | ||
@@ -29,6 +31,30 @@ if (data.Success) { | ||
} else { | ||
fn(data.Message); | ||
var err = new Error(data.Message); | ||
err.body = data | ||
fn(err); | ||
} | ||
}); | ||
}); | ||
} | ||
function onError(err) { | ||
res.removeListener('end', onEnd) | ||
fn(err) | ||
} | ||
res.once('end', onEnd); | ||
res.once('error', onError); | ||
} | ||
} | ||
function _request(path, params, fn) { | ||
var options = { | ||
host: 'www.dwolla.com' | ||
, path: API_PATH + path | ||
}; | ||
if (params) { | ||
options.path += '?' + qs.stringify(params); | ||
} | ||
var req = https.request(options, resHandler(fn)); | ||
req.end(); | ||
@@ -46,20 +72,3 @@ } | ||
}; | ||
var req = https.request(options, function(res) { | ||
var data = ''; | ||
res.on('data', function(chunk) { | ||
data += chunk; | ||
}); | ||
res.on('end', function() { | ||
try { | ||
data = JSON.parse(data); | ||
} catch (e) { | ||
fn('Error parsing response from Dwolla API.', data); | ||
} | ||
if (data.Success) { | ||
fn(null, data.Response); | ||
} else { | ||
fn(data.Message); | ||
} | ||
}); | ||
}); | ||
var req = https.request(options, resHandler(fn)); | ||
req.write(JSON.stringify(post_data)); | ||
@@ -66,0 +75,0 @@ req.end(); |
@@ -5,3 +5,3 @@ { | ||
"description": "Dwolla API for node.js", | ||
"version": "0.0.8", | ||
"version": "0.1.0", | ||
"repository": { | ||
@@ -13,3 +13,3 @@ "type": "git", | ||
"engines": { | ||
"node": ">=0.4.7 <0.9.0" | ||
"node": ">=0.4.7 <0.10.0" | ||
}, | ||
@@ -22,4 +22,4 @@ "dependencies": {}, | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "mocha -t 6000" | ||
} | ||
} |
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
21167
0
529