currency-rate 0.2.0 → 0.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3840cff6b0d67d1daba2cf2a74231d2c8655311e
4
- data.tar.gz: 9057b69eeef323940d40e0f127abe91cc902e949
3
+ metadata.gz: e0b5e77d6b38d2c35b7571ad074be82db677be4c
4
+ data.tar.gz: 8a30a9a49e696c626435ccc290c80eca6995350a
5
5
  SHA512:
6
- metadata.gz: 64b511ad2f1a37c491a0e3d805c0053130dfeceb9e19874a8a3a981b175840098abbb529d9a89881b466ed15bd4364eeecfc9be04b3aefa6b8d05b7851f798d4
7
- data.tar.gz: 9b4708166f703fb4ebc34563073dd846e593fe87b2a17716ee5b76f1a0d60800caf1efcd1a75f94f869d381b448ba4123a0fae54de26f351720cbcef933b30bf
6
+ metadata.gz: b0fdd7232a2fbb6721adbe444a9a90beb1b197d348ee4d08e435b9f32e1984f4a6c86d46fdb2e09dbcdcc54f384c7c375c0ff98d074f4c7f8dbb6d86b6992a0e
7
+ data.tar.gz: e0fca9cf058bfc219ac771bc89759ace677e9f4da365103ec4f239ea06b5e5cffb20fa337ff1125cd9f491c6b6cdb7a7096743a9973af8ec1f59b8dbd6942fc7
data/README.md CHANGED
@@ -39,7 +39,7 @@ In the second case, we are trying to get the exchange rate for USD/BTC pair, whi
39
39
  "how much in BTC would 1 USD be?". If the source (Bitstamp, in this case) doesn't provide the
40
40
  inverted rate, the Adapter inverts the rate itself using the exchange rate for BTC/USD.
41
41
 
42
- You can also using `anchor_currency` with `#get`:
42
+ You can also use `anchor_currency` argument with `#get`:
43
43
 
44
44
  CurrencyRate.get('Bitstamp', 'USD', 'EUR', anchor_currency: 'BTC')
45
45
 
@@ -63,3 +63,15 @@ for how and when to store/fetch data, not other classes.
63
63
  Credits
64
64
  -------
65
65
  This gem was extracted from [straight gem](https://github.com/MyceliumGear/straight), thanks to all the people who added various exchange rate adapters and contributed code.
66
+
67
+ TODO
68
+ ----
69
+
70
+ 1. Remove code duplication in Adapters, specifically for
71
+ `#rate_for`, `#invert_rate` and `#currency_pair_rate` methods.
72
+
73
+ 2. Allow both lower case and upper case currency codes.
74
+
75
+ 3. Clean up tests, I have a feeling there some completely useless ones.
76
+
77
+ 4. Adapters should have a default "to" currency. For example, everyone knows Bitfinex trades BTC for USD mostly.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -5,7 +5,8 @@ module CurrencyRate
5
5
 
6
6
  def rate_for(from,to)
7
7
  super
8
- rate = rate_to_f(@rates['ticker']['last'])
8
+ raise raise CurrencyNotSupported unless [from,to].include?('CNY')
9
+ rate = rate_to_f(@rates['ticker'] && @rates['ticker']['last'])
9
10
  invert_rate(from,to,rate)
10
11
  end
11
12
 
data/lib/currency_rate.rb CHANGED
@@ -40,11 +40,15 @@ module CurrencyRate
40
40
  to == 'BTC' ? result : result.round(2)
41
41
  end
42
42
 
43
- private
43
+ private
44
44
 
45
45
  def self.adapter_class(s)
46
46
  return s unless s.kind_of?(String) # if we pass class, no need to convert
47
- adapter = "#{s}_adapter".classify(CurrencyRate).instance
47
+ adapter = classify_string("#{s}_adapter", CurrencyRate).instance
48
+ end
49
+
50
+ def self.classify_string(s, prefix="")
51
+ Kernel.const_get(prefix.to_s + "::" + s.split('_').collect(&:capitalize).join)
48
52
  end
49
53
 
50
54
  end
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: http://api.huobi.com/staticmarket/ticker_btc_json.js
5
+ uri: https://data.btcchina.com/data/ticker
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
@@ -18,66 +18,37 @@ http_interactions:
18
18
  code: 200
19
19
  message: OK
20
20
  headers:
21
- Date:
22
- - Mon, 20 Jun 2016 07:13:19 GMT
23
- Content-Type:
24
- - application/javascript;charset=UTF-8
25
- Content-Length:
26
- - '152'
27
- Connection:
28
- - keep-alive
29
- Set-Cookie:
30
- - __jsluid=4232513531b381fc752eef8d4dd55251; path=/
21
+ Access-Control-Allow-Methods:
22
+ - GET
31
23
  Access-Control-Allow-Origin:
32
24
  - "*"
33
- X-Frame-Options:
34
- - SAMEORIGIN
35
- X-Cache:
36
- - bypass
37
- body:
38
- encoding: UTF-8
39
- string: '{"time":"1466406799","ticker":{"open":5108.77,"vol":512967.119,"symbol":"btccny","last":5084.51,"buy":5084.51,"sell":5084.93,"high":5138,"low":5010.5}
40
- }'
41
- http_version:
42
- recorded_at: Mon, 20 Jun 2016 07:13:19 GMT
43
- - request:
44
- method: get
45
- uri: http://api.huobi.com/staticmarket/ticker_ltc_json.js
46
- body:
47
- encoding: US-ASCII
48
- string: ''
49
- headers:
50
- Accept-Encoding:
51
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
52
- Accept:
53
- - "*/*"
54
- User-Agent:
55
- - Ruby
56
- response:
57
- status:
58
- code: 200
59
- message: OK
60
- headers:
61
- Date:
62
- - Mon, 20 Jun 2016 07:13:20 GMT
25
+ Cache-Control:
26
+ - no-store, no-cache, must-revalidate, post-check=0, pre-check=0
63
27
  Content-Type:
64
- - application/javascript;charset=UTF-8
65
- Content-Length:
66
- - '147'
28
+ - application/json
29
+ Date:
30
+ - Tue, 21 Jun 2016 08:28:10 GMT
31
+ Expires:
32
+ - Thu, 19 Nov 1981 08:52:00 GMT
33
+ Front-End-Https:
34
+ - 'on'
35
+ Pragma:
36
+ - no-cache
37
+ Server:
38
+ - nginx/1.8.1
39
+ Set-Cookie:
40
+ - btcchina_lang=en; expires=Wed, 21-Jun-2017 08:28:10 GMT; path=/; domain=.btcc.com
41
+ X-Cache-Cfc:
42
+ - "- 1466497690.039"
43
+ X-Powered-By:
44
+ - PHP/5.4.45
45
+ Transfer-Encoding:
46
+ - chunked
67
47
  Connection:
68
48
  - keep-alive
69
- Set-Cookie:
70
- - __jsluid=7312808630c655d05ce1143b909ff703; path=/
71
- Access-Control-Allow-Origin:
72
- - "*"
73
- X-Frame-Options:
74
- - SAMEORIGIN
75
- X-Cache:
76
- - bypass
77
49
  body:
78
50
  encoding: UTF-8
79
- string: '{"time":"1466406800","ticker":{"open":37.46,"vol":46953638.9983,"symbol":"ltccny","last":36.92,"buy":36.91,"sell":36.92,"high":37.59,"low":36.59}
80
- }'
51
+ string: '{"ticker":{"high":"5090.00","low":"4615.02","buy":"4785.55","sell":"4786.12","last":"4785.55","vol":"58752.19850000","date":1466497687,"vwap":"4738.11","prev_close":"4931.64","open":"4931.65"}}'
81
52
  http_version:
82
- recorded_at: Mon, 20 Jun 2016 07:13:20 GMT
53
+ recorded_at: Tue, 21 Jun 2016 08:28:10 GMT
83
54
  recorded_with: VCR 3.0.3
@@ -19,15 +19,15 @@ http_interactions:
19
19
  message: OK
20
20
  headers:
21
21
  Date:
22
- - Mon, 20 Jun 2016 07:03:48 GMT
22
+ - Tue, 21 Jun 2016 08:25:20 GMT
23
23
  Content-Type:
24
24
  - application/javascript;charset=UTF-8
25
25
  Content-Length:
26
- - '147'
26
+ - '149'
27
27
  Connection:
28
28
  - keep-alive
29
29
  Set-Cookie:
30
- - __jsluid=d0d079a4dbfaaec600a13a4d86867881; path=/
30
+ - __jsluid=683b360451a7f7c973ef086944f6a50e; path=/
31
31
  Access-Control-Allow-Origin:
32
32
  - "*"
33
33
  X-Frame-Options:
@@ -36,10 +36,10 @@ http_interactions:
36
36
  - bypass
37
37
  body:
38
38
  encoding: UTF-8
39
- string: '{"time":"1466406228","ticker":{"open":5108.77,"vol":510742.6937,"symbol":"btccny","last":5081,"buy":5081,"sell":5081.09,"high":5138,"low":5010.5}
39
+ string: '{"time":"1466497520","ticker":{"open":4961.18,"vol":602328.2638,"symbol":"btccny","last":4791.5,"buy":4792.1,"sell":4792.99,"high":4993,"low":4650}
40
40
  }'
41
41
  http_version:
42
- recorded_at: Mon, 20 Jun 2016 07:03:48 GMT
42
+ recorded_at: Tue, 21 Jun 2016 08:25:20 GMT
43
43
  - request:
44
44
  method: get
45
45
  uri: http://api.huobi.com/staticmarket/ticker_ltc_json.js
@@ -59,15 +59,15 @@ http_interactions:
59
59
  message: OK
60
60
  headers:
61
61
  Date:
62
- - Mon, 20 Jun 2016 07:03:49 GMT
62
+ - Tue, 21 Jun 2016 08:25:21 GMT
63
63
  Content-Type:
64
64
  - application/javascript;charset=UTF-8
65
65
  Content-Length:
66
- - '145'
66
+ - '147'
67
67
  Connection:
68
68
  - keep-alive
69
69
  Set-Cookie:
70
- - __jsluid=77e576c3013fc72045c6db3c1486abac; path=/
70
+ - __jsluid=37a542d8ce58ca1b0f4ff9619ec029c2; path=/
71
71
  Access-Control-Allow-Origin:
72
72
  - "*"
73
73
  X-Frame-Options:
@@ -76,8 +76,8 @@ http_interactions:
76
76
  - bypass
77
77
  body:
78
78
  encoding: UTF-8
79
- string: '{"time":"1466406229","ticker":{"open":37.46,"vol":46826640.2353,"symbol":"ltccny","last":36.9,"buy":36.9,"sell":36.91,"high":37.59,"low":36.59}
79
+ string: '{"time":"1466497521","ticker":{"open":36.11,"vol":65225442.1187,"symbol":"ltccny","last":34.25,"buy":34.24,"sell":34.25,"high":36.26,"low":32.53}
80
80
  }'
81
81
  http_version:
82
- recorded_at: Mon, 20 Jun 2016 07:03:49 GMT
82
+ recorded_at: Tue, 21 Jun 2016 08:25:21 GMT
83
83
  recorded_with: VCR 3.0.3
@@ -11,12 +11,12 @@ RSpec.describe CurrencyRate::BTCChinaAdapter do
11
11
  end
12
12
 
13
13
  before(:each) do
14
- @exchange_adapter = CurrencyRate::HuobiAdapter.instance
14
+ @exchange_adapter = CurrencyRate::BTCChinaAdapter.instance
15
15
  end
16
16
 
17
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)
18
+ expect(@exchange_adapter.rate_for('BTC', 'CNY')).to eq(4785.55)
19
+ expect(@exchange_adapter.rate_for('CNY', 'BTC')).to eq(0.00020896239721662085)
20
20
  expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
21
21
  end
22
22
 
@@ -15,10 +15,10 @@ RSpec.describe CurrencyRate::HuobiAdapter do
15
15
  end
16
16
 
17
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)
18
+ expect(@exchange_adapter.rate_for('BTC', 'CNY')).to eq(4791.5)
19
+ expect(@exchange_adapter.rate_for('CNY', 'BTC')).to eq(0.0002087029114056141)
20
+ expect(@exchange_adapter.rate_for('LTC', 'CNY')).to eq(34.25)
21
+ expect(@exchange_adapter.rate_for('CNY', 'LTC')).to eq(0.029197080291970802)
22
22
  expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
23
23
  end
24
24
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: currency-rate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Snitko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-20 00:00:00.000000000 Z
11
+ date: 2016-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: satoshi-unit
@@ -124,7 +124,6 @@ files:
124
124
  - lib/btc_adapters/kraken_adapter.rb
125
125
  - lib/btc_adapters/localbitcoins_adapter.rb
126
126
  - lib/btc_adapters/okcoin_adapter.rb
127
- - lib/core_ext/classify.rb
128
127
  - lib/core_ext/deep_get.rb
129
128
  - lib/currency_rate.rb
130
129
  - lib/fiat_adapter.rb
@@ -1,7 +0,0 @@
1
- class String
2
-
3
- def classify(prefix="")
4
- Kernel.const_get(prefix.to_s + "::" + self.split('_').collect(&:capitalize).join)
5
- end
6
-
7
- end