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,5 +1,6 @@
1
1
  module Bitex
2
2
  # A withdrawal of USD from your bitex.la balance
3
+ #
3
4
  class UsdWithdrawal
4
5
  # @!attribute id
5
6
  # @return [Integer] This UsdWithdrawal's unique ID.
@@ -17,19 +18,16 @@ module Bitex
17
18
  # Returns the status of this withdrawal.
18
19
  # * :received Our engine is checking if you have enough funds.
19
20
  # * :pending your withdrawal was accepted and is being processed.
20
- # * :done your withdrawal was processed and it's on its way through
21
- # the withdrawal channel you chose.
21
+ # * :done your withdrawal was processed and it's on its way through the withdrawal channel you chose.
22
22
  # * :cancelled your withdrawal could not be processed.
23
23
  attr_accessor :status
24
24
 
25
25
  # @!attribute reason
26
26
  # Returns the reason for cancellation of this withdrawal, if any.
27
27
  # * :not_cancelled
28
- # * :insufficient_funds The instruction was received, but you didn't have enough
29
- # funds available
28
+ # * :insufficient_funds The instruction was received, but you didn't have enough funds available.
30
29
  # * :no_instructions We could not understand the instructions you provided.
31
- # * :recipient_unknown we could not issue this withdrawal because you're
32
- # not the receiving party.
30
+ # * :recipient_unknown we could not issue this withdrawal because you're not the receiving party.
33
31
  attr_accessor :reason
34
32
 
35
33
  # @!attribute countr
@@ -42,7 +40,7 @@ module Bitex
42
40
 
43
41
  # @!attribute payment_method
44
42
  # Returns the payment method for this withdrawal.
45
- # * :international_bank International bank transfer
43
+ # * :international_bank International bank transfer.
46
44
  # * :bb we'll contact you regarding this withdrawal.
47
45
  attr_accessor :payment_method
48
46
 
@@ -56,42 +54,31 @@ module Bitex
56
54
  attr_accessor :instructions
57
55
 
58
56
  # @visibility private
57
+ # rubocop:disable Metrics/AbcSize
59
58
  def self.from_json(json)
60
- status_lookup = {
61
- 1 => :received,
62
- 2 => :pending,
63
- 3 => :done,
64
- 4 => :cancelled,
65
- }
66
- reason_lookup = {
67
- 0 => :not_cancelled,
68
- 1 => :insufficient_funds,
69
- 2 => :no_instructions,
70
- 3 => :recipient_unknown,
71
- }
72
59
  Api.from_json(new, json) do |thing|
73
- thing.amount = BigDecimal.new(json[3].to_s)
74
- thing.status = status_lookup[json[4]]
75
- thing.reason = reason_lookup[json[5]]
60
+ thing.amount = (json[3].presence || 0).to_d
61
+ thing.status = statuses[json[4]]
62
+ thing.reason = reasons[json[5]]
76
63
  thing.country = json[6]
77
64
  thing.currency = json[7]
78
- thing.payment_method = json[8]
65
+ thing.payment_method = payment_methods[json[8]]
79
66
  thing.label = json[9]
80
67
  thing.kyc_profile_id = json[10]
81
68
  thing.instructions = json[11]
82
69
  end
83
70
  end
71
+ # rubocop:enable Metrics/AbcSize
84
72
 
85
- def self.create!(country, amount, currency, method, instructions, label, profile=nil)
86
- from_json(Api.private(:post, "/private/usd/withdrawals", {
87
- country: country,
88
- amount: amount,
89
- currency: currency,
90
- payment_method: method,
91
- instructions: instructions,
92
- label: label,
93
- kyc_profile_id: profile,
94
- }))
73
+ def self.create!(country, amount, currency, method, instructions, label, profile = nil)
74
+ from_json(
75
+ Api.private(
76
+ :post,
77
+ '/private/usd/withdrawals',
78
+ country: country, amount: amount, currency: currency, payment_method: method, instructions: instructions, label: label,
79
+ kyc_profile_id: profile
80
+ )
81
+ )
95
82
  end
96
83
 
97
84
  def self.find(id)
@@ -99,7 +86,19 @@ module Bitex
99
86
  end
100
87
 
101
88
  def self.all
102
- Api.private(:get, "/private/usd/withdrawals").collect{|x| from_json(x) }
89
+ Api.private(:get, '/private/usd/withdrawals').map { |sw| from_json(sw) }
90
+ end
91
+
92
+ def self.payment_methods
93
+ { 1 => :bb, 2 => :international_bank }
94
+ end
95
+
96
+ def self.reasons
97
+ { 0 => :not_cancelled, 1 => :insufficient_funds, 2 => :no_instructions, 3 => :recipient_unknown }
98
+ end
99
+
100
+ def self.statuses
101
+ { 1 => :received, 2 => :pending, 3 => :done, 4 => :cancelled }
103
102
  end
104
103
  end
105
104
  end
@@ -1,3 +1,3 @@
1
1
  module Bitex
2
- VERSION = "0.3"
2
+ VERSION = '0.4.0'.freeze
3
3
  end
@@ -2,19 +2,31 @@ require 'spec_helper'
2
2
 
3
3
  describe Bitex::Ask do
4
4
  let(:as_json) do
5
- [2,12345678,946685400,1,100.00000000,100.00000000,1000.00000000,1,0,10.0,'User#1']
5
+ [
6
+ 1, # 0 - API class reference
7
+ 12345678, # 1 - id
8
+ 946685400, # 2 - created_at
9
+ 1, # 3 - orderbook
10
+ 100.0, # 4 - quantity
11
+ 100.0, # 5 - remaining_quantity
12
+ 1000.0, # 6 - price
13
+ 1, # 7 - status
14
+ 0, # 8 - reason
15
+ 10.0, # 9 - produced_amount
16
+ 'User#1' # 10 - issuer
17
+ ]
6
18
  end
7
-
19
+
8
20
  it_behaves_like 'API class'
9
- it_behaves_like 'API class with a specie'
21
+ it_behaves_like 'API class with a orderbook'
10
22
  it_behaves_like 'JSON deserializable order'
11
23
 
12
24
  describe 'Api calls' do
13
- before(:each){ Bitex.api_key = 'valid_api_key' }
25
+ before(:each) { Bitex.api_key = 'valid_api_key' }
14
26
  it_behaves_like 'Order', 'asks'
15
27
  end
16
28
 
17
- { quantity: 100.0, remaining_quantity: 100.0, produced_amount: 10.0}.each do |field, value|
29
+ { quantity: 100.0, remaining_quantity: 100.0, produced_amount: 10.0 }.each do |field, value|
18
30
  it "sets #{field} as BigDecimal" do
19
31
  thing = subject.class.from_json(as_json).send(field)
20
32
  thing.should be_a BigDecimal
@@ -2,19 +2,31 @@ require 'spec_helper'
2
2
 
3
3
  describe Bitex::Bid do
4
4
  let(:as_json) do
5
- [1,12345678,946685400,1,100.00000000,100.00000000,1000.00000000,1,0,10.0,'User#1']
5
+ [
6
+ 1, # 0 - API class reference
7
+ 12_345_678, # 1 - id
8
+ 946_685_400, # 2 - created_at
9
+ 1, # 3 - orderbook
10
+ 100.0, # 4 - quantity
11
+ 100.0, # 5 - remaining_quantity
12
+ 1_000.0, # 6 - price
13
+ 1, # 7 - status
14
+ 0, # 8 - reason
15
+ 10.0, # 9 - produced_amount
16
+ 'User#1' # 10 - issuer
17
+ ]
6
18
  end
7
-
19
+
8
20
  it_behaves_like 'API class'
9
- it_behaves_like 'API class with a specie'
21
+ it_behaves_like 'API class with a orderbook'
10
22
  it_behaves_like 'JSON deserializable order'
11
23
 
12
24
  describe 'Api calls' do
13
- before(:each){ Bitex.api_key = 'valid_api_key' }
25
+ before(:each) { Bitex.api_key = 'valid_api_key' }
14
26
  it_behaves_like 'Order', 'bids'
15
27
  end
16
28
 
17
- { amount: 100.0, remaining_amount: 100.0, produced_quantity: 10.0}.each do |field, value|
29
+ { amount: 100.0, remaining_amount: 100.0, produced_quantity: 10.0 }.each do |field, value|
18
30
  it "sets #{field} as BigDecimal" do
19
31
  thing = subject.class.from_json(as_json).send(field)
20
32
  thing.should be_a BigDecimal
@@ -2,14 +2,24 @@ require 'spec_helper'
2
2
 
3
3
  describe Bitex::Buy do
4
4
  let(:as_json) do
