currency-rate 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/currency-rate.gemspec +4 -6
  4. data/lib/adapter.rb +36 -4
  5. data/lib/btc_adapters/average_rate_adapter.rb +2 -0
  6. data/lib/btc_adapters/bitfinex_adapter.rb +9 -0
  7. data/lib/btc_adapters/bitpay_adapter.rb +9 -2
  8. data/lib/btc_adapters/bitstamp_adapter.rb +9 -1
  9. data/lib/btc_adapters/btcchina_adapter.rb +5 -1
  10. data/lib/btc_adapters/btce_adapter.rb +9 -1
  11. data/lib/btc_adapters/coinbase_adapter.rb +9 -0
  12. data/lib/btc_adapters/huobi_adapter.rb +9 -0
  13. data/lib/btc_adapters/kraken_adapter.rb +9 -0
  14. data/lib/btc_adapters/localbitcoins_adapter.rb +9 -0
  15. data/lib/btc_adapters/okcoin_adapter.rb +9 -0
  16. data/lib/currency_rate.rb +6 -1
  17. data/lib/fiat_adapters/fixer_adapter.rb +11 -0
  18. data/lib/fiat_adapters/yahoo_adapter.rb +8 -0
  19. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/average_rate_adapter.yml +307 -281
  20. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/bitfinex_adapter.yml +46 -50
  21. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/bitpay_adapter.yml +272 -0
  22. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/btcchina_adapter.yml +9 -8
  23. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/btce_adapter.yml +30 -30
  24. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/coinbase_adapter.yml +36 -16
  25. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/huobi_adapter.yml +20 -20
  26. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/kraken_adapter.yml +12 -12
  27. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/localbitcoins_adapter.yml +88 -83
  28. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/okcoin_adapter.yml +52 -36
  29. data/spec/fixtures/vcr/exchange_rate_adapters/fiat_adapters/fixer_adapter.yml +16 -12
  30. data/spec/fixtures/vcr/exchange_rate_adapters/fiat_adapters/yahoo_adapter.yml +9 -11
  31. data/spec/lib/btc_adapter_spec.rb +12 -1
  32. data/spec/lib/btc_adapters/average_rate_adapter_spec.rb +1 -6
  33. data/spec/lib/btc_adapters/bitfinex_adapter_spec.rb +6 -6
  34. data/spec/lib/btc_adapters/bitpay_adapter_spec.rb +5 -5
  35. data/spec/lib/btc_adapters/bitstamp_adapter_spec.rb +9 -9
  36. data/spec/lib/btc_adapters/btcchina_adapter_spec.rb +4 -4
  37. data/spec/lib/btc_adapters/btce_adapter_spec.rb +10 -10
  38. data/spec/lib/btc_adapters/coinbase_adapter_spec.rb +4 -4
  39. data/spec/lib/btc_adapters/huobi_adapter_spec.rb +6 -6
  40. data/spec/lib/btc_adapters/kraken_adapter_spec.rb +6 -6
  41. data/spec/lib/btc_adapters/localbitcoins_adapter_spec.rb +4 -4
  42. data/spec/lib/btc_adapters/okcoin_adapter_spec.rb +11 -11
  43. data/spec/lib/fiat_adapters/fixer_adapter_spec.rb +5 -5
  44. data/spec/lib/fiat_adapters/yahoo_adapter_spec.rb +5 -5
  45. metadata +3 -4
  46. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/bitpay_adapter_yml.yml +0 -272
  47. data/spec/fixtures/vcr/exchange_rate_adapters/btc_adapters/bitstamp_adapter.yml +0 -153
@@ -19,7 +19,7 @@ http_interactions:
19
19
  message: OK
20
20
  headers:
21
21
  Date:
22
- - Sat, 18 Jun 2016 17:13:22 GMT
22
+ - Mon, 06 Feb 2017 05:25:06 GMT
23
23
  Content-Type:
24
24
  - text/html;charset=UTF-8
25
25
  Transfer-Encoding:
@@ -27,11 +27,11 @@ http_interactions:
27
27
  Connection:
28
28
  - keep-alive
29
29
  Set-Cookie:
30
- - __cfduid=d54b9b2ef78b8ab5afdc1544d4eefe7851466270002; expires=Sun, 18-Jun-17
31
- 17:13:22 GMT; path=/; domain=.okcoin.com; HttpOnly
32
- - coin_session_id_o=18547993-3305-4fe5-9181-746f999c04d6OROA; Domain=okcoin.com;
30
+ - __cfduid=dcd408d8dd74dabec10b946cf9b7f32f21486358706; expires=Tue, 06-Feb-18
31
+ 05:25:06 GMT; path=/; domain=.okcoin.com; HttpOnly
32
+ - coin_session_id_o=68dac424-1704-4903-80be-8c305ec61336qOsg; Domain=okcoin.com;
33
33
  Path=/; Secure; HttpOnly
