bitex 0.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +63 -0
  3. data/.rubocop.yml +32 -0
  4. data/.ruby-version +1 -0
  5. data/bitex.gemspec +21 -18
  6. data/lib/bitex.rb +7 -1
  7. data/lib/bitex/api.rb +34 -41
  8. data/lib/bitex/ask.rb +74 -0
  9. data/lib/bitex/base_order.rb +106 -0
  10. data/lib/bitex/bid.rb +72 -0
  11. data/lib/bitex/buy.rb +8 -5
  12. data/lib/bitex/kyc_file.rb +31 -9
  13. data/lib/bitex/kyc_profile.rb +113 -38
  14. data/lib/bitex/{market.rb → market_data.rb} +3 -3
  15. data/lib/bitex/match.rb +30 -15
  16. data/lib/bitex/order.rb +6 -238
  17. data/lib/bitex/payment.rb +30 -18
  18. data/lib/bitex/rates.rb +6 -8
  19. data/lib/bitex/sell.rb +5 -5
  20. data/lib/bitex/specie_deposit.rb +9 -4
  21. data/lib/bitex/specie_withdrawal.rb +29 -28
  22. data/lib/bitex/trade.rb +4 -5
  23. data/lib/bitex/transaction.rb +7 -8
  24. data/lib/bitex/usd_deposit.rb +46 -47
  25. data/lib/bitex/usd_withdrawal.rb +33 -34
  26. data/lib/bitex/version.rb +1 -1
  27. data/spec/ask_spec.rb +17 -5
  28. data/spec/bid_spec.rb +17 -5
  29. data/spec/buy_spec.rb +14 -4
  30. data/spec/kyc_file_spec.rb +34 -18
  31. data/spec/kyc_profile_spec.rb +158 -122
  32. data/spec/order_spec.rb +1 -1
  33. data/spec/payment_spec.rb +51 -45
  34. data/spec/sell_spec.rb +14 -4
  35. data/spec/spec_helper.rb +7 -6
  36. data/spec/specie_deposit_spec.rb +10 -4
  37. data/spec/specie_withdrawal_spec.rb +26 -25
  38. data/spec/support/from_json_shared_examples.rb +20 -22
  39. data/spec/support/order_shared_examples.rb +14 -17
  40. data/spec/support/request_stubs.rb +18 -12
  41. data/spec/trade_spec.rb +5 -5
  42. data/spec/transaction_spec.rb +12 -13
  43. data/spec/usd_deposit_spec.rb +120 -105
  44. data/spec/usd_withdrawal_spec.rb +89 -79
  45. metadata +57 -10
@@ -1,39 +1,36 @@
1
1
  shared_examples_for 'Order' do |api_path|
2
2
  it 'lists all' do
3
- stub_private(:get, "/private/orders", 'orders')
3
+ stub_private(:get, '/private/orders', 'orders')
4
4
  order, empty = subject.class.all
5
5
  order.should be_a subject.class
6
6
  empty.should be_nil
7
7
  end
8
-
8
+
9
9
  it 'gets one' do
10
10
  stub_private(:get, "/private/#{api_path}/12345678", "#{api_path}_show")
11
- order = subject.class.find(12345678)
11
+ order = subject.class.find(12_345_678)
12
12
  order.should be_a subject.class
13
- order.id.should == 12345678
13
+ order.id.should == 12_345_678
14
14
  end
15
-
16
- it 'places for btc' do
17
- stub_private(:post, "/private/#{api_path}", "#{api_path}_create",
18
- {amount: 100.50, price: 1000.00, specie: 1})
19
- order = subject.class.create!(:btc, 100.50, 1000.00)
15
+
16
+ it 'places for btc_usd' do
17
+ stub_private(:post, "/private/#{api_path}", "#{api_path}_create", { amount: 100.50, price: 1000.00, orderbook: 1 })
18
+ order = subject.class.create!(:btc_usd, 100.50, 1_000.00)
20
19
  order.should be_a subject.class
