currency-rate 0.1.1 → 0.2.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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -0
  3. data/VERSION +1 -1
  4. data/currency-rate.gemspec +22 -3
  5. data/lib/adapter.rb +17 -9
  6. data/lib/btc_adapter.rb +4 -6
  7. data/lib/btc_adapters/average_rate_adapter.rb +4 -3
  8. data/lib/btc_adapters/bitfinex_adapter.rb +30 -0
  9. data/lib/btc_adapters/bitpay_adapter.rb +10 -3
  10. data/lib/btc_adapters/bitstamp_adapter.rb +24 -5
  11. data/lib/btc_adapters/btcchina_adapter.rb +13 -0
  12. data/lib/btc_adapters/btce_adapter.rb +26 -5
  13. data/lib/btc_adapters/coinbase_adapter.rb +2 -2
  14. data/lib/btc_adapters/huobi_adapter.rb +30 -0
  15. data/lib/btc_adapters/kraken_adapter.rb +14 -5
  16. data/lib/btc_adapters/localbitcoins_adapter.rb +10 -3
  17. data/lib/btc_adapters/okcoin_adapter.rb +24 -5
  18. data/lib/currency_rate.rb +11 -10
  19. data/lib/fiat_adapter.rb +4 -18
  20. data/lib/fiat_adapters/fixer_adapter.rb +20 -5
  21. data/lib/fiat_adapters/yahoo_adapter.rb +28 -6
  22. data/spec/currency_rate_spec.rb +10 -6
  23. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/average_rate_adapter.yml +423 -0
  24. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/bitfinex_adapter.yml +125 -0
  25. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/bitpay_adapter_yml.yml +272 -0
  26. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/bitstamp_adapter.yml +153 -0
  27. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/btcchina_adapter.yml +83 -0
  28. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/btce_adapter.yml +223 -0
  29. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/coinbase_adapter.yml +76 -0
  30. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/huobi_adapter.yml +83 -0
  31. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/kraken_adapter.yml +83 -0
  32. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/localbitcoins_adapter.yml +128 -0
  33. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/okcoin_adapter.yml +207 -0
  34. data/spec/fixtures/vcr/exchange_rate_adapters/fiat_adapters/fixer_adapter.yml +81 -0
  35. data/spec/fixtures/vcr/exchange_rate_adapters/fiat_adapters/yahoo_adapter.yml +50 -0
  36. data/spec/lib/btc_adapter_spec.rb +16 -28
  37. data/spec/lib/btc_adapters/average_rate_adapter_spec.rb +4 -4
  38. data/spec/lib/btc_adapters/bitfinex_adapter_spec.rb +38 -0
  39. data/spec/lib/btc_adapters/bitpay_adapter_spec.rb +8 -3
  40. data/spec/lib/btc_adapters/bitstamp_adapter_spec.rb +8 -3
  41. data/spec/lib/btc_adapters/btcchina_adapter_spec.rb +36 -0
  42. data/spec/lib/btc_adapters/btce_adapter_spec.rb +10 -3
  43. data/spec/lib/btc_adapters/coinbase_adapter_spec.rb +5 -3
  44. data/spec/lib/btc_adapters/huobi_adapter_spec.rb +38 -0
  45. data/spec/lib/btc_adapters/kraken_adapter_spec.rb +6 -3
  46. data/spec/lib/btc_adapters/localbitcoins_adapter_spec.rb +4 -3
  47. data/spec/lib/btc_adapters/okcoin_adapter_spec.rb +11 -3
  48. data/spec/lib/fiat_adapters/fixer_adapter_spec.rb +5 -2
  49. data/spec/lib/fiat_adapters/yahoo_adapter_spec.rb +5 -2
  50. metadata +21 -2