34
- - language=1; Expires=Sat, 25-Jun-2016 17:13:22 GMT; Path=/
34
+ - language=0; Expires=Mon, 13-Feb-2017 05:25:06 GMT; Path=/
35
35
  Cache-Control:
36
36
  - no-store
37
37
  Expires:
@@ -47,12 +47,12 @@ http_interactions:
47
47
  Server:
48
48
  - cloudflare-nginx
49
49
  Cf-Ray:
50
- - 2b505f1c1f0b3132-SIN
50
+ - 32cc2dfb8a2b311a-SIN
51
51
  body:
52
52
  encoding: ASCII-8BIT
53
- string: '{"date":"1466270002","ticker":{"buy":"5.661","high":"5.989","last":"5.661","low":"5.386","sell":"5.663","vol":"91684.538"}}'
53
+ string: '{"date":"1486358706","ticker":{"buy":"3.96","high":"4.077","last":"3.987","low":"3.93","sell":"3.976","vol":"28472.362"}}'
54
54
  http_version:
55
- recorded_at: Sat, 18 Jun 2016 17:13:22 GMT
55
+ recorded_at: Mon, 06 Feb 2017 05:25:06 GMT
56
56
  - request:
57
57
  method: get
58
58
  uri: https://www.okcoin.com/api/v1/ticker.do?symbol=btc_usd
@@ -72,7 +72,7 @@ http_interactions:
72
72
  message: OK
73
73
  headers:
74
74
  Date:
75
- - Sat, 18 Jun 2016 17:13:23 GMT
75
+ - Mon, 06 Feb 2017 05:25:07 GMT
76
76
  Content-Type:
77
77
  - text/html;charset=UTF-8
78
78
  Transfer-Encoding:
@@ -80,11 +80,11 @@ http_interactions:
80
80
  Connection:
81
81
  - keep-alive
82
82
  Set-Cookie:
83
- - __cfduid=dcccbf67194b5cb96029f601c9bfd3a581466270003; expires=Sun, 18-Jun-17
84
- 17:13:23 GMT; path=/; domain=.okcoin.com; HttpOnly
85
- - coin_session_id_o=bd9c892b-ff15-46f7-9552-8f438f5f53bfxuST; Domain=okcoin.com;
83
+ - __cfduid=dc9a2ad3f9bbd6c665d8087a781f7d0831486358707; expires=Tue, 06-Feb-18
84
+ 05:25:07 GMT; path=/; domain=.okcoin.com; HttpOnly
85
+ - coin_session_id_o=ec68edca-aa27-41a6-83f8-905eb19b1c2eqMwU; Domain=okcoin.com;
86
86
  Path=/; Secure; HttpOnly
87
- - language=0; Expires=Sat, 25-Jun-2016 17:13:23 GMT; Path=/
87
+ - language=0; Expires=Mon, 13-Feb-2017 05:25:07 GMT; Path=/
88
88
  Cache-Control:
89
89
  - no-store
90
90
  Expires:
@@ -100,15 +100,15 @@ http_interactions:
100
100
  Server:
101
101
  - cloudflare-nginx
102
102
  Cf-Ray:
103
- - 2b505f1f88e231fe-SIN
103
+ - 32cc2dff1a350817-SIN
104
104
  body:
105
105
  encoding: ASCII-8BIT
106
- string: '{"date":"1466270003","ticker":{"buy":"769.38","high":"775.51","last":"769.05","low":"725.01","sell":"769.39","vol":"11944.5331"}}'
106
+ string: '{"date":"1486358707","ticker":{"buy":"1021.1","high":"1034.5","last":"1021.09","low":"1008.53","sell":"1022.49","vol":"1220.093"}}'
107
107
  http_version:
108
- recorded_at: Sat, 18 Jun 2016 17:13:23 GMT
108
+ recorded_at: Mon, 06 Feb 2017 05:25:07 GMT
109
109
  - request:
110
110
  method: get
111
- uri: https://www.okcoin.cn/api/ticker.do?symbol=btc_cny
111
+ uri: https://www.okcoin.cn/api/ticker.do?symbol=ltc_cny
112
112
  body:
113
113
  encoding: US-ASCII
114
114
  string: ''
@@ -124,40 +124,48 @@ http_interactions:
124
124
  code: 200
