From 20792c8dc6a9edeaf48ee3f3f671849326b342c0 Mon Sep 17 00:00:00 2001 From: Tramptac Date: Wed, 1 Oct 2014 18:05:49 +0200 Subject: [PATCH 1/2] Add /api/v1/accounts & /api/v1/accounts/balance --- lib/index.js | 18 ++++++++++++++++++ test/index.js | 25 +++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/lib/index.js b/lib/index.js index 71959ba..3b06f77 100644 --- a/lib/index.js +++ b/lib/index.js @@ -144,7 +144,25 @@ function Coinbase (options) { post(url, options, callback); }; + + /* GET /api/v1/accounts/ */ + this.accounts = function (callback) { + var url = self.baseUrl + 'accounts'; + log('get ' + url); + + get(url, callback); + }; + + /* GET /api/v1/accounts/:account_id/balance */ + this.accounts.balance = function (account_id,callback) { + var url = self.baseUrl + 'accounts/'+account_id+'/balance'; + + log('get ' + url); + + get(url, callback); + }; + this.buttons = {}; /* POST https://coinbase.com/api/v1/buttons */ this.buttons.create = function (param, callback) { diff --git a/test/index.js b/test/index.js index dace328..bff3716 100644 --- a/test/index.js +++ b/test/index.js @@ -75,6 +75,31 @@ describe('coinbase.account.generateReceiveAddress', function () { }); }); }); +describe('coinbase.accounts', function () { + it('should return the user\'s accounts', function (done) { + coinbase.accounts(function (err, data) { + if (err) return done(err); + log('data: ' + util.inspect(data, null, 5)); + data.should.have.property('accounts'); + data.should.have.property('total_count'); + data.should.have.property('num_pages'); + data.should.have.property('current_page'); + done(); + }); + }); +}); +describe('coinbase.accounts.balance', function () { + it('should return the user\'s account balance', function (done) { + var account_id = 'SPECIFY_ME'; + coinbase.accounts.balance(account_id, function (err, data) { + if (err) return done(err); + log('data: ' + util.inspect(data, null, 5)); + data.should.have.property('amount'); + data.should.have.property('currency'); + done(); + }); + }); +}); describe('coinbase.button', function () { it('should generate a new button', function (done) { var param = { From 8bf4a3ec25982c667f80c7eb8e2aff374aff3100 Mon Sep 17 00:00:00 2001 From: EtienneTatur Date: Tue, 10 Mar 2015 17:39:05 +0100 Subject: [PATCH 2/2] Update test env var --- test/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/index.js b/test/index.js index bff3716..0df6c80 100644 --- a/test/index.js +++ b/test/index.js @@ -9,6 +9,7 @@ var Coinbase = require('../lib/index'); if (!process.env.COINBASE_API_KEY) throw new Error('You must specify a COINBASE_API_KEY environment variable to run tests'); if (!process.env.COINBASE_API_SECRET) throw new Error('You must specify a COINBASE_API_SECRET environment variable to run tests'); +if (!process.env.COINBASE_ACCOUNT_ID) throw new Error('You must specify a COINBASE_ACCOUNT_ID environment variable to run tests'); var coinbase = new Coinbase({ APIKey: process.env.COINBASE_API_KEY, @@ -90,8 +91,7 @@ describe('coinbase.accounts', function () { }); describe('coinbase.accounts.balance', function () { it('should return the user\'s account balance', function (done) { - var account_id = 'SPECIFY_ME'; - coinbase.accounts.balance(account_id, function (err, data) { + coinbase.accounts.balance(process.env.COINBASE_ACCOUNT_ID, function (err, data) { if (err) return done(err); log('data: ' + util.inspect(data, null, 5)); data.should.have.property('amount');