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..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, @@ -75,6 +76,30 @@ 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) { + 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'); + data.should.have.property('currency'); + done(); + }); + }); +}); describe('coinbase.button', function () { it('should generate a new button', function (done) { var param = {