125
125
  message: OK
126
126
  headers:
127
- Server:
128
- - nginx
129
- Date:
130
- - Sat, 18 Jun 2016 17:13:26 GMT
131
127
  Content-Type:
132
128
  - text/html;charset=UTF-8
133
129
  Content-Length:
134
- - '147'
130
+ - '137'
135
131
  Connection:
136
132
  - keep-alive
133
+ Server:
134
+ - nginx
135
+ Date:
136
+ - Mon, 06 Feb 2017 05:17:50 GMT
137
137
  Set-Cookie:
138
- - coin_session_id_o=bbb48e4c-ae94-4acf-83aa-77b35644656aSooe; Domain=okcoin.cn;
138
+ - coin_session_id_o=19deb5f4-42b3-44db-bf93-bdc34ca3fce5JdXY; Domain=okcoin.cn;
139
139
  Path=/; Secure; HttpOnly
140
- - language=0; Expires=Sat, 25-Jun-2016 17:13:26 GMT; Path=/
140
+ - language=0; Expires=Mon, 13-Feb-2017 05:25:11 GMT; Path=/
141
141
  Cache-Control:
142
142
  - no-store
143
143
  Expires:
144
144
  - Thu, 01 Jan 1970 00:00:00 GMT
145
145
  Pragma:
146
146
  - no-cache
147
+ Vary:
148
+ - Accept-Encoding, User-Agent
147
149
  X-Frame-Options:
148
150
  - SAMEORIGIN
149
151
  Access-Control-Allow-Credentials:
150
152
  - 'true'
151
153
  Access-Control-Allow-Origin:
152
154
  - https://img.okcoin.cn
155
+ X-Cache:
156
+ - Miss from cloudfront
157
+ Via:
158
+ - 1.1 f7b7c91216531cea229d3692df41a83f.cloudfront.net (CloudFront)
159
+ X-Amz-Cf-Id:
160
+ - lw6KX9NKKZUUqQfWhBOC4iYcsz76x5LCHSRG1Y3Dd4lUHPG_7mlavQ==
153
161
  body:
154
162
  encoding: UTF-8
155
- string: '{"date":"1466270006","ticker":{"buy":"5112.95","change":0.02,"high":"5160.0","last":"5113.0","low":"4841.12","sell":"5113.0","vol":"1292892.0608"}}'
163
+ string: '{"date":"1486358711","ticker":{"buy":"27.97","change":-0.0018,"high":"28.14","last":"28.0","low":"27.78","sell":"28.0","vol":"372709.5"}}'
156
164
  http_version:
157
- recorded_at: Sat, 18 Jun 2016 17:13:26 GMT
165
+ recorded_at: Mon, 06 Feb 2017 05:25:11 GMT
158
166
  - request:
159
167
  method: get
160
- uri: https://www.okcoin.cn/api/ticker.do?symbol=ltc_cny
168
+ uri: https://www.okcoin.cn/api/ticker.do?symbol=btc_cny
161
169
  body:
162
170
  encoding: US-ASCII
163
171
  string: ''
@@ -173,35 +181,43 @@ http_interactions:
173
181
  code: 200
174
182
  message: OK
175
183
  headers:
176
- Server:
177
- - nginx
178
- Date:
179
- - Sat, 18 Jun 2016 17:13:27 GMT
180
184
  Content-Type:
181
185
  - text/html;charset=UTF-8
182
186
  Content-Length:
183
- - '144'
187
+ - '145'
184
188
  Connection:
185
189
  - keep-alive
190
+ Server:
191
+ - nginx
192
+ Date:
193
+ - Mon, 06 Feb 2017 05:17:51 GMT
186
194
  Set-Cookie:
187
- - coin_session_id_o=d98d2276-90bb-4dd8-8b53-7cc2e9dc4627aNON; Domain=okcoin.cn;
195
+ - coin_session_id_o=e074cb43-2205-4007-9c48-c19c5874ca69GlaR; Domain=okcoin.cn;
188
196
  Path=/; Secure; HttpOnly
189
- - language=0; Expires=Sat, 25-Jun-2016 17:13:27 GMT; Path=/
197
+ - language=0; Expires=Mon, 13-Feb-2017 05:25:12 GMT; Path=/
190
198
  Cache-Control:
191
199
  - no-store
192
200
  Expires:
193
201
  - Thu, 01 Jan 1970 00:00:00 GMT
194
202
  Pragma:
195
203
  - no-cache
204
+ Vary:
205
+ - Accept-Encoding, User-Agent
196
206
  X-Frame-Options:
197
207
  - SAMEORIGIN