@@ -0,0 +1,50 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://query.yahooapis.com/v1/public/yql?env=store://datatables.org/alltableswithkeys&format=json&q=SELECT%20*%20FROM%20yahoo.finance.xchange%20WHERE%20pair%20IN(%22USDAUD%22,%22USDBGN%22,%22USDBRL%22,%22USDCAD%22,%22USDCHF%22,%22USDCNY%22,%22USDCZK%22,%22USDDKK%22,%22USDGBP%22,%22USDHKD%22,%22USDHRK%22,%22USDHUF%22,%22USDIDR%22,%22USDILS%22,%22USDINR%22,%22USDJPY%22,%22USDKRW%22,%22USDMXN%22,%22USDMYR%22,%22USDNOK%22,%22USDNZD%22,%22USDPHP%22,%22USDPLN%22,%22USDRON%22,%22USDRUB%22,%22USDSEK%22,%22USDSGD%22,%22USDTHB%22,%22USDTRY%22,%22USDUSD%22,%22USDZAR%22,%22USDEUR%22)
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ X-Yql-Host:
22
+ - main-2327bac4-1df8-11e6-a4df-d4ae52974c31
23
+ X-Content-Type-Options:
24
+ - nosniff
25
+ Access-Control-Allow-Origin:
26
+ - "*"
27
+ Content-Type:
28
+ - application/json; charset=UTF-8
29
+ Cache-Control:
30
+ - no-cache
31
+ Date:
32
+ - Sun, 19 Jun 2016 07:10:46 GMT
33
+ Age:
34
+ - '0'
35
+ Server:
36
+ - ATS
37
+ Via:
38
+ - http/1.1 a14.ue.bf1.yahoo.net (ApacheTrafficServer [cMsSf ])
39
+ Y-Trace:
40
+ - BAEAQAAAAAC2YQNA_AaEuAAAAAAAAAAAZOzi9VN5UAwAAAAAAAAAAAAFNZxJY.NpAAU1nElkwG5.Cp0MAAAAAA--
41
+ Transfer-Encoding:
42
+ - chunked
43
+ Connection:
44
+ - keep-alive
45
+ body:
46
+ encoding: UTF-8
47
+ string: '{"query":{"count":32,"created":"2016-06-19T07:10:46Z","lang":"en-US","results":{"rate":[{"id":"USDAUD","Name":"USD/AUD","Rate":"1.3524","Date":"6/18/2016","Time":"12:29pm","Ask":"1.3530","Bid":"1.3524"},{"id":"USDBGN","Name":"USD/BGN","Rate":"1.7333","Date":"6/18/2016","Time":"12:29pm","Ask":"1.7436","Bid":"1.7333"},{"id":"USDBRL","Name":"USD/BRL","Rate":"3.4162","Date":"6/18/2016","Time":"12:29pm","Ask":"3.4208","Bid":"3.4162"},{"id":"USDCAD","Name":"USD/CAD","Rate":"1.2895","Date":"6/18/2016","Time":"12:29pm","Ask":"1.2900","Bid":"1.2895"},{"id":"USDCHF","Name":"USD/CHF","Rate":"0.9598","Date":"6/18/2016","Time":"12:29pm","Ask":"0.9600","Bid":"0.9598"},{"id":"USDCNY","Name":"USD/CNY","Rate":"6.5705","Date":"6/18/2016","Time":"12:29pm","Ask":"6.5718","Bid":"6.5705"},{"id":"USDCZK","Name":"USD/CZK","Rate":"24.0020","Date":"6/18/2016","Time":"12:29pm","Ask":"24.0200","Bid":"24.0020"},{"id":"USDDKK","Name":"USD/DKK","Rate":"6.5953","Date":"6/18/2016","Time":"12:29pm","Ask":"6.5972","Bid":"6.5953"},{"id":"USDGBP","Name":"USD/GBP","Rate":"0.6964","Date":"6/18/2016","Time":"12:29pm","Ask":"0.6968","Bid":"0.6964"},{"id":"USDHKD","Name":"USD/HKD","Rate":"7.7614","Date":"6/18/2016","Time":"12:29pm","Ask":"7.7616","Bid":"7.7614"},{"id":"USDHRK","Name":"USD/HRK","Rate":"6.6707","Date":"6/18/2016","Time":"12:29pm","Ask":"6.6732","Bid":"6.6707"},{"id":"USDHUF","Name":"USD/HUF","Rate":"278.5100","Date":"6/18/2016","Time":"12:29pm","Ask":"278.9000","Bid":"278.5100"},{"id":"USDIDR","Name":"USD/IDR","Rate":"13337.5000","Date":"6/18/2016","Time":"12:29pm","Ask":"13340.0000","Bid":"13337.5000"},{"id":"USDILS","Name":"USD/ILS","Rate":"3.8674","Date":"6/18/2016","Time":"12:29pm","Ask":"3.8766","Bid":"3.8674"},{"id":"USDINR","Name":"USD/INR","Rate":"67.0724","Date":"6/18/2016","Time":"12:29pm","Ask":"67.0910","Bid":"67.0724"},{"id":"USDJPY","Name":"USD/JPY","Rate":"104.1700","Date":"6/18/2016","Time":"12:29pm","Ask":"104.2000","Bid":"104.1700"},{"id":"USDKRW","Name":"USD/KRW","Rate":"1170.5450","Date":"6/18/2016","Time":"12:29pm","Ask":"1171.9000","Bid":"1170.5450"},{"id":"USDMXN","Name":"USD/MXN","Rate":"18.8280","Date":"6/18/2016","Time":"12:29pm","Ask":"18.8330","Bid":"18.8280"},{"id":"USDMYR","Name":"USD/MYR","Rate":"4.0885","Date":"6/18/2016","Time":"12:29pm","Ask":"4.0895","Bid":"4.0885"},{"id":"USDNOK","Name":"USD/NOK","Rate":"8.3600","Date":"6/18/2016","Time":"12:29pm","Ask":"8.3656","Bid":"8.3600"},{"id":"USDNZD","Name":"USD/NZD","Rate":"1.4176","Date":"6/18/2016","Time":"12:29pm","Ask":"1.4180","Bid":"1.4176"},{"id":"USDPHP","Name":"USD/PHP","Rate":"46.4395","Date":"6/18/2016","Time":"12:29pm","Ask":"46.4700","Bid":"46.4395"},{"id":"USDPLN","Name":"USD/PLN","Rate":"3.9162","Date":"6/18/2016","Time":"12:29pm","Ask":"3.9166","Bid":"3.9162"},{"id":"USDRON","Name":"USD/RON","Rate":"4.0220","Date":"6/18/2016","Time":"12:29pm","Ask":"4.0246","Bid":"4.0220"},{"id":"USDRUB","Name":"USD/RUB","Rate":"64.7795","Date":"6/18/2016","Time":"12:29pm","Ask":"64.8100","Bid":"64.7795"},{"id":"USDSEK","Name":"USD/SEK","Rate":"8.3321","Date":"6/18/2016","Time":"12:29pm","Ask":"8.3336","Bid":"8.3321"},{"id":"USDSGD","Name":"USD/SGD","Rate":"1.3499","Date":"6/18/2016","Time":"12:29pm","Ask":"1.3504","Bid":"1.3499"},{"id":"USDTHB","Name":"USD/THB","Rate":"35.2355","Date":"6/18/2016","Time":"12:29pm","Ask":"35.2640","Bid":"35.2355"},{"id":"USDTRY","Name":"USD/TRY","Rate":"2.9269","Date":"6/18/2016","Time":"12:29pm","Ask":"2.9290","Bid":"2.9269"},{"id":"USDUSD","Name":"USD/USD","Rate":"1.0000","Date":"N/A","Time":"N/A","Ask":"1.0000","Bid":"1.0000"},{"id":"USDZAR","Name":"USD/ZAR","Rate":"15.1519","Date":"6/18/2016","Time":"12:29pm","Ask":"15.1828","Bid":"15.1519"},{"id":"USDEUR","Name":"USD/EUR","Rate":"0.8868","Date":"6/18/2016","Time":"12:29pm","Ask":"0.8870","Bid":"0.8868"}]}}}'
48
+ http_version:
49
+ recorded_at: Sun, 19 Jun 2016 07:10:46 GMT
50
+ recorded_with: VCR 3.0.3
@@ -6,45 +6,33 @@ RSpec.describe CurrencyRate::BtcAdapter do
6
6
  FETCH_URL = ''