21
20
  order.status.should == :received
22
21
  end
23
22
 
24
- it 'places for btc and waits until processed by our matching engine' do
25
- stub_private(:post, "/private/#{api_path}", "#{api_path}_create",
26
- {amount: 100.50, price: 1000.00, specie: 1})
23
+ it 'places for btc_usd and waits until processed by our matching engine' do
24
+ stub_private(:post, "/private/#{api_path}", "#{api_path}_create", { amount: 100.50, price: 1_000.00, orderbook: 1})
27
25
  stub_private(:get, "/private/#{api_path}/12345678", "#{api_path}_show")
28
- order = subject.class.create!(:btc, 100.50, 1000.00, true)
26
+ order = subject.class.create!(:btc_usd, 100.50, 1_000.00, true)
29
27
  order.should be_a subject.class
30
28
  order.status.should == :executing
31
29
  end
32
-
30
+
33
31
  it 'cancels one' do
34
- stub_private(:post, "/private/#{api_path}", "#{api_path}_create",
35
- {amount: 100.50, price: 1000.00, specie: 1})
36
- order = subject.class.create!(:btc, 100.50, 1000.00)
32
+ stub_private(:post, "/private/#{api_path}", "#{api_path}_create", { amount: 100.50, price: 1_000.00, orderbook: 1})
33
+ order = subject.class.create!(:btc_usd, 100.50, 1_000.00)
37
34
  stub_private(:post, "/private/#{api_path}/#{order.id}/cancel", "#{api_path}_cancel")
38
35
  order.cancel!
39
36
  order.status.should == :cancelling
@@ -1,25 +1,31 @@
1
1
  require 'open-uri'
2
+
2
3
  module RequestStubs
3
4
  def stub_get(path, fixture)
4
5
  stub_api(:get, path, fixture, {})
5
6
  end
6
-
7
+
7
8
  def stub_private(method, path, fixture, options = {})
8
9
  options[:api_key] = 'valid_api_key'
9
10
  stub_api(method, path, fixture, options)
10
11
  end
11
-
12
+
12
13
  def stub_api(method, path, fixture, options)
13
- fixture_path = File.expand_path("../../fixtures/#{fixture}.json", __FILE__)
14
- with = if method == :get
15
- {query: options}
16
- elsif method == :put
17
- {body: options.to_query }
18
- else
19
- {body: options.collect{|k,v| "#{k}=#{CGI.escape(v.to_s).gsub('+','%20')}"}* '&' }
20
- end
14
+ params =
15
+ if method == :get
16
+ { query: options }
17
+ elsif method == :put
18
+ { body: options.to_query }
19
+ else
20
+ { body: options.map { |k, v| "#{k}=#{CGI.escape(v.to_s).gsub('+', '%20')}" } * '&' }
21
+ end
22
+
21
23
  stub_request(method, "https://bitex.la/api-v1/rest#{path}")
22
- .with(with)
23
- .to_return(status: 200, body: File.read(fixture_path))
24
+ .with(params)
25
+ .to_return(status: 200, body: File.read(fixture_path(fixture)))
26
+ end
27
+
28
+ def fixture_path(filename)
29
+ File.expand_path("../../fixtures/#{filename}.json", __FILE__)
24
30
  end
25
31
  end
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Bitex::Trade do
4
- before(:each) do
5
- Bitex.api_key = 'valid_api_key'
6
- end
7
-
4
+ before(:each) { Bitex.api_key = 'valid_api_key' }
5
+
8
6
  it 'gets all trades' do
9
- stub_private(:get, "/private/trades", 'trades')
7
+ stub_private(:get, '/private/trades', :trades)
8
+
10
9
  buy, sell, other = Bitex::Trade.all
10
+
11
11
  buy.should be_a Bitex::Buy
12
12
  sell.should be_a Bitex::Sell
13
13
  other.should be_nil
@@ -1,19 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Bitex::Transaction do
4
- before(:each) do
5
- Bitex.api_key = 'valid_api_key'
6
- end
7
-
4
+ before(:each) { Bitex.api_key = 'valid_api_key' }
5
+
8
6
  it 'gets account summary' do
9
- stub_private(:get, "/private/account_summary", 'account_summary')
10
- buy, sell, specie_deposit, specie_withdrawal, usd_deposit, usd_withdrawal =
11
- Bitex::Transaction.all
12
- buy.should be_a Bitex::Bid
13
- sell.should be_a Bitex::Ask
14
- specie_deposit.should be_a Bitex::SpecieDeposit
15
- specie_withdrawal.should be_a Bitex::SpecieWithdrawal
16
- usd_deposit.should be_a Bitex::UsdDeposit
17
- usd_withdrawal.should be_a Bitex::UsdWithdrawal
7
+ stub_private(:get, '/private/account_summary', :account_summary)
8
+
9
+ buy, sell, specie_deposit, specie_withdrawal, usd_deposit, usd_withdrawal = Bitex::Transaction.all
10
+
11
+ buy.should be_an Bitex::Bid
12
+ sell.should be_an Bitex::Ask
13
+ specie_deposit.should be_an Bitex::SpecieDeposit
14
+ specie_withdrawal.should be_an Bitex::SpecieWithdrawal
15
+ usd_deposit.should be_an Bitex::UsdDeposit
16
+ usd_withdrawal.should be_an Bitex::UsdWithdrawal
18
17
  end
19
18
  end
@@ -1,124 +1,139 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Bitex::UsdDeposit do
4
- before :each do
5
- Bitex.api_key = 'valid_api_key'
6
- end
4
+ before(:each) { Bitex.api_key = 'valid_api_key' }
5
+
6
+ let(:api_class_id) { 7 }
7
+ let(:id) { 12_345_678 }
8
+ let(:created_at) { 946_685_400 }
9
+ let(:requested_amount) { 110.0 }
10
+ let(:amount) { 100.0 }
11
+ let(:deposit_method) { 1 }
12
+ let(:status) { 1 }
13
+ let(:reason) { 0 }
14
+ let(:country) { 'UY' }
15
+ let(:currency) { 'UYU' }
16
+ let(:kyc_profile_id) { 1 }
17
+ let(:request_details) { 'bank of new york mellon' }
18
+ let(:astropay_response_body) { { 'status' => 'OK', 'link' => 'https://astr.com' } }
19
+ let(:third_party_reference) { 'REFERENCE' }
7
20
 
8
21
  let(:as_json) do
9
- [ 7,12345678,946685400,110.0000000, 100.00000000,1,1,0,
10
- 'UY', 'UYU', 1, 'bank of new york mellon',
11
- {"status" => "OK","link" => "https://astr.com"}, 'ABABABABA']
22
+ [api_class_id, id, created_at, requested_amount, amount, deposit_method, status, reason, country,
23
+ currency, kyc_profile_id, request_details, astropay_response_body, third_party_reference]
12
24
  end
13
25
 
14
26
  it_behaves_like 'API class'
15
27
 
16
- it "sets amount as BigDecimal" do
17
- thing = Bitex::UsdDeposit.from_json(as_json).amount
18
- thing.should be_a BigDecimal
19
- thing.should == 100.0
20
- end
28
+ context 'deserializing from json' do
29
+ let(:deposit) { Bitex::UsdDeposit.from_json(as_json) }
21
30
 
22
- it "sets amount as BigDecimal" do
23
- thing = Bitex::UsdDeposit.from_json(as_json).requested_amount
24
- thing.should be_a BigDecimal
25
- thing.should == 110.0
26
- end
27
-
28
- it "sets country" do
29
- Bitex::UsdDeposit.from_json(as_json).country.should == 'UY'
30
- end
31
-
32
- it "sets currency" do
33
- Bitex::UsdDeposit.from_json(as_json).currency.should == 'UYU'
34
- end
35
-
36
- it "sets kyc profile" do
37
- Bitex::UsdDeposit.from_json(as_json).kyc_profile_id.should == 1
38
- end
39
-
40
- it "sets details" do
41
- Bitex::UsdDeposit.from_json(as_json).request_details.should ==
42
- 'bank of new york mellon'
43
- end
44
-
45
- it "sets the astropay_response_body" do
46
- Bitex::UsdDeposit.from_json(as_json).astropay_response_body.should ==
47
- {"status" => "OK","link" => "https://astr.com"}
48
- end
31
+ it 'sets amount as BigDecimal' do
32
+ deposit.amount.should be_an BigDecimal
33
+ deposit.amount.should eq amount
34
+ end
49
35
 
50
- it "sets the third party reference" do
51
- Bitex::UsdDeposit.from_json(as_json).third_party_reference.should == 'ABABABABA'
52
- end
36
+ it 'sets requested amount as BigDecimal' do
37
+ deposit.requested_amount.should be_an BigDecimal
38
+ deposit.requested_amount.should eq requested_amount
39
+ end
53
40
 
54
- { 1 => :astropay,
55
- 2 => :other,
56
- }.each do |code, symbol|
57
- it "sets status #{code} to #{symbol}" do
58
- as_json[5] = code
59
- Bitex::UsdDeposit.from_json(as_json).deposit_method.should == symbol
41
+ it 'sets country' do
42
+ deposit.country.should be_an String
43
+ deposit.country.should eq country
60
44
  end
61
- end
62
45
 
63
- { 1 => :pending,
64
- 2 => :done,
65
- 3 => :cancelled,
66
- }.each do |code, symbol|
67
- it "sets status #{code} to #{symbol}" do
68
- as_json[6] = code
69
- Bitex::UsdDeposit.from_json(as_json).status.should == symbol
46
+ it 'sets currency' do
47
+ deposit.currency.should be_an String
48
+ deposit.currency.should eq currency
70
49
  end
71
- end
72
50
 
