currency-rate 0.3.7 → 0.3.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6a7717da50f7013b0f430545b761e05f6fa88ea8
4
- data.tar.gz: f0e499bed1863467e640448da5f23eb9219bc53d
3
+ metadata.gz: f90626ba2850871f4a11109c3325c0fb93eacfa2
4
+ data.tar.gz: 1bdfde8354857ea4eb18c7bbc82df9cc6d57dacd
5
5
  SHA512:
6
- metadata.gz: 8cedcc1c71864a83e88ce7ae444b139d469f628897ab411ae4c64b517e57c9af81a35531313beb8b712994d3a8f01a4ff28d9ef26c319264a6f53ac4093bd384
7
- data.tar.gz: f8be39baeccb40a9a6ebe0e1de6bfb0403499b1978c201e9bbd87bc98590f5ae1719d09ddd16a3bfea31201920ad73b50f34e032d0a584f51e0d0f99f0dc61cf
6
+ metadata.gz: b331ad6154585cfb839900aa2be697b6da4636967a2679bdc3cbf4c8062cb094b30300944908a1695681741cbf47a36dc04b746b4d64b59164fab511e82d4281
7
+ data.tar.gz: a0f0b4a9b4b6281154619dd6e4d7ee10c8d99b9771840b7a21bdecc78c696ccd96bcad0cc3dd342d17d9c07d69f718521020807509e69651512243964c6546ad
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ gem 'satoshi-unit'
4
4
 
5
5
  group :development do
6
6
  gem "bundler", "~> 1.0"
7
- gem "jeweler", "~> 2.1.1", git: 'git@github.com:technicalpickles/jeweler.git'
7
+ gem "jeweler", "~> 2.3.7", git: 'git@github.com:technicalpickles/jeweler.git'
8
8
  gem "rspec"
9
9
  gem 'webmock'
10
10
  gem 'vcr'
@@ -1,23 +1,24 @@
1
1
  GIT
2
2
  remote: git@github.com:technicalpickles/jeweler.git
3
- revision: ec91e05d06f2835ee30568fa42b5fa7d451444b6
3
+ revision: afab16b95fbac811f3ab233e058d39eb4e300284
4
4
  specs:
5
- jeweler (2.1.1)
5
+ jeweler (2.3.7)
6
6
  builder
7
- bundler (>= 1.0)
7
+ bundler (>= 1)
8
8
  git (>= 1.2.5)
9
- github_api
9
+ github_api (~> 0.16.0)
10
10
  highline (>= 1.6.15)
11
11
  nokogiri (>= 1.5.10)
12
+ psych (~> 2.2)
12
13
  rake
13
14
  rdoc
14
- semver
15
+ semver2
15
16
 
16
17
  GEM
17
18
  remote: https://rubygems.org/
18
19
  specs:
19
20
  addressable (2.4.0)
20
- builder (3.2.2)
21
+ builder (3.2.3)
21
22
  crack (0.4.3)
22
23
  safe_yaml (~> 1.0.0)
23
24
  descendants_tracker (0.0.4)
@@ -26,33 +27,34 @@ GEM
26
27
  faraday (0.9.2)
27
28
  multipart-post (>= 1.2, < 3)
28
29
  git (1.3.0)
29
- github_api (0.14.0)
30
+ github_api (0.16.0)
30
31
  addressable (~> 2.4.0)
31
32
  descendants_tracker (~> 0.0.4)
32
33
  faraday (~> 0.8, < 0.10)
33
34
  hashie (>= 3.4)
34
- oauth2
35
+ mime-types (>= 1.16, < 3.0)
36
+ oauth2 (~> 1.0)
35
37
  hashdiff (0.3.0)
36
- hashie (3.4.4)
38
+ hashie (3.5.5)
37
39
  highline (1.7.8)
38
- json (1.8.3)
39
- jwt (1.5.1)
40
- mini_portile2 (2.0.0)
40
+ jwt (1.5.6)
41
+ mime-types (2.99.3)
42
+ mini_portile2 (2.2.0)
41
43
  multi_json (1.12.1)
42
- multi_xml (0.5.5)
44
+ multi_xml (0.6.0)
43
45
  multipart-post (2.0.0)