7
7
  end
8
8
 
9
+ class SomeExchangeAdapter < CurrencyRate::BtcAdapter
10
+ def rate_for(from,to)
11
+ super
12
+ rate = rate_to_f(750)
13
+ invert_rate(from,to,rate)
14
+ end
15
+ end
16
+
9
17
  before(:each) do
10
18
  @exchange_adapter = CurrencyRate::BtcAdapter.instance
11
19
  end
12
20
 
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
-
21
+ it "inverts currency rate when needed" do
22
+ allow(SomeExchangeAdapter.instance).to receive(:fetch_rates!)
23
+ @exchange_adapter = SomeExchangeAdapter.instance
24
+ expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.0013333333333333333)
38
25
  end
39
26
 
27
+
40
28
  it "when checking for rates, only calls fetch_rates! if they were checked long time ago or never" do
41
29
  uri_mock = double('uri mock')
42
30
  expect(URI).to receive(:parse).and_return(uri_mock).once
43
31
  expect(uri_mock).to receive(:read).and_return('{ "USD": 534.4343 }').once
44
- @exchange_adapter.rate_for('USD')
45
- @exchange_adapter.rate_for('USD') # not calling fetch_rates! because we've just checked
32
+ @exchange_adapter.rate_for('USD', 'BTC')
33
+ @exchange_adapter.rate_for('USD', 'BTC') # not calling fetch_rates! because we've just checked
46
34
  @exchange_adapter.instance_variable_set(:@rates_updated_at, Time.now-1900)
