straight 0.2.3 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -0
  3. data/Gemfile +7 -5
  4. data/Gemfile.lock +17 -7
  5. data/README.md +3 -0
  6. data/Rakefile +9 -0
  7. data/VERSION +1 -1
  8. data/lib/straight.rb +9 -1
  9. data/lib/straight/address_providers/base.rb +28 -0
  10. data/lib/straight/address_providers/bip32.rb +22 -0
  11. data/lib/straight/blockchain_adapter.rb +17 -1
  12. data/lib/straight/blockchain_adapters/biteasy_adapter.rb +14 -13
  13. data/lib/straight/blockchain_adapters/blockchain_info_adapter.rb +15 -14
  14. data/lib/straight/blockchain_adapters/insight_adapter.rb +76 -0
  15. data/lib/straight/blockchain_adapters/mycelium_adapter.rb +74 -49
  16. data/lib/straight/exchange_rate_adapter.rb +2 -2
  17. data/lib/straight/exchange_rate_adapters/average_rate_adapter.rb +1 -1
  18. data/lib/straight/exchange_rate_adapters/okcoin_adapter.rb +1 -1
  19. data/lib/straight/faraday_monkeypatch.rb +22 -0
  20. data/lib/straight/gateway.rb +71 -34
  21. data/lib/straight/order.rb +43 -32
  22. data/straight.gemspec +20 -27
  23. metadata +30 -26
  24. data/spec/lib/blockchain_adapters/biteasy_adapter_spec.rb +0 -48
  25. data/spec/lib/blockchain_adapters/blockchain_info_adapter_spec.rb +0 -57
  26. data/spec/lib/blockchain_adapters/mycelium_adapter_spec.rb +0 -58
  27. data/spec/lib/exchange_rate_adapter_spec.rb +0 -55
  28. data/spec/lib/exchange_rate_adapters/average_rate_adapter_spec.rb +0 -43
  29. data/spec/lib/exchange_rate_adapters/bitpay_adapter_spec.rb +0 -27
  30. data/spec/lib/exchange_rate_adapters/bitstamp_adapter_spec.rb +0 -27
  31. data/spec/lib/exchange_rate_adapters/btce_adapter_spec.rb +0 -27
  32. data/spec/lib/exchange_rate_adapters/coinbase_adapter_spec.rb +0 -27
  33. data/spec/lib/exchange_rate_adapters/kraken_adapter_spec.rb +0 -27
  34. data/spec/lib/exchange_rate_adapters/localbitcoins_adapter_spec.rb +0 -27
  35. data/spec/lib/exchange_rate_adapters/okcoin_adapter_spec.rb +0 -27
  36. data/spec/lib/gateway_spec.rb +0 -98
  37. data/spec/lib/order_spec.rb +0 -128
  38. data/spec/spec_helper.rb +0 -1
metadata CHANGED
@@ -1,45 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: straight
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Snitko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-30 00:00:00.000000000 Z
11
+ date: 2015-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: money-tree
14
+ name: btcruby
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.9.0
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.9.0
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: satoshi-unit
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '0.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '0.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.13.5
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.13.5
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
@@ -106,6 +120,7 @@ extra_rdoc_files:
106
120
  files:
107
121
  - ".document"
108
122
  - ".rspec"
123
+ - ".travis.yml"
109
124
  - Gemfile
110
125
  - Gemfile.lock
111
126
  - LICENSE.txt
@@ -113,9 +128,12 @@ files:
113
128
  - Rakefile
114
129
  - VERSION
115
130
  - lib/straight.rb
131
+ - lib/straight/address_providers/base.rb
132
+ - lib/straight/address_providers/bip32.rb
116
133
  - lib/straight/blockchain_adapter.rb
117
134
  - lib/straight/blockchain_adapters/biteasy_adapter.rb
118
135
  - lib/straight/blockchain_adapters/blockchain_info_adapter.rb
136
+ - lib/straight/blockchain_adapters/insight_adapter.rb
119
137
  - lib/straight/blockchain_adapters/mycelium_adapter.rb
120
138
  - lib/straight/exchange_rate_adapter.rb
121
139
  - lib/straight/exchange_rate_adapters/average_rate_adapter.rb
@@ -126,23 +144,9 @@ files:
126
144
  - lib/straight/exchange_rate_adapters/kraken_adapter.rb
127
145
  - lib/straight/exchange_rate_adapters/localbitcoins_adapter.rb
128
146
  - lib/straight/exchange_rate_adapters/okcoin_adapter.rb
147
+ - lib/straight/faraday_monkeypatch.rb
129
148
  - lib/straight/gateway.rb
130
149
  - lib/straight/order.rb
131
- - spec/lib/blockchain_adapters/biteasy_adapter_spec.rb
132
- - spec/lib/blockchain_adapters/blockchain_info_adapter_spec.rb
133
- - spec/lib/blockchain_adapters/mycelium_adapter_spec.rb
134
- - spec/lib/exchange_rate_adapter_spec.rb
135
- - spec/lib/exchange_rate_adapters/average_rate_adapter_spec.rb
136
- - spec/lib/exchange_rate_adapters/bitpay_adapter_spec.rb
137
- - spec/lib/exchange_rate_adapters/bitstamp_adapter_spec.rb
138
- - spec/lib/exchange_rate_adapters/btce_adapter_spec.rb
139
- - spec/lib/exchange_rate_adapters/coinbase_adapter_spec.rb
140
- - spec/lib/exchange_rate_adapters/kraken_adapter_spec.rb
141
- - spec/lib/exchange_rate_adapters/localbitcoins_adapter_spec.rb
142
- - spec/lib/exchange_rate_adapters/okcoin_adapter_spec.rb
143
- - spec/lib/gateway_spec.rb
144
- - spec/lib/order_spec.rb
145
- - spec/spec_helper.rb
146
150
  - straight.gemspec
147
151
  homepage: http://github.com/snitko/straight
148
152
  licenses:
@@ -1,48 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Straight::Blockchain::BiteasyAdapter do
4
-
5
- subject(:adapter) { Straight::Blockchain::BiteasyAdapter.mainnet_adapter }
6
-
7
- it "fetches the balance for a given address" do
8
- address = "3B1QZ8FpAaHBgkSB5gFt76ag5AW9VeP8xp"
9
- expect(adapter.fetch_balance_for(address)).to be_kind_of(Integer)
10
- end
11
-
12
- it "fetches a single transaction" do
13
- tid = 'ae0d040f48d75fdc46d9035236a1782164857d6f0cca1f864640281115898560'
14
- expect(adapter.fetch_transaction(tid)[:total_amount]).to eq(832947)
15
- end
16
-
17
- it "calculates total_amount of a transaction for the given address only" do
18
- t = { 'data' => {'outputs' => [{ 'value' => 1, 'to_address' => 'address1'}, { 'value' => 2, 'to_address' => 'address2'}] } }
19
- expect(adapter.send(:straighten_transaction, t, address: 'address1')[:total_amount]).to eq(1)
20
- end
21
-
22
- it "fetches all transactions for the current address" do
23
- address = "3B1QZ8FpAaHBgkSB5gFt76ag5AW9VeP8xp"
24
- expect(adapter).to receive(:straighten_transaction).with(anything, address: address).at_least(:once)
25
- expect(adapter.fetch_transactions_for(address)).not_to be_empty
26
- end
27
-
28
- it "calculates the number of confirmations for each transaction" do
29
- tid = 'ae0d040f48d75fdc46d9035236a1782164857d6f0cca1f864640281115898560'
30
- expect(adapter.fetch_transaction(tid)[:confirmations]).to be > 0
31
- end
32
-
33
- it "gets a transaction id among other data" do
34
- tid = 'ae0d040f48d75fdc46d9035236a1782164857d6f0cca1f864640281115898560'
35
- expect(adapter.fetch_transaction(tid)[:tid]).to eq(tid)
36
- end
37
-
38
- it "raises an exception when something goes wrong with fetching data" do
39
- expect( -> { adapter.send(:api_request, "/a-404-request") }).to raise_error(Straight::Blockchain::Adapter::RequestError)
40
- end
41
-
42
- it "uses the same Singleton instance" do
43
- a = Straight::Blockchain::BiteasyAdapter.mainnet_adapter
44
- b = Straight::Blockchain::BiteasyAdapter.mainnet_adapter
45
- expect(a).to eq(b)
46
- end
47
-
48
- end
@@ -1,57 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Straight::Blockchain::BlockchainInfoAdapter do
4
-
5
- subject(:adapter) { Straight::Blockchain::BlockchainInfoAdapter.mainnet_adapter }
6
-
7
- it "fetches all transactions for the current address" do
8
- address = "3B1QZ8FpAaHBgkSB5gFt76ag5AW9VeP8xp"
9
- expect(adapter).to receive(:straighten_transaction).with(anything, address: address).at_least(:once)
10
- expect(adapter.fetch_transactions_for(address)).not_to be_empty
11
- end
12
-
13
- it "fetches the balance for a given address" do
14
- address = "3B1QZ8FpAaHBgkSB5gFt76ag5AW9VeP8xp"
15
- expect(adapter.fetch_balance_for(address)).to be_kind_of(Integer)
16
- end
17
-
18
- it "fetches a single transaction" do
19
- tid = 'ae0d040f48d75fdc46d9035236a1782164857d6f0cca1f864640281115898560'
20
- expect(adapter.fetch_transaction(tid)[:total_amount]).to eq(832947)
21
- end
22
-
23
- it "calculates the number of confirmations for each transaction" do
24
- tid = 'ae0d040f48d75fdc46d9035236a1782164857d6f0cca1f864640281115898560'
25
- expect(adapter.fetch_transaction(tid)[:confirmations]).to be > 0
26
- end
27
-
28
- it "gets a transaction id among other data" do
29
- tid = 'ae0d040f48d75fdc46d9035236a1782164857d6f0cca1f864640281115898560'
30
- expect(adapter.fetch_transaction(tid)[:tid]).to eq(tid)
31
- end
32
-
33
- it "caches blockchain.info latestblock requests" do
34
- expect(adapter).to receive(:api_request).once.and_return('{ "height": 1 }')
35
- adapter.send(:calculate_confirmations, { "block_height" => 1 }, force_latest_block_reload: true)
36
- adapter.send(:calculate_confirmations, { "block_height" => 1 })
37
- adapter.send(:calculate_confirmations, { "block_height" => 1 })
38
- adapter.send(:calculate_confirmations, { "block_height" => 1 })
39
- adapter.send(:calculate_confirmations, { "block_height" => 1 })
40
- end
41
-
42
- it "raises an exception when something goes wrong with fetching datd" do
43
- expect( -> { adapter.send(:api_request, "/a-404-request") }).to raise_error(Straight::Blockchain::Adapter::RequestError)
44
- end
45
-
46
- it "calculates total_amount of a transaction for the given address only" do
47
- t = { 'out' => [{ 'value' => 1, 'addr' => 'address1'}, { 'value' => 1, 'addr' => 'address2'}] }
48
- expect(adapter.send(:straighten_transaction, t, address: 'address1')[:total_amount]).to eq(1)
49
- end
50
-
51
- it "uses the same Singleton instance" do
52
- a = Straight::Blockchain::BlockchainInfoAdapter.mainnet_adapter
53
- b = Straight::Blockchain::BlockchainInfoAdapter.mainnet_adapter
54
- expect(a).to eq(b)
55
- end
56
-
57
- end
@@ -1,58 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Straight::Blockchain::MyceliumAdapter do
4
-
5
- subject(:adapter) { Straight::Blockchain::MyceliumAdapter.mainnet_adapter }
6
-
7
- it "fetches all transactions for the current address" do
8
- address = "3B1QZ8FpAaHBgkSB5gFt76ag5AW9VeP8xp"
9
- expect(adapter).to receive(:straighten_transaction).with(anything, address: address).at_least(:once)
10
- expect(adapter.fetch_transactions_for(address)).not_to be_empty
11
- end
12
-
13
- it "fetches the balance for a given address" do
14
- address = "1NX8bgWdPq2NahtTbTUAAdsTwpMpvt7nLy"
15
- expect(adapter.fetch_balance_for(address)).to be_kind_of(Integer)
16
- end
17
-
18
- it "fetches a single transaction" do
19
- tid = 'ae0d040f48d75fdc46d9035236a1782164857d6f0cca1f864640281115898560'
20
- expect(adapter.fetch_transaction(tid)[:total_amount]).to eq(832947)
21
- end
22
-
23
- it "calculates the number of confirmations for each transaction" do
24
- tid = 'ae0d040f48d75fdc46d9035236a1782164857d6f0cca1f864640281115898560'
25
- expect(adapter.fetch_transaction(tid)[:confirmations]).to be > 0
26
- end
27
-
28
- it "gets a transaction id among other data" do
29
- tid = 'ae0d040f48d75fdc46d9035236a1782164857d6f0cca1f864640281115898560'
30
- expect(adapter.fetch_transaction(tid)[:tid]).to eq(tid)
31
- end
32
-
33
- it "gets the latest block number" do
34
- expect(adapter.latest_block[:block]["height"]).to be_kind_of(Integer)
35
- end
36
-
37
- it "caches latestblock requests" do
38
- latest_block_response = double('Blockchain info latest block response')
39
- expect(latest_block_response).to receive(:body).and_return('{ "r": { "height": 1 }}')
40
- expect(HTTParty).to receive(:post).with("https://mws2.mycelium.com/wapi/wapi/queryUnspentOutputs", anything).once.and_return(latest_block_response)
41
- adapter.send(:calculate_confirmations, 1, force_latest_block_reload: true)
42
- adapter.send(:calculate_confirmations, 1)
43
- adapter.send(:calculate_confirmations, 1)
44
- adapter.send(:calculate_confirmations, 1)
45
- adapter.send(:calculate_confirmations, 1)
46
- end
47
-
48
- it "raises an exception when something goes wrong with fetching datd" do
49
- expect( -> { adapter.send(:api_request, "/a-404-request") }).to raise_error(Straight::Blockchain::Adapter::RequestError)
50
- end
51
-
52
- it "uses the same Singleton instance" do
53
- a = Straight::Blockchain::MyceliumAdapter.mainnet_adapter
54
- b = Straight::Blockchain::MyceliumAdapter.mainnet_adapter
55
- expect(a).to eq(b)
56
- end
57
-
58
- end
@@ -1,55 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Straight::ExchangeRate::Adapter do
4
-
5
- class Straight::ExchangeRate::Adapter
6
- FETCH_URL = ''
7
- end
8
-
9
- before(:each) do
10
- @exchange_adapter = Straight::ExchangeRate::Adapter.instance
11
- end
12
-
13
- describe "converting currencies" do
14
-
15
- before(:each) do
16
- allow(@exchange_adapter).to receive(:fetch_rates!)
17
- allow(@exchange_adapter).to receive(:rate_for).with('USD').and_return(450.5412)
18
- end
19
-
20
- it "converts amount from currency into BTC" do
21
- expect(@exchange_adapter.convert_from_currency(2252.706, currency: 'USD')).to eq(500000000)
22
- end
23
-
24
- it "converts from btc into currency" do
25
- expect(@exchange_adapter.convert_to_currency(500000000, currency: 'USD')).to eq(2252.706)
26
- end
27
-
28
- it "shows btc amounts in various denominations" do
29
- expect(@exchange_adapter.convert_from_currency(2252.706, currency: 'USD', btc_denomination: :btc)).to eq(5)
30
- expect(@exchange_adapter.convert_to_currency(5, currency: 'USD', btc_denomination: :btc)).to eq(2252.706)
31
- end
32
-
33
- it "accepts string as amount and converts it properly" do
34
- expect(@exchange_adapter.convert_from_currency('2252.706', currency: 'USD', btc_denomination: :btc)).to eq(5)
35
- expect(@exchange_adapter.convert_to_currency('5', currency: 'USD', btc_denomination: :btc)).to eq(2252.706)
36
- end
37
-
38
- end
39
-
40
- it "when checking for rates, only calls fetch_rates! if they were checked long time ago or never" do
41
- uri_mock = double('uri mock')
42
- expect(URI).to receive(:parse).and_return(uri_mock).twice
43
- expect(uri_mock).to receive(:read).and_return('{ "USD": 534.4343 }').twice
44
- @exchange_adapter.rate_for('USD')
45
- @exchange_adapter.rate_for('USD') # not calling fetch_rates! because we've just checked
46
- @exchange_adapter.instance_variable_set(:@rates_updated_at, Time.now-1900)
47
- @exchange_adapter.rate_for('USD')
48
- end
49
-
50
- it "raises exception if rate is nil" do
51
- rate = nil
52
- expect( -> { @exchange_adapter.rate_to_f(rate) }).to raise_error(Straight::ExchangeRate::Adapter::CurrencyNotSupported)
53
- end
54
-
55
- end
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Straight::ExchangeRate::AverageRateAdapter do
4
-
5
- before(:each) do
6
- @average_rates_adapter = Straight::ExchangeRate::AverageRateAdapter.instance(
7
- Straight::ExchangeRate::BitstampAdapter,
8
- Straight::ExchangeRate::BitpayAdapter.instance,
9
- )
10
- end
11
-
12
- it "calculates average rate" do
13
- json_response_bistamp = '{"high": "232.89", "last": "100", "timestamp": "1423457015", "bid": "224.00", "vwap": "224.57", "volume": "14810.41127494", "low": "217.28", "ask": "224.13"}'
14
- json_response_bitpay = '[{"code":"USD","name":"US Dollar","rate":200},{"code":"EUR","name":"Eurozone Euro","rate":197.179544}]'
15
- uri_mock = double('uri mock')
16
- allow(uri_mock).to receive(:read).with(read_timeout: 4).and_return(json_response_bistamp, json_response_bitpay)
17
- allow(URI).to receive(:parse).and_return(uri_mock)
18
- expect(@average_rates_adapter.rate_for('USD')).to eq 150
19
- end
20
-
21
- it "fetches rates for all adapters" do
22
- expect(@average_rates_adapter.fetch_rates!).not_to be_empty
23
- end
24
-
25
- it 'raises error if all adapters failed to fetch rates' do
26
- adapter_mocks = [double('adapter_1'), double('adapter_2')]
27
- adapter_mocks.each do |adapter|
28
- expect(adapter).to receive(:fetch_rates!).and_raise(Straight::ExchangeRate::Adapter::FetchingFailed)
29
- end
30
- average_rates_adapter = Straight::ExchangeRate::AverageRateAdapter.instance(*adapter_mocks)
31
- expect( -> { average_rates_adapter.fetch_rates! }).to raise_error(Straight::ExchangeRate::Adapter::FetchingFailed)
32
- end
33
-
34
- it "raises exception if all adapters fail to get rates" do
35
- expect( -> { @average_rates_adapter.rate_for('FEDcoin') }).to raise_error(Straight::ExchangeRate::Adapter::CurrencyNotSupported)
36
- end
37
-
38
- it "raises exception if unallowed method is called" do # fetch_rates! is not to be used in AverageRateAdapter itself
39
- expect( -> { @average_rates_adapter.get_rate_value_from_hash(nil, 'nothing') }).to raise_error("This method is not supposed to be used in #{@average_rates_adapter.class}.")
40
- expect( -> { @average_rates_adapter.rate_to_f(nil) }).to raise_error("This method is not supposed to be used in #{@average_rates_adapter.class}.")
41
- end
42
-
43
- end
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Straight::ExchangeRate::BitpayAdapter do
4
-
5
- before(:each) do
6
- @exchange_adapter = Straight::ExchangeRate::BitpayAdapter.instance
7
- end
8
-
9
- it "finds the rate for currency code" do
10
- expect(@exchange_adapter.rate_for('USD')).to be_kind_of(Float)
11
- expect( -> { @exchange_adapter.rate_for('FEDcoin') }).to raise_error(Straight::ExchangeRate::Adapter::CurrencyNotSupported)
12
- end
13
-
14
- it "raises exception if rate is nil" do
15
- json_response_1 = '[{},{}]'
16
- json_response_2 = '[{"code":"USD","name":"US Dollar","rat":223.59},{"code":"EUR","name":"Eurozone Euro","rate":197.179544}]'
17
- json_response_3 = '[{"code":"USD","name":"US Dollar","rate":null},{"code":"EUR","name":"Eurozone Euro","rate":197.179544}]'
18
- uri_mock = double('uri mock')
19
- allow(uri_mock).to receive(:read).with(read_timeout: 4).and_return(json_response_1, json_response_2, json_response_3)
20
- allow(URI).to receive(:parse).and_return(uri_mock)
21
- 3.times do
22
- @exchange_adapter.fetch_rates!
23
- expect( -> { @exchange_adapter.rate_for('USD') }).to raise_error(Straight::ExchangeRate::Adapter::CurrencyNotSupported)
24
- end
25
- end
26
-
27
- end
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Straight::ExchangeRate::BitstampAdapter do
4
-
5
- before(:each) do
6
- @exchange_adapter = Straight::ExchangeRate::BitstampAdapter.instance
7
- end
8
-
9
- it "finds the rate for currency code" do
10
- expect(@exchange_adapter.rate_for('USD')).to be_kind_of(Float)
11
- expect( -> { @exchange_adapter.rate_for('FEDcoin') }).to raise_error(Straight::ExchangeRate::Adapter::CurrencyNotSupported)
12
- end
13
-
14
- it "raises exception if rate is nil" do
15
- json_response_1 = '{}'
16
- json_response_2 = '{"high": "232.89", "list": "224.13", "timestamp": "1423457015", "bid": "224.00", "vwap": "224.57", "volume": "14810.41127494", "low": "217.28", "ask": "224.13"}'
17
- json_response_3 = '{"high": "232.89", "last": null, "timestamp": "1423457015", "bid": "224.00", "vwap": "224.57", "volume": "14810.41127494", "low": "217.28", "ask": "224.13"}'
18
- uri_mock = double('uri mock')
19
- allow(uri_mock).to receive(:read).with(read_timeout: 4).and_return(json_response_1, json_response_2, json_response_3)
20
- allow(URI).to receive(:parse).and_return(uri_mock)
21
- 3.times do
22
- @exchange_adapter.fetch_rates!
23
- expect( -> { @exchange_adapter.rate_for('USD') }).to raise_error(Straight::ExchangeRate::Adapter::CurrencyNotSupported)
24
- end
25
- end
26
-
27
- end
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Straight::ExchangeRate::BtceAdapter do
4
-
5
- before(:each) do
6
- @exchange_adapter = Straight::ExchangeRate::BtceAdapter.instance
7
- end
8
-
9
- it "finds the rate for currency code" do
10
- expect(@exchange_adapter.rate_for('USD')).to be_kind_of(Float)
11
- expect( -> { @exchange_adapter.rate_for('FEDcoin') }).to raise_error(Straight::ExchangeRate::Adapter::CurrencyNotSupported)
12
- end
13
-
14
- it "rases exception if rate is nil" do
15
- json_response_1 = '{"ticker":{}}'
16
- json_response_2 = '{"ticker":{"high":235,"low":215.89999,"avg":225.449995,"vol":2848293.72397,"vol_cur":12657.55799,"bambo":221.444,"buy":221.629,"sell":220.98,"updated":1422678812,"server_time":1422678813}}'
17
- json_response_3 = '{"ticker":{"high":235,"low":215.89999,"avg":225.449995,"vol":2848293.72397,"vol_cur":12657.55799,"last":null,"buy":221.629,"sell":220.98,"updated":1422678812,"server_time":1422678813}}'
18
- uri_mock = double('uri mock')
19
- allow(uri_mock).to receive(:read).with(read_timeout: 4).and_return(json_response_1, json_response_2, json_response_3)
20
- allow(URI).to receive(:parse).and_return(uri_mock)
21
- 3.times do
22
- @exchange_adapter.fetch_rates!
23
- expect( -> { @exchange_adapter.rate_for('USD') }).to raise_error(Straight::ExchangeRate::Adapter::CurrencyNotSupported)
24
- end
25
- end
26
-
27
- end