money-coinmarketcap-bank 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -4
- data/lib/money/bank/coin_market_cap.rb +10 -7
- data/money-coinmarketcap-bank.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83b6668ba3bb114442aa216d2c401f16d690d8b6
|
4
|
+
data.tar.gz: 46b28111fb02990f0d307a63f8beb937f2ef4a62
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcb1a8b28f54441af37187705522bef2e618ca96dd63d6cbcd86922b3a8cbcb647c811f1dac57b31341552d297d7dc0f60f2356d9a861bc113b1e155f767828d
|
7
|
+
data.tar.gz: 1d627d488780741e5a2f65302c9f69819e4a01e9a0edaf765b37d2cc26a819cb2ada55aad6ca6083dddd5f0a74d1b504ed9b1093d78063b6ce59f047616ea5d0
|
data/README.md
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
money-coinmarketcap-bank
|
2
|
+
========================
|
3
|
+
CoinMarketCap frontend for ruby-money
|
3
4
|
|
4
|
-
Attach this gem to ruby-money to use it as bank and get the exchange rate from [
|
5
|
+
Attach this gem to ruby-money to use it as bank and get the exchange rate from [coinmarketcap.com](http://coinmarketcap.com/).
|
5
6
|
|
6
7
|
This gem is basically a clone of [money-uphold-bank](https://github.com/subvisual/money-uphold-bank).
|
7
|
-
|
8
|
+
All the credits go to its creators.
|
8
9
|
|
9
10
|
# Usage
|
10
11
|
|
@@ -12,13 +12,16 @@ class Money
|
|
12
12
|
# Seconds after which the current rates are automatically expired
|
13
13
|
attr_accessor :ttl_in_seconds
|
14
14
|
|
15
|
+
# Parsed UpholdBank result as a Hash
|
16
|
+
attr_reader :tickers
|
17
|
+
|
15
18
|
# Rates expiration time
|
16
19
|
attr_reader :rates_expire_at
|
17
20
|
|
18
21
|
def initialize(*args, &block)
|
19
22
|
super
|
20
23
|
|
21
|
-
|
24
|
+
self.ttl_in_seconds = 3600 # 1 hour
|
22
25
|
end
|
23
26
|
|
24
27
|
def update_rates
|
@@ -55,17 +58,17 @@ class Money
|
|
55
58
|
rate
|
56
59
|
end
|
57
60
|
|
58
|
-
def
|
59
|
-
return @coins if @coins
|
60
|
-
|
61
|
+
def currencies
|
61
62
|
response = open(EXCHANGE_URL).read
|
62
63
|
@coins = JSON.parse(response)['markets']
|
64
|
+
@rates_expire_at = Time.now + ttl_in_seconds
|
65
|
+
@coins
|
63
66
|
end
|
64
67
|
|
65
68
|
def add_exchange_rates
|
66
|
-
|
67
|
-
iso_from =
|
68
|
-
|
69
|
+
currencies.each do |currency|
|
70
|
+
iso_from = currency['symbol']
|
71
|
+
currency['price'].each do |iso_to, rate|
|
69
72
|
next unless Money::Currency.find(iso_from) && Money::Currency.find(iso_to)
|
70
73
|
add_rate(iso_from, iso_to, rate)
|
71
74
|
add_rate(iso_to, iso_from, 1.0 / rate)
|