Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jeopard/historical-bank-ruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: lh-innovationhub/historical-bank-ruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 12 commits
  • 11 files changed
  • 3 contributors

Commits on Apr 14, 2020

  1. Relax redis version

    MatjazKavcic committed Apr 14, 2020
    Copy the full SHA
    ffd3548 View commit details
  2. Add rake dependency

    MatjazKavcic committed Apr 14, 2020
    Copy the full SHA
    d56fb94 View commit details
  3. Copy the full SHA
    ef2575b View commit details

Commits on Mar 28, 2022

  1. Copy the full SHA
    23937f0 View commit details
  2. Merge pull request #1 from lh-innovationhub/fix-deprecation-redis

    Fix deprecation for redis pipelines syntax
    MatjazKavcic authored Mar 28, 2022
    Copy the full SHA
    b82038f View commit details

Commits on Feb 17, 2023

  1. Copy the full SHA
    a5c0b9c View commit details

Commits on May 22, 2024

  1. Copy the full SHA
    30c2dff View commit details
  2. Merge pull request #3 from lh-innovationhub/fix-performance

    Improve performance by fixing getting rates from memory
    MatjazKavcic authored May 22, 2024
    Copy the full SHA
    f81a321 View commit details

Commits on Feb 25, 2025

  1. Upgrade Ruby 2 -> 3, Redis 3 -> 4+ (#4)

    * drop travis
    
    * Update CONTRIBUTING.md
    
    * add testing on Github actions
    
    * Bump Ruby 2 -> 3, update Redis 3 -> 4+
    
    * fix syntax required for Ruby 3
    
    * update syntax for RSpec
    
    * Ruby 2 Array =~ operator is confusing and works differently in Ruby 3. Refactor
    
    * no need to spin up different redis locally
    
    * add BigDecimal and don't rely on .to_d
    
    * iso_currency_code
    swiknaba authored Feb 25, 2025
    Copy the full SHA
    cd7f931 View commit details
  2. 👮 🤖

    swiknaba committed Feb 25, 2025
    Copy the full SHA
    637deca View commit details
  3. Copy the full SHA
    9094579 View commit details
  4. Delete .travis.yml

    swiknaba committed Feb 25, 2025
    Copy the full SHA
    7bd81fe View commit details
36 changes: 36 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Test
on: [push]
jobs:
test:
name: ${{ matrix.ruby }}
runs-on: ubuntu-latest

services:
redis:
image: redis
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
strategy:
fail-fast: false
matrix:
ruby:
- "3.1"
- "3.2"
- "3.3"
- "3.4"

steps:
- uses: actions/checkout@v4
- name: Set up Ruby ${{ matrix.ruby }}
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run Tests
run: bundle exec rspec
21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Contributing to historical-bank-ruby

We're glad you want to make a contribution!
We're glad you want to make a contribution!

Fork this repository and send in a pull request when you're finished with your changes. Link any relevant issues in too.
Fork this repository and send in a pull request when you're finished with your changes. Link any relevant issues in too.

Take note of the build status of your pull request, only builds that pass will be accepted. Please also keep to our conventions and style so we can keep this repository as clean as possible.
Take note of the build status of your pull request, only builds that pass will be accepted. Please also keep to our conventions and style so we can keep this repository as clean as possible.


## Steps

1. Fork the repo
2. Grab dependencies: `bundle install`
3. Make sure specs are green: `./spec/redis-server.sh` to run the Redis server and `bundle exec rspec` to run the specs. Alternatively, you can run your own Redis server in `localhost`, and add the port as an env var before running the specs, `REDIS_PORT=6379 bundle exec rspec`
3. Make sure specs are green: us e.g. `brew services start redis` the run Redis server and then `bundle exec rspec` to run the specs.
4. Make your changes
5. Run `rubocop -a`
6. Make sure specs are still green
@@ -57,7 +57,7 @@ Provider.
- Add another store (e.g. DynamoDB, MongoDB, Cassandra, Postgres, etc)


## License
## License

By contributing your code, you agree to license your contribution under the terms of the APLv2: https://github.com/jeopard/historical-bank-ruby/blob/master/LICENSE

24 changes: 12 additions & 12 deletions historical-bank.gemspec
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@ Gem::Specification.new do |s|
s.homepage = 'https://github.com/jeopard/historical-bank-ruby'
s.license = 'Apache-2.0'

require 'rake'
s.files = Dir['lib/**/*.rb', 'examples/*.rb', 'spec/**/*.rb']
s.files += ['Gemfile', 'historical-bank.gemspec', 'README.md', 'LICENSE',
'CONTRIBUTING.md', 'AUTHORS', 'CHANGELOG.md',
@@ -38,17 +37,18 @@ Gem::Specification.new do |s|

s.require_path = 'lib'

s.required_ruby_version = '>= 2.0.0'
s.required_ruby_version = '>= 3.1.0'

s.add_runtime_dependency 'money', '~> 6.7'
s.add_runtime_dependency 'httparty', '~> 0.14'
s.add_runtime_dependency 'redis', ['>=3.3', '~> 4.0']
s.add_runtime_dependency 'bigdecimal', '>= 3.0'
s.add_runtime_dependency 'httparty', '~> 0.19'
s.add_runtime_dependency 'money', '~> 6.7'
s.add_runtime_dependency 'redis', '>= 4.0'

s.add_development_dependency 'rspec', '~> 3.5'
s.add_development_dependency 'pry-byebug', '~> 3.4'
s.add_development_dependency 'rubocop', '~> 0.52'
s.add_development_dependency 'rack-test', '~> 0.6'
s.add_development_dependency 'webmock', '~> 2.3'
s.add_development_dependency 'faker', '~> 1.6'
s.add_development_dependency 'timecop', '~> 0.8'
s.add_development_dependency 'faker'
s.add_development_dependency 'pry-byebug'
s.add_development_dependency 'rack-test'
s.add_development_dependency 'rspec'
s.add_development_dependency 'rubocop'
s.add_development_dependency 'timecop'
s.add_development_dependency 'webmock'
end
8 changes: 4 additions & 4 deletions lib/money/rates_provider/open_exchange_rates.rb
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@ def initialize(oer_app_id, base_currency, timeout, oer_account_type)
# oer.fetch_rates(Date.new(2016, 10, 5))
# If Free or Developer account in openexchangerates.org, it will return only for the given date
# # => {"AED"=>{"2016-10-05"=>#<BigDecimal:7fa19a188e98,'0.3672682E1',18(36)>}, {"AFN"=>{"2016-10-05"=>#<BigDecimal:7fa19a188e98,'0.3672682E1',18(36)>}, ...
# If Enterprise or Unlimited account, it will return for the entire month for the given date
# If Enterprise or Unlimited account, it will return for the entire month for the given date
# # => {"AED"=>{"2016-10-01"=>#<BigDecimal:7fa19a188e98,'0.3672682E1',18(36)>, "2016-10-02"=>#<BigDecimal:7fa19b11a5c8,'0.367296E1',18(36)>, ...
def fetch_rates(date)
if date < MIN_DATE || date > max_date
@@ -98,7 +98,7 @@ def fetch_rates(date)
# Hash[iso_currency][iso_date], as it will allow more efficient caching/retrieving
response['rates'].each do |iso_date, day_rates|
day_rates.each do |iso_currency, rate|
result[iso_currency][iso_date] = rate.to_d
result[iso_currency][iso_date] = BigDecimal(rate.to_s)
end
end

@@ -124,7 +124,7 @@ def fetch_time_series_rates(date)
raise RequestFailed, "Month rates request failed for #{date} - "\
"Code: #{response.code} - Body: #{response.body}"
end
response
response
end

def fetch_historical_rates(date)
@@ -138,7 +138,7 @@ def fetch_historical_rates(date)
end

# Making the return value comply to the same structure returned from the #fetch_month_rates method (/time-series.json API)
{
{
'start_date' => date_string,
'end_date' => date_string,
'base' => response['base'],
9 changes: 5 additions & 4 deletions lib/money/rates_store/historical_redis.rb
Original file line number Diff line number Diff line change
@@ -90,9 +90,10 @@ def add_rates(currency_date_rate_hash)
end

@redis.pipelined do |pipeline|
currency_date_rate_hash.each do |iso_currency, iso_date_rate_hash|
k = key(iso_currency)
pipeline.mapped_hmset(k, iso_date_rate_hash)
currency_date_rate_hash.each do |iso_currency_code, iso_date_rate_hash|
k = key(iso_currency_code)
string_rates = iso_date_rate_hash.transform_values(&:to_s)
pipeline.mapped_hmset(k, string_rates)
end
end
rescue Redis::BaseError => e
@@ -115,7 +116,7 @@ def get_rates(currency)
iso_date_rate_hash = @redis.hgetall(k)

iso_date_rate_hash.each do |iso_date, rate_string|
iso_date_rate_hash[iso_date] = rate_string.to_d
iso_date_rate_hash[iso_date] = BigDecimal(rate_string)
end
rescue Redis::BaseError => e
raise RequestFailed, 'Error while retrieving rates for '\
52 changes: 26 additions & 26 deletions spec/bank/historical_spec.rb
Original file line number Diff line number Diff line change
@@ -45,23 +45,23 @@ module Bank
describe '#add_rates' do
let(:usd_date_rate_hash) do
{
'2015-09-10' => 0.11111.to_d,
'2015-09-11' => 0.22222.to_d,
'2015-09-12' => 0.33333.to_d
'2015-09-10' => BigDecimal('0.11111'),
'2015-09-11' => BigDecimal('0.22222'),
'2015-09-12' => BigDecimal('0.33333')
}
end
let(:currency_date_rate_hash) do
{
'USD' => usd_date_rate_hash,
'GBP' => {
'2015-09-10' => 0.44444.to_d,
'2015-09-11' => 0.55555.to_d,
'2015-09-12' => 0.66666.to_d
'2015-09-10' => BigDecimal('0.44444'),
'2015-09-11' => BigDecimal('0.55555'),
'2015-09-12' => BigDecimal('0.66666')
},
'VND' => {
'2015-09-10' => 0.77777.to_d,
'2015-09-11' => 0.88888.to_d,
'2015-09-12' => 0.99999.to_d
'2015-09-10' => BigDecimal('0.77777'),
'2015-09-11' => BigDecimal('0.88888'),
'2015-09-12' => BigDecimal('0.99999')
}
}
end
@@ -127,7 +127,7 @@ module Bank
end

context 'when datetime is a Date' do
let(:datetime) { Faker::Date.between(Date.today - 100, Date.today + 100) }
let(:datetime) { Faker::Date.between(from: Date.today - 100, to: Date.today + 100) }
let(:from_currency) { 'EUR' }
let(:to_currency) { Money::Currency.new('USD') }

@@ -179,7 +179,7 @@ module Bank
end

context 'and it is a Date' do
let(:datetime) { Faker::Date.between(Date.today - 100, Date.today + 100) }
let(:datetime) { Faker::Date.between(from: Date.today - 100, to: Date.today + 100) }

it 'returns the correct rate' do
expect(subject).to be_within(0.00000001).of(rate)
@@ -202,10 +202,10 @@ module Bank
let(:from_currency) { Currency.wrap('USD') }
let(:from_money) { Money.new(10_000, from_currency) }
let(:to_currency) { Currency.wrap('GBP') }
let(:datetime) { Faker::Time.between(Date.today - 300, Date.today - 2) }
let(:datetime) { Faker::Time.between(from: Date.today - 300, to: Date.today - 2) }
let(:date) { datetime.utc.to_date }
let(:from_currency_base_rate) { 1.1250721881474421.to_d }
let(:to_currency_base_rate) { 0.7346888078084116.to_d }
let(:from_currency_base_rate) { BigDecimal('1.1250721881474421') }
let(:to_currency_base_rate) { BigDecimal('0.7346888078084116') }
let(:from_currency_base_rates) do
{
(date - 1).iso8601 => rand,
@@ -246,7 +246,7 @@ module Bank
end

describe 'datetime type' do
let(:datetime) { Faker::Time.between(Date.today - 300, Date.today - 2) }
let(:datetime) { Faker::Time.between(from: Date.today - 300, to: Date.today - 2) }
let(:date) { datetime.utc.to_date }
let(:from_currency_base_rates_store) { from_currency_base_rates }
let(:to_currency_base_rates_store) { to_currency_base_rates }
@@ -401,8 +401,8 @@ module Bank
let(:from_currency) { Currency.wrap('USD') }
let(:from_money) { Money.new(500_00, from_currency) }
let(:to_currency) { Currency.wrap('GBP') }
let(:from_currency_base_rate) { 1.13597.to_d }
let(:to_currency_base_rate) { 0.735500.to_d }
let(:from_currency_base_rate) { BigDecimal('1.13597') }
let(:to_currency_base_rate) { BigDecimal('0.735500') }
let(:expected_result) { Money.new(323_73, to_currency) }

it { is_expected.to eq expected_result }
@@ -412,8 +412,8 @@ module Bank
let(:from_currency) { Currency.wrap('INR') }
let(:from_money) { Money.new(6_516_200, from_currency) }
let(:to_currency) { Currency.wrap('CAD') }
let(:from_currency_base_rate) { 73.5602.to_d }
let(:to_currency_base_rate) { 1.46700.to_d }
let(:from_currency_base_rate) { BigDecimal('73.5602') }
let(:to_currency_base_rate) { BigDecimal('1.46700') }
let(:expected_result) { Money.new(1_299_52, to_currency) }

it { is_expected.to eq expected_result }
@@ -424,8 +424,8 @@ module Bank
let(:from_currency) { Currency.wrap('SGD') }
let(:from_money) { Money.new(345_67, from_currency) }
let(:to_currency) { Currency.wrap('VND') }
let(:from_currency_base_rate) { 1.57222.to_d }
let(:to_currency_base_rate) { 25_160.75.to_d }
let(:from_currency_base_rate) { BigDecimal('1.57222') }
let(:to_currency_base_rate) { BigDecimal('25_160.75') }
let(:expected_result) { Money.new(5_531_870, to_currency) }

it { is_expected.to eq expected_result }
@@ -436,16 +436,16 @@ module Bank
let(:from_currency) { Currency.wrap('CNY') }
let(:from_money) { Money.new(987_654, from_currency) }
let(:to_currency) { Currency.wrap('KWD') }
let(:from_currency_base_rate) { 7.21517.to_d }
let(:to_currency_base_rate) { 0.342725.to_d }
let(:from_currency_base_rate) { BigDecimal('7.21517') }
let(:to_currency_base_rate) { BigDecimal('0.342725') }
let(:expected_result) { Money.new(469_142, to_currency) }

it { is_expected.to eq expected_result }
end
end

context 'when OER client fails with ArgumentError' do
let(:datetime) { Faker::Time.between(Date.new(1990, 1, 1), Date.new(1998, 12, 31)) }
let(:datetime) { Faker::Time.between(from: Date.new(1990, 1, 1), to: Date.new(1998, 12, 31)) }
let(:from_currency_base_rates_store) { nil }
let(:to_currency_base_rates_store) { nil }
let(:rates_provider) { nil }
@@ -467,8 +467,8 @@ module Bank
let(:from_money) { Money.new(10_000, from_currency) }
let(:to_currency) { Currency.wrap('GBP') }
let(:utc_date) { Time.now.utc.to_date }
let(:from_currency_base_rate) { 1.1250721881474421.to_d }
let(:to_currency_base_rate) { 0.7346888078084116.to_d }
let(:from_currency_base_rate) { BigDecimal('1.1250721881474421') }
let(:to_currency_base_rate) { BigDecimal('0.7346888078084116') }
let(:from_currency_base_rates_store) do
{
(utc_date - 3).iso8601 => rand,
Loading