money-open-exchange-rates 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -12,6 +12,10 @@ moe.cache = 'path/to/file/cache'
12
12
  Money.default_bank = moe
13
13
  ```
14
14
 
15
+ ## Tests
16
+
17
+ bundle exec ruby test/open_exchange_rates_bank_test.rb
18
+
15
19
  ## Refs
16
20
 
17
21
  * https://github.com/currencybot/open-exchange-rates
@@ -9,7 +9,7 @@ class Money
9
9
 
10
10
  class OpenExchangeRatesBank < Money::Bank::VariableExchange
11
11
 
12
- OER_URL = 'http://openexchangerates.org/latest.php'
12
+ OER_URL = 'http://openexchangerates.org/latest.json'
13
13
 
14
14
  attr_accessor :cache
15
15
  attr_reader :doc, :oer_rates, :rates_source
@@ -18,6 +18,7 @@ class Money
18
18
  exchange_rates.each do |exchange_rate|
19
19
  rate = exchange_rate.last
20
20
  currency = exchange_rate.first
21
+ next unless Money::Currency.find(currency)
21
22
  set_rate('USD', currency, rate)
22
23
  end
23
24
  end
data/test/latest.json CHANGED
@@ -1,129 +1,167 @@
1
1
  {
2
2
  "disclaimer": "This data is collected from various providers and provided free of charge for informational purposes only, with no guarantee whatsoever of accuracy, validity, availability or fitness for any purpose; use at your own risk. Other than that - have fun, and please share/watch/fork if you think data like this should be free!",
3
3
  "license": "all code open-source under GPL v3 [http://www.opensource.org/licenses/GPL-3.0]. all data made available by various providers; copyright may apply; not for resale; no warranties given.",
4
- "timestamp": 1318931535,
4
+ "timestamp": 1323614876,
5
5
  "base": "USD",
6
6
  "rates": {
7
- "AED": 3.67000274,
8
- "ALL": 103.01253573,
9
- "ANG": 1.79614315,
10
- "ARS": 4.22279733,
11
- "AUD": 0.985166,
12
- "AWG": 1.788773,
13
- "BBD": 1.99964999,
14
- "BDT": 76.15338649,
15
- "BGN": 1.41994959,
16
- "BHD": 0.37704772,
17
- "BIF": 1218.55496226,
18
- "BMD": 0.99949722,
19
- "BND": 1.27225861,
20
- "BOB": 6.91736836,
21
- "BRL": 1.77381475,
22
- "BSD": 0.99954175,
23
- "BTN": 49.05028406,
24
- "BYR": 7308.49243258,
25
- "BZD": 1.98384726,
26
- "CAD": 1.02336071,
27
- "CHF": 0.90167657,
28
- "CLP": 487.11197257,
29
- "CNY": 6.38085304,
30
- "COP": 1826.6698892,
31
- "CRC": 521.8990447,
32
- "CZK": 18.0694024,
33
- "DKK": 5.44049406,
34
- "DOP": 38.25438217,
35
- "DZD": 73.81094439,
36
- "EEK": 12.07815511,
37
- "EGP": 5.97000248,
38
- "ETB": 17.19251636,
39
- "EUR": 0.73062465,
40
- "FJD": 1.83036833,
41
- "GBP": 0.63603926,
42
- "GMD": 28.76426182,
43
- "GNF": 7306.12192981,
44
- "GTQ": 7.83918646,
45
- "HKD": 7.77640265,
46
- "HNL": 18.87502384,
47
- "HRK": 5.45529344,
48
- "HTG": 40.35709926,
49
- "HUF": 214.84221403,
50
- "IDR": 7306.81897687,
51
- "ILS": 3.64949785,
52
- "INR": 49.37039746,
53
- "IQD": 1217.80316493,
54
- "IRR": 7307.93452885,
55
- "ISK": 115.9989631,
56
- "JMD": 85.97569959,
57
- "JOD": 0.70868135,
58
- "JPY": 76.72400038,
59
- "KES": 98.76466584,
60
- "KMF": 365.42927124,
61
- "KRW": 1218.09757292,
62
- "KWD": 0.27560788,
63
- "KYD": 0.81903871,
64
- "KZT": 149.11496117,
65
- "LBP": 1461.32661693,
66
- "LKR": 110.70093173,
67
- "LSL": 8.0465418,
68
- "LTL": 2.52287977,
69
- "LVL": 0.51543231,
70
- "MAD": 8.21085207,
71
- "MDL": 11.61789383,
72
- "MKD": 44.55887535,
73
- "MNT": 1217.94260361,
74
- "MOP": 8.00333931,
75
- "MRO": 292.28205422,
76
- "MUR": 28.88162297,
77
- "MVR": 15.31876757,
78
- "MWK": 166.11689667,
79
- "MXN": 13.51340243,
80
- "MYR": 3.13293632,
81
- "NAD": 8.04971592,
82
- "NGN": 162.42231002,
83
- "NIO": 22.76948135,
84
- "NOK": 5.65814755,
85
- "NPR": 78.5914389,
86
- "NZD": 1.26937516,
87
- "OMR": 0.38491346,
88
- "PAB": 0.99933189,
89
- "PEN": 2.72220031,
90
- "PGK": 2.17003989,
91
- "PHP": 43.24670259,
92
- "PKR": 87.00825226,
93
- "PLN": 3.17724869,
94
- "PYG": 3655.78872997,
95
- "QAR": 3.64122541,
96
- "RON": 3.18309814,
97
- "RUB": 31.24605524,
98
- "RWF": 609.18567356,
99
- "SAR": 3.7488354,
100
- "SBD": 7.38406858,
101
- "SCR": 12.62561094,
102
- "SEK": 6.69630223,
103
- "SGD": 1.27495292,
104
- "SKK": 22.07966229,
105
- "SLL": 3654.18384486,
106
- "SVC": 8.74162128,
107
- "SZL": 8.05732772,
108
- "THB": 30.70586701,
109
- "TND": 1.42622659,
110
- "TOP": 1.70695633,
111
- "TRY": 1.86605172,
112
- "TTD": 6.40445307,
113
- "TWD": 30.07194885,
114
- "TZS": 1826.90594941,
115
- "UAH": 8.00396967,
116
- "UGX": 2435.87459922,
7
+ "AED": 3.6733,
8
+ "AFN": 43,
9
+ "ALL": 104.019997,
10
+ "AMD": 383.119995,
11
+ "ANG": 1.79,
12
+ "AOA": 94.699997,
13
+ "ARS": 4.271,
14
+ "AUD": 0.978522,
15
+ "AWG": 1.7898,
16
+ "AZN": 0.7864,
17
+ "BAM": 1.46415,
18
+ "BBD": 2,
19
+ "BDT": 77.330002,
20
+ "BGN": 1.4663,
21
+ "BHD": 0.37705,
22
+ "BIF": 1308,
23
+ "BMD": 1,
24
+ "BND": 1.293,
25
+ "BOB": 6.91,
26
+ "BRL": 1.8059,
27
+ "BSD": 1,
28
+ "BTN": 52.035,
29
+ "BWP": 7.4516,
30
+ "BYR": 8675,
31
+ "BZD": 1.9855,
32
+ "CAD": 1.016,
33
+ "CDF": 895.183472,
34
+ "CHF": 0.92295,
35
+ "CLF": 0.02292,
36
+ "CLP": 510.149994,
37
+ "CNY": 6.337,
38
+ "COP": 1925.599976,
39
+ "CRC": 502.600006,
40
+ "CUP": 1,
41
+ "CVE": 82.449997,
42
+ "CZK": 19.006001,
43
+ "DJF": 178.449997,
44
+ "DKK": 5.5579,
45
+ "DOP": 38.549999,
46
+ "DZD": 74.550003,
47
+ "EGP": 6.0226,
48
+ "ETB": 17.272449,
49
+ "EUR": 0.747021,
50
+ "FJD": 1.8484,
51
+ "FKP": 0.6384,
52
+ "GBP": 0.638142,
53
+ "GEL": 1.65485,
54
+ "GHS": 1.6455,
55
+ "GIP": 0.63845,
56
+ "GMD": 29.030001,
57
+ "GNF": 7195,
58
+ "GTQ": 7.7795,
59
+ "GYD": 206.199997,
60
+ "HKD": 7.7821,
61
+ "HNL": 18.92,
62
+ "HRK": 5.61,
63
+ "HTG": 40.349998,
64
+ "HUF": 225.639999,
65
+ "IDR": 9053,
66
+ "IEP": 0.588339,
67
+ "ILS": 3.76165,
68
+ "INR": 51.889999,
69
+ "IQD": 1168.75,
70
+ "IRR": 10888,
71
+ "ISK": 118.900002,
72
+ "JMD": 86.489998,
73
+ "JOD": 0.7105,
74
+ "JPY": 77.629997,
75
+ "KES": 89.449997,
76
+ "KGS": 46.609402,
77
+ "KHR": 4030.300049,
78
+ "KMF": 367.524109,
79
+ "KPW": 900,
80
+ "KRW": 1145.400024,
81
+ "KWD": 0.27705,
82
+ "KZT": 147.820007,
83
+ "LAK": 7995.799805,
84
+ "LBP": 1505,
85
+ "LKR": 113.885002,
86
+ "LRD": 72.5,
87
+ "LSL": 8.09,
88
+ "LTL": 2.5821,
89
+ "LVL": 0.5218,
90
+ "LYD": 1.2416,
91
+ "MAD": 8.3563,
92
+ "MDL": 11.7,
93
+ "MGA": 2095,
94
+ "MKD": 46.185001,
95
+ "MMK": 6.51,
96
+ "MNT": 1352.5,
97
+ "MOP": 8.01585,
98
+ "MRO": 288,
99
+ "MUR": 29.18,
100
+ "MVR": 15.31,
101
+ "MWK": 164.649994,
102
+ "MXN": 13.5745,
103
+ "MYR": 3.1525,
104
+ "MZN": 27.558001,
105
+ "NAD": 8.119,
106
+ "NGN": 161.75,
107
+ "NIO": 22.915001,
108
+ "NOK": 5.7476,
109
+ "NPR": 82.300003,
110
+ "NZD": 1.289325,
111
+ "OMR": 0.38465,
112
+ "PAB": 1,
113
+ "PEN": 2.697,
114
+ "PGK": 2.1277,
115
+ "PHP": 43.470001,
116
+ "PKR": 89.019997,
117
+ "PLN": 3.3702,
118
+ "PYG": 4435,
119
+ "QAR": 3.6416,
120
+ "RON": 3.2461,
121
+ "RSD": 77.095497,
122
+ "RUB": 31.4657,
123
+ "RWF": 602.814758,
124
+ "SAR": 3.7504,
125
+ "SBD": 7.362893,
126
+ "SCR": 13.1239,
127
+ "SDG": 2.6785,
128
+ "SEK": 6.7308,
129
+ "SGD": 1.2925,
130
+ "SHP": 0.63845,
131
+ "SLL": 4378.5,
132
+ "SOS": 1627,
133
+ "SRD": 3.275,
134
+ "STD": 18411.5,
135
+ "SVC": 8.7475,
136
+ "SYP": 54.150002,
137
+ "SZL": 8.091,
138
+ "THB": 30.91,
139
+ "TJS": 4.7587,
140
+ "TMT": 2.8475,
141
+ "TND": 1.4776,
142
+ "TOP": 1.709527,
143
+ "TRY": 1.843,
144
+ "TTD": 6.38645,
145
+ "TWD": 30.212,
146
+ "TZS": 1612.5,
147
+ "UAH": 8,
148
+ "UGX": 2465,
117
149
  "USD": 1,
118
- "UYU": 19.97292206,
119
- "VUV": 92.53276399,
120
- "WST": 2.28297876,
121
- "XAF": 487.33923469,
122
- "XCD": 2.69810192,
123
- "XOF": 487.27721607,
124
- "XPF": 85.9900992,
125
- "YER": 214.97524163,
126
- "ZAR": 8.05499975,
127
- "ZMK": 3636.84384705
150
+ "UYU": 19.799999,
151
+ "UZS": 1783.849976,
152
+ "VEF": 4.2949,
153
+ "VND": 21005,
154
+ "VUV": 92.199997,
155
+ "WST": 2.372813,
156
+ "XAF": 490.032135,
157
+ "XCD": 2.7,
158
+ "XDR": 0.642197,
159
+ "XOF": 490.279999,
160
+ "XPF": 89.150002,
161
+ "YER": 213.054993,
162
+ "ZAR": 8.1,
163
+ "ZMK": 5089.5,
164
+ "ZWD": 378.700012,
165
+ "ZWL": 322.355011
128
166
  }
129
167
  }
@@ -14,6 +14,7 @@ describe Money::Bank::OpenExchangeRatesBank do
14
14
 
15
15
  it "should update itself with exchange rates from OpenExchangeRates" do
16
16
  @bank.oer_rates.keys.each do |currency|
17
+ next unless Money::Currency.find(currency)
17
18
  @bank.get_rate("USD", currency).must_be :>, 0
18
19
  end
19
20
  end
@@ -21,6 +22,7 @@ describe Money::Bank::OpenExchangeRatesBank do
21
22
  it "should return the correct oer rates using oer" do
22
23
  @bank.update_rates
23
24
  @bank.oer_rates.keys.each do |currency|
25
+ next unless Money::Currency.find(currency)
24
26
  subunit = Money::Currency.wrap(currency).subunit_to_unit
25
27
  @bank.exchange(100, "USD", currency).cents.must_equal (@bank.oer_rates[currency].to_f * subunit).round
26
28
  end
@@ -29,11 +31,12 @@ describe Money::Bank::OpenExchangeRatesBank do
29
31
  it "should return the correct oer rates using exchange_with" do
30
32
  @bank.update_rates
31
33
  @bank.oer_rates.keys.each do |currency|
34
+ next unless Money::Currency.find(currency)
32
35
  subunit = Money::Currency.wrap(currency).subunit_to_unit
33
36
  @bank.exchange_with(Money.new(100, "USD"), currency).cents.must_equal (@bank.oer_rates[currency].to_f * subunit).round
34
37
  @bank.exchange_with(1.to_money("USD"), currency).cents.must_equal (@bank.oer_rates[currency].to_f * subunit).round
35
38
  end
36
- @bank.exchange_with(5000.to_money('JPY'), 'USD').cents.must_equal 6517
39
+ @bank.exchange_with(5000.to_money('JPY'), 'USD').cents.must_equal 6441
37
40
  end
38
41
 
39
42
  # in response to #4
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: money-open-exchange-rates
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-19 00:00:00.000000000Z
12
+ date: 2011-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yajl-ruby
16
- requirement: &8234140 !ruby/object:Gem::Requirement
16
+ requirement: &20494700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.8.3
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *8234140
24
+ version_requirements: *20494700
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: money
27
- requirement: &8233040 !ruby/object:Gem::Requirement
27
+ requirement: &20492640 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.7.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *8233040
35
+ version_requirements: *20492640
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: minitest
38
- requirement: &8231820 !ruby/object:Gem::Requirement
38
+ requirement: &20491460 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '2.0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *8231820
46
+ version_requirements: *20491460
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rr
49
- requirement: &8231140 !ruby/object:Gem::Requirement
49
+ requirement: &20490720 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 1.0.4
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *8231140
57
+ version_requirements: *20490720
58
58
  description: A gem that calculates the exchange rate using published rates from open-exchange-rates.
59
59
  Compatible with the money gem.
60
60
  email: laurent@spkdev.net