44
- nokogiri (1.6.7.2)
45
- mini_portile2 (~> 2.0.0.rc2)
46
- oauth2 (1.1.0)
47
- faraday (>= 0.8, < 0.10)
48
- jwt (~> 1.0, < 1.5.2)
46
+ nokogiri (1.8.0)
47
+ mini_portile2 (~> 2.2.0)
48
+ oauth2 (1.4.0)
49
+ faraday (>= 0.8, < 0.13)
50
+ jwt (~> 1.0)
49
51
  multi_json (~> 1.3)
50
52
  multi_xml (~> 0.5)
51
53
  rack (>= 1.2, < 3)
52
- rack (1.6.4)
53
- rake (11.1.2)
54
- rdoc (4.2.2)
55
- json (~> 1.4)
54
+ psych (2.2.4)
55
+ rack (2.0.3)
56
+ rake (12.0.0)
57
+ rdoc (5.1.0)
56
58
  rspec (3.4.0)
57
59
  rspec-core (~> 3.4.0)
58
60
  rspec-expectations (~> 3.4.0)
@@ -68,8 +70,8 @@ GEM
68
70
  rspec-support (3.4.1)
69
71
  safe_yaml (1.0.4)
70
72
  satoshi-unit (0.1.8)
71
- semver (1.0.1)
72
- thread_safe (0.3.5)
73
+ semver2 (3.4.2)
74
+ thread_safe (0.3.6)
73
75
  vcr (3.0.3)
74
76
  webmock (2.0.3)
75
77
  addressable (>= 2.3.6)
@@ -81,11 +83,11 @@ PLATFORMS
81
83
 
82
84
  DEPENDENCIES
83
85
  bundler (~> 1.0)
84
- jeweler (~> 2.1.1)!
86
+ jeweler (~> 2.3.7)!
85
87
  rspec
86
88
  satoshi-unit
87
89
  vcr
88
90
  webmock
89
91
 
90
92
  BUNDLED WITH
91
- 1.12.0
93
+ 1.15.1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.7
1
+ 0.3.8
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: currency-rate 0.3.3 ruby lib
5
+ # stub: currency-rate 0.3.8 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "currency-rate"
9
- s.version = "0.3.7"
9
+ s.version = "0.3.8"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Roman Snitko"]
14
- s.date = "2017-03-29"
14
+ s.date = "2017-07-26"
15
15
  s.description = "Fetches exchange rates from various sources and does the conversion"
16
16
  s.email = "roman.snitko@gmail.com"