198
208
  Access-Control-Allow-Credentials:
199
209
  - 'true'
200
210
  Access-Control-Allow-Origin:
201
211
  - https://img.okcoin.cn
212
+ X-Cache:
213
+ - Miss from cloudfront
214
+ Via:
215
+ - 1.1 fdf852f8150530112aa9b7977369878b.cloudfront.net (CloudFront)
216
+ X-Amz-Cf-Id:
217
+ - OpXRqfGeg8Sit7eP430SY_mRdMPQlzB-Wv11Mu6HBmMxGS3qJXCFfQ==
202
218
  body:
203
219
  encoding: UTF-8
204
- string: '{"date":"1466270007","ticker":{"buy":"37.67","change":0.014,"high":"38.2","last":"37.68","low":"36.2","sell":"37.68","vol":"98101757.02760004"}}'
220
+ string: '{"date":"1486358712","ticker":{"buy":"7204.0","change":-0.0035,"high":"7299.0","last":"7203.0","low":"7110.0","sell":"7209.0","vol":"12382.117"}}'
205
221
  http_version:
206
- recorded_at: Sat, 18 Jun 2016 17:13:27 GMT
222
+ recorded_at: Mon, 06 Feb 2017 05:25:13 GMT
207
223
  recorded_with: VCR 3.0.3
@@ -19,26 +19,28 @@ http_interactions:
19
19
  message: OK
20
20
  headers:
21
21
  Server:
22
- - nginx/1.11.1
22
+ - nginx/1.11.8
23
23
  Date:
24
- - Sun, 19 Jun 2016 06:58:50 GMT
24
+ - Mon, 06 Feb 2017 05:25:14 GMT
25
25
  Content-Type:
26
26
  - application/json
27
27
  Content-Length:
28
- - '452'
28
+ - '447'
29
29
  Connection:
30
30
  - keep-alive
31
+ Cache-Control:
32
+ - public, must-revalidate, max-age=900
31
33
  Last-Modified:
32
- - Fri, 17 Jun 2016 00:00:00 GMT
34
+ - Fri, 03 Feb 2017 00:00:00 GMT
33
35
  Vary:
34
36
  - Origin
35
37
  X-Content-Type-Options:
36
38
  - nosniff
37
39
  body:
38
40
  encoding: UTF-8
39
- string: '{"base":"EUR","date":"2016-06-17","rates":{"AUD":1.5234,"BGN":1.9558,"BRL":3.8942,"CAD":1.4519,"CHF":1.0818,"CNY":7.4171,"CZK":27.069,"DKK":7.4362,"GBP":0.7877,"HKD":8.7338,"HRK":7.521,"HUF":314.26,"IDR":14996.53,"ILS":4.3572,"INR":75.4975,"JPY":117.34,"KRW":1318.22,"MXN":21.2471,"MYR":4.6153,"NOK":9.431,"NZD":1.5959,"PHP":52.258,"PLN":4.4463,"RON":4.5355,"RUB":73.2867,"SEK":9.3815,"SGD":1.5187,"THB":39.704,"TRY":3.2988,"USD":1.1254,"ZAR":17.1218}}'
41
+ string: '{"base":"EUR","date":"2017-02-03","rates":{"AUD":1.4057,"BGN":1.9558,"BRL":3.3641,"CAD":1.4023,"CHF":1.0695,"CNY":7.3776,"CZK":27.021,"DKK":7.4376,"GBP":0.86013,"HKD":8.3343,"HRK":7.4331,"HUF":309.46,"IDR":14334.0,"ILS":4.0323,"INR":72.31,"JPY":121.49,"KRW":1232.2,"MXN":22.016,"MYR":4.7561,"NOK":8.8568,"NZD":1.4781,"PHP":53.461,"PLN":4.2972,"RON":4.5158,"RUB":63.611,"SEK":9.442,"SGD":1.5186,"THB":37.653,"TRY":4.0118,"USD":1.0741,"ZAR":14.421}}'
40
42
  http_version:
41
- recorded_at: Sun, 19 Jun 2016 06:58:50 GMT
43
+ recorded_at: Mon, 06 Feb 2017 05:25:14 GMT
42
44
  - request:
43
45
  method: get
44
46
  uri: http://api.fixer.io/latest?base=usd
@@ -58,24 +60,26 @@ http_interactions:
58
60
  message: OK
59
61
  headers:
60
62
  Server:
61
- - nginx/1.11.1
63
+ - nginx/1.11.8
62
64
  Date:
63
- - Sun, 19 Jun 2016 06:58:51 GMT
65
+ - Mon, 06 Feb 2017 05:25:14 GMT
64
66
  Content-Type:
65
67
  - application/json
66
68
  Content-Length:
67
- - '447'
69
+ - '448'
68
70
  Connection:
69
71
  - keep-alive
72
+ Cache-Control:
73
+ - public, must-revalidate, max-age=900
70
74
  Last-Modified:
71
- - Fri, 17 Jun 2016 00:00:00 GMT
75
+ - Fri, 03 Feb 2017 00:00:00 GMT
72
76
  Vary:
73
77
  - Origin
74
78
  X-Content-Type-Options:
75
79
  - nosniff
76
80
  body:
77
81
  encoding: UTF-8
78
- string: '{"base":"USD","date":"2016-06-17","rates":{"AUD":1.3537,"BGN":1.7379,"BRL":3.4603,"CAD":1.2901,"CHF":0.96126,"CNY":6.5906,"CZK":24.053,"DKK":6.6076,"GBP":0.69993,"HKD":7.7606,"HRK":6.683,"HUF":279.24,"IDR":13326.0,"ILS":3.8717,"INR":67.085,"JPY":104.27,"KRW":1171.3,"MXN":18.88,"MYR":4.101,"NOK":8.3801,"NZD":1.4181,"PHP":46.435,"PLN":3.9509,"RON":4.0301,"RUB":65.121,"SEK":8.3361,"SGD":1.3495,"THB":35.28,"TRY":2.9312,"ZAR":15.214,"EUR":0.88857}}'
82
+ string: '{"base":"USD","date":"2017-02-03","rates":{"AUD":1.3087,"BGN":1.8209,"BRL":3.132,"CAD":1.3056,"CHF":0.99572,"CNY":6.8686,"CZK":25.157,"DKK":6.9245,"GBP":0.80079,"HKD":7.7593,"HRK":6.9203,"HUF":288.11,"IDR":13345.0,"ILS":3.7541,"INR":67.321,"JPY":113.11,"KRW":1147.2,"MXN":20.497,"MYR":4.428,"NOK":8.2458,"NZD":1.3761,"PHP":49.773,"PLN":4.0007,"RON":4.2043,"RUB":59.223,"SEK":8.7906,"SGD":1.4138,"THB":35.055,"TRY":3.735,"ZAR":13.426,"EUR":0.93101}}'
79
83
  http_version:
80
- recorded_at: Sun, 19 Jun 2016 06:58:51 GMT
84
+ recorded_at: Mon, 06 Feb 2017 05:25:14 GMT
81
85
  recorded_with: VCR 3.0.3
@@ -19,32 +19,30 @@ http_interactions:
19
19
  message: OK
20
20
  headers:
21
21
  X-Yql-Host:
22
- - main-2327bac4-1df8-11e6-a4df-d4ae52974c31
22
+ - prod_bf1_1;paas.yql;queryyahooapiscomproductionbf1;d587643e-e9f8-11e6-a255-d4ae52974c31
23
23
  X-Content-Type-Options:
24
24
  - nosniff
25
25
  Access-Control-Allow-Origin:
26
26
  - "*"
27
27
  Content-Type:
28
- - application/json; charset=UTF-8
28
+ - application/json;charset=utf-8
29
29
  Cache-Control:
30
30
  - no-cache
31
31
  Date:
32
- - Sun, 19 Jun 2016 07:10:46 GMT
32
+ - Mon, 06 Feb 2017 05:25:15 GMT
33
33
  Age:
34
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
35
  Transfer-Encoding:
42
36
  - chunked
43
37
  Connection:
44
38
  - keep-alive
39
+ Via:
40
+ - http/1.1 a32.ue.bf1.yahoo.net (ApacheTrafficServer [cMsSf ])
41
+ Server:
42
+ - ATS
45
43
  body:
46
44
  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"}]}}}'