47
- @exchange_adapter.rate_for('USD')
35
+ @exchange_adapter.rate_for('USD', 'BTC')
48
36
  end
49
37
 
50
38
  it "raises exception if rate is nil" do
@@ -2,11 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe CurrencyRate::AverageRateAdapter do
4
4
 
5
- before :all do
5
+ before :each do
6
6
  VCR.insert_cassette 'exchange_rate_adapters/btc_adapters/average_rate_adapter'
7
7
  end
8
8
 
9
- after :all do
9
+ after :each do
10
10
  VCR.eject_cassette
11
11
  end
12
12
 
@@ -23,7 +23,7 @@ RSpec.describe CurrencyRate::AverageRateAdapter do
23
23
  uri_mock = double('uri mock')
24
24
  allow(uri_mock).to receive(:read).with(read_timeout: 4).and_return(json_response_bistamp, json_response_bitpay)
25
25
  allow(URI).to receive(:parse).and_return(uri_mock)
26
- expect(@average_rates_adapter.rate_for('USD')).to eq 150
26
+ expect(@average_rates_adapter.rate_for('BTC', 'USD')).to eq 150
27
27
  end
28
28
 
29
29
  it "fetches rates for all adapters" do
@@ -40,7 +40,7 @@ RSpec.describe CurrencyRate::AverageRateAdapter do
40
40
  end
41
41
 
42
42
  it "raises exception if all adapters fail to get rates" do