17
17
  s.extra_rdoc_files = [
@@ -88,14 +88,14 @@ Gem::Specification.new do |s|
88
88
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
89
89
  s.add_runtime_dependency(%q<satoshi-unit>, [">= 0"])
90
90
  s.add_development_dependency(%q<bundler>, ["~> 1.0"])
91
- s.add_development_dependency(%q<jeweler>, ["~> 2.1.1"])
91
+ s.add_development_dependency(%q<jeweler>, ["~> 2.3.7"])
92
92
  s.add_development_dependency(%q<rspec>, [">= 0"])
93
93
  s.add_development_dependency(%q<webmock>, [">= 0"])
94
94
  s.add_development_dependency(%q<vcr>, [">= 0"])
95
95
  else
96
96
  s.add_dependency(%q<satoshi-unit>, [">= 0"])
97
97
  s.add_dependency(%q<bundler>, ["~> 1.0"])
98
- s.add_dependency(%q<jeweler>, ["~> 2.1.1"])
98
+ s.add_dependency(%q<jeweler>, ["~> 2.3.7"])
99
99
  s.add_dependency(%q<rspec>, [">= 0"])
100
100
  s.add_dependency(%q<webmock>, [">= 0"])
101
101
  s.add_dependency(%q<vcr>, [">= 0"])
@@ -103,7 +103,7 @@ Gem::Specification.new do |s|
103
103
  else
104
104
  s.add_dependency(%q<satoshi-unit>, [">= 0"])
105
105
  s.add_dependency(%q<bundler>, ["~> 1.0"])
106
- s.add_dependency(%q<jeweler>, ["~> 2.1.1"])
106
+ s.add_dependency(%q<jeweler>, ["~> 2.3.7"])
107
107
  s.add_dependency(%q<rspec>, [">= 0"])
108
108
  s.add_dependency(%q<webmock>, [">= 0"])
109
109
  s.add_dependency(%q<vcr>, [">= 0"])
@@ -33,7 +33,6 @@ module CurrencyRate
33
33
  end
34
34
 
35
35
  def rate_for(from,to)
36
-
37
36
  begin
38
37
  @rates = self.storage.fetch(self.class.to_s) { self.fetch_rates! }
39
38
  rescue FetchingFailed => e
@@ -3,9 +3,15 @@ module CurrencyRate
3
3
 
4
4
  FETCH_URL = {
5
5
  "usd_btc" => 'https://api.kraken.com/0/public/Ticker?pair=xbtusd',
6
- "eur_btc" => 'https://api.kraken.com/0/public/Ticker?pair=xbteur'
6
+ "eur_btc" => 'https://api.kraken.com/0/public/Ticker?pair=xbteur',
7
+ "usd_ltc" => 'https://api.kraken.com/0/public/Ticker?pair=ltcusd',
8
+ "eur_ltc" => 'https://api.kraken.com/0/public/Ticker?pair=ltceur',
7
9
  }
8
10
  DEFAULT_CURRENCIES = ["USD", "BTC"]
11
+ CRYPTO_CURRENCIES = ["BTC", "LTC"]
12
+ ASSET_MAP = {
13
+ "BTC" => "XBT",
14
+ }
9
15
 
10
16
  def rate_for(to,from)
11
17
  super
@@ -15,9 +21,9 @@ module CurrencyRate
15
21
 
16
22
  def currency_pair_rate(currency1, currency2)
17
23
  rate = @rates["#{currency1.downcase}_#{currency2.downcase}"] || @rates["#{currency2.downcase}_#{currency1.downcase}"]
18
- raise CurrencyNotSupported unless rate || [currency1, currency2].include?("BTC")
19
- currency = currency1 == "BTC" ? currency2 : currency1
20
- rate['result']["XXBTZ#{currency}"]['c'].first
24
+ raise CurrencyNotSupported unless rate || ([currency1, currency2] & CRYPTO_CURRENCIES).any?
25
+ fiat, crypto = CRYPTO_CURRENCIES.include?(currency1) ? [currency2, currency1] : [currency1, currency2]
26
+ rate['result']["X#{ta(crypto)}Z#{ta(fiat)}"]['c'].first
21
27
  end
22
28
 
23
29
  def supported_currency_pairs
@@ -28,5 +34,9 @@ module CurrencyRate
28
34
  end
29
35
  end
30
36
 
37
+ def translate_asset(asset)
38
+ ASSET_MAP[asset] || asset
39
+ end
40
+ alias_method :ta, :translate_asset
31
41
  end
32
42
  end
@@ -19,7 +19,7 @@ module CurrencyRate
19
19
 
20
20
  # Setting default values for anchor currency depending on
21
21
  # which adapter type is un use.
22
- anchor_currency = if a.kind_of?(BtcAdapter)
22
+ anchor_currency ||= if a.kind_of?(BtcAdapter)
23
23
  'BTC' if anchor_currency.nil?
24
24
  else
25
25
  'USD' if anchor_currency.nil?
@@ -19,7 +19,7 @@ http_interactions:
19
19
  message: OK
20
20
  headers:
21
21
  Date:
22
- - Mon, 06 Feb 2017 05:24:58 GMT
22
+ - Fri, 07 Jul 2017 14:22:20 GMT
23
23
  Content-Type:
24
24
  - application/json; charset=utf-8
25
25
  Transfer-Encoding:
@@ -27,19 +27,23 @@ http_interactions:
27
27
  Connection:
28
28
  - keep-alive
29
29
  Set-Cookie:
30
- - __cfduid=deb478f2bbc3b2d0079764973622b4cd51486358697; expires=Tue, 06-Feb-18
31
- 05:24:57 GMT; path=/; domain=.kraken.com; HttpOnly
30
+ - __cfduid=dfca5540f20daad70ed370ad0034ba1b71499437339; expires=Sat, 07-Jul-18
31
+ 14:22:19 GMT; path=/; domain=.kraken.com; HttpOnly
32
+ Cache-Control:
33
+ - public,max-age=1,smaxage=1
32
34
  Vary:
33
35
  - Accept-Encoding
36
+ Cf-Cache-Status:
37
+ - EXPIRED
34
38
  Server:
35
39
  - cloudflare-nginx
36
40
  Cf-Ray:
37
- - 32cc2dc4ee4e1123-SIN
41
+ - 37ab748addd3235a-FRA
38
42
  body:
39
43
  encoding: ASCII-8BIT
40
- string: '{"error":[],"result":{"XXBTZUSD":{"a":["1018.00000","1","1.000"],"b":["1017.71000","24","24.000"],"c":["1018.00000","0.00139780"],"v":["140.87496222","1186.97757850"],"p":["1019.57961","1017.84325"],"t":[407,2092],"l":["1013.75000","1005.40000"],"h":["1024.00000","1030.00000"],"o":"1017.88600"}}}'
44
+ string: '{"error":[],"result":{"XXBTZUSD":{"a":["2511.88400","1","1.000"],"b":["1018.00000","5","5.000"],"c":["1018.00000","0.30000000"],"v":["2633.12341463","3864.11048862"],"p":["2561.39405","2572.10762"],"t":[6405,9427],"l":["2500.00000","2500.00000"],"h":["2613.99300","2615.00000"],"o":"2605.64100"}}}'
41
45
  http_version:
42
- recorded_at: Mon, 06 Feb 2017 05:24:58 GMT
46
+ recorded_at: Fri, 07 Jul 2017 14:22:20 GMT
43
47
  - request:
44
48
  method: get
45
49
  uri: https://api.kraken.com/0/public/Ticker?pair=xbteur
@@ -59,7 +63,7 @@ http_interactions:
59
63
  message: OK
60
64
  headers:
61
65
  Date:
62
- - Mon, 06 Feb 2017 05:25:00 GMT
66
+ - Fri, 07 Jul 2017 14:22:21 GMT
63
67
  Content-Type:
64
68
  - application/json; charset=utf-8
65
69
  Transfer-Encoding:
@@ -67,17 +71,109 @@ http_interactions:
67
71
  Connection:
68
72
  - keep-alive
69
73
  Set-Cookie:
70
- - __cfduid=d28404188131d0b4033e5ad505afba3711486358699; expires=Tue, 06-Feb-18
71
- 05:24:59 GMT; path=/; domain=.kraken.com; HttpOnly
74
+ - __cfduid=d0b780324eb697ad65322504814dd480e1499437340; expires=Sat, 07-Jul-18
75
+ 14:22:20 GMT; path=/; domain=.kraken.com; HttpOnly
76
+ Cache-Control:
77
+ - public,max-age=1,smaxage=1
72
78
  Vary:
73
79
  - Accept-Encoding
80
+ Cf-Cache-Status:
81
+ - EXPIRED
74
82
  Server:
75
83
  - cloudflare-nginx
76
84
  Cf-Ray:
77
- - 32cc2dcdab5030ae-SIN
85
+ - 37ab74922c9c648d-FRA
78
86
  body:
79
87
  encoding: ASCII-8BIT
80
- string: '{"error":[],"result":{"XXBTZEUR":{"a":["946.99900","1","1.000"],"b":["945.33000","6","6.000"],"c":["945.33000","0.33190000"],"v":["350.90083527","4825.99524551"],"p":["945.36841","944.38709"],"t":[687,6669],"l":["940.00000","935.00000"],"h":["948.00000","959.08900"],"o":"943.60000"}}}'
88
+ string: '{"error":[],"result":{"XXBTZEUR":{"a":["2209.91100","5","5.000"],"b":["945.33000","1","1.000"],"c":["945.33000","0.02653398"],"v":["5233.29645560","7648.83316547"],"p":["2235.89989","2249.70379"],"t":[13098,20659],"l":["2189.67000","2189.67000"],"h":["2288.25800","2290.77900"],"o":"2284.69200"}}}'
81
89
  http_version:
82
- recorded_at: Mon, 06 Feb 2017 05:25:00 GMT
90
+ recorded_at: Fri, 07 Jul 2017 14:22:21 GMT
91
+ - request:
92
+ method: get
93
+ uri: https://api.kraken.com/0/public/Ticker?pair=ltcusd
94
+ body:
95
+ encoding: US-ASCII
96
+ string: ''
97
+ headers:
98
+ Accept-Encoding:
99
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
100
+ Accept:
101
+ - "*/*"
102
+ User-Agent:
103
+ - Ruby
104
+ response:
105
+ status:
106
+ code: 200
107
+ message: OK
108
+ headers:
109
+ Date:
110
+ - Fri, 07 Jul 2017 14:22:22 GMT
111
+ Content-Type:
112
+ - application/json; charset=utf-8
113
+ Transfer-Encoding:
114
+ - chunked
115
+ Connection:
116
+ - keep-alive
117
+ Set-Cookie:
118
+ - __cfduid=dd849ee171f061fcd7e20d8a89f4a99811499437341; expires=Sat, 07-Jul-18
119
+ 14:22:21 GMT; path=/; domain=.kraken.com; HttpOnly
120
+ Cache-Control:
121
+ - public,max-age=2,smaxage=2
122
+ Vary:
123
+ - Accept-Encoding
124
+ Cf-Cache-Status:
125
+ - EXPIRED
126
+ Server:
127
+ - cloudflare-nginx
128
+ Cf-Ray:
129
+ - 37ab7499cbe90f93-FRA
130
+ body:
131
+ encoding: ASCII-8BIT
132
+ string: '{"error":[],"result":{"XLTCZUSD":{"a":["46.31299","10","10.000"],"b":["46.10008","20","20.000"],"c":["46.10003","1.00000000"],"v":["25860.06146258","41962.36292092"],"p":["48.20874","49.25912"],"t":[2468,3047],"l":["45.78800","45.78800"],"h":["51.59990","52.10031"],"o":"51.01002"}}}'
133
+ http_version:
134
+ recorded_at: Fri, 07 Jul 2017 14:22:22 GMT
135
+ - request:
136
+ method: get
137
+ uri: https://api.kraken.com/0/public/Ticker?pair=ltceur
138
+ body:
139
+ encoding: US-ASCII
140
+ string: ''
141
+ headers:
142
+ Accept-Encoding:
143
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
144
+ Accept:
145
+ - "*/*"
146
+ User-Agent:
147
+ - Ruby
148
+ response:
149
+ status:
150
+ code: 200
151
+ message: OK
152
+ headers:
153
+ Date:
154
+ - Fri, 07 Jul 2017 14:22:23 GMT
155
+ Content-Type:
156
+ - application/json; charset=utf-8
157
+ Transfer-Encoding:
158
+ - chunked
159
+ Connection:
160
+ - keep-alive
161
+ Set-Cookie:
162
+ - __cfduid=d089377bfcb6d87fdebdd75f0d910ec541499437342; expires=Sat, 07-Jul-18
163
+ 14:22:22 GMT; path=/; domain=.kraken.com; HttpOnly
164
+ Cache-Control:
165
+ - public,max-age=1,smaxage=1
166
+ Vary:
167
+ - Accept-Encoding
168
+ Cf-Cache-Status:
169
+ - EXPIRED
170
+ Server:
171
+ - cloudflare-nginx
172
+ Cf-Ray:
173
+ - 37ab74a14cae27b0-FRA
174
+ body:
175
+ encoding: ASCII-8BIT
176
+ string: '{"error":[],"result":{"XLTCZEUR":{"a":["40.74999","86","86.000"],"b":["40.62900","30","30.000"],"c":["40.74999","0.01050000"],"v":["53028.04209664","63233.70263117"],"p":["41.75383","42.21588"],"t":[4052,5246],"l":["40.02000","40.02000"],"h":["45.08076","45.67800"],"o":"45.00925"}}}'
177
+ http_version:
178
+ recorded_at: Fri, 07 Jul 2017 14:22:23 GMT
83
179
  recorded_with: VCR 3.0.3
@@ -17,6 +17,8 @@ RSpec.describe CurrencyRate::CoinbaseAdapter do
17
17
  it "finds the rate for currency code" do
18
18
  expect(@exchange_adapter.rate_for('BTC', 'USD')).to eq(1019.98)
19
19
  expect(@exchange_adapter.rate_for('USD', 'BTC')).to eq(0.00098)
20
+ expect(@exchange_adapter.rate_for('LTC', 'USD')).to eq(3.95)
21
+ expect(@exchange_adapter.rate_for('USD', 'LTC')).to eq(0.253165)
20
22
  expect( -> { @exchange_adapter.rate_for('FEDcoin', 'USD') }).to raise_error(CurrencyRate::Adapter::CurrencyNotSupported)
21
23
  end
22
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.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Snitko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-29 00:00:00.000000000 Z
11
+ date: 2017-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: satoshi-unit
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 2.1.1
47
+ version: 2.3.7
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 2.1.1
54
+ version: 2.3.7
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement