From b9f1ce30977b7d87fd79cc348bcf366f6fe6b8d2 Mon Sep 17 00:00:00 2001 From: Alex Ianus Date: Fri, 9 May 2014 16:57:20 +0700 Subject: [PATCH] Added accounts method --- lib/coinbase/client.rb | 6 +++++ spec/client_spec.rb | 54 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/lib/coinbase/client.rb b/lib/coinbase/client.rb index 7f58059..5e469be 100644 --- a/lib/coinbase/client.rb +++ b/lib/coinbase/client.rb @@ -32,6 +32,12 @@ def balance options={} h['amount'].to_money(h['currency']) end + def accounts options={} + accts = get '/accounts', options + accts = convert_money_objects(accts) + accts + end + def receive_address options={} get '/account/receive_address', options end diff --git a/spec/client_spec.rb b/spec/client_spec.rb index a1aefe6..2df9137 100644 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -39,6 +39,60 @@ a.callback_url.should == "http://example.com/callback" end + it "should list accounts" do + accounts_response = <<-eos + { + "accounts": [ + { + "id": "536a541fa9393bb3c7000023", + "name": "My Wallet", + "balance": { + "amount": "50.00000000", + "currency": "BTC" + }, + "native_balance": { + "amount": "500.12", + "currency": "USD" + }, + "created_at": "2014-05-07T08:41:19-07:00", + "primary": true, + "active": true + }, + { + "id": "536a541fa9393bb3c7000034", + "name": "Savings", + "balance": { + "amount": "0.00000000", + "currency": "BTC" + }, + "native_balance": { + "amount": "0.00", + "currency": "USD" + }, + "created_at": "2014-05-07T08:50:10-07:00", + "primary": false, + "active": true + } + ], + "total_count": 2, + "num_pages": 1, + "current_page": 1 + } + eos + + fake :get, '/accounts', JSON.parse(accounts_response) + r = @c.accounts + r.total_count.should == 2 + primary_account = r.accounts.select { |acct| acct.primary }.first + primary_account.id.should == "536a541fa9393bb3c7000023" + primary_account.balance.should == 50.to_money("BTC") + + # Make sure paging works + fake :get, '/accounts?page=2', JSON.parse(accounts_response) + r = @c.accounts :page => 2 + FakeWeb.last_request.path.should include("page=2") + end + # Buttons it "should create a new button" do