43
- expect( -> { @average_rates_adapter.rate_for('FEDcoin') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
43
+ expect( -> { @average_rates_adapter.rate_for('BTC', 'FEDcoin') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
44
44
  end
45
45
 
46
46
  it "raises exception if unallowed method is called" do # fetch_rates! is not to be used in AverageRateAdapter itself
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CurrencyRate::BitfinexAdapter do
4
+
5
+ before :all do
6
+ VCR.insert_cassette 'exchange_rate_adapters/btc_adapters/bitfinex_adapter'
7
+ end
8
+
9
+ after :all do
10
+ VCR.eject_cassette
11
+ end
12
+
13
+ before(:each) do
14
+ @exchange_adapter = CurrencyRate::BitfinexAdapter.instance
15
+ end
16
+
17
+ it "finds the rate for currency code" do
18
+ expect(@exchange_adapter.rate_for('BTC', 'USD')).to eq(763.0)
19
+ expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.001310615989515072)
20
+ expect(@exchange_adapter.rate_for('LTC', 'USD')).to eq(5.5105)
21
+ expect(@exchange_adapter.rate_for('USD', 'LTC')).to eq(0.1814717357771527)
22
+ expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
23
+ end
24
+
25
+ it "raises exception if rate is nil" do
26
+ json_response_1 = '{}'
27
+ json_response_2 = '{"mid":"762.495","bid":"762.49","ask":"762.5","last_price":"762.5","low":"743.1","high":"775.0","volume":"25680.26724445","timestamp":"1466405569.857112499"}'
28
+ json_response_3 = '{"mid":"762.495","bid":"762.49","ask":"762.5","last_price":"762.5","low":"743.1","high":"775.0","volume":"25680.26724445","timestamp":"1466405569.857112499"}'
29
+ uri_mock = double('uri mock')
30
+ allow(uri_mock).to receive(:read).with(read_timeout: 4).and_return(json_response_1, json_response_2, json_response_3)
31
+ allow(URI).to receive(:parse).and_return(uri_mock)
32
+ 3.times do
33
+ @exchange_adapter.fetch_rates!
34
+ expect( -> { @exchange_adapter.rate_for('FEDcoin', 'BTC') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
35
+ end
36
+ end
37
+
38
+ end
@@ -15,8 +15,13 @@ RSpec.describe CurrencyRate::BitpayAdapter do
15
15
  end
16
16
 
17
17
  it "finds the rate for currency code" do
18
- expect(@exchange_adapter.rate_for('USD')).to be_kind_of(Float)
19
- expect( -> { @exchange_adapter.rate_for('FEDcoin') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
18
+ expect(@exchange_adapter.rate_for('BTC', 'USD')).to eq(748.02)
19
+ expect(@exchange_adapter.rate_for('BTC', 'BTC')).to eq(1)
20
+ expect(@exchange_adapter.rate_for('BTC', 'EUR')).to eq(663.359096)
21
+ expect(@exchange_adapter.rate_for('EUR', 'BTC')).to eq(1)
22
+ expect( -> { @exchange_adapter.rate_for('USD', 'EUR') }).to raise_exception(CurrencyRate::Adapter::CurrencyNotSupported)
23
+ expect( -> { @exchange_adapter.rate_for('EUR', 'USD') }).to raise_exception(CurrencyRate::Adapter::CurrencyNotSupported)
24
+ expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
20
25
  end
21
26
 
22
27
  it "raises exception if rate is nil" do
@@ -28,7 +33,7 @@ RSpec.describe CurrencyRate::BitpayAdapter do
28
33
  allow(URI).to receive(:parse).and_return(uri_mock)
29
34
  3.times do
30
35
  @exchange_adapter.fetch_rates!
31
- expect( -> { @exchange_adapter.rate_for('USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
36
+ expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
32
37
  end
33
38
  end
34
39
 
@@ -15,8 +15,13 @@ RSpec.describe CurrencyRate::BitstampAdapter do
15
15
  end
16
16
 
17
17
  it "finds the rate for currency code" do
18
- expect(@exchange_adapter.rate_for('USD')).to be_kind_of(Float)
19
- expect( -> { @exchange_adapter.rate_for('FEDcoin') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
18
+ expect(@exchange_adapter.rate_for('BTC', 'USD')).to eq(751.97)
19
+ expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.0013298402861816295)
20
+ expect(@exchange_adapter.rate_for('BTC', 'EUR')).to eq(674.5)
21
+ expect(@exchange_adapter.rate_for('EUR', 'BTC')).to eq(0.0014825796886582653)
22
+ expect(@exchange_adapter.rate_for('USD', 'EUR')).to eq(0.9008846687447073)
23
+ expect(@exchange_adapter.rate_for('EUR', 'USD')).to eq(1.11002)
24
+ expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
20
25
  end
21
26
 
22
27
  it "raises exception if rate is nil" do
@@ -28,7 +33,7 @@ RSpec.describe CurrencyRate::BitstampAdapter do
28
33
  allow(URI).to receive(:parse).and_return(uri_mock)
29
34
  3.times do
30
35
  @exchange_adapter.fetch_rates!
31
- expect( -> { @exchange_adapter.rate_for('USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
36
+ expect( -> { @exchange_adapter.rate_for('FEDcoin', 'BTC') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
32
37
  end
33
38
  end
34
39
 
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CurrencyRate::BTCChinaAdapter do
4
+
5
+ before :all do
6
+ VCR.insert_cassette 'exchange_rate_adapters/btc_adapters/btcchina_adapter'
7
+ end
8
+
9
+ after :all do
10
+ VCR.eject_cassette
11
+ end
12
+
13
+ before(:each) do
14
+ @exchange_adapter = CurrencyRate::HuobiAdapter.instance
15
+ end
16
+
17
+ it "finds the rate for currency code" do
18
+ expect(@exchange_adapter.rate_for('BTC', 'CNY')).to eq(5084.51)
19
+ expect(@exchange_adapter.rate_for('CNY', 'BTC')).to eq(0.00019667578586727137)
20
+ expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
21
+ end
22
+
23
+ it "raises exception if rate is nil" do
24
+ json_response_1 = '{}'
25
+ json_response_2 = '{"ticker":{"high":"5119.92","low":"4980.00","buy":"5081.50","sell":"5081.97","last":"5081.98","vol":"44572.00110000","date":1466406593,"vwap":"5056.91","prev_close":"5096.97","open":"5096.28"}}'
26
+ json_response_3 = '{"ticker":{"high":"5119.92","low":"4980.00","buy":"5081.50","sell":"5081.97","last":"5081.98","vol":"44572.00110000","date":1466406593,"vwap":"5056.91","prev_close":"5096.97","open":"5096.28"}}'
27
+ uri_mock = double('uri mock')
28
+ allow(uri_mock).to receive(:read).with(read_timeout: 4).and_return(json_response_1, json_response_2, json_response_3)
29
+ allow(URI).to receive(:parse).and_return(uri_mock)
30
+ 3.times do
31
+ @exchange_adapter.fetch_rates!
32
+ expect( -> { @exchange_adapter.rate_for('FEDcoin', 'BTC') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
33
+ end
34
+ end
35
+
36
+ end
@@ -15,8 +15,15 @@ RSpec.describe CurrencyRate::BtceAdapter do
15
15
  end
16
16
 
17
17
  it "finds the rate for currency code" do
18
- expect(@exchange_adapter.rate_for('USD')).to be_kind_of(Float)
19
- expect( -> { @exchange_adapter.rate_for('FEDcoin') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
18
+ expect(@exchange_adapter.rate_for('BTC', 'USD')).to eq(723.872)
19
+ expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.0013814597055833075)
20
+ expect(@exchange_adapter.rate_for('BTC', 'EUR')).to eq(665.022)
21
+ expect(@exchange_adapter.rate_for('EUR', 'BTC')).to eq(0.0015037096517107704)
22
+ expect(@exchange_adapter.rate_for('USD', 'RUB')).to eq(60.5)
23
+ expect(@exchange_adapter.rate_for('RUB', 'USD')).to eq(0.01652892561983471)
24
+ expect(@exchange_adapter.rate_for('EUR', 'RUB')).to eq(65.63)
25
+ expect(@exchange_adapter.rate_for('RUB', 'EUR')).to eq(0.015236934328813043)
26
+ expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
20
27
  end
21
28
 
22
29
  it "rases exception if rate is nil" do
@@ -28,7 +35,7 @@ RSpec.describe CurrencyRate::BtceAdapter do
28
35
  allow(URI).to receive(:parse).and_return(uri_mock)
29
36
  3.times do
30
37
  @exchange_adapter.fetch_rates!
31
- expect( -> { @exchange_adapter.rate_for('USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
38
+ expect( -> { @exchange_adapter.rate_for('USD', 'EUR') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
32
39
  end
33
40
  end
34
41
 
@@ -15,8 +15,9 @@ RSpec.describe CurrencyRate::CoinbaseAdapter do
15
15
  end
16
16
 
17
17
  it "finds the rate for currency code" do
18
- expect(@exchange_adapter.rate_for('USD')).to be_kind_of(Float)
19
- expect( -> { @exchange_adapter.rate_for('FEDcoin') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
18
+ expect(@exchange_adapter.rate_for('BTC', 'USD')).to eq(760.85)
19
+ expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.001314)
20
+ expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
20
21
  end
21
22
 
22
23
  it "raises exception if rate is nil" do
@@ -28,8 +29,9 @@ RSpec.describe CurrencyRate::CoinbaseAdapter do
28
29
  allow(URI).to receive(:parse).and_return(uri_mock)
29
30
  3.times do
30
31
  @exchange_adapter.fetch_rates!
31
- expect( -> { @exchange_adapter.rate_for('USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
32
+ expect( -> { @exchange_adapter.rate_for('FEDCoin', 'BTC') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
32
33
  end
34
+
33
35
  end
34
36
 
35
37
  end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CurrencyRate::HuobiAdapter do
4
+
5
+ before :all do
6
+ VCR.insert_cassette 'exchange_rate_adapters/btc_adapters/huobi_adapter'
7
+ end
8
+
9
+ after :all do
10
+ VCR.eject_cassette
11
+ end
12
+
13
+ before(:each) do
14
+ @exchange_adapter = CurrencyRate::HuobiAdapter.instance
15
+ end
16
+
17
+ it "finds the rate for currency code" do
18
+ expect(@exchange_adapter.rate_for('BTC', 'CNY')).to eq(5081.0)
19
+ expect(@exchange_adapter.rate_for('CNY', 'BTC')).to eq(0.000196811651249754)
20
+ expect(@exchange_adapter.rate_for('LTC', 'CNY')).to eq(36.9)
21
+ expect(@exchange_adapter.rate_for('CNY', 'LTC')).to eq(0.02710027100271003)
22
+ expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
23
+ end
24
+
25
+ it "raises exception if rate is nil" do
26
+ json_response_1 = '{}'
27
+ json_response_2 = '{"time":"1466406045","ticker":{"open":5108.77,"vol":533438.162,"symbol":"btccny","last":5081.29,"buy":5081.13,"sell":5081.29,"high":5138,"low":5010.5} }'
28
+ json_response_3 = '{"time":"1466406045","ticker":{"open":5108.77,"vol":533438.162,"symbol":"btccny","last":5081.29,"buy":5081.13,"sell":5081.29,"high":5138,"low":5010.5} }'
29
+ uri_mock = double('uri mock')
30
+ allow(uri_mock).to receive(:read).with(read_timeout: 4).and_return(json_response_1, json_response_2, json_response_3)
31
+ allow(URI).to receive(:parse).and_return(uri_mock)
32
+ 3.times do
33
+ @exchange_adapter.fetch_rates!
34
+ expect( -> { @exchange_adapter.rate_for('FEDcoin', 'BTC') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
35
+ end
36
+ end
37
+
38
+ end
@@ -15,8 +15,11 @@ RSpec.describe CurrencyRate::KrakenAdapter do
15
15
  end
16
16
 
17
17
  it "finds the rate for currency code" do
18
- expect(@exchange_adapter.rate_for('USD')).to be_kind_of(Float)
19
- expect( -> { @exchange_adapter.rate_for('FEDcoin') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
18
+ expect(@exchange_adapter.rate_for('BTC', 'USD')).to eq(755.15)
19
+ expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.0013242402171753957)
20
+ expect(@exchange_adapter.rate_for('BTC', 'EUR')).to eq(671.215)
21
+ expect(@exchange_adapter.rate_for('EUR', 'BTC')).to eq(0.0014898355966419105)
22
+ expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
20
23
  end
21
24
 
22
25
  it "raises exception if rate is nil" do
@@ -28,7 +31,7 @@ RSpec.describe CurrencyRate::KrakenAdapter do
28
31
  allow(URI).to receive(:parse).and_return(uri_mock)
29
32
  3.times do
30
33
  @exchange_adapter.fetch_rates!
31
- expect( -> { @exchange_adapter.rate_for('USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
34
+ expect( -> { @exchange_adapter.rate_for('FEDCoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
32
35
  end
33
36
  end
34
37
 
@@ -15,8 +15,9 @@ RSpec.describe CurrencyRate::LocalbitcoinsAdapter do
15
15
  end
16
16
 
17
17
  it "finds the rate for currency code" do
18
- expect(@exchange_adapter.rate_for('USD')).to be_kind_of(Float)
19
- expect( -> { @exchange_adapter.rate_for('FEDcoin') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
18
+ expect(@exchange_adapter.rate_for('BTC', 'USD')).to eq(591.95)
19
+ expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.0016893318692457132)
20
+ expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
20
21
  end
21
22
 
22
23
  it "rases exception if rate is nil" do
@@ -28,7 +29,7 @@ RSpec.describe CurrencyRate::LocalbitcoinsAdapter do
28
29
  allow(URI).to receive(:parse).and_return(uri_mock)
29
30
  3.times do
30
31
  @exchange_adapter.fetch_rates!
31
- expect( -> { @exchange_adapter.rate_for('USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
32
+ expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
32
33
  end
33
34
  end
34
35
 
@@ -15,8 +15,16 @@ RSpec.describe CurrencyRate::OkcoinAdapter do
15
15
  end
16
16
 
17
17
  it "finds the rate for currency code" do
18
- expect(@exchange_adapter.rate_for('USD')).to be_kind_of(Float)
19
- expect( -> { @exchange_adapter.rate_for('FEDcoin') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
18
+ expect(@exchange_adapter.rate_for('BTC', 'USD')).to eq(769.05)
19
+ expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.0013003055718093753)
20
+ expect(@exchange_adapter.rate_for('BTC', 'CNY')).to eq(5113.0)
21
+ expect(@exchange_adapter.rate_for('CNY', 'BTC')).to eq(0.00019557989438685703)
22
+
23
+ expect(@exchange_adapter.rate_for('LTC', 'USD')).to eq(5.661)
24
+ expect(@exchange_adapter.rate_for('USD', 'LTC')).to eq(0.17664723547076489)
25
+ expect(@exchange_adapter.rate_for('LTC', 'CNY')).to eq(37.68)
26
+ expect(@exchange_adapter.rate_for('CNY', 'LTC')).to eq(0.02653927813163482)
27
+ expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
20
28
  end
21
29
 
22
30
  it "raises exception if rate is nil" do
@@ -28,7 +36,7 @@ RSpec.describe CurrencyRate::OkcoinAdapter do
28
36
  3.times do |i|
29
37
  @exchange_adapter.instance_variable_set :@rates_updated_at, Time.now
30
38
  @exchange_adapter.instance_variable_set :@rates, JSON.parse(response[i])
31
- expect( -> { @exchange_adapter.rate_for('USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
39
+ expect( -> { @exchange_adapter.rate_for('FEDcoin', 'BTC') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
32
40
  end
33
41
  end
34
42
 
@@ -15,8 +15,11 @@ RSpec.describe CurrencyRate::FixerAdapter do
15
15
  end
16
16
 
17
17
  it "finds the rate for currency code" do
18
- expect(@exchange_adapter.rate_for('RUB')).to be_kind_of(Numeric)
19
- expect( -> { @exchange_adapter.rate_for('KZT') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
18
+ expect(@exchange_adapter.rate_for('EUR', 'USD')).to eq(1.12)
19
+ expect(@exchange_adapter.rate_for('USD', 'EUR')).to eq(0.88)
20
+ expect(@exchange_adapter.rate_for('USD', 'RUB')).to eq(65.12)
21
+ expect(@exchange_adapter.rate_for('RUB', 'USD')).to eq(0.02)
22
+ expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
20
23
  end
21
24
 
22
25
  end