45
+ string: '{"query":{"count":32,"created":"2017-02-06T05:25:15Z","lang":"en-US","results":{"rate":[{"id":"USDAUD","Name":"USD/AUD","Rate":"1.3030","Date":"2/6/2017","Time":"1:22am","Ask":"1.3034","Bid":"1.3030"},{"id":"USDBGN","Name":"USD/BGN","Rate":"1.8209","Date":"2/3/2017","Time":"3:15pm","Ask":"N/A","Bid":"1.8209"},{"id":"USDBRL","Name":"USD/BRL","Rate":"3.1172","Date":"2/6/2017","Time":"2:30am","Ask":"3.1192","Bid":"3.1172"},{"id":"USDCAD","Name":"USD/CAD","Rate":"1.3020","Date":"2/6/2017","Time":"1:48am","Ask":"1.3020","Bid":"1.3020"},{"id":"USDCHF","Name":"USD/CHF","Rate":"0.9922","Date":"2/6/2017","Time":"2:31am","Ask":"0.9923","Bid":"0.9922"},{"id":"USDCNY","Name":"USD/CNY","Rate":"6.8577","Date":"2/6/2017","Time":"3:33am","Ask":"6.8587","Bid":"6.8577"},{"id":"USDCZK","Name":"USD/CZK","Rate":"25.0595","Date":"2/5/2017","Time":"11:44pm","Ask":"25.0663","Bid":"25.0595"},{"id":"USDDKK","Name":"USD/DKK","Rate":"6.8977","Date":"2/6/2017","Time":"2:49am","Ask":"6.8988","Bid":"6.8977"},{"id":"USDGBP","Name":"USD/GBP","Rate":"0.8009","Date":"2/6/2017","Time":"0:29am","Ask":"0.8010","Bid":"0.8009"},{"id":"USDHKD","Name":"USD/HKD","Rate":"7.7577","Date":"2/6/2017","Time":"3:33am","Ask":"7.7578","Bid":"7.7577"},{"id":"USDHRK","Name":"USD/HRK","Rate":"6.8568","Date":"2/6/2017","Time":"3:40am","Ask":"6.9317","Bid":"6.8568"},{"id":"USDHUF","Name":"USD/HUF","Rate":"287.1700","Date":"2/6/2017","Time":"3:50am","Ask":"287.3700","Bid":"287.1700"},{"id":"USDIDR","Name":"USD/IDR","Rate":"13325.0000","Date":"2/6/2017","Time":"3:34am","Ask":"13335.0000","Bid":"13325.0000"},{"id":"USDILS","Name":"USD/ILS","Rate":"3.7405","Date":"2/6/2017","Time":"3:31am","Ask":"3.7505","Bid":"3.7405"},{"id":"USDINR","Name":"USD/INR","Rate":"67.1750","Date":"2/6/2017","Time":"2:30am","Ask":"67.2250","Bid":"67.1750"},{"id":"USDJPY","Name":"USD/JPY","Rate":"112.4610","Date":"2/6/2017","Time":"2:49am","Ask":"112.4740","Bid":"112.4610"},{"id":"USDKRW","Name":"USD/KRW","Rate":"1135.5000","Date":"2/6/2017","Time":"3:52am","Ask":"1136.5000","Bid":"1135.5000"},{"id":"USDMXN","Name":"USD/MXN","Rate":"20.3983","Date":"2/6/2017","Time":"1:22am","Ask":"20.4025","Bid":"20.3983"},{"id":"USDMYR","Name":"USD/MYR","Rate":"4.4250","Date":"2/6/2017","Time":"3:32am","Ask":"4.4255","Bid":"4.4250"},{"id":"USDNOK","Name":"USD/NOK","Rate":"8.2099","Date":"2/6/2017","Time":"0:30am","Ask":"8.2124","Bid":"8.2099"},{"id":"USDNZD","Name":"USD/NZD","Rate":"1.3654","Date":"2/6/2017","Time":"3:50am","Ask":"1.3664","Bid":"1.3654"},{"id":"USDPHP","Name":"USD/PHP","Rate":"49.7200","Date":"2/6/2017","Time":"3:32am","Ask":"49.7300","Bid":"49.7200"},{"id":"USDPLN","Name":"USD/PLN","Rate":"3.9914","Date":"2/6/2017","Time":"3:34am","Ask":"3.9936","Bid":"3.9914"},{"id":"USDRON","Name":"USD/RON","Rate":"4.1763","Date":"2/6/2017","Time":"1:23am","Ask":"4.2037","Bid":"4.1763"},{"id":"USDRUB","Name":"USD/RUB","Rate":"59.5127","Date":"2/5/2017","Time":"11:43pm","Ask":"59.5477","Bid":"59.5127"},{"id":"USDSEK","Name":"USD/SEK","Rate":"8.7621","Date":"2/6/2017","Time":"3:49am","Ask":"8.7645","Bid":"8.7621"},{"id":"USDSGD","Name":"USD/SGD","Rate":"1.4076","Date":"2/6/2017","Time":"3:50am","Ask":"1.4077","Bid":"1.4076"},{"id":"USDTHB","Name":"USD/THB","Rate":"35.0100","Date":"2/5/2017","Time":"11:50pm","Ask":"35.0600","Bid":"35.0100"},{"id":"USDTRY","Name":"USD/TRY","Rate":"3.6997","Date":"2/6/2017","Time":"2:32am","Ask":"3.7007","Bid":"3.6997"},{"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":"13.2577","Date":"2/5/2017","Time":"11:50pm","Ask":"13.2847","Bid":"13.2577"},{"id":"USDEUR","Name":"USD/EUR","Rate":"0.9272","Date":"2/6/2017","Time":"3:49am","Ask":"0.9277","Bid":"0.9272"}]}}}'
48
46
  http_version:
