Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
Added accounts method
Browse files Browse the repository at this point in the history
  • Loading branch information
aianus committed May 10, 2014
1 parent 5113ae9 commit b9f1ce3
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/coinbase/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
54 changes: 54 additions & 0 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b9f1ce3

Please sign in to comment.