arbolito 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +11 -1
- data/arbolito.gemspec +2 -2
- data/lib/arbolito.rb +1 -0
- data/lib/arbolito/exchange/alpha_vantage.rb +45 -0
- data/lib/arbolito/exchange/yahoo_finance.rb +26 -24
- data/lib/arbolito/version.rb +1 -1
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39c67c7fc0b5d92aee360462456aa02a90b725f8
|
4
|
+
data.tar.gz: 970cdd3e45248a88523809ecdfc61437d6055f95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 369cd395a3c52d0b20b17e8578e6460a37b3487eec8f6a6434842ab8abfbfefc6505aa7a3a649f316263fd8b3cb72a350b72902ec2ee4d2b3c3d0d430c912617
|
7
|
+
data.tar.gz: aea0d2c5fad8944d11ad826815b7cf435cba0f4d1acd442129d77e3e68f4bc42da38be6d9a213e8a4c2305b6284b8aa6f01b5e717e23673becd32aa85c81171a
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -9,7 +9,7 @@ It's like your Florida street best companion!
|
|
9
9
|
## Features
|
10
10
|
* Doesn't encapsulates the currencies in any object model, it just use `BigDecimal` class and `Hash`
|
11
11
|
* You can add manually price rates
|
12
|
-
* If the rate isn't found it fetches the rate using Yahoo Finance API as exchange
|
12
|
+
* If the rate isn't found it fetches the rate using Yahoo Finance API as exchange or you can implement your own exchange.
|
13
13
|
* You implement your own exchange and configure it
|
14
14
|
* It stores in memory the rates fetched with a configurable expiration time
|
15
15
|
* You can implement your own store and configure it
|
@@ -83,6 +83,16 @@ Arbolito.set(:store, Store::Mongo)
|
|
83
83
|
|
84
84
|
```
|
85
85
|
|
86
|
+
# Update: 2017-11-03
|
87
|
+
Yahoo discountinued their Yahoo Finance API so I've implemented another Exchange [Alpha Vantage](https://www.alphavantage.co/).
|
88
|
+
|
89
|
+
To use you need to get an API Key from them and the configure it like this.
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
api_key = ENV['API_KEY']
|
93
|
+
Arbolito.set(:exchange, Arbolito::Exchange::AlphaVantage.new(api_key))
|
94
|
+
```
|
95
|
+
|
86
96
|
## Implementing Store and Exchange
|
87
97
|
|
88
98
|
Please take a look at the code to see how you can implement your own stores and exchanges.
|
data/arbolito.gemspec
CHANGED
@@ -20,6 +20,6 @@ Gem::Specification.new do |s|
|
|
20
20
|
|
21
21
|
s.add_development_dependency "bundler", "~> 1.10"
|
22
22
|
s.add_development_dependency "rake", "~> 10.0"
|
23
|
-
s.add_development_dependency "rspec"
|
24
|
-
s.add_development_dependency "pry"
|
23
|
+
s.add_development_dependency "rspec", "~> 3.3"
|
24
|
+
s.add_development_dependency "pry", "~> 0.10"
|
25
25
|
end
|
data/lib/arbolito.rb
CHANGED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Arbolito
|
5
|
+
module Exchange
|
6
|
+
class AlphaVantage
|
7
|
+
BaseURL = 'https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=%s&to_currency=%s&apikey=%s'.freeze
|
8
|
+
|
9
|
+
attr_reader :api_key
|
10
|
+
|
11
|
+
def initialize(api_key)
|
12
|
+
@api_key = api_key
|
13
|
+
end
|
14
|
+
|
15
|
+
def find_current_rate(quote)
|
16
|
+
data = response(build_uri(quote.from,quote.to))
|
17
|
+
rated_at_str = "#{data['6. Last Refreshed']} #{data['7. Time Zone']}"
|
18
|
+
rated_at = Time.strptime(rated_at_str,'%Y-%m-%d %H:%M:%S %Z')
|
19
|
+
|
20
|
+
values = {
|
21
|
+
quote: quote.to_hash,
|
22
|
+
price: data['5. Exchange Rate'],
|
23
|
+
rated_at: rated_at.localtime
|
24
|
+
}
|
25
|
+
|
26
|
+
Currency::Rate.new(
|
27
|
+
values[:price],
|
28
|
+
values[:quote].to_hash,
|
29
|
+
values[:rated_at]
|
30
|
+
)
|
31
|
+
end
|
32
|
+
|
33
|
+
def response(uri)
|
34
|
+
response = Net::HTTP.get(uri)
|
35
|
+
json = JSON.parse(response)
|
36
|
+
json['Realtime Currency Exchange Rate']
|
37
|
+
end
|
38
|
+
|
39
|
+
def build_uri(from, to)
|
40
|
+
url = BaseURL % [from.upcase, to.upcase, api_key]
|
41
|
+
URI(url)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -3,35 +3,37 @@ require 'net/http'
|
|
3
3
|
module Arbolito
|
4
4
|
module Exchange
|
5
5
|
class YahooFinance
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
def initialize(api_key = '')
|
7
|
+
end
|
8
|
+
# DEPRECATED Yahoo Finance is not supported anymore by Yahoo so use Alpha Vantage API
|
9
|
+
def find_current_rate(quote)
|
10
|
+
warn "[DEPRECATION] Yahoo Finance `find_current_rate` is deprecated. Please use AlphaVantage `find_current_rate` instead."
|
11
|
+
data = response(build_uri(quote))
|
9
12
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
values = {
|
14
|
+
quote: quote,
|
15
|
+
price: data[1],
|
16
|
+
}
|
14
17
|
|
15
|
-
|
16
|
-
|
18
|
+
build_rate(values)
|
19
|
+
end
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
private
|
22
|
+
def response(uri)
|
23
|
+
response = Net::HTTP.get(uri)
|
24
|
+
data = response.gsub(/"|\\n/,'').split(',')
|
25
|
+
end
|
23
26
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
27
|
+
def build_uri(quote)
|
28
|
+
param = "#{quote.from.upcase}#{quote.to.upcase}"
|
29
|
+
URI("http://download.finance.yahoo.com/d/quotes.csv?s=#{param}=X&f=nl1d1t1")
|
30
|
+
end
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
32
|
+
def build_rate(values)
|
33
|
+
Currency::Rate.new(
|
34
|
+
values[:price],
|
35
|
+
values[:quote].to_hash
|
36
|
+
)
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
data/lib/arbolito/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arbolito
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jvillarejo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -42,30 +42,30 @@ dependencies:
|
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '3.3'
|
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: '
|
54
|
+
version: '3.3'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: pry
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
61
|
+
version: '0.10'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
68
|
+
version: '0.10'
|
69
69
|
description: A currency conversion api for the minimalist developer
|
70
70
|
email:
|
71
71
|
- contact@jonvillage.com
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- lib/arbolito/currency/non_expirable_rate.rb
|
89
89
|
- lib/arbolito/currency/quote.rb
|
90
90
|
- lib/arbolito/currency/rate.rb
|
91
|
+
- lib/arbolito/exchange/alpha_vantage.rb
|
91
92
|
- lib/arbolito/exchange/yahoo_finance.rb
|
92
93
|
- lib/arbolito/store/memory.rb
|
93
94
|
- lib/arbolito/version.rb
|
@@ -111,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
111
112
|
version: '0'
|
112
113
|
requirements: []
|
113
114
|
rubyforge_project:
|
114
|
-
rubygems_version: 2.
|
115
|
+
rubygems_version: 2.5.1
|
115
116
|
signing_key:
|
116
117
|
specification_version: 4
|
117
118
|
summary: A currency conversion api for the minimalist developer
|