-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
api.exchangerate.io needs access_key to access the query #28
base: master
Are you sure you want to change the base?
Conversation
cd59e0c
to
7f5e0ee
Compare
|
||
uri = URI("https://api.exchangeratesapi.io/latest?base=#{base}") | ||
uri = URI("http://api.exchangeratesapi.io/v1/latest?access_key=#{access_key}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the change to HTTP is because exchangeratesapi.io now only supports HTTPS for paid plans.
@@ -6,11 +6,14 @@ | |||
data = JSON.parse(File.read('data.json')) | |||
base = data['base'] | |||
units = data['units'] | |||
access_key = "5413e55dd50ddb2555c63a9cd57c0306" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The access key should be made configurable (like in #26).
def get_currency_rate_with_symble(base, *targets) | ||
default_base = 'EUR' | ||
access_key = "5413e55dd50ddb2555c63a9cd57c0306" | ||
uri = URI("http://api.exchangeratesapi.io/v1/latest?access_key=#{access_key}") | ||
result = JSON.parse(Net::HTTP.get(uri)) | ||
res = Hash['success' => result['success'], 'base' => base, 'timestamp' => result['timestamp']] | ||
rates = Hash[] | ||
targets.each do | target | | ||
rates[target] = result['rates'][target] * result['rates'][default_base] / result['rates'][base] | ||
end | ||
res['rates'] = rates | ||
return res | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is because the free plan for exchangeratesapi.io always uses EUR as the base currency.
@@ -13,6 +13,22 @@ | |||
base = data['base'] | |||
units = data['units'] | |||
|
|||
|
|||
def get_currency_rate_with_symble(base, *targets) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_currency_rate_with_symbol
?
Provided a convenient way to adjust this api.exchangerate.io API change.