synapsepay
Advanced tools
Comparing version 0.5.1 to 0.5.2
@@ -10,7 +10,7 @@ 'use strict'; | ||
* @param user [Object] | ||
* @param options [Object] : can be null (if getting all nodes) or | ||
* @param options [Object] : can be null (if getting all nodes) or | ||
(if getting info on single node) | ||
{ _id: node_id, | ||
full_dehydrate: 'yes' //optional } | ||
* @param callback [function(error, nodeResponseObject)] | ||
full_dehydrate: 'yes' //optional } | ||
* @param callback [function(error, nodeResponseObject)] | ||
**/ | ||
@@ -25,2 +25,3 @@ get(user, options, callback) { | ||
let url = user.json._links.self.href + '/nodes'; | ||
if (options) { | ||
@@ -30,28 +31,58 @@ // if node_id provided | ||
url += '/' + options._id; | ||
const idParams = []; | ||
if (options.force_refresh) { | ||
idParams.push(`force_refresh=${options.force_refresh}`); | ||
} | ||
if (options.full_dehydrate) { | ||
idParams.push(`full_dehydrate=${options.full_dehydrate}`); | ||
} | ||
if (idParams.length > 0) { | ||
url += `?${idParams.join('&')}`; | ||
} | ||
APIClient.get(url, config, (err, json) => { | ||
if (err) { | ||
callback(err); | ||
} else { | ||
callback(null, new Node(user, json)); | ||
} | ||
}); | ||
} else { | ||
const params = []; | ||
if (options.page) { | ||
params.push(`page=${options.page}`); | ||
} | ||
if (options.per_page) { | ||
params.push(`per_page=${options.per_page}`); | ||
} | ||
if (options.type) { | ||
params.push(`type=${options.type}`); | ||
} | ||
if (params.length > 0) { | ||
url += `?${params.join('&')}`; | ||
} | ||
APIClient.get(url, config, (err, json) => { | ||
if (err) { | ||
callback(err); | ||
} else { | ||
callback(null, json); | ||
} | ||
}); | ||
} | ||
if (options.force_refresh && !options.full_dehydrate) { | ||
url += `?full_dehydrate=yes&force_refresh=${options.force_refresh}`; | ||
} | ||
if (options.full_dehydrate) { | ||
url += `?full_dehydrate=${options.full_dehydrate}`; | ||
} | ||
if (options.full_dehydrate && options.force_refresh) { | ||
url += `&force_refresh=${options.force_refresh}`; | ||
} | ||
} | ||
APIClient.get(url, config, (err, json) => { | ||
if (err) { | ||
callback(err); | ||
} else { | ||
if (json.nodes) { | ||
} else { | ||
APIClient.get(url, config, (err, json) => { | ||
if (err) { | ||
callback(err); | ||
} else { | ||
callback(null, json); | ||
} else { | ||
callback(null, new Node(user, json)); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
}, | ||
/** Create a node associated w/ a user | ||
* @param user [Object] | ||
* @param user [Object] | ||
* @param payload [Object] : different depending on node type | ||
@@ -58,0 +89,0 @@ Look at docs for details on format (https://docs.synapsepay.com/docs/add-ach-us-node) |
@@ -26,6 +26,7 @@ 'use strict'; | ||
let url = node.json._links.self.href + '/trans'; | ||
if (options) { | ||
if (options._id) { | ||
url += '/' + options._id; | ||
APIClient.get(url, config, (err, json) => { | ||
@@ -39,2 +40,14 @@ if (err) { | ||
} else { | ||
const params = []; | ||
if (options.page) { | ||
params.push(`page=${options.page}`); | ||
} | ||
if (options.per_page) { | ||
params.push(`per_page=${options.per_page}`); | ||
} | ||
if (params.length > 0) { | ||
url += `?${params.join('&')}`; | ||
} | ||
APIClient.get(url, config, (err, json) => { | ||
@@ -41,0 +54,0 @@ if (err) { |
{ | ||
"name": "synapsepay", | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"description": "Node.js Library for SynapsePay API v3.x Rest", | ||
@@ -5,0 +5,0 @@ "repository": { |
39117
946