currency-rate 1.4.1 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +22 -0
- data/Gemfile +3 -8
- data/Rakefile +6 -25
- data/api_keys.yml.sample +1 -0
- data/currency-rate.gemspec +33 -133
- data/lib/adapters/crypto/binance_adapter.rb +3 -3
- data/lib/adapters/crypto/bitfinex_adapter.rb +2 -2
- data/lib/adapters/crypto/bitpay_adapter.rb +1 -1
- data/lib/adapters/crypto/bitstamp_adapter.rb +11 -5
- data/lib/adapters/crypto/btc_china_adapter.rb +1 -1
- data/lib/adapters/crypto/btc_e_adapter.rb +1 -1
- data/lib/adapters/crypto/coin_market_cap_adapter.rb +31 -0
- data/lib/adapters/crypto/coinbase_adapter.rb +1 -1
- data/lib/adapters/crypto/exmo_adapter.rb +2 -2
- data/lib/adapters/crypto/huobi_adapter.rb +1 -1
- data/lib/adapters/crypto/kraken_adapter.rb +21 -15
- data/lib/adapters/crypto/localbitcoins_adapter.rb +1 -1
- data/lib/adapters/crypto/okcoin_adapter.rb +1 -1
- data/lib/adapters/fiat/bonbast_adapter.rb +25 -0
- data/lib/adapters/fiat/currency_layer_adapter.rb +1 -1
- data/lib/adapters/fiat/fixer_adapter.rb +1 -1
- data/lib/adapters/fiat/forge_adapter.rb +1 -1
- data/lib/adapters/fiat/free_forex_adapter.rb +1 -1
- data/lib/adapters/fiat/yahoo_adapter.rb +1 -1
- data/lib/configuration.rb +4 -0
- data/lib/currency_rate.rb +3 -1
- data/lib/currency_rate/version.rb +3 -0
- data/lib/fetcher.rb +26 -6
- data/lib/synchronizer.rb +1 -1
- metadata +23 -95
- data/VERSION +0 -1
- data/spec/fixtures/adapters/binance_rates.yml +0 -993
- data/spec/fixtures/adapters/bitfinex_rates.yml +0 -4050
- data/spec/fixtures/adapters/bitpay_rates.yml +0 -490
- data/spec/fixtures/adapters/bitstamp_rates.yml +0 -61
- data/spec/fixtures/adapters/btc_china_rates.yml +0 -11
- data/spec/fixtures/adapters/btce_rates.yml +0 -60
- data/spec/fixtures/adapters/coinbase_rates.yml +0 -181
- data/spec/fixtures/adapters/currency_layer_rates.yml +0 -174
- data/spec/fixtures/adapters/exmo_rates.yml +0 -1251
- data/spec/fixtures/adapters/fixer_rates.yml +0 -174
- data/spec/fixtures/adapters/forge_rates.yml +0 -75
- data/spec/fixtures/adapters/free_forex_rates.yml +0 -59
- data/spec/fixtures/adapters/huobi_rates.yml +0 -22
- data/spec/fixtures/adapters/kraken_rates.yml +0 -507
- data/spec/fixtures/adapters/localbitcoins_rates.yml +0 -493
- data/spec/fixtures/adapters/normalized/binance_rates.yml +0 -134
- data/spec/fixtures/adapters/normalized/bitfinex_rates.yml +0 -95
- data/spec/fixtures/adapters/normalized/bitpay_rates.yml +0 -164
- data/spec/fixtures/adapters/normalized/bitstamp_rates.yml +0 -9
- data/spec/fixtures/adapters/normalized/btc_china_rates.yml +0 -1
- data/spec/fixtures/adapters/normalized/btce_rates.yml +0 -5
- data/spec/fixtures/adapters/normalized/coinbase_rates.yml +0 -179
- data/spec/fixtures/adapters/normalized/currency_layer_rates.yml +0 -169
- data/spec/fixtures/adapters/normalized/exmo_rates.yml +0 -42
- data/spec/fixtures/adapters/normalized/fixer_rates.yml +0 -170
- data/spec/fixtures/adapters/normalized/forge_rates.yml +0 -16
- data/spec/fixtures/adapters/normalized/free_forex_rates.yml +0 -16
- data/spec/fixtures/adapters/normalized/huobi_rates.yml +0 -2
- data/spec/fixtures/adapters/normalized/kraken_rates.yml +0 -21
- data/spec/fixtures/adapters/normalized/localbitcoins_rates.yml +0 -73
- data/spec/fixtures/adapters/normalized/okcoin_rates.yml +0 -4
- data/spec/fixtures/adapters/normalized/yahoo_rates.yml +0 -160
- data/spec/fixtures/adapters/okcoin_rates.yml +0 -40
- data/spec/fixtures/adapters/yahoo_rates.yml +0 -1119
- data/spec/lib/adapter_spec.rb +0 -54
- data/spec/lib/adapters/crypto/binance_adapter_spec.rb +0 -13
- data/spec/lib/adapters/crypto/bitfinex_adapter_spec.rb +0 -13
- data/spec/lib/adapters/crypto/bitpay_adapter_spec.rb +0 -13
- data/spec/lib/adapters/crypto/bitstamp_adapter_spec.rb +0 -13
- data/spec/lib/adapters/crypto/btc_china_adapter_spec.rb +0 -13
- data/spec/lib/adapters/crypto/btc_e_adapter_spec.rb +0 -13
- data/spec/lib/adapters/crypto/coinbase_adapter_spec.rb +0 -13
- data/spec/lib/adapters/crypto/exmo_adapter_spec.rb +0 -13
- data/spec/lib/adapters/crypto/huobi_adapter_spec.rb +0 -13
- data/spec/lib/adapters/crypto/kraken_adapter_spec.rb +0 -13
- data/spec/lib/adapters/crypto/localbitcoins_adapter_spec.rb +0 -13
- data/spec/lib/adapters/crypto/okcoin_adapter_spec.rb +0 -13
- data/spec/lib/adapters/fiat/currency_layer_adapter_spec.rb +0 -23
- data/spec/lib/adapters/fiat/fixer_adapter_spec.rb +0 -13
- data/spec/lib/adapters/fiat/forge_adapter_spec.rb +0 -23
- data/spec/lib/adapters/fiat/free_forex_adapter_spec.rb +0 -13
- data/spec/lib/adapters/fiat/yahoo_adapter_spec.rb +0 -13
- data/spec/lib/currency_rate_spec.rb +0 -9
- data/spec/lib/fetcher_spec.rb +0 -124
- data/spec/lib/storage/file_storage_spec.rb +0 -38
- data/spec/lib/synchronizer_spec.rb +0 -99
- data/spec/spec_helper.rb +0 -28
- data/spec/support/matchers/eq_any_of.rb +0 -3
@@ -1,38 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe CurrencyRate::FileStorage do
|
4
|
-
before do
|
5
|
-
@data = { "key" => "value" }
|
6
|
-
@serializer = CurrencyRate::Storage::YAMLSerializer.new
|
7
|
-
@serialized_data = @serializer.serialize(@data)
|
8
|
-
@storage = CurrencyRate::FileStorage.new(serializer: @serializer)
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "#read" do
|
12
|
-
before do
|
13
|
-
allow(File).to receive(:read).and_return(@serialized_data)
|
14
|
-
allow(File).to receive(:exist?).and_return(true)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "returns deserialized data from file" do
|
18
|
-
expect(@storage.read("exchange")).to eq(@data)
|
19
|
-
end
|
20
|
-
|
21
|
-
context "when exchange file doesn't exist" do
|
22
|
-
before do
|
23
|
-
allow(File).to receive(:read).and_raise(StandardError)
|
24
|
-
end
|
25
|
-
|
26
|
-
it "returns nil" do
|
27
|
-
expect(@storage.read("exchange")).to be_nil
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "#write" do
|
33
|
-
it "writes serialized data to file" do
|
34
|
-
expect(File).to receive(:write).with(kind_of(String), @serialized_data)
|
35
|
-
@storage.write("exchange", @data)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,99 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
RSpec.describe CurrencyRate::Synchronizer do
|
4
|
-
before do
|
5
|
-
@storage_double = double("storage")
|
6
|
-
@synchronizer = CurrencyRate::Synchronizer.new(storage: @storage_double)
|
7
|
-
|
8
|
-
@kraken_data = normalized_data_for :kraken
|
9
|
-
@crypto_adapters = ["Kraken"]
|
10
|
-
allow(CurrencyRate::KrakenAdapter.instance).to receive(:fetch_rates).and_return(@kraken_data)
|
11
|
-
allow(CurrencyRate.configuration).to receive(:crypto_adapters).and_return(@crypto_adapters)
|
12
|
-
|
13
|
-
@yahoo_data = normalized_data_for :yahoo
|
14
|
-
@fiat_adapters = ["Yahoo"]
|
15
|
-
allow(CurrencyRate::YahooAdapter.instance).to receive(:fetch_rates).and_return(@yahoo_data)
|
16
|
-
allow(CurrencyRate.configuration).to receive(:fiat_adapters).and_return(@fiat_adapters)
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "#sync_crypto!" do
|
20
|
-
it "saves crypto rates to given storage" do
|
21
|
-
expect(@storage_double).to receive(:write).with("kraken", @kraken_data)
|
22
|
-
@synchronizer.sync_crypto!
|
23
|
-
end
|
24
|
-
|
25
|
-
it "doesn't fetch fiat rates" do
|
26
|
-
expect(@storage_double).not_to receive(:write).with("yahoo", @yahoo_data)
|
27
|
-
@synchronizer.sync_crypto!
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
describe "#sync_fiat!" do
|
32
|
-
it "saves fiat rates to given storage" do
|
33
|
-
expect(@storage_double).to receive(:write).with("yahoo", @yahoo_data)
|
34
|
-
@synchronizer.sync_fiat!
|
35
|
-
end
|
36
|
-
|
37
|
-
it "doesn't fetch crypto rates" do
|
38
|
-
expect(@storage_double).not_to receive(:write).with("kraken", @kraken_data)
|
39
|
-
@synchronizer.sync_fiat!
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe "#sync!" do
|
44
|
-
before do
|
45
|
-
@kraken_data = normalized_data_for :kraken
|
46
|
-
@crypto_adapters = ["Kraken"]
|
47
|
-
allow(CurrencyRate::KrakenAdapter.instance).to receive(:fetch_rates).and_return(@kraken_data)
|
48
|
-
allow(CurrencyRate.configuration).to receive(:crypto_adapters).and_return(@crypto_adapters)
|
49
|
-
|
50
|
-
@yahoo_data = normalized_data_for :yahoo
|
51
|
-
@fiat_adapters = ["Yahoo"]
|
52
|
-
allow(CurrencyRate::YahooAdapter.instance).to receive(:fetch_rates).and_return(@yahoo_data)
|
53
|
-
allow(CurrencyRate.configuration).to receive(:fiat_adapters).and_return(@fiat_adapters)
|
54
|
-
end
|
55
|
-
|
56
|
-
it "saves fetched rates to given storage" do
|
57
|
-
expect(@storage_double).to receive(:write).with("kraken", @kraken_data)
|
58
|
-
expect(@storage_double).to receive(:write).with("yahoo", @yahoo_data)
|
59
|
-
@synchronizer.sync!
|
60
|
-
end
|
61
|
-
|
62
|
-
context "when adapter returned nil data" do
|
63
|
-
before do
|
64
|
-
allow(CurrencyRate::KrakenAdapter.instance).to receive(:fetch_rates).and_return(nil)
|
65
|
-
allow(@storage_double).to receive(:write).with("yahoo", @yahoo_data)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "doesn't try to save nil data to the storage" do
|
69
|
-
expect(@storage_double).not_to receive(:write).with("kraken", nil)
|
70
|
-
@synchronizer.sync!
|
71
|
-
end
|
72
|
-
|
73
|
-
it "doesn't throw an exception" do
|
74
|
-
expect { @synchronizer.sync! }.not_to raise_error
|
75
|
-
end
|
76
|
-
|
77
|
-
it "saves other successfully fetched adapters data" do
|
78
|
-
expect(@storage_double).to receive(:write).with("yahoo", @yahoo_data)
|
79
|
-
@synchronizer.sync!
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
context "when adapter fetching failed with and error" do
|
84
|
-
before do
|
85
|
-
allow(CurrencyRate::KrakenAdapter.instance).to receive(:fetch_rates).and_raise("Error!")
|
86
|
-
allow(@storage_double).to receive(:write).with("yahoo", @yahoo_data)
|
87
|
-
end
|
88
|
-
|
89
|
-
it "catches the exception" do
|
90
|
-
expect { @synchronizer.sync! }.not_to raise_error
|
91
|
-
end
|
92
|
-
|
93
|
-
it "continues fetching other adapters" do
|
94
|
-
expect(@storage_double).to receive(:write).with("yahoo", @yahoo_data)
|
95
|
-
@synchronizer.sync!
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require "yaml"
|
2
|
-
require "byebug"
|
3
|
-
require "webmock/rspec"
|
4
|
-
|
5
|
-
require_relative "../lib/currency_rate"
|
6
|
-
|
7
|
-
Dir[File.join CurrencyRate.root, "spec/support/**/*.rb"].each { |f| require f }
|
8
|
-
|
9
|
-
def exchange_data_for(name)
|
10
|
-
YAML.load_file File.join(CurrencyRate.root, "spec/fixtures/adapters/#{name}_rates.yml")
|
11
|
-
end
|
12
|
-
|
13
|
-
def normalized_data_for(name)
|
14
|
-
floating = YAML.load_file File.join(CurrencyRate.root, "spec/fixtures/adapters/normalized/#{name}_rates.yml")
|
15
|
-
floating.each { |k, v| floating[k] = BigDecimal.new(v.to_s) if k != "anchor" }
|
16
|
-
end
|
17
|
-
|
18
|
-
def data_for(name)
|
19
|
-
[exchange_data_for(name), normalized_data_for(name)]
|
20
|
-
end
|
21
|
-
|
22
|
-
RSpec.configure do |config|
|
23
|
-
config.default_formatter = "doc"
|
24
|
-
end
|
25
|
-
|
26
|
-
CurrencyRate.configure do |config|
|
27
|
-
config.logger[:level] = :fatal
|
28
|
-
end
|