73
- { 0 => :not_cancelled,
74
- 1 => :did_not_credit,
75
- 2 => :sender_unknown,
76
- 3 => :other,
77
- 4 => :user_cancelled,
78
- }.each do |code, symbol|
79
- it "sets reason #{code} to #{symbol}" do
80
- as_json[7] = code
81
- Bitex::UsdDeposit.from_json(as_json).reason.should == symbol
51
+ it 'sets kyc profile' do
52
+ deposit.kyc_profile_id.should be_an Integer
53
+ deposit.kyc_profile_id.should be kyc_profile_id
54
+ end
55
+
56
+ it 'sets details' do
57
+ deposit.request_details.should be_an String
58
+ deposit.request_details.should eq request_details
59
+ end
60
+
61
+ it 'sets the astropay_response_body' do
62
+ deposit.astropay_response_body.should be_an Hash
63
+ deposit.astropay_response_body.keys.all? { |key| key.should be_an String }
64
+ deposit.astropay_response_body.values.all? { |value| value.should be_an String }
65
+ deposit.astropay_response_body.should eq astropay_response_body
66
+ end
67
+
68
+ it 'sets the third party reference' do
69
+ deposit.third_party_reference.should be_an String
70
+ deposit.third_party_reference.should eq third_party_reference
71
+ end
72
+
73
+ Bitex::UsdDeposit.deposit_methods.each do |code, deposit_method|
74
+ it "sets deposit_method #{code} to #{deposit_method}" do
75
+ as_json[5] = code
76
+ deposit.deposit_method.should be deposit_method
77
+ end
78
+ end
79
+
80
+ Bitex::UsdDeposit.statuses.each do |code, status|
81
+ it "sets status #{code} to #{status}" do
82
+ as_json[6] = code
83
+ deposit.status.should be status
84
+ end
85
+ end
86
+
87
+ Bitex::UsdDeposit.reasons.each do |code, reason|
88
+ it "sets reason #{code} to #{reason}" do
89
+ as_json[7] = code
90
+ deposit.reason.should be reason
91
+ end
92
+ end
93
+
94
+ it 'creates a new deposit' do
95
+ stub_private(
96
+ :post,
97
+ '/private/usd/deposits',
98
+ :usd_deposit,
99
+ country: country, amount: amount, currency: currency, deposit_method: deposit_method, request_details: request_details
100
+ )
101
+
102
+ deposit = Bitex::UsdDeposit.create!(country, amount, currency, deposit_method, request_details)
103
+
104
+ deposit.should be_an Bitex::UsdDeposit
105
+ deposit.astropay_response_body.should be_an Hash
106
+ deposit.status.should be :pending
107
+ end
108
+
109
+ it 'finds a single usd deposit' do
110
+ stub_private(:get, "/private/usd/deposits/#{id}", :usd_deposit)
111
+
112
+ deposit = Bitex::UsdDeposit.find(id)
113
+
114
+ deposit.should be_an Bitex::UsdDeposit
115
+ deposit.status.should be :pending
116
+ end
117
+
118
+ it 'cancels a deposit' do
119
+ stub_private(:get, "/private/usd/deposits/#{id}", :usd_deposit)
120
+ stub_private(:post, "/private/usd/deposits/#{id}/cancel", :cancelled_usd_deposit)
121
+
122
+ deposit = Bitex::UsdDeposit.find(id).cancel!
123
+
124
+ deposit.should be_an Bitex::UsdDeposit
125
+ deposit.status.should be :cancelled
126
+ deposit.reason.should be :user_cancelled
127
+ end
128
+
129
+ it 'lists all usd deposits' do
130
+ stub_private(:get, '/private/usd/deposits', :usd_deposits)
131
+
132
+ deposits = Bitex::UsdDeposit.all
133
+
134
+ deposits.should be_an Array
135
+ deposits.all? { |deposit| deposit.should be_an Bitex::UsdDeposit }
136
+ deposits.all? { |deposit| deposit.status.should be :pending }
82
137
  end
83
- end
84
-
85
- it 'creates a new deposit' do
86
- stub_private(:post, "/private/usd/deposits", 'usd_deposit', {
87
- country: 'UY',
88
- amount: 110,
89
- currency: 'UYU',
90
- deposit_method: 'astropay',
91
- request_details: 'bank of new york mellon',
92
- })
93
- deposit = Bitex::UsdDeposit.create!('UY', 110, 'UYU', 'astropay',
94
- 'bank of new york mellon')
95
- deposit.should be_a Bitex::UsdDeposit
96
- deposit.astropay_response_body.should be_a Hash
97
- deposit.status.should == :pending
98
- end
99
-
100
- it 'finds a single usd deposit' do
101
- stub_private(:get, '/private/usd/deposits/1', 'usd_deposit')
102
- deposit = Bitex::UsdDeposit.find(1)
103
- deposit.should be_a Bitex::UsdDeposit
104
- deposit.status.should == :pending
105
- end
106
-
107
- it 'cancels a deposit' do
108
- stub_private(:get, '/private/usd/deposits/12345678', 'usd_deposit')
109
- stub_private(:post, '/private/usd/deposits/12345678/cancel', 'cancelled_usd_deposit')
110
- deposit = Bitex::UsdDeposit.find(12345678)
111
- deposit.cancel!
112
- deposit.should be_a Bitex::UsdDeposit
113
- deposit.status.should == :cancelled
114
- deposit.reason.should == :user_cancelled
115
- end
116
-
117
- it 'lists all usd deposits' do
118
- stub_private(:get, '/private/usd/deposits', 'usd_deposits')
119
- deposits = Bitex::UsdDeposit.all
120
- deposits.should be_an Array
121
- deposits.first.should be_an Bitex::UsdDeposit
122
- deposits.first.status.should == :pending
123
138
  end
124
139
  end
@@ -1,101 +1,111 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Bitex::UsdWithdrawal do
4
- before :each do
5
- Bitex.api_key = 'valid_api_key'
6
- end
4
+ before(:each) { Bitex.api_key = 'valid_api_key' }
5
+
6
+ let(:api_class_id) { 8 }
7
+ let(:id) { 12_345_678 }
8
+ let(:created_at) { 946_685_400 }
9
+ let(:amount) { 100.0 }
10
+ let(:status) { 1 }
11
+ let(:reason) { 0 }
12
+ let(:country) { 'UY' }
13
+ let(:currency) { 'UYU' }
14
+ let(:payment_method) { 1 }
15
+ let(:label) { 'billy bob' }
16
+ let(:kyc_profile_id) { 1 }
17
+ let(:instructions) { 'instructions' }
7
18
 
8
19
  let(:as_json) do
9
- [8,12345678,946685400,100.00000000,1,0,'UY','UYU', 'bb', 'billy bob', 1, 'las instrucciones']
20
+ [api_class_id, id, created_at, amount, status, reason, country, currency, payment_method, label, kyc_profile_id, instructions]
10
21
  end
11
22
 
12
23
  it_behaves_like 'API class'
13
24
 
14
- it "sets amount as BigDecimal" do
15
- thing = Bitex::UsdWithdrawal.from_json(as_json).amount
16
- thing.should be_a BigDecimal
17
- thing.should == 100.0
18
- end
25
+ context 'Deserializing from json' do
26
+ let(:withdrawal) { Bitex::UsdWithdrawal.from_json(as_json) }
19
27
 
20
- it 'sets country' do
21
- thing = Bitex::UsdWithdrawal.from_json(as_json).country
22
- thing.should == 'UY'
23
- end
28
+ it 'sets amount as BigDecimal' do
29
+ withdrawal.amount.should be_an BigDecimal
30
+ withdrawal.amount.should eq amount
31
+ end
24
32
 
25
- it 'sets currency' do
26
- thing = Bitex::UsdWithdrawal.from_json(as_json).currency
27
- thing.should == 'UYU'
28
- end
33
+ it 'sets country' do
34
+ withdrawal.country.should be_an String
35
+ withdrawal.country.should eq country
36
+ end
29
37
 
30
- it 'sets payment method' do
31
- thing = Bitex::UsdWithdrawal.from_json(as_json).payment_method
32
- thing.should == 'bb'
33
- end
38
+ it 'sets currency' do
39
+ withdrawal.currency.should be_an String
40
+ withdrawal.currency.should eq currency
41
+ end
34
42
 
35
- it 'sets label' do
36
- thing = Bitex::UsdWithdrawal.from_json(as_json).label
37
- thing.should == 'billy bob'
38
- end
43
+ it 'sets payment method' do
44
+ withdrawal.payment_method.should be_an Symbol
45
+ withdrawal.payment_method.should be Bitex::UsdWithdrawal.payment_methods[payment_method]
46
+ end
39
47
 
40
- it 'sets kyc profile id' do
41
- thing = Bitex::UsdWithdrawal.from_json(as_json).kyc_profile_id
42
- thing.should == 1
43
- end
48
+ it 'sets label' do
49
+ withdrawal.label.should be_an String
50
+ withdrawal.label.should eq label
51
+ end
44
52
 
45
- it 'sets instructions' do
46
- thing = Bitex::UsdWithdrawal.from_json(as_json).instructions
47
- thing.should == 'las instrucciones'
48
- end
53
+ it 'sets kyc profile id' do
54
+ withdrawal.kyc_profile_id.should be_an Integer
55
+ withdrawal.kyc_profile_id.should be kyc_profile_id
56
+ end
49
57
 
50
- { 1 => :received,
51
- 2 => :pending,
52
- 3 => :done,
53
- 4 => :cancelled,
54
- }.each do |code, symbol|
55
- it "sets status #{code} to #{symbol}" do
56
- as_json[4] = code
57
- Bitex::UsdWithdrawal.from_json(as_json).status.should == symbol
58
+ it 'sets instructions' do
59
+ withdrawal.instructions.should be_an String
60
+ withdrawal.instructions.should eq instructions
58
61
  end
59
- end
60
62
 
61
- { 0 => :not_cancelled,
62
- 1 => :insufficient_funds,
63
- 2 => :no_instructions,
64
- 3 => :recipient_unknown,
65
- }.each do |code, symbol|
66
- it "sets reason #{code} to #{symbol}" do
67
- as_json[5] = code
68
- Bitex::UsdWithdrawal.from_json(as_json).reason.should == symbol
63
+ Bitex::UsdWithdrawal.statuses.each do |code, status|
64
+ it "sets status #{code} to #{status}" do
65
+ as_json[4] = code
66
+ withdrawal.status.should be status
67
+ end
69
68
  end
70
- end
71
69
 
72
- it 'creates a new withdrawal' do
73
- stub_private(:post, "/private/usd/withdrawals", 'usd_withdrawal', {
74
- country: 'UY',
75
- amount: 110,
76
- currency: 'UYU',
77
- payment_method: 'bb',
78
- instructions: 'bank of new york mellon',
79
- label: 'a label',
80
- })
81
- deposit = Bitex::UsdWithdrawal.create!('UY', 110, 'UYU', 'bb',
82
- 'bank of new york mellon', 'a label')
83
- deposit.should be_a Bitex::UsdWithdrawal
84
- deposit.status.should == :received
85
- end
86
-
87
- it 'finds a single usd deposit' do
88
- stub_private(:get, '/private/usd/withdrawals/1', 'usd_withdrawal')
89
- deposit = Bitex::UsdWithdrawal.find(1)
90
- deposit.should be_a Bitex::UsdWithdrawal
91
- deposit.status.should == :received
92
- end
93
-
94
- it 'lists all usd deposits' do
95
- stub_private(:get, '/private/usd/withdrawals', 'usd_withdrawals')
96
- deposits = Bitex::UsdWithdrawal.all
97
- deposits.should be_an Array
98
- deposits.first.should be_an Bitex::UsdWithdrawal
99
- deposits.first.status.should == :received
70
+ Bitex::UsdWithdrawal.reasons.each do |code, reason|
71
+ it "sets reason #{code} to #{reason}" do
72
+ as_json[5] = code
73
+ withdrawal.reason.should be reason
74
+ end
75
+ end
76
+
77
+ it 'creates a new withdrawal' do
78
+ stub_private(
79
+ :post,
80
+ '/private/usd/withdrawals',
81
+ :usd_withdrawal,
82
+ country: country, amount: amount, currency: currency, payment_method: payment_method, instructions: instructions,
83
+ label: label
84
+ )
85
+
86
+ withdrawal = Bitex::UsdWithdrawal.create!(country, amount, currency, payment_method, instructions, label)
87
+
88
+ withdrawal.should be_an Bitex::UsdWithdrawal
89
+ withdrawal.status.should == :received
90
+ end
91
+
92
+ it 'finds a single usd withdrawal' do
93
+ stub_private(:get, "/private/usd/withdrawals/#{id}", :usd_withdrawal)
94
+
95
+ withdrawal = Bitex::UsdWithdrawal.find(id)
96
+
97
+ withdrawal.should be_an Bitex::UsdWithdrawal
98
+ withdrawal.status.should == :received
99
+ end
100
+
101
+ it 'lists all usd withdrawals' do
102
+ stub_private(:get, '/private/usd/withdrawals', :usd_withdrawals)
103
+
104
+ withdrawals = Bitex::UsdWithdrawal.all
105
+
106
+ withdrawals.should be_an Array
107
+ withdrawals.all? { |withdrawal| withdrawal.should be_an Bitex::UsdWithdrawal }
108
+ withdrawals.all? { |withdrawal| withdrawal.status.should be :received }
109
+ end
100
110
  end
101
111
  end