balanced-node-new
Advanced tools
Comparing version 0.4.4 to 0.4.5
@@ -1,2 +0,2 @@ | ||
var balanced = require('../lib_new/balanced'), | ||
var balanced = require('../lib/balanced'), | ||
config = require('./definitions'); | ||
@@ -7,3 +7,3 @@ | ||
// Invalid Test | ||
balanced.bank_account.create({ | ||
new balanced.bank_account().create({ | ||
account_number: '8887776665555', | ||
@@ -22,3 +22,3 @@ routing_number: '100000007', | ||
// Valid Test | ||
balanced.bank_account.create({ | ||
new balanced.bank_account().create({ | ||
account_number: '9900000002', | ||
@@ -35,3 +35,3 @@ routing_number: '021000021', | ||
// Now get an account by ID | ||
balanced.bank_account.id({bank_account_id: res.id}, function(err, bankAccount) { | ||
new balanced.bank_account(res.uri).id(function(err, bankAccount) { | ||
if(err) { | ||
@@ -43,3 +43,3 @@ return console.log(err); | ||
// new customer | ||
balanced.customer.create({ | ||
new balanced.customer().create({ | ||
name: 'John Doe' | ||
@@ -53,6 +53,4 @@ }, function(err, customer) { | ||
// add bank to customer | ||
balanced.customer.add_bank({ | ||
new balanced.customer(customer.uri).add_bank({ | ||
bank_account_uri: bankAccount.uri | ||
}, { | ||
customer_id: customer.id | ||
}, function(err, res) { | ||
@@ -59,0 +57,0 @@ if(err) { |
@@ -55,7 +55,15 @@ function balanced() { | ||
function makeMethods(json) { | ||
scope = {}; | ||
var scope = function(uri) { | ||
this.path = null; | ||
if(typeof uri !== 'undefined') { | ||
this.path = uri; | ||
} | ||
return this; | ||
}; | ||
var method_keys = Object.keys(json.methods); | ||
for(var i = 0; i < method_keys.length; i++) { | ||
var m = json.methods[method_keys[i]]; | ||
scope[method_keys[i]] = createModuleMethod(m, method_keys[i], json); | ||
scope.prototype[method_keys[i]] = createModuleMethod(m, method_keys[i], json); | ||
} | ||
@@ -68,3 +76,3 @@ return scope; | ||
if(arguments.length === 1) { | ||
callback = options; | ||
callback = uriOptions; | ||
options = undefined; | ||
@@ -88,21 +96,25 @@ uriOptions = {}; | ||
if(typeof uriOptions === 'string') { | ||
data.path = uriOptions; | ||
if(this.path !== null) { | ||
data.path = this.path; | ||
} else { | ||
uriOptions.marketplace_uri = $scope.requestOptions.marketplace_uri; | ||
if(uriOptions) { | ||
var pathPieces = data.path.split('/'); | ||
for(var i = 0; i < pathPieces.length; i++) { | ||
if(pathPieces[i].indexOf(':') >= 0) { | ||
var variablePieces = pathPieces[i].substr(1).split('.'); | ||
var newVar = uriOptions; | ||
if(variablePieces.length === 1 && typeof uriOptions != 'object') { | ||
newVar = uriOptions; | ||
} else { | ||
for(var j = 0; j < variablePieces.length; j++) { | ||
newVar = newVar[variablePieces[j]]; | ||
if(typeof uriOptions === 'string') { | ||
data.path = uriOptions; | ||
} else { | ||
uriOptions.marketplace_uri = $scope.requestOptions.marketplace_uri; | ||
if(uriOptions) { | ||
var pathPieces = data.path.split('/'); | ||
for(var i = 0; i < pathPieces.length; i++) { | ||
if(pathPieces[i].indexOf(':') >= 0) { | ||
var variablePieces = pathPieces[i].substr(1).split('.'); | ||
var newVar = uriOptions; | ||
if(variablePieces.length === 1 && typeof uriOptions != 'object') { | ||
newVar = uriOptions; | ||
} else { | ||
for(var j = 0; j < variablePieces.length; j++) { | ||
newVar = newVar[variablePieces[j]]; | ||
} | ||
} | ||
pathPieces[i] = newVar; | ||
data.path = pathPieces.join('/'); | ||
} | ||
pathPieces[i] = newVar; | ||
data.path = pathPieces.join('/'); | ||
} | ||
@@ -109,0 +121,0 @@ } |
{ | ||
"name": "balanced-node-new", | ||
"description": "Offical Balanced Payments API Client for node.js, https://www.balancedpayments.com/docs/api", | ||
"version": "0.4.4", | ||
"version": "0.4.5", | ||
"author": "Balanced Payments / uh-sem-blee, Co. | typefoo", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -39,3 +39,3 @@ Balanced Node.js library | ||
// Create a credit card | ||
balanced.card.create({ | ||
new balanced.card().create({ | ||
card_number: "5105105105105100", | ||
@@ -64,3 +64,3 @@ expiration_year: 2020, | ||
```js | ||
balanced.customer.create({ name: "Valued Customer" }, function (err, newCustomer) { | ||
new balanced.customer().create({ name: "Valued Customer" }, function (err, newCustomer) { | ||
if (err) { | ||
@@ -76,3 +76,3 @@ console.error("customer.create", err); | ||
```js | ||
balanced.customer.add_bank(newCustomer.uri, { | ||
new balanced.customer(newCustomer.uri).add_bank({ | ||
bank_account_uri: <bank_account_uri> | ||
@@ -82,2 +82,2 @@ }, function(err, response){ ... }) | ||
In this API call we use the customer's URI as the request path and a JSON packet of required data. | ||
In this API call we use the customer's URI on the customer object when calling the `add_bank` method with a JSON packet of required data. |
@@ -126,3 +126,3 @@ var https = require('https'), | ||
balanced[action.module][action.method](uriOptions, data, function(err, res) { | ||
new balanced[action.module]()[action.method](uriOptions, data, function(err, res) { | ||
if(err) { | ||
@@ -129,0 +129,0 @@ var ret = { |
39254
1457