Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shwangdev
Copy link

Provided a convenient way to adjust this api.exchangerate.io API change.

@shwangdev shwangdev force-pushed the master branch 2 times, most recently from cd59e0c to 7f5e0ee Compare April 28, 2021 07:37

uri = URI("https://api.exchangeratesapi.io/latest?base=#{base}")
uri = URI("http://api.exchangeratesapi.io/v1/latest?access_key=#{access_key}")
Copy link
Contributor

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"
Copy link
Contributor

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).

Comment on lines +17 to +29
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
Copy link
Contributor

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)
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants