From 942bc2c4870109bcd9a39c34ec3dc4b66cfc179e Mon Sep 17 00:00:00 2001 From: Joe Wegner Date: Wed, 19 Dec 2012 14:12:14 -0600 Subject: [PATCH 1/3] balanced.account.assets completed --- index.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ tests/index.js | 21 +++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/index.js b/index.js index e9d6cbe..802b14b 100644 --- a/index.js +++ b/index.js @@ -108,6 +108,52 @@ module.exports = function(api_secret, marketplace_id) { client("GET", "/v1/marketplaces/"+marketplace_id+"/accounts/"+account_id+"/transactions", cb) + }, + + assets: function(account_id, opts, cb){ + + if(typeof(opts) !== "object"){ + cb = opts + opts = {} + } + + opts.card_limit = opts.card_limit || 10 + opts.bank_account_limit = opts.bank_account_limit || 10 + + var sentinel = 2 + var completed = 0 + + var assets = {} + var errors = [] + + client("GET", "/v1/marketplaces/"+marketplace_id+"/accounts/"+account_id+"/cards?limit="+opts.card_limit, function(err, res) { + if(err) { + errors.push(err); + } else { + assets.cards = res.items + } + + completed++ + + if(completed >= sentinel && typeof(cb) === "function") { + cb(errors.length > 0 ? errors : false, assets) + } + }) + + client("GET", "/v1/marketplaces/"+marketplace_id+"/accounts/"+account_id+"/bank_accounts?limit="+opts.bank_account_limit, function(err, res) { + if(err) { + errors.push(err); + } else { + assets.bank_accounts = res.items + } + + completed++ + + if(completed >= sentinel && typeof(cb) === "function") { + cb(errors.length >= 0 ? errors : false, assets) + } + }) + } }, diff --git a/tests/index.js b/tests/index.js index a050edb..843e571 100644 --- a/tests/index.js +++ b/tests/index.js @@ -294,6 +294,27 @@ describe('balanced', function(){ }) }) + describe('.assets', function(done){ + + it('should get all the cards/bank accounts for this account', function(done){ + + balanced.account.assets(test.account_id, function(err, res){ + + assert.notEqual(res.cards, null, "res.cards is null") + assert.notEqual(res.bank_accounts, null, "res.bank_accounts is null") + assert.equal(res.cards.length > 0, true, "res.cards doesn't have any content") + assert.equal(res.bank_accounts.length > 0, true, "res.bank_accounts doesn't have any content") + + console.log(res) + + done() + + }) + + }) + + }) + }) From 875631fd193b1216dd3dde9eab3f08963d609565 Mon Sep 17 00:00:00 2001 From: Joe Wegner Date: Wed, 19 Dec 2012 14:16:42 -0600 Subject: [PATCH 2/3] Remove debug --- tests/index.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/index.js b/tests/index.js index 843e571..ba38b7d 100644 --- a/tests/index.js +++ b/tests/index.js @@ -305,8 +305,6 @@ describe('balanced', function(){ assert.equal(res.cards.length > 0, true, "res.cards doesn't have any content") assert.equal(res.bank_accounts.length > 0, true, "res.bank_accounts doesn't have any content") - console.log(res) - done() }) From ee313167b3da51e41bcd7c8b4e7c478775c10464 Mon Sep 17 00:00:00 2001 From: Joe Wegner Date: Thu, 20 Dec 2012 08:09:18 -0600 Subject: [PATCH 3/3] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 73e8ed4..67343bd 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,8 @@ All methods take a callback as their last parameter, it's called with an error, * `.underwrite(account_id, underwriting_info, cb)` - adds extra deatils for underwriting purposes * `.get(account_id, cb)` - returns account details * `.transactions(account_id, cb)` - returns object of credits and debits for the account + * `.assets(account_id, options, cb)` - return all cards and bank accounts for the account + * `options` _(optional)_ - Accepts `card_limit` and `bank_account_limit` keys * `.marketplace` * `.accounts(cb)` - get all of the marketplace's accounts * `.debits(cb)` - get all of the marketplace's debits @@ -78,4 +80,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file +THE SOFTWARE.