49
- recorded_at: Sun, 19 Jun 2016 07:10:46 GMT
47
+ recorded_at: Mon, 06 Feb 2017 05:25:15 GMT
50
48
  recorded_with: VCR 3.0.3
@@ -3,7 +3,8 @@ require 'spec_helper'
3
3
  RSpec.describe CurrencyRate::BtcAdapter do
4
4
 
5
5
  class CurrencyRate::Adapter
6
- FETCH_URL = ''
6
+ FETCH_URL = ''
7
+ DEFAULT_CURRENCIES = { from: "BTC", to: "USD" }
7
8
  end
8
9
 
9
10
  class SomeExchangeAdapter < CurrencyRate::BtcAdapter
@@ -12,6 +13,10 @@ RSpec.describe CurrencyRate::BtcAdapter do
12
13
  rate = rate_to_f(750)
13
14
  invert_rate(from,to,rate)
14
15
  end
16
+
17
+ def supported_currency_pairs
18
+ ["USD/BTC"]
19
+ end
15
20
  end
16
21
 
17
22
  before(:each) do
@@ -29,6 +34,7 @@ RSpec.describe CurrencyRate::BtcAdapter do
29
34
  uri_mock = double('uri mock')
30
35
  expect(URI).to receive(:parse).and_return(uri_mock).once
31
36
  expect(uri_mock).to receive(:read).and_return('{ "USD": 534.4343 }').once
37
+ allow(@exchange_adapter).to receive(:supported_currency_pairs).and_return(["USD/BTC"])
32
38
  @exchange_adapter.rate_for('USD', 'BTC')
33
39
  @exchange_adapter.rate_for('USD', 'BTC') # not calling fetch_rates! because we've just checked
34
40
  @exchange_adapter.instance_variable_set(:@rates_updated_at, Time.now-1900)
@@ -40,4 +46,9 @@ RSpec.describe CurrencyRate::BtcAdapter do
40
46
  expect( -> { @exchange_adapter.rate_to_f(rate) }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
41
47
  end
42
48
 
49
+ it "raises exception if target currency is not in supported currencies" do
50
+ @exchange_adapter = SomeExchangeAdapter.instance
51
+ expect( -> { @exchange_adapter.rate_for("BTC", "CNY") }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
52
+ end
53
+
43
54
  end
@@ -18,12 +18,7 @@ RSpec.describe CurrencyRate::AverageRateAdapter do
18
18
  end
19
19
 
20
20
  it "calculates average rate" do
21
- json_response_bistamp = '{"high": "232.89", "last": "100", "timestamp": "1423457015", "bid": "224.00", "vwap": "224.57", "volume": "14810.41127494", "low": "217.28", "ask": "224.13"}'
22
- json_response_bitpay = '[{"code":"USD","name":"US Dollar","rate":200},{"code":"EUR","name":"Eurozone Euro","rate":197.179544}]'
23
- uri_mock = double('uri mock')
24
- allow(uri_mock).to receive(:read).with(read_timeout: 4).and_return(json_response_bistamp, json_response_bitpay)
25
- allow(URI).to receive(:parse).and_return(uri_mock)
26
- expect(@average_rates_adapter.rate_for('BTC', 'USD')).to eq 150
21
+ expect(@average_rates_adapter.rate_for('BTC', 'USD')).to eq 1016.38
27
22
  end
28
23
 
29
24
  it "fetches rates for all adapters" do
@@ -2,11 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe CurrencyRate::BitfinexAdapter do
4
4
 
5
- before :all do
5
+ before :each do
6
6
  VCR.insert_cassette 'exchange_rate_adapters/btc_adapters/bitfinex_adapter'
7
7
  end
8
8
 
9
- after :all do
9
+ after :each do
10
10
  VCR.eject_cassette
11
11
  end
12
12
 
@@ -15,10 +15,10 @@ RSpec.describe CurrencyRate::BitfinexAdapter do
15
15
  end
16
16
 
17
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.001310616)
20
- expect(@exchange_adapter.rate_for('LTC', 'USD')).to eq(5.5105)
21
- expect(@exchange_adapter.rate_for('USD', 'LTC')).to eq(0.181471736)
18
+ expect(@exchange_adapter.rate_for('BTC', 'USD')).to eq(1016.9)
19
+ expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.000983381)
20
+ expect(@exchange_adapter.rate_for('LTC', 'USD')).to eq(3.9526)
21
+ expect(@exchange_adapter.rate_for('USD', 'LTC')).to eq(0.252998027)
22
22
  expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
