lbank 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/main.yml +18 -0
- data/.github/workflows/publish.yml +21 -0
- data/.ruby-version +1 -1
- data/Gemfile +1 -0
- data/README.md +4 -2
- data/lib/lbank/errors.rb +4 -0
- data/lib/lbank/version.rb +1 -1
- data/lib/lbank.rb +7 -2
- data/spec/lbank_spec.rb +14 -15
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e42cbb5d1055bb80343d70d081956c326c8c155f614a37a7d578d20312fd7331
|
4
|
+
data.tar.gz: d00fa3314b87dc16a75c4ea993088e0551e6f9bcc254c89e3ab7afc3895b1936
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7494eea07bb8049fb3ded4845d54176df58803f97458295483ba760c4ff0b74e1a6ec68266ceccaf3d14f96eabfcf2c55a44ba8faeb3b3504e75b73280c07485
|
7
|
+
data.tar.gz: 8702c03fe0f58083025262832af803d80331d2ea1fa131a134353fb683a4373d70a50be9e700c0813012e18c7e5382c54d04a4a6a9c3ada1dc3c572dc8533794
|
@@ -0,0 +1,18 @@
|
|
1
|
+
name: Build
|
2
|
+
on: [push,pull_request]
|
3
|
+
jobs:
|
4
|
+
build:
|
5
|
+
runs-on: ubuntu-latest
|
6
|
+
strategy:
|
7
|
+
matrix:
|
8
|
+
ruby-version:
|
9
|
+
- 3.0
|
10
|
+
- 3.4
|
11
|
+
name: Ruby ${{ matrix.ruby-version }} sample
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v4
|
14
|
+
- uses: ruby/setup-ruby@v1
|
15
|
+
with:
|
16
|
+
ruby-version: ${{ matrix.ruby-version }}
|
17
|
+
- run: bundle install
|
18
|
+
- run: bundle exec rake spec
|
@@ -0,0 +1,21 @@
|
|
1
|
+
name: Publish gem to rubygems
|
2
|
+
on:
|
3
|
+
release:
|
4
|
+
types: [published]
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v4
|
10
|
+
- uses: ruby/setup-ruby@v1
|
11
|
+
|
12
|
+
# setup .gem/credentials
|
13
|
+
- run: mkdir -p ~/.gem
|
14
|
+
- env:
|
15
|
+
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
|
16
|
+
run: >-
|
17
|
+
echo -e "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}" > ~/.gem/credentials
|
18
|
+
- run: chmod 0600 ~/.gem/credentials
|
19
|
+
|
20
|
+
- run: gem build lbank.gemspec --output=release.gem
|
21
|
+
- run: gem push release.gem
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.3.5
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# Lbank
|
2
2
|
|
3
|
-
[](https://rubygems.org/gems/lbank)
|
4
|
+
[](https://github.com/laurynas/lbank/actions)
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
4
6
|
|
5
|
-
Fetches currency rates from Lithuanian Central Bank website
|
7
|
+
Fetches currency rates from Lithuanian Central Bank website https://lb.lt.
|
6
8
|
Does currency conversion.
|
7
9
|
Supports historic currency rates.
|
8
10
|
|
data/lib/lbank/errors.rb
ADDED
data/lib/lbank/version.rb
CHANGED
data/lib/lbank.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'lbank/version'
|
2
2
|
require 'lbank/memory_cache'
|
3
|
+
require 'lbank/errors'
|
3
4
|
require 'active_support/time'
|
4
5
|
require 'faraday'
|
5
6
|
require 'faraday_middleware'
|
@@ -29,6 +30,10 @@ module Lbank
|
|
29
30
|
|
30
31
|
cache.fetch(cache_key(date)) do
|
31
32
|
response = connection.post(URL, tp: RATE_TYPE, dt: date)
|
33
|
+
error = response.body['FxRates']['OprlErr']
|
34
|
+
|
35
|
+
raise ResponseError.new(error['Desc']) if error
|
36
|
+
|
32
37
|
fx_rates = response.body['FxRates']['FxRate']
|
33
38
|
|
34
39
|
rates = { fx_rates[0]['CcyAmt'][0]['Ccy'] => 1 }
|
@@ -41,8 +46,8 @@ module Lbank
|
|
41
46
|
end
|
42
47
|
end
|
43
48
|
|
44
|
-
def convert_currency(amount, from_currency, to_currency,
|
45
|
-
rates = currency_rates(
|
49
|
+
def convert_currency(amount, from_currency, to_currency, time = nil)
|
50
|
+
rates = currency_rates(time)
|
46
51
|
from_rate = rates[from_currency.to_s]
|
47
52
|
to_rate = rates[to_currency.to_s]
|
48
53
|
|
data/spec/lbank_spec.rb
CHANGED
@@ -1,28 +1,27 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Lbank do
|
4
|
+
let(:date) { Date.new(2012, 8, 4) }
|
5
|
+
|
4
6
|
describe '#currency_rates' do
|
5
|
-
subject { described_class.currency_rates }
|
7
|
+
subject { described_class.currency_rates(date) }
|
6
8
|
|
7
9
|
its(['USD']) { is_expected.to be > 0 }
|
8
|
-
end
|
9
|
-
|
10
|
-
describe '#convert_currency' do
|
11
|
-
it 'converts currency' do
|
12
|
-
expect(subject.convert_currency(10, 'USD', 'EUR')).to be > 0
|
13
|
-
expect(subject.convert_currency(10, 'EUR', 'LTL')).to eq 34.528
|
14
10
|
|
15
|
-
|
11
|
+
context 'when invalid time' do
|
12
|
+
let(:date) { Time.now + 1.week }
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
it 'raises error' do
|
15
|
+
expect { subject }.to raise_error(Lbank::ResponseError, /No data/)
|
16
|
+
end
|
20
17
|
end
|
21
18
|
end
|
22
19
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
describe '#convert_currency' do
|
21
|
+
it 'converts currency' do
|
22
|
+
expect(subject.convert_currency(10, 'EUR', 'LTL', date).round(2)).to eq 34.53
|
23
|
+
expect(subject.convert_currency(1, 'USD', 'EUR', date).round(2)).to eq 0.82
|
24
|
+
expect(subject.convert_currency(100, 'RUB', 'USD', date).round(2)).to eq 3.08
|
25
|
+
end
|
27
26
|
end
|
28
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lbank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Laurynas Butkus
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -101,6 +101,8 @@ executables: []
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
+
- ".github/workflows/main.yml"
|
105
|
+
- ".github/workflows/publish.yml"
|
104
106
|
- ".gitignore"
|
105
107
|
- ".rspec"
|
106
108
|
- ".ruby-version"
|
@@ -111,6 +113,7 @@ files:
|
|
111
113
|
- Rakefile
|
112
114
|
- lbank.gemspec
|
113
115
|
- lib/lbank.rb
|
116
|
+
- lib/lbank/errors.rb
|
114
117
|
- lib/lbank/memory_cache.rb
|
115
118
|
- lib/lbank/version.rb
|
116
119
|
- spec/lbank_spec.rb
|
@@ -118,7 +121,7 @@ files:
|
|
118
121
|
homepage: https://github.com/laurynas/lbank
|
119
122
|
licenses: []
|
120
123
|
metadata: {}
|
121
|
-
post_install_message:
|
124
|
+
post_install_message:
|
122
125
|
rdoc_options: []
|
123
126
|
require_paths:
|
124
127
|
- lib
|
@@ -133,9 +136,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
136
|
- !ruby/object:Gem::Version
|
134
137
|
version: '0'
|
135
138
|
requirements: []
|
136
|
-
|
137
|
-
|
138
|
-
signing_key:
|
139
|
+
rubygems_version: 3.5.16
|
140
|
+
signing_key:
|
139
141
|
specification_version: 4
|
140
142
|
summary: Fetches currency rates from Lithuanian Central Bank website. Does currency
|
141
143
|
conversion. Supports historic currency rates.
|