ynab_convert 1.0.8 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/publish.yml +36 -0
- data/.github/workflows/test.yml +31 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +10 -2
- data/Gemfile.lock +39 -14
- data/Guardfile +1 -29
- data/README.md +82 -7
- data/lib/ynab_convert/api_clients/api_client.rb +24 -0
- data/lib/ynab_convert/api_clients/currency_api.rb +66 -0
- data/lib/ynab_convert/documents/statements/example_statement.rb +16 -0
- data/lib/ynab_convert/documents/statements/n26_statement.rb +24 -0
- data/lib/ynab_convert/documents/statements/statement.rb +39 -0
- data/lib/ynab_convert/documents/statements/ubs_chequing_statement.rb +20 -0
- data/lib/ynab_convert/documents/statements/ubs_credit_statement.rb +19 -0
- data/lib/ynab_convert/documents/statements/wise_statement.rb +17 -0
- data/lib/ynab_convert/documents/ynab4_files/ynab4_file.rb +58 -0
- data/lib/ynab_convert/documents.rb +17 -0
- data/lib/ynab_convert/logger.rb +1 -1
- data/lib/ynab_convert/processors/example_processor.rb +24 -0
- data/lib/ynab_convert/processors/n26_processor.rb +26 -0
- data/lib/ynab_convert/processors/processor.rb +75 -0
- data/lib/ynab_convert/processors/ubs_chequing_processor.rb +21 -0
- data/lib/ynab_convert/processors/ubs_credit_processor.rb +17 -0
- data/lib/ynab_convert/processors/wise_processor.rb +19 -0
- data/lib/ynab_convert/processors.rb +2 -2
- data/lib/ynab_convert/transformers/cleaners/cleaner.rb +17 -0
- data/lib/ynab_convert/transformers/cleaners/n26_cleaner.rb +13 -0
- data/lib/ynab_convert/transformers/cleaners/ubs_chequing_cleaner.rb +98 -0
- data/lib/ynab_convert/transformers/cleaners/ubs_credit_cleaner.rb +45 -0
- data/lib/ynab_convert/transformers/cleaners/wise_cleaner.rb +39 -0
- data/lib/ynab_convert/transformers/enhancers/enhancer.rb +20 -0
- data/lib/ynab_convert/transformers/enhancers/n26_enhancer.rb +74 -0
- data/lib/ynab_convert/transformers/enhancers/wise_enhancer.rb +87 -0
- data/lib/ynab_convert/transformers/formatters/example_formatter.rb +12 -0
- data/lib/ynab_convert/transformers/formatters/formatter.rb +91 -0
- data/lib/ynab_convert/transformers/formatters/n26_formatter.rb +19 -0
- data/lib/ynab_convert/transformers/formatters/ubs_chequing_formatter.rb +12 -0
- data/lib/ynab_convert/transformers/formatters/ubs_credit_formatter.rb +12 -0
- data/lib/ynab_convert/transformers/formatters/wise_formatter.rb +35 -0
- data/lib/ynab_convert/transformers.rb +18 -0
- data/lib/ynab_convert/validators/ynab4_row_validator.rb +83 -0
- data/lib/ynab_convert/validators.rb +9 -0
- data/lib/ynab_convert/version.rb +1 -1
- data/lib/ynab_convert.rb +22 -3
- data/ynab_convert.gemspec +4 -0
- metadata +94 -10
- data/.travis.yml +0 -20
- data/lib/ynab_convert/processor/base.rb +0 -226
- data/lib/ynab_convert/processor/example.rb +0 -124
- data/lib/ynab_convert/processor/n26.rb +0 -70
- data/lib/ynab_convert/processor/revolut.rb +0 -103
- data/lib/ynab_convert/processor/ubs_chequing.rb +0 -137
- data/lib/ynab_convert/processor/ubs_credit.rb +0 -83
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca5eb6c8faa90e9ed7b1c7330d765dd2e9a5db77e87566575308d10fe3c4282e
|
4
|
+
data.tar.gz: 00f55f5d57d92f1b9adfe8ba8ff02a2724b80239b871bc643a5f053f2b0a9f24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: faddd2eb742c5d29fcf2d7a96481306a6b0dd053d8fe7e7ec23354b9bd7cd404fc16b2c4689ae3d7880623e952cdb6275869debf83a17fa0a44244e2a22b5873
|
7
|
+
data.tar.gz: 05d475c355ad37263e815580aaa3386821a7048c0fa62ed767d48f7996f76e8b59c13d2518a20fe9d69a4245786a79e61a40e49ca61aa727c616ead202521035
|
@@ -0,0 +1,36 @@
|
|
1
|
+
---
|
2
|
+
name: ruby
|
3
|
+
|
4
|
+
on:
|
5
|
+
push:
|
6
|
+
branches: [master]
|
7
|
+
|
8
|
+
permissions:
|
9
|
+
contents: read
|
10
|
+
|
11
|
+
jobs:
|
12
|
+
publish:
|
13
|
+
name: Build + Publish
|
14
|
+
runs-on: ubuntu-latest
|
15
|
+
permissions:
|
16
|
+
packages: write
|
17
|
+
contents: read
|
18
|
+
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v3
|
21
|
+
- name: Set up Ruby
|
22
|
+
uses: ruby/setup-ruby@v1
|
23
|
+
with:
|
24
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
25
|
+
- name: Run tests
|
26
|
+
run: bundle exec rake ci
|
27
|
+
- name: Publish to RubyGems
|
28
|
+
run: |
|
29
|
+
mkdir -p $HOME/.gem
|
30
|
+
touch $HOME/.gem/credentials
|
31
|
+
chmod 0600 $HOME/.gem/credentials
|
32
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
33
|
+
gem build *.gemspec
|
34
|
+
gem push *.gem
|
35
|
+
env:
|
36
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
@@ -0,0 +1,31 @@
|
|
1
|
+
---
|
2
|
+
name: ruby
|
3
|
+
|
4
|
+
on:
|
5
|
+
push:
|
6
|
+
branches: [master]
|
7
|
+
pull_request:
|
8
|
+
branches: [master]
|
9
|
+
|
10
|
+
permissions:
|
11
|
+
contents: read
|
12
|
+
|
13
|
+
jobs:
|
14
|
+
test:
|
15
|
+
runs-on: ubuntu-latest
|
16
|
+
strategy:
|
17
|
+
matrix:
|
18
|
+
ruby-version: ["2.6", "2.7"]
|
19
|
+
|
20
|
+
steps:
|
21
|
+
- uses: actions/checkout@v3
|
22
|
+
- name: Set up Ruby
|
23
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
24
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
25
|
+
# uses: ruby/setup-ruby@v1
|
26
|
+
uses: ruby/setup-ruby@v1
|
27
|
+
with:
|
28
|
+
ruby-version: ${{ matrix.ruby-version }}
|
29
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
30
|
+
- name: Run tests
|
31
|
+
run: bundle exec rake ci
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,14 +1,22 @@
|
|
1
1
|
---
|
2
2
|
# See https://github.com/rubocop/rubocop/blob/master/config/default.yml for all
|
3
3
|
# options
|
4
|
-
require:
|
4
|
+
require:
|
5
|
+
- rubocop-rake
|
6
|
+
- rubocop-rspec
|
5
7
|
|
6
8
|
AllCops:
|
7
9
|
DisplayCopNames: true
|
10
|
+
NewCops: enable
|
11
|
+
TargetRubyVersion: 2.6
|
8
12
|
|
9
|
-
|
13
|
+
Layout/LineLength:
|
14
|
+
AllowHeredoc: true
|
15
|
+
AllowURI: true
|
16
|
+
AutoCorrect: true
|
10
17
|
Exclude:
|
11
18
|
- ynab_convert.gemspec
|
19
|
+
Max: 80
|
12
20
|
|
13
21
|
Metrics/BlockLength:
|
14
22
|
Exclude:
|
data/Gemfile.lock
CHANGED
@@ -1,18 +1,23 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
ynab_convert (
|
4
|
+
ynab_convert (2.0.3)
|
5
5
|
i18n
|
6
6
|
slop
|
7
|
+
timecop
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: https://rubygems.org/
|
10
11
|
specs:
|
11
|
-
|
12
|
+
addressable (2.8.0)
|
13
|
+
public_suffix (>= 2.0.2, < 5.0)
|
14
|
+
ast (2.4.2)
|
12
15
|
backport (1.1.2)
|
13
16
|
byebug (11.0.1)
|
14
17
|
coderay (1.1.2)
|
15
|
-
concurrent-ruby (1.1.
|
18
|
+
concurrent-ruby (1.1.10)
|
19
|
+
crack (0.4.5)
|
20
|
+
rexml
|
16
21
|
diff-lcs (1.3)
|
17
22
|
docile (1.3.2)
|
18
23
|
ffi (1.11.2)
|
@@ -34,6 +39,7 @@ GEM
|
|
34
39
|
guard-rubocop (1.3.0)
|
35
40
|
guard (~> 2.0)
|
36
41
|
rubocop (~> 0.20)
|
42
|
+
hashdiff (1.0.1)
|
37
43
|
htmlentities (4.3.4)
|
38
44
|
i18n (1.10.0)
|
39
45
|
concurrent-ruby (~> 1.0)
|
@@ -52,23 +58,26 @@ GEM
|
|
52
58
|
notiffany (0.1.3)
|
53
59
|
nenv (~> 0.1)
|
54
60
|
shellany (~> 0.0)
|
55
|
-
parallel (1.
|
56
|
-
parser (2.
|
57
|
-
ast (~> 2.4.
|
61
|
+
parallel (1.21.0)
|
62
|
+
parser (2.7.2.0)
|
63
|
+
ast (~> 2.4.1)
|
58
64
|
pry (0.12.2)
|
59
65
|
coderay (~> 1.1.0)
|
60
66
|
method_source (~> 0.9.0)
|
61
67
|
pry-byebug (3.7.0)
|
62
68
|
byebug (~> 11.0)
|
63
69
|
pry (~> 0.10)
|
70
|
+
public_suffix (4.0.6)
|
64
71
|
racc (1.6.0)
|
65
|
-
rainbow (3.
|
72
|
+
rainbow (3.1.1)
|
66
73
|
rake (13.0.1)
|
67
74
|
rb-fsevent (0.10.3)
|
68
75
|
rb-inotify (0.10.0)
|
69
76
|
ffi (~> 1.0)
|
77
|
+
regexp_parser (2.2.1)
|
70
78
|
reverse_markdown (1.3.0)
|
71
79
|
nokogiri
|
80
|
+
rexml (3.2.5)
|
72
81
|
rspec (3.9.0)
|
73
82
|
rspec-core (~> 3.9.0)
|
74
83
|
rspec-expectations (~> 3.9.0)
|
@@ -82,23 +91,30 @@ GEM
|
|
82
91
|
diff-lcs (>= 1.2.0, < 2.0)
|
83
92
|
rspec-support (~> 3.9.0)
|
84
93
|
rspec-support (3.9.0)
|
85
|
-
rubocop (0.
|
86
|
-
jaro_winkler (~> 1.5.1)
|
94
|
+
rubocop (0.93.1)
|
87
95
|
parallel (~> 1.10)
|
88
|
-
parser (>= 2.
|
96
|
+
parser (>= 2.7.1.5)
|
89
97
|
rainbow (>= 2.2.2, < 4.0)
|
98
|
+
regexp_parser (>= 1.8)
|
99
|
+
rexml
|
100
|
+
rubocop-ast (>= 0.6.0)
|
90
101
|
ruby-progressbar (~> 1.7)
|
91
|
-
unicode-display_width (>= 1.4.0, <
|
102
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
103
|
+
rubocop-ast (1.4.1)
|
104
|
+
parser (>= 2.7.1.5)
|
92
105
|
rubocop-rake (0.5.0)
|
93
106
|
rubocop
|
94
|
-
|
107
|
+
rubocop-rspec (1.44.1)
|
108
|
+
rubocop (~> 0.87)
|
109
|
+
rubocop-ast (>= 0.7.1)
|
110
|
+
ruby-progressbar (1.11.0)
|
95
111
|
shellany (0.0.1)
|
96
112
|
simplecov (0.17.1)
|
97
113
|
docile (~> 1.1)
|
98
114
|
json (>= 1.8, < 3)
|
99
115
|
simplecov-html (~> 0.10.0)
|
100
116
|
simplecov-html (0.10.2)
|
101
|
-
slop (4.9.
|
117
|
+
slop (4.9.2)
|
102
118
|
solargraph (0.37.2)
|
103
119
|
backport (~> 1.1)
|
104
120
|
bundler (>= 1.17.2)
|
@@ -113,7 +129,13 @@ GEM
|
|
113
129
|
yard (~> 0.9)
|
114
130
|
thor (0.20.3)
|
115
131
|
tilt (2.0.10)
|
116
|
-
|
132
|
+
timecop (0.9.5)
|
133
|
+
unicode-display_width (1.8.0)
|
134
|
+
vcr (6.1.0)
|
135
|
+
webmock (3.14.0)
|
136
|
+
addressable (>= 2.8.0)
|
137
|
+
crack (>= 0.3.2)
|
138
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
117
139
|
yard (0.9.20)
|
118
140
|
|
119
141
|
PLATFORMS
|
@@ -129,8 +151,11 @@ DEPENDENCIES
|
|
129
151
|
rspec-core
|
130
152
|
rubocop
|
131
153
|
rubocop-rake
|
154
|
+
rubocop-rspec
|
132
155
|
simplecov
|
133
156
|
solargraph
|
157
|
+
vcr
|
158
|
+
webmock
|
134
159
|
ynab_convert!
|
135
160
|
|
136
161
|
BUNDLED WITH
|
data/Guardfile
CHANGED
@@ -44,37 +44,9 @@ group :red_green_refactor, halt_on_fail: true do
|
|
44
44
|
# Ruby files
|
45
45
|
ruby = dsl.ruby
|
46
46
|
dsl.watch_spec_files_for(ruby.lib_files)
|
47
|
-
|
48
|
-
# Rails files
|
49
|
-
rails = dsl.rails(view_extensions: %w[erb haml slim])
|
50
|
-
dsl.watch_spec_files_for(rails.app_files)
|
51
|
-
dsl.watch_spec_files_for(rails.views)
|
52
|
-
|
53
|
-
watch(rails.controllers) do |m|
|
54
|
-
[
|
55
|
-
rspec.spec.call("routing/#{m[1]}_routing"),
|
56
|
-
rspec.spec.call("controllers/#{m[1]}_controller"),
|
57
|
-
rspec.spec.call("acceptance/#{m[1]}")
|
58
|
-
]
|
59
|
-
end
|
60
|
-
|
61
|
-
# Rails config changes
|
62
|
-
watch(rails.spec_helper) { rspec.spec_dir }
|
63
|
-
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
|
64
|
-
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
|
65
|
-
|
66
|
-
# Capybara features specs
|
67
|
-
watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
|
68
|
-
watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
|
69
|
-
|
70
|
-
# Turnip features and steps
|
71
|
-
watch(%r{^spec/acceptance/(.+)\.feature$})
|
72
|
-
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
|
73
|
-
Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance'
|
74
|
-
end
|
75
47
|
end
|
76
48
|
|
77
|
-
guard :rubocop, cli: ['--auto-correct', '--display-cop-names'] do
|
49
|
+
guard :rubocop, cli: ['--auto-correct-all', '--display-cop-names'] do
|
78
50
|
watch('Gemfile')
|
79
51
|
watch('Rakefile')
|
80
52
|
watch('bin/convert')
|
data/README.md
CHANGED
@@ -27,35 +27,110 @@ latest one on 2019-12-01.
|
|
27
27
|
`-i` argument | Institution's full name | Institution's website | Remarks
|
28
28
|
---|---|---|---
|
29
29
|
`example` | Example Bank | N/A | Reference processor implementation, not a real institution
|
30
|
-
`n26` | N26 | [n26.com](n26.com) | N26 CSV statements
|
31
|
-
`revolut` | Revolut Ltd | [revolut.com](https://www.revolut.com/) | The processor isn't aware of currencies. Make sure the statements processed with `revolut` are in the same currency that your YNAB is in
|
30
|
+
`n26` | N26 | [n26.com](n26.com) | N26 CSV statements, will convert EUR amounts to CHF (hardcoded for now)
|
32
31
|
`ubs_chequing` | UBS Switzerland (private banking) | [ubs.ch](https://ubs.ch) | Private chequing and joint accounts
|
33
32
|
`ubs_credit` | UBS Switzerland (credit cards) | [ubs.ch](https://ubs.ch) | Both MasterCard and Visa
|
33
|
+
`wise` | Wise (Transferwise) cards | [wise.com](https://wise.com) | Performs currency conversion (hardcoded to CHF for now)
|
34
34
|
|
35
35
|
## Contributing
|
36
36
|
|
37
37
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
38
38
|
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
39
|
-
prompt that will allow you to experiment.
|
39
|
+
prompt that will allow you to experiment. To run Rubocop and RSpec in watch
|
40
|
+
mode, use `bundle exec guard`.
|
40
41
|
|
41
42
|
To install this gem onto your local machine, run `bundle exec rake install`.
|
43
|
+
Alternatively, the gem can also be run from `bin/ynab_convert`.
|
42
44
|
|
43
45
|
Bug reports and pull requests are welcome on GitHub at
|
44
46
|
https://github.com/coaxial/ynab_convert.
|
45
47
|
|
46
|
-
###
|
48
|
+
### Architecture
|
49
|
+
|
50
|
+
Here is the class diagram:
|
51
|
+
```mermaid
|
52
|
+
classDiagram
|
53
|
+
Documents <|-- Statement
|
54
|
+
Documents <|-- YNAB4File
|
55
|
+
Transformers <|-- Cleaner
|
56
|
+
Transformers <|-- Formatter
|
57
|
+
Transformers <|-- Enhancer
|
58
|
+
Validators <|-- YNAB4Row
|
59
|
+
Processors <|-- Processor
|
60
|
+
|
61
|
+
class Statement{
|
62
|
+
#Hash csv_import_options
|
63
|
+
#String filepath
|
64
|
+
#String institution_name
|
65
|
+
}
|
66
|
+
|
67
|
+
class YNAB4File{
|
68
|
+
#Hash csv_export_options
|
69
|
+
#String filename
|
70
|
+
#update_dates(row)
|
71
|
+
}
|
72
|
+
|
73
|
+
class Processor{
|
74
|
+
#to_ynab!()
|
75
|
+
}
|
76
|
+
|
77
|
+
class Cleaner{
|
78
|
+
#run(row)
|
79
|
+
}
|
80
|
+
|
81
|
+
class Enhancer{
|
82
|
+
#run(row)
|
83
|
+
}
|
84
|
+
|
85
|
+
class Formatter{
|
86
|
+
#run(row)
|
87
|
+
}
|
88
|
+
|
89
|
+
class YNAB4Row{
|
90
|
+
+valid?(row)
|
91
|
+
}
|
92
|
+
```
|
93
|
+
|
94
|
+
Each financial institution gets its own class for most of these base classes.
|
95
|
+
|
96
|
+
For instance, adding "Some Bank" would require creating the following new
|
97
|
+
classes:
|
98
|
+
|
99
|
+
- `class Processors::SomeBank < Processor`
|
100
|
+
- `class Transformers::Cleaners::SomeBank < Cleaner`
|
101
|
+
- `class Transformers::Formatter::SomeBank < Formatter`
|
102
|
+
- `class Transformers::Enhancer::SomeBank < Enhancer`
|
103
|
+
- `class Documents::Statements::SomeBank < Statement`
|
104
|
+
|
105
|
+
Each of these classes would implement the expected interface for its type, and
|
106
|
+
the `Processor::SomeBank` would instantiate them all. `Validators` and `YNAB4File`
|
107
|
+
aren't related to a particular institution, there is no need to derive a child
|
108
|
+
class for each bank.
|
109
|
+
|
110
|
+
Note that any of the `Transformers::` classes are optional, and it is possible
|
111
|
+
that some institution only requires a `Cleaner` but no `Formatter` or
|
112
|
+
`Enhancer` (for example).
|
113
|
+
|
114
|
+
### Debugging
|
47
115
|
|
48
116
|
Run `ynab_convert` with `YNAB_CONVERT_DEBUG=true`, or use the rake task
|
49
117
|
`spec:debug`. Debug logging goes to STDERR.
|
50
118
|
|
119
|
+
Or add `byebug` or `pry` statements in the code (works with guard and with rspec).
|
120
|
+
|
51
121
|
### Adding a new financial institution
|
52
122
|
|
53
123
|
If there is no processor for your financial institution, you can contribute one
|
54
124
|
to the project.
|
55
125
|
|
56
|
-
|
57
|
-
|
58
|
-
|
126
|
+
Looking at the other, real-world processors in `lib/processors` is helpful.
|
127
|
+
|
128
|
+
Note that if the processor name's case cannot be camel cased from its lowercase
|
129
|
+
string, it will need to be added manually in `lib/ynab_convert.rb` in the
|
130
|
+
`processor_class_name` method. For instance, the USB Chequing processor is
|
131
|
+
called with `-i ubs_chequing` from the command line. That makes the gem try to
|
132
|
+
use `Processors::UbsChequing` as the processor class, but it's actually called
|
133
|
+
`Processors::UBSChequing`.
|
59
134
|
|
60
135
|
Be sure to add tests to your processor as well before you make a PR.
|
61
136
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module APIClients
|
7
|
+
# Base APIClient
|
8
|
+
class APIClient
|
9
|
+
# @param api_base_path [String] Base path to the API
|
10
|
+
def initialize(api_base_path:)
|
11
|
+
@api_base_path = api_base_path
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def make_request(endpoint:)
|
17
|
+
uri = URI(URI.join(@api_base_path, endpoint))
|
18
|
+
|
19
|
+
response = Net::HTTP.get_response(uri)
|
20
|
+
|
21
|
+
JSON.parse(response.body, symbolize_names: true)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ynab_convert/api_clients/api_client'
|
4
|
+
|
5
|
+
module APIClients
|
6
|
+
# Client for currency-api
|
7
|
+
# (https://github.com/fawazahmed0/currency-api#readme)
|
8
|
+
class CurrencyAPI < APIClient
|
9
|
+
# The days that are missing from the API's otherwise normally available
|
10
|
+
# range
|
11
|
+
MISSING_DAYS = { '2021-09-14' => true }.freeze
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
api_base_path = 'https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/'
|
15
|
+
@available_date_range = {
|
16
|
+
min: Date.parse('2020-11-22'),
|
17
|
+
max: Date.today - 1 # yesterday
|
18
|
+
}
|
19
|
+
|
20
|
+
super(api_base_path: api_base_path)
|
21
|
+
end
|
22
|
+
|
23
|
+
# @param base_currency [Symbol] ISO symbol for base currency
|
24
|
+
# @param date [Date, String] The date on which to get the rates for
|
25
|
+
# @return [Hash<Symbol, Numeric>] The rates for that day in base_currency
|
26
|
+
def historical(base_currency:, date:)
|
27
|
+
parsed_date = date.is_a?(Date) ? date : Date.parse(date)
|
28
|
+
handle_date_out_of_bounds(parsed_date) if out_of_bounds?(parsed_date)
|
29
|
+
# Some days are missing from the API, use the previous day's rate if
|
30
|
+
# a missing day is requested
|
31
|
+
parsed_date -= 1 if missing_day?(date)
|
32
|
+
currency = base_currency.downcase
|
33
|
+
endpoint = "#{parsed_date}/currencies/#{currency}.min.json"
|
34
|
+
rates = make_request(endpoint: endpoint)
|
35
|
+
|
36
|
+
rates[currency]
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# The currency-api only has rates since 2020-11-22 and until yesterday
|
42
|
+
# (the current day's rate are updated at 23:59 on that day). This method
|
43
|
+
# ensures the requested date falls within the available range.
|
44
|
+
# @param date [Date] The date to check
|
45
|
+
# @return [Boolean] Whether the date is out of bounds for this API
|
46
|
+
def out_of_bounds?(date)
|
47
|
+
date < @available_date_range[:min] || date > @available_date_range[:max]
|
48
|
+
end
|
49
|
+
|
50
|
+
# @param date [Date] The date to show in the error message
|
51
|
+
def handle_date_out_of_bounds(date)
|
52
|
+
error_message = "#{date} is out of the currency-api available date "\
|
53
|
+
"range (#{@available_date_range[:min]}–#{@available_date_range[:max]})"
|
54
|
+
|
55
|
+
raise Errno::EDOM, error_message
|
56
|
+
end
|
57
|
+
|
58
|
+
# Indicates whether a date is missing from the API's normally available
|
59
|
+
# date range
|
60
|
+
# @param date [Date] the date to check
|
61
|
+
# @return [Boolean] whether the date is unavailable in the API
|
62
|
+
def missing_day?(date)
|
63
|
+
MISSING_DAYS.key?(date.to_s)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ynab_convert/documents/statements/statement'
|
4
|
+
|
5
|
+
module Documents
|
6
|
+
module Statements
|
7
|
+
# Example of a Statement
|
8
|
+
class Example < Statement
|
9
|
+
def initialize(filepath:)
|
10
|
+
csv_import_options = { col_sep: ';', quote_char: nil, headers: true }
|
11
|
+
|
12
|
+
super(filepath: filepath, csv_import_options: csv_import_options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ynab_convert/documents/statements/statement'
|
4
|
+
|
5
|
+
module Documents
|
6
|
+
module Statements
|
7
|
+
# Represents a statement from N26 Bank
|
8
|
+
class N26 < Statement
|
9
|
+
# @param filepath [String] Path to CSV statement
|
10
|
+
# @return [void]
|
11
|
+
def initialize(filepath:)
|
12
|
+
csv_import_options = {
|
13
|
+
col_sep: ',',
|
14
|
+
quote_char: '"',
|
15
|
+
headers: true,
|
16
|
+
encoding: 'bom|utf-8'
|
17
|
+
}
|
18
|
+
|
19
|
+
super(filepath: filepath,
|
20
|
+
csv_import_options: csv_import_options,)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Documents
|
4
|
+
module Statements
|
5
|
+
# The base Statement class from which other Statements inherit.
|
6
|
+
# Represents a CSV statement from a financial institution, typically from
|
7
|
+
# its online banking portal.
|
8
|
+
class Statement
|
9
|
+
attr_reader :csv_import_options, :filepath
|
10
|
+
|
11
|
+
# @param filepath [String] path to the CSV file
|
12
|
+
# @param csv_import_options [CSV::DEFAULT_OPTIONS] options describing
|
13
|
+
# the particular CSV flavour (column separator, etc). Any
|
14
|
+
# CSV::DEFAULT_OPTIONS is valid.
|
15
|
+
def initialize(filepath:, csv_import_options: CSV::DEFAULT_OPTIONS)
|
16
|
+
validate(filepath)
|
17
|
+
|
18
|
+
default_options = CSV::DEFAULT_OPTIONS.merge(converters: %i[numeric
|
19
|
+
date])
|
20
|
+
@filepath = filepath
|
21
|
+
@csv_import_options = default_options.merge(csv_import_options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def institution_name
|
25
|
+
self.class.name.split('::').last
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
# Verifies that the file exists at path, raises an error if not.
|
31
|
+
# @param path [String] path to the file
|
32
|
+
def validate(path)
|
33
|
+
return if ::File.exist?(path)
|
34
|
+
|
35
|
+
raise Errno::ENOENT, "file not found #{path}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Documents
|
4
|
+
module Statements
|
5
|
+
# UBS Switzerland Chequing accounts statement
|
6
|
+
class UBSChequing < Statement
|
7
|
+
# @param filepath [String] path to CSV statement
|
8
|
+
def initialize(filepath:)
|
9
|
+
csv_import_options = {
|
10
|
+
col_sep: ';',
|
11
|
+
quote_char: nil,
|
12
|
+
encoding: Encoding::UTF_8,
|
13
|
+
headers: true
|
14
|
+
}
|
15
|
+
|
16
|
+
super(filepath: filepath, csv_import_options: csv_import_options)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Documents
|
4
|
+
module Statements
|
5
|
+
# UBS Switzerland Credit Card accounts statement
|
6
|
+
class UBSCredit < Statement
|
7
|
+
def initialize(filepath:)
|
8
|
+
csv_import_options = {
|
9
|
+
col_sep: ';',
|
10
|
+
quote_char: nil,
|
11
|
+
headers: true,
|
12
|
+
encoding: "#{Encoding::ISO_8859_1}:#{Encoding::UTF_8}",
|
13
|
+
skip_lines: 'sep=;'
|
14
|
+
}
|
15
|
+
super(filepath: filepath, csv_import_options: csv_import_options)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Documents
|
4
|
+
module Statements
|
5
|
+
# Wise card accounts statement
|
6
|
+
class Wise < Statement
|
7
|
+
def initialize(filepath:)
|
8
|
+
csv_import_options = {
|
9
|
+
col_sep: ',',
|
10
|
+
quote_char: '"',
|
11
|
+
headers: true
|
12
|
+
}
|
13
|
+
super(filepath: filepath, csv_import_options: csv_import_options)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|