5
- [4,12345678,946685400,1,100.50000000,201.0000000,0.05000000,2.00000000,456]
5
+ [
6
+ 4, # 0 - API class reference
7
+ 12_345_678, # 1 - id
8
+ 946_685_400, # 2 - created_at
9
+ 1, # 3 - orderbook
10
+ 100.5, # 4 - quantity
11
+ 201, # 5 - amount
12
+ 0.05, # 6 - fee
13
+ 2, # 7 - price
14
+ 456 # 8 - bid_id
15
+ ]
6
16
  end
7
-
17
+
8
18
  it_behaves_like 'API class'
9
- it_behaves_like 'API class with a specie'
19
+ it_behaves_like 'API class with a orderbook'
10
20
  it_behaves_like 'JSON deserializable match'
11
21
 
12
- it "sets the bid id" do
22
+ it 'sets the bid id' do
13
23
  thing = subject.class.from_json(as_json).bid_id
14
24
  thing.should == 456
15
25
  end
@@ -1,30 +1,46 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Bitex::KycFile do
4
- before :each do
5
- Bitex.api_key = 'valid_api_key'
6
- end
4
+ before(:each) { Bitex.api_key = 'valid_api_key' }
7
5
 
8
- let(:as_json) do
9
- [1,2,'http://foo.bar.example/photo.jpg', 'photo.jpg', 'application/jpeg', 10000]
10
- end
6
+ let(:id) { 1 }
7
+ let(:kyc_profile_id) { 2 }
8
+ let(:url) { 'http://foo.bar.example/photo.jpg' }
9
+ let(:file_name) { 'photo.jpg' }
10
+ let(:file_size) { 10_000 }
11
+ let(:content_type) { 'application/jpeg' }
12
+
13
+ let(:as_json) { [id, kyc_profile_id, url, file_name, content_type, file_size] }
14
+ let(:kyc_file) { subject.class.from_json(as_json) }
15
+ let(:kyc_files) { Bitex::KycFile.all }
16
+
17
+ context 'deserializing from json' do
18
+ it 'sets url as String' do
19
+ kyc_file.url.should be_an String
20
+ kyc_file.url.should eq url
21
+ end
11
22
 
12
- { id: 1,
13
- kyc_profile_id: 2,
14
- url:'http://foo.bar.example/photo.jpg',
15
- file_name: 'photo.jpg',
16
- content_type: 'application/jpeg',
17
- file_size: 10000
18
- }.each do |field, value|
19
- it "sets #{field}" do
20
- subject.class.from_json(as_json).send(field).should == value
23
+ it 'sets file name as String' do
24
+ kyc_file.file_name.should be_an String
25
+ kyc_file.file_name.should eq file_name
26
+ end
27
+
28
+ it 'sets file size as Integer' do
29
+ kyc_file.file_size.should be_an Integer
30
+ kyc_file.file_size.should eq file_size
31
+ end
32
+
33
+ it 'sets content type as String' do
34
+ kyc_file.content_type.should be_an String
35
+ kyc_file.content_type.should eq content_type
21
36
  end
22
37
  end
23
38
 
24
39
  it 'lists all kyc profiles' do
25
- stub_private(:get, '/private/kyc_files', 'kyc_files')
26
- kyc_files = Bitex::KycFile.all
40
+ stub_private(:get, '/private/kyc_files', :kyc_files)
41
+
27
42
  kyc_files.should be_an Array
28
- kyc_files.first.should be_an Bitex::KycFile
43
+ kyc_files.sample.should be_an Bitex::KycFile
44
+ kyc_files.find(id: id).should be_present
29
45
  end
30
46
  end
@@ -1,154 +1,190 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Bitex::KycProfile do
4
- before :each do
5
- Bitex.api_key = 'valid_api_key'
6
- end
4
+ before(:each) { Bitex.api_key = 'valid_api_key' }
7
5
 
8
- let(:params_for_create_or_update) do
9
- { first_name: 'Billy',
10
- last_name: 'Bob',
11
- personal_id_number: '33222111N',
12
- personal_id_issuer: 'AR',
13
- personal_id_type: 'passport',
14
- tax_id: '4332221115',
15
- birth_date: Time.at(946685400),
16
- nationality: 'brazilian',
17
- gender: 'male',
18
- occupation: 'Singer',
19
- home_address: 'Argentina, Buenos Aires, etc',
20
- work_address: 'Argentina, La Plata',
21
- phone_numbers: '+51 555 120921',
22
- legal_entity: true,
23
- politically_exposed_person: true,
24
- usage_tier: 'micro'
25
- }
26
- end
27
-
28
- let(:rest_params_for_create_or_update) do
29
- { first_name: 'Billy',
30
- last_name: 'Bob',
31
- personal_id_number: '33222111N',
32
- personal_id_issuer: 'AR',
33
- personal_id_type: 'passport',
34
- tax_id: '4332221115',
35
- birth_date: '1999/12/31',
36
- nationality: 'brazilian',
37
- gender: 'male',
38
- occupation: 'Singer',
39
- home_address: 'Argentina, Buenos Aires, etc',
40
- work_address: 'Argentina, La Plata',
41
- phone_numbers: '+51 555 120921',
42
- legal_entity: true,
43
- politically_exposed_person: true,
44
- usage_tier: 'micro',
6
+ let(:id) { 1 }
7
+ let(:first_name) { 'Billy' }
8
+ let(:last_name) { 'Bob' }
9
+ let(:personal_id_number) { '33222111N' }
10
+ let(:personal_id_issuer) { 'AR' }
11
+ let(:personal_id_type) { :passport }
12
+ let(:tax_id) { 4_332_221_115 }
13
+ let(:birth_date) { Time.at(946_685_400).utc }
14
+ let(:rest_birth_date) { '2000/01/01' }
15
+ let(:nationality) { 'brazilian' }
16
+ let(:gender) { :male }
17
+ let(:occupation) { 'Singer' }
18
+ let(:home_address) { 'Argentina, Buenos Aires, etc' }
19
+ let(:work_address) { 'Argentina, La Plata' }
20
+ let(:phone_numbers) { '+51 555 120921' }
21
+ let(:legal_entity) { true }
22
+ let(:politically_exposed_person) { true }
23
+ let(:usage_tier) { :micro }
24
+ let(:accepted_usage_tier) { :micro }
25
+
26
+ let(:kyc_profile_params) do
27
+ {
28
+ first_name: first_name, last_name: last_name, personal_id_number: personal_id_number,
29
+ personal_id_issuer: personal_id_issuer, personal_id_type: personal_id_type, tax_id: tax_id, birth_date: birth_date,
30
+ nationality: nationality, gender: gender, occupation: occupation, home_address: home_address, work_address: work_address,
31
+ phone_numbers: phone_numbers, legal_entity: legal_entity, politically_exposed_person: politically_exposed_person,
32
+ usage_tier: usage_tier
45
33
  }
46
34
  end
47
35
 
48
36
  let(:as_json) do
49
- [ 1, # Kyc Profile id.
50
- 'Billy', # Name
51
- 'Bob', # Last Name.
52
- '33222111N', # Personal ID Number
53
- 'AR', # ISO country code for the issuer of this ID.
54
- 'passport', # Type of ID
55
- '4332221115', # Tax Id
56
- 946685400, # Birth date as unix timestamp.
57
- 'brazilian', # Nationality
58
- 'male', # Gender
59
- 'Singer', # Occupation
60
- 'Argentina, Buenos Aires, etc', # Home address.
61
- 'Argentina, La Plata', # Work address.
62
- '+51 555 120921', # Phone numbers.
63
- true, # Is legal entity.
64
- true, # Is politically exposed.
65
- 'micro', # Requested usage tier.
66
- 'micro', # Current usage tier as accepted by
67
- # our compliance officers.
68
- ]
37
+ [id, first_name, last_name, personal_id_number, personal_id_issuer, personal_id_type, tax_id, birth_date, nationality,
38
+ gender, occupation, home_address, work_address, phone_numbers, legal_entity, politically_exposed_person, usage_tier,
39
+ accepted_usage_tier]
69
40
  end
70
41
 
71
- { id: 1,
72
- first_name: 'Billy',
73
- last_name: 'Bob',
74
- personal_id_number: '33222111N',
75
- personal_id_issuer: 'AR',
76
- personal_id_type: 'passport',
77
- tax_id: '4332221115',
78
- birth_date: Time.at(946685400),
79
- nationality: 'brazilian',
80
- gender: 'male',
81
- occupation: 'Singer',
82
- home_address: 'Argentina, Buenos Aires, etc',
83
- work_address: 'Argentina, La Plata',
84
- phone_numbers: '+51 555 120921',
85
- legal_entity: true,
86
- politically_exposed_person: true,
87
- usage_tier: 'micro',
88
- accepted_usage_tier: 'micro',
89
- }.each do |field, value|
90
- it "sets #{field}" do
91
- subject.class.from_json(as_json).send(field).should == value
42
+ let(:kyc_profile) { subject.class.from_json(as_json) }
43
+
44
+ context 'deserializing from json' do
45
+ it 'sets first name as String' do
46
+ kyc_profile.first_name.should be_an String
47
+ kyc_profile.first_name.should eq first_name
48
+ end
49
+
50
+ it 'sets last name as String' do
51
+ kyc_profile.last_name.should be_an String
52
+ kyc_profile.last_name.should eq last_name
53
+ end
54
+
55
+ it 'sets personal ID number as String' do
56
+ kyc_profile.personal_id_number.should be_an String
57
+ kyc_profile.personal_id_number.should eq personal_id_number
58
+ end
59
+
60
+ it 'sets personal ID issuer as String' do
61
+ kyc_profile.personal_id_issuer.should be_an String
62
+ kyc_profile.personal_id_issuer.should eq personal_id_issuer
63
+ end
64
+
65
+ it 'sets personal ID type as Symbol' do
66
+ kyc_profile.personal_id_type.should be_an Symbol
67
+ kyc_profile.personal_id_type.should eq personal_id_type
68
+ end
69
+
70
+ it 'sets tax ID as Integer' do
71
+ kyc_profile.tax_id.should be_an Integer
72
+ kyc_profile.tax_id.should eq tax_id
73
+ end
74
+
75
+ it 'sets birth date as Time' do
76
+ kyc_profile.birth_date.should be_an Time
77
+ kyc_profile.birth_date.should eq birth_date
78
+ end
79
+
80
+ it 'can have a nil birth_date' do
81
+ as_json[7] = nil
82
+
83
+ kyc_profile.birth_date.should be_nil
84
+ end
85
+
86
+ it 'sets nationality as String' do
87
+ kyc_profile.nationality.should be_an String
88
+ kyc_profile.nationality.should eq nationality
89
+ end
90
+
91
+ it 'sets gender as Symbol' do
92
+ kyc_profile.gender.should be_an Symbol
93
+ kyc_profile.gender.should be gender
94
+ end
95
+
96
+ it 'sets occupation as String' do
97
+ kyc_profile.occupation.should be_an String
98
+ kyc_profile.occupation.should eq occupation
99
+ end
100
+
101
+ it 'sets home address as String' do
102
+ kyc_profile.home_address.should be_an String
103
+ kyc_profile.home_address.should eq home_address
104
+ end
105
+
106
+ it 'sets work address as String' do
107
+ kyc_profile.work_address.should be_an String
108
+ kyc_profile.work_address.should eq work_address
109
+ end
110
+
111
+ it 'sets phone numbers as String' do
112
+ kyc_profile.phone_numbers.should be_an String
113
+ kyc_profile.phone_numbers.should eq phone_numbers
114
+ end
115
+
116
+ it 'sets legal entity as Boolean' do
117
+ kyc_profile.legal_entity.should be_an TrueClass
118
+ kyc_profile.legal_entity.should eq legal_entity
119
+ end
120
+
121
+ it 'sets politically exposed person as Boolean' do
122
+ kyc_profile.politically_exposed_person.should be_an TrueClass
123
+ kyc_profile.politically_exposed_person.should eq politically_exposed_person
124
+ end
125
+
126
+ it 'sets usage tier as Symbol' do
127
+ kyc_profile.usage_tier.should be_an Symbol
128
+ kyc_profile.usage_tier.should eq usage_tier
129
+ end
130
+
131
+ it 'sets accepted usage tier as Symbol' do
132
+ kyc_profile.accepted_usage_tier.should be_an Symbol
133
+ kyc_profile.accepted_usage_tier.should eq accepted_usage_tier
92
134
  end
93
135
  end
94
136
 
95
137
  it 'creates a new kyc profile' do
96
- stub_private(:post, "/private/kyc_profiles", 'kyc_profile',
97
- rest_params_for_create_or_update)
98
- Bitex::KycProfile.create!(params_for_create_or_update)
99
- .should be_a Bitex::KycProfile
138
+ stub_private(:post, '/private/kyc_profiles', :kyc_profile, kyc_profile_params.merge(birth_date: rest_birth_date))
139
+
140
+ Bitex::KycProfile.create!(kyc_profile_params).should be_a Bitex::KycProfile
100
141
  end
101
-
142
+
102
143
  it 'finds a single kyc profile' do
103
- stub_private(:get, '/private/kyc_profiles/1', 'kyc_profile')
104
- kyc_profile = Bitex::KycProfile.find(1)
144
+ stub_private(:get, "/private/kyc_profiles/#{id}", :kyc_profile)
145
+
146
+ kyc_profile = Bitex::KycProfile.find(id)
147
+
105
148
  kyc_profile.should be_a Bitex::KycProfile
149
+ kyc_profile.id.should eq id
150
+ end
151
+
152
+ it 'updates a kyc profile' do
153
+ stub_private(:put, "/private/kyc_profiles/#{id}", :kyc_profile, kyc_profile_params.merge(birth_date: rest_birth_date))
154
+
155
+ kyc_profile.update!(kyc_profile_params)
156
+ kyc_profile.birth_date.should eq birth_date
106
157
  end
107
-
158
+
108
159
  it 'lists all kyc profiles' do
109
- stub_private(:get, '/private/kyc_profiles', 'kyc_profiles')
160
+ stub_private(:get, '/private/kyc_profiles', :kyc_profiles)
161
+
110
162
  kyc_profiles = Bitex::KycProfile.all
163
+
111
164
  kyc_profiles.should be_an Array
112
165
  kyc_profiles.first.should be_an Bitex::KycProfile
113
166
  end
114
167
 
115
- it 'updates a kyc profile' do
116
- stub_private(:put, "/private/kyc_profiles/1", 'kyc_profile',
117
- rest_params_for_create_or_update)
118
- kyc_profile = Bitex::KycProfile.from_json(as_json)
119
- kyc_profile.update!(params_for_create_or_update)
120
- end
121
-
122
168
  it 'creates a kyc file' do
123
- path = File.expand_path('../fixtures/file.jpg', __FILE__)
124
- stub_private(:post, '/private/kyc_profiles/1/kyc_files', 'kyc_file',
125
- {document: path, document_content_type: 'image/jpg'})
126
- kyc_profile = Bitex::KycProfile.from_json(as_json)
127
- kyc_file = kyc_profile.add_kyc_file!(path, 'image/jpg')
128
- kyc_file.should be_a Bitex::KycFile
169
+ path = File.expand_path('fixtures/file.jpg', __dir__)
170
+ stub_private(:post, "/private/kyc_profiles/#{id}/kyc_files", :kyc_file, document: path, document_content_type: 'image/jpg')
171
+
172
+ kyc_profile.add_kyc_file!(path, 'image/jpg') { |kyc_file| kyc_file.should be_a Bitex::KycFile }
129
173
  end
130
174
 
131
175
  it 'creates a kyc file without specifying content type' do
132
- path = File.expand_path('../fixtures/file.jpg', __FILE__)
133
- stub_private(:post, '/private/kyc_profiles/1/kyc_files', 'kyc_file',
134
- {document: path})
135
- kyc_profile = Bitex::KycProfile.from_json(as_json)
136
- kyc_file = kyc_profile.add_kyc_file!(path)
137
- kyc_file.should be_a Bitex::KycFile
176
+ path = File.expand_path('fixtures/file.jpg', __dir__)
177
+ stub_private(:post, '/private/kyc_profiles/1/kyc_files', :kyc_file, document: path)
178
+
179
+ kyc_profile.add_kyc_file!(path) { |kyc_file| kyc_file.should be_a Bitex::KycFile }
138
180
  end
139
-
181
+
140
182
  it 'lists a profiles kyc files' do
141
- stub_private(:get, '/private/kyc_profiles/1/kyc_files', 'kyc_files')
142
- kyc_profile = Bitex::KycProfile.from_json(as_json)
143
- kyc_files = kyc_profile.kyc_files
144
- kyc_files.should be_an Array
145
- kyc_files.first.should be_a Bitex::KycFile
146
- end
147
-
148
- it 'can have a nil birth_date' do
149
- json = as_json.dup
150
- json[7] = nil
151
- kyc_profile = Bitex::KycProfile.from_json(json)
152
- kyc_profile.birth_date.should be_nil
183
+ stub_private(:get, "/private/kyc_profiles/#{id}/kyc_files", :kyc_files)
184
+
185
+ kyc_profile.kyc_files do |kyc_files|
186
+ kyc_files.should be_an Array
187
+ kyc_files.sample.should be_a Bitex::KycFile
188
+ end
153
189
  end
154
190
  end