23
23
  end
24
24
 
@@ -2,11 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe CurrencyRate::BitpayAdapter do
4
4
 
5
- before :all do
6
- VCR.insert_cassette 'exchange_rate_adapters/btc_adapters/bitpay_adapter.yml'
5
+ before :each do
6
+ VCR.insert_cassette 'exchange_rate_adapters/btc_adapters/average_rate_adapter' # contains request to Bitpay
7
7
  end
8
8
 
9
- after :all do
9
+ after :each do
10
10
  VCR.eject_cassette
11
11
  end
12
12
 
@@ -15,9 +15,9 @@ 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('BTC', 'USD')).to eq(748.02)
18
+ expect(@exchange_adapter.rate_for('BTC', 'USD')).to eq(1015.59)
19
19
  expect(@exchange_adapter.rate_for('BTC', 'BTC')).to eq(1)
20
- expect(@exchange_adapter.rate_for('BTC', 'EUR')).to eq(663.359096)
20
+ expect(@exchange_adapter.rate_for('BTC', 'EUR')).to eq(941.895743)
21
21
  expect(@exchange_adapter.rate_for('EUR', 'BTC')).to eq(1)
22
22
  expect( -> { @exchange_adapter.rate_for('USD', 'EUR') }).to raise_exception(CurrencyRate::Adapter::CurrencyNotSupported)
23
23
  expect( -> { @exchange_adapter.rate_for('EUR', 'USD') }).to raise_exception(CurrencyRate::Adapter::CurrencyNotSupported)
@@ -2,11 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe CurrencyRate::BitstampAdapter do
4
4
 
5
- before :all do
6
- VCR.insert_cassette 'exchange_rate_adapters/btc_adapters/bitstamp_adapter'
5
+ before :each do
6
+ VCR.insert_cassette 'exchange_rate_adapters/btc_adapters/average_rate_adapter' # contains request to Bistamp
7
7
  end
8
8
 
9
- after :all do
9
+ after :each do
10
10
  VCR.eject_cassette
11
11
  end
12
12
 
@@ -15,12 +15,12 @@ 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('BTC', 'USD')).to eq(751.97)
19
- expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.00132984)
20
- expect(@exchange_adapter.rate_for('BTC', 'EUR')).to eq(674.5)
21
- expect(@exchange_adapter.rate_for('EUR', 'BTC')).to eq(0.00148258)
22
- expect(@exchange_adapter.rate_for('USD', 'EUR')).to eq(0.900884669)
23
- expect(@exchange_adapter.rate_for('EUR', 'USD')).to eq(1.11002)
18
+ expect(@exchange_adapter.rate_for('BTC', 'USD')).to eq(1017.17)
19
+ expect(@exchange_adapter.rate_for('USD', 'BTC').to_f).to eq(0.00098312)
20
+ expect(@exchange_adapter.rate_for('BTC', 'EUR')).to eq(946.0)
21
+ expect(@exchange_adapter.rate_for('EUR', 'BTC').to_f).to eq(0.001057082)
22
+ expect(@exchange_adapter.rate_for('USD', 'EUR').to_f).to eq(0.933619643)
23
+ expect(@exchange_adapter.rate_for('EUR', 'USD')).to eq(1.0711)
24
24
  expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
25
25
  end
26
26
 
@@ -2,11 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  RSpec.describe CurrencyRate::BTCChinaAdapter do
4
4
 
5
- before :all do
5
+ before :each do
6
6
  VCR.insert_cassette 'exchange_rate_adapters/btc_adapters/btcchina_adapter'
7
7
  end
8
8
 
9
- after :all do
9
+ after :each do
10
10
  VCR.eject_cassette
11
11
  end
12
12
 
@@ -15,8 +15,8 @@ RSpec.describe CurrencyRate::BTCChinaAdapter 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(4785.55)
19
- expect(@exchange_adapter.rate_for('CNY', 'BTC')).to eq(0.000208962)
18
+ expect(@exchange_adapter.rate_for('BTC', 'CNY')).to eq(7243.99)
19
+ expect(@exchange_adapter.rate_for('CNY', 'BTC').to_f).to eq(0.000138045)
20
20
  expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
21
21
  end
22
22