liberic 0.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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE +8 -0
- data/README.md +181 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/examples/steuersatz.xml +89 -0
- data/examples/submit_ekst.rb +13 -0
- data/lib/liberic.rb +18 -0
- data/lib/liberic/boot.rb +37 -0
- data/lib/liberic/config.rb +157 -0
- data/lib/liberic/helpers.rb +1 -0
- data/lib/liberic/helpers/invocation.rb +27 -0
- data/lib/liberic/process.rb +105 -0
- data/lib/liberic/response.rb +2 -0
- data/lib/liberic/response/errors.rb +9 -0
- data/lib/liberic/response/version.rb +38 -0
- data/lib/liberic/sdk.rb +5 -0
- data/lib/liberic/sdk/api.rb +205 -0
- data/lib/liberic/sdk/configuration.rb +8 -0
- data/lib/liberic/sdk/def.rb +6 -0
- data/lib/liberic/sdk/fehlercodes.rb +192 -0
- data/lib/liberic/sdk/types.rb +56 -0
- data/lib/liberic/version.rb +3 -0
- data/liberic.gemspec +36 -0
- metadata +144 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: a3be6116156a7f918e5d217e47e3e09a58023495
|
|
4
|
+
data.tar.gz: 90675cbf53ac79e4182a4865133b34647f269ef1
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 8d109778b4a2c79e109e1916a8bd66c90f7ee81859a0e40b8cc028273e8860431d54d16894cc384939a0dc84f53bc0b86ee55d43eed1cffd898b4b9dd1a58839
|
|
7
|
+
data.tar.gz: 9cb29639017d509eacdae33caead67e027b38e3456627aa1388c61b7533ceaa8afb3be821f09111f24cc11babbcb217a934d14191c2fd9293a29f37397efbcf3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Contributor Code of Conduct
|
|
2
|
+
|
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
|
4
|
+
|
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
|
6
|
+
|
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
|
8
|
+
|
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
|
10
|
+
|
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
|
12
|
+
|
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
Copyright (c) 2015-2016 Malte Münchert
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
5
|
+
|
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# Liberic
|
|
2
|
+
|
|
3
|
+
Liberic is a ruby wrapper for ERiC, a C library to interact with German
|
|
4
|
+
Tax Authority's ELSTER service.
|
|
5
|
+
|
|
6
|
+
**WARNING:** This gem is at a very early stage and not able to do much useful stuff.
|
|
7
|
+
|
|
8
|
+
## Documentation
|
|
9
|
+
|
|
10
|
+
This README can only give a brief overview. You can look up the complete
|
|
11
|
+
[documentation on RubyDoc.info](http://www.rubydoc.info/github/mpm/liberic-ruby).
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
Add this line to your application's Gemfile:
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
gem 'liberic'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
And then execute:
|
|
22
|
+
|
|
23
|
+
$ bundle
|
|
24
|
+
|
|
25
|
+
Or install it yourself (not possible yet) as:
|
|
26
|
+
|
|
27
|
+
$ gem install liberic
|
|
28
|
+
|
|
29
|
+
The ERiC library files are not distributed with this gem. They must be
|
|
30
|
+
obtained from the [ELSTER Downloads Page](https://www.elster.de/ssl/secure/eric.php). (Requires your personal credentials which have to be requested from ELSTER).
|
|
31
|
+
|
|
32
|
+
Follow the installation instructions from the ERiC documentation.
|
|
33
|
+
|
|
34
|
+
After extracting the downloaded library files to a location of your choice, there should be a folder
|
|
35
|
+
containing at least three subfolders:
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
bin/
|
|
39
|
+
include/
|
|
40
|
+
lib/
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Currently, the environment variable `ERIC_HOME` needs to be set to this
|
|
44
|
+
folder or the gem will not find the library files.
|
|
45
|
+
|
|
46
|
+
For example:
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
$ export ERIC_HOME=/opt/ERiC-23.3.8.0/Linux-x86_64
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Additional steps on OS X
|
|
53
|
+
On *Mac OS X* you need to process the libraries to fix the interal paths
|
|
54
|
+
(credits to @deviantbits):
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
libs=`ls $ERIC_HOME/lib/*.dylib`
|
|
58
|
+
plugins=`ls $ERIC_HOME/lib/plugins2/*.dylib`
|
|
59
|
+
|
|
60
|
+
for target in $libs
|
|
61
|
+
do
|
|
62
|
+
for lib in $libs
|
|
63
|
+
do
|
|
64
|
+
install_name_tool -change "@rpath/"`basename $lib` "$ERIC_HOME/lib/"`basename $lib` $target
|
|
65
|
+
done
|
|
66
|
+
|
|
67
|
+
for plugin in $plugins
|
|
68
|
+
do
|
|
69
|
+
install_name_tool -change "@rpath/plugins2/"`basename $plugin` "$ERIC_HOME/lib/plugins2/"`basename $plugin` $target
|
|
70
|
+
done
|
|
71
|
+
done
|
|
72
|
+
|
|
73
|
+
for target in $plugins
|
|
74
|
+
do
|
|
75
|
+
for lib in $libs
|
|
76
|
+
do
|
|
77
|
+
install_name_tool -change "@rpath/"`basename $lib` "$ERIC_HOME/lib/"`basename $lib` $target
|
|
78
|
+
done
|
|
79
|
+
done
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Check your settings by running:
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
$ ls $ERIC_HOME/lib/libericapi.*
|
|
86
|
+
```
|
|
87
|
+
This should list you one file with an operating system dependend suffix.
|
|
88
|
+
|
|
89
|
+
## Usage
|
|
90
|
+
|
|
91
|
+
The gem exposes an interface to ERiC's native functions inside the
|
|
92
|
+
`Liberic::SDK::API` namespace.
|
|
93
|
+
|
|
94
|
+
Function names have been converted from camel case and stripped of the
|
|
95
|
+
'Eric' prefix, otherwise the original (German) names have been kept.
|
|
96
|
+
|
|
97
|
+
For example:
|
|
98
|
+
|
|
99
|
+
```c
|
|
100
|
+
EricSystemCheck();
|
|
101
|
+
```
|
|
102
|
+
is in Ruby:
|
|
103
|
+
|
|
104
|
+
```ruby
|
|
105
|
+
Liberic::SDK::API.system_check
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
A more Ruby friendly encapsulation of the ERiC functionality is in the
|
|
109
|
+
making (check out `Liberic::Process`).
|
|
110
|
+
|
|
111
|
+
## Examples
|
|
112
|
+
|
|
113
|
+
The following script will load an example tax filing (from the SDK) to
|
|
114
|
+
validate it with ERiC.
|
|
115
|
+
|
|
116
|
+
```ruby
|
|
117
|
+
require 'liberic'
|
|
118
|
+
|
|
119
|
+
# Use a convenience wrapper that deals with creating a buffer for the
|
|
120
|
+
# native function's results. This will also raise a Ruby exception if
|
|
121
|
+
# the native function returns anything else then 0 (= OK).
|
|
122
|
+
version_info = Liberic::Helpers::Invocation.with_result_buffer do |handle|
|
|
123
|
+
|
|
124
|
+
# Call ERiC function EricVersion()
|
|
125
|
+
Liberic::SDK::API::version(handle)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# version info contains XML with all ERiC libraries and their versions.
|
|
129
|
+
puts version_info
|
|
130
|
+
|
|
131
|
+
# Read example file that declares income tax for 2011. Assumes you have extraced
|
|
132
|
+
# the 'Beispiel' folder that comes with the ERiC libraries.
|
|
133
|
+
tax_filing = File.read(File.expand_path('Beispiel/ericdemo-java/steuersatz.xml', Liberic.eric_home))
|
|
134
|
+
|
|
135
|
+
# Liberic::Process is a high level wrapper around ERiC's EricBearbeiteVorgang() function.
|
|
136
|
+
submission = Liberic::Process.new(tax_filing, 'ESt_2011')
|
|
137
|
+
|
|
138
|
+
# Check for validity of the XML schema
|
|
139
|
+
submission.check
|
|
140
|
+
|
|
141
|
+
# Submit tax filing for a dry run (validity of the fields will be checked).
|
|
142
|
+
result = submission.execute
|
|
143
|
+
|
|
144
|
+
# Will be empty if everything was ok. Otherwise, result contains XML with a list of offending fields.
|
|
145
|
+
# Try editing the example file to see this in action- for example change the year of birth to a future year, etc.
|
|
146
|
+
puts result
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Features
|
|
150
|
+
|
|
151
|
+
This gem is rather early stage. It does not implement all ERiC features
|
|
152
|
+
yet. It does support submitting various tax filings via
|
|
153
|
+
`Liberic::Process` which should be sufficient for the majority of use
|
|
154
|
+
cases. Dealing with certificates (necessary for retrieving the tax
|
|
155
|
+
assessment or cryptographically signing a tax filing) is possible, but
|
|
156
|
+
no Ruby style wrapper exists yet.
|
|
157
|
+
|
|
158
|
+
Please refer to `Liberic::SDK::API` and the official docs for this.
|
|
159
|
+
|
|
160
|
+
## Bugs
|
|
161
|
+
|
|
162
|
+
This library is used in production for submitting tax filings. Not all
|
|
163
|
+
of the methods implemented in `Liberic::SDK::API` have been tested
|
|
164
|
+
though, so the data types defined there might be wrong.
|
|
165
|
+
|
|
166
|
+
Please consider this if you encounter problems and are looking for bugs
|
|
167
|
+
in your code.
|
|
168
|
+
|
|
169
|
+
Pull requests, improvements and examples are welcome, we are all in this
|
|
170
|
+
together :)
|
|
171
|
+
|
|
172
|
+
## Development
|
|
173
|
+
|
|
174
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
175
|
+
|
|
176
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
177
|
+
|
|
178
|
+
## Contributing
|
|
179
|
+
|
|
180
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mpm/liberic. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
|
181
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "liberic"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="ISO-8859-15"?>
|
|
2
|
+
<Elster xmlns="http://www.elster.de/2002/XMLSchema">
|
|
3
|
+
<TransferHeader version="8">
|
|
4
|
+
<Verfahren>ElsterErklaerung</Verfahren>
|
|
5
|
+
<DatenArt>ESt</DatenArt>
|
|
6
|
+
<Vorgang>send-NoSig</Vorgang>
|
|
7
|
+
<Testmerker>700000004</Testmerker>
|
|
8
|
+
<HerstellerID>74931</HerstellerID>
|
|
9
|
+
<DatenLieferant>Softwaretester ERiC</DatenLieferant>
|
|
10
|
+
<Datei><Verschluesselung>CMSEncryptedData</Verschluesselung><Kompression>GZIP</Kompression><DatenGroesse>12345</DatenGroesse><TransportSchluessel></TransportSchluessel></Datei>
|
|
11
|
+
</TransferHeader>
|
|
12
|
+
<DatenTeil>
|
|
13
|
+
<Nutzdatenblock>
|
|
14
|
+
<NutzdatenHeader version="10">
|
|
15
|
+
<NutzdatenTicket>adfjasldkfuweor456asvs</NutzdatenTicket>
|
|
16
|
+
<Empfaenger id="F">9198</Empfaenger>
|
|
17
|
+
<Hersteller>
|
|
18
|
+
<ProduktName>ERICTest</ProduktName>
|
|
19
|
+
<ProduktVersion>2009.1/0</ProduktVersion>
|
|
20
|
+
</Hersteller>
|
|
21
|
+
<DatenLieferant>Softwaretester ERiC</DatenLieferant>
|
|
22
|
+
</NutzdatenHeader>
|
|
23
|
+
<Nutzdaten>
|
|
24
|
+
<Jahressteuererklaerung version="2">
|
|
25
|
+
<Vorsatz unterfallart="10" ordNrArt="S" vorgang="01">
|
|
26
|
+
<StNr>9198011310010</StNr>
|
|
27
|
+
<Zeitraum>2011</Zeitraum>
|
|
28
|
+
<Erstelldatum>20090910</Erstelldatum>
|
|
29
|
+
<Erstellzeit>123705</Erstellzeit>
|
|
30
|
+
<AbsName>Testfallversand ERiC</AbsName>
|
|
31
|
+
<AbsStr>Testgasse 1a</AbsStr>
|
|
32
|
+
<AbsPlz>12345</AbsPlz>
|
|
33
|
+
<AbsOrt>Musterstadt</AbsOrt>
|
|
34
|
+
<Copyright>(c) 2009 Bayerisches Landesamt f�r Steuern</Copyright>
|
|
35
|
+
<Rueckuebermittlung bescheid="nein"></Rueckuebermittlung>
|
|
36
|
+
</Vorsatz>
|
|
37
|
+
<Feld index="01" lfdNr="00001" nr="0100001" wert="X"/>
|
|
38
|
+
<Feld index="01" lfdNr="00001" nr="0100201" wert="Maier"/>
|
|
39
|
+
<Feld index="01" lfdNr="00001" nr="0100301" wert="Hans"/>
|
|
40
|
+
<Feld index="01" lfdNr="00001" nr="0100401" wert="05.05.1955"/>
|
|
41
|
+
<Feld index="01" lfdNr="00001" nr="0100402" wert="03"/>
|
|
42
|
+
<Feld index="01" lfdNr="00001" nr="0100501" wert="Musterstr. 55"/>
|
|
43
|
+
<Feld index="01" lfdNr="00001" nr="0100601" wert="55555"/>
|
|
44
|
+
<Feld index="01" lfdNr="00001" nr="0100602" wert="Musterort"/>
|
|
45
|
+
<Feld index="01" lfdNr="00001" nr="0103301" wert="X"/>
|
|
46
|
+
<Feld index="01" lfdNr="00001" nr="0103504" wert="X"/>
|
|
47
|
+
<Feld index="01" lfdNr="00001" nr="0103204" wert="X"/>
|
|
48
|
+
<Feld index="01" lfdNr="00001" nr="0104001" wert="X"/>
|
|
49
|
+
<Feld index="01" lfdNr="00001" nr="0104002" wert="1"/>
|
|
50
|
+
<Feld index="01" lfdNr="00001" nr="0104003" wert="X"/>
|
|
51
|
+
<Feld index="01" lfdNr="00001" nr="0101401" wert="1234567890"/>
|
|
52
|
+
<Feld index="01" lfdNr="00001" nr="0101402" wert="12345678"/>
|
|
53
|
+
<Feld index="01" lfdNr="00001" nr="0101501" wert="Musterbank"/>
|
|
54
|
+
<Feld index="01" lfdNr="00001" nr="0101601" wert="X"/>
|
|
55
|
+
<!-- Start Anlage N -->
|
|
56
|
+
<Feld index="01" lfdNr="00001" nr="0200002" wert="1"/>
|
|
57
|
+
<Feld index="01" lfdNr="00001" nr="0200201" wert="30000"/>
|
|
58
|
+
<Feld index="01" lfdNr="00001" nr="0200301" wert="2010,10"/>
|
|
59
|
+
<Feld index="01" lfdNr="00001" nr="0200401" wert="800,80"/>
|
|
60
|
+
<Feld index="01" lfdNr="00001" nr="0200501" wert="50,10"/>
|
|
61
|
+
<!-- Ende Anlage N -->
|
|
62
|
+
<!-- Start Anlage Kap -->
|
|
63
|
+
<Feld index="01" lfdNr="00001" nr="1900401" wert="1"/>
|
|
64
|
+
<Feld index="01" lfdNr="00001" nr="1901401" wert="345"/>
|
|
65
|
+
<Feld index="01" lfdNr="00001" nr="1900701" wert="145"/>
|
|
66
|
+
<Feld index="01" lfdNr="00001" nr="1901501" wert="105"/>
|
|
67
|
+
<!-- Ende Anlage Kap -->
|
|
68
|
+
<!-- Start Anlage Kind -->
|
|
69
|
+
<Feld index="01" lfdNr="00001" nr="0500107" wert="Susi"/>
|
|
70
|
+
<Feld index="01" lfdNr="00001" nr="0500701" wert="01.06.2011"/>
|
|
71
|
+
<Feld index="01" lfdNr="00001" nr="0500702" wert="300"/>
|
|
72
|
+
<Feld index="01" lfdNr="00001" nr="0500703" wert="01.06.2011-31.12.2011"/>
|
|
73
|
+
<Feld index="01" lfdNr="00001" nr="0500102" wert="Musterweg 4711"/>
|
|
74
|
+
<Feld index="01" lfdNr="00001" nr="0500807" wert="1"/>
|
|
75
|
+
<!-- Ende Anlage Kind -->
|
|
76
|
+
<!-- Start Anlage R -->
|
|
77
|
+
<Feld index="01" lfdNr="00001" nr="1800101" wert="1"/>
|
|
78
|
+
<Feld index="01" lfdNr="00001" nr="1800301" wert="2570"/>
|
|
79
|
+
<Feld index="01" lfdNr="00001" nr="1800501" wert="01.01.2006"/>
|
|
80
|
+
<!-- Ende Anlage R -->
|
|
81
|
+
<!-- Start Anlage Vor -->
|
|
82
|
+
<Feld index="01" lfdNr="00001" nr="2000401" wert="1001"/>
|
|
83
|
+
<Feld index="01" lfdNr="00001" nr="2000801" wert="0"/>
|
|
84
|
+
<!-- Ende Anlage Vor -->
|
|
85
|
+
</Jahressteuererklaerung>
|
|
86
|
+
</Nutzdaten>
|
|
87
|
+
</Nutzdatenblock>
|
|
88
|
+
</DatenTeil>
|
|
89
|
+
</Elster>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "liberic"
|
|
5
|
+
|
|
6
|
+
tax_filing = File.read(File.expand_path('steuersatz.xml', File.dirname(__FILE__)))
|
|
7
|
+
|
|
8
|
+
submission = Liberic::Process.new(tax_filing, 'ESt_2011')
|
|
9
|
+
|
|
10
|
+
submission.check
|
|
11
|
+
|
|
12
|
+
result = submission.execute(action: :print_and_submit)
|
|
13
|
+
puts result
|
data/lib/liberic.rb
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'ffi'
|
|
2
|
+
require 'nokogiri'
|
|
3
|
+
require 'logger'
|
|
4
|
+
require 'liberic/version'
|
|
5
|
+
require 'liberic/boot'
|
|
6
|
+
require 'liberic/helpers'
|
|
7
|
+
require 'liberic/response'
|
|
8
|
+
require 'liberic/sdk'
|
|
9
|
+
require 'liberic/process'
|
|
10
|
+
require 'liberic/config'
|
|
11
|
+
|
|
12
|
+
module Liberic
|
|
13
|
+
check_eric_version!
|
|
14
|
+
|
|
15
|
+
def config
|
|
16
|
+
@config ||= Config.new
|
|
17
|
+
end
|
|
18
|
+
end
|
data/lib/liberic/boot.rb
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module Liberic
|
|
2
|
+
class InitializationError < StandardError
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
extend self
|
|
6
|
+
|
|
7
|
+
def eric_home
|
|
8
|
+
ERIC_HOME
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def library_path
|
|
12
|
+
suffix = if RUBY_PLATFORM =~ /linux/
|
|
13
|
+
'so'
|
|
14
|
+
elsif RUBY_PLATFORM =~ /darwin/
|
|
15
|
+
'dylib'
|
|
16
|
+
else
|
|
17
|
+
'dll'
|
|
18
|
+
end
|
|
19
|
+
File.expand_path("libericapi.#{suffix}", ERIC_LIB_FOLDER)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
ERIC_HOME = ENV['ERIC_HOME'] || raise(InitializationError.new('ERIC_HOME environment variable not found (set it to the path to the ERiC libraries)'))
|
|
23
|
+
ERIC_LIB_FOLDER = File.expand_path('lib', ERIC_HOME)
|
|
24
|
+
|
|
25
|
+
def check_eric_version!
|
|
26
|
+
version_response = Response::Version.new(
|
|
27
|
+
Helpers::Invocation.with_result_buffer do |handle|
|
|
28
|
+
SDK::API::version(handle)
|
|
29
|
+
end
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
eric_version = version_response.for_library('libericapi')
|
|
33
|
+
if !SDK::Configuration::LIBERICAPI_VERSION.include?(eric_version)
|
|
34
|
+
raise InitializationError.new("ERiC #{SDK::Configuration::LIBERICAPI_VERSION.join(', ')} required, but #{eric_version} found.")
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
module Liberic
|
|
2
|
+
|
|
3
|
+
# Provides an interface to ERiC's configuration parameters and logging.
|
|
4
|
+
#
|
|
5
|
+
# == Scope
|
|
6
|
+
#
|
|
7
|
+
# This class is not meant to be instantiated directly. An instance is created
|
|
8
|
+
# the first time it is accessed in the Liberic namespace.
|
|
9
|
+
#
|
|
10
|
+
# Liberic.config # will return an instance of Config
|
|
11
|
+
#
|
|
12
|
+
# == Configuration parameters
|
|
13
|
+
#
|
|
14
|
+
# Configuration parameters can be accessed with the hash notation.
|
|
15
|
+
# Keys are passed to ERiC directly, so they must be in German (see ERiC
|
|
16
|
+
# documentation for this).
|
|
17
|
+
#
|
|
18
|
+
# Example:
|
|
19
|
+
#
|
|
20
|
+
# Liberic.config['validieren.fehler_max'] # 30
|
|
21
|
+
#
|
|
22
|
+
# +Config+ provides an english abstraction to these parameters with +attr_accessor+
|
|
23
|
+
# like getter/setter methods:
|
|
24
|
+
#
|
|
25
|
+
# Liberic.config.validation_error_limit = 30
|
|
26
|
+
#
|
|
27
|
+
# The most common settings are (german names in paranthesis)
|
|
28
|
+
#
|
|
29
|
+
# * +data_path+ (basis.data_dir) directory to store PDFs and certificates in
|
|
30
|
+
# * +allow_test_id+ (basis.test_id_erlaubt) allow fake tax ids when processing tax filings
|
|
31
|
+
# * +detailed_logs+ (log.detailed) set log level to debug. Also disables rolling logs (if +detailed_logs+ is +false+, ERiC will create a maximum of ten log files on disk, each with 1 MB of size. The oldest file will be deleted when rolling over). *WARNING*: Logging to disk is disabled after instantiating +Config+. See +:logger:+ for details.
|
|
32
|
+
# * +validation_error_limit+ (validieren.fehler_max) limits the amount of errors that are returned when processing or checking tax filings. This means even though 50 fields inside the tax report are missing, only the first 30 are reported as part of the response.
|
|
33
|
+
# * +online+ (transfer.netz.doi) allow connecting to the actual tax authority's production systems.
|
|
34
|
+
#
|
|
35
|
+
class Config
|
|
36
|
+
attr_reader :logger
|
|
37
|
+
|
|
38
|
+
def initialize
|
|
39
|
+
install_logger
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Assign an instance of Logger that will be called whenever ERiC creates
|
|
43
|
+
# log output.
|
|
44
|
+
# Please note that ERiC's mechanism to write log files to disk is disabled
|
|
45
|
+
# as soon as a +Config+ class is instantiated!
|
|
46
|
+
#
|
|
47
|
+
# ==== Attributes
|
|
48
|
+
#
|
|
49
|
+
# * +logger+ - A Ruby Logger instance or nil
|
|
50
|
+
#
|
|
51
|
+
# ==== Examples
|
|
52
|
+
#
|
|
53
|
+
# An instance of +Config+ is provided in the +Liberic+ namespace. A logger
|
|
54
|
+
# can be assigned like this:
|
|
55
|
+
#
|
|
56
|
+
# Liberic.config.logger = Logger.new(STDOUT)
|
|
57
|
+
# Liberic.config.logger.level = Logger::WARN
|
|
58
|
+
#
|
|
59
|
+
# ERiC does not send debug log messages by default. To do this, change ERiC's
|
|
60
|
+
# configuration:
|
|
61
|
+
#
|
|
62
|
+
# Liberic.config.detailed_logs = true
|
|
63
|
+
#
|
|
64
|
+
# and make sure +:level:+ of your +Logger+ is not filtering debug messages.
|
|
65
|
+
#
|
|
66
|
+
def logger=(logger)
|
|
67
|
+
@logger = logger
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
{
|
|
71
|
+
'basis.home_dir' => :eric_home,
|
|
72
|
+
'basis.log_dir' => :log_path,
|
|
73
|
+
'basis.data_dir' => :data_path,
|
|
74
|
+
'basis.test_id_erlaubt' => :allow_test_id,
|
|
75
|
+
'log.detailed' => :detailed_logs,
|
|
76
|
+
'transfer.connect_timeout' => :connect_timeout,
|
|
77
|
+
'transfer.response_timeout' => :response_timeout,
|
|
78
|
+
'validieren.fehler_max' => :validation_error_limit,
|
|
79
|
+
'transfer.netz.doi' => :online,
|
|
80
|
+
'http.proxy_host' => :proxy_host,
|
|
81
|
+
'http.proxy_port' => :proxy_port,
|
|
82
|
+
'http.proxy_username' => :proxy_username,
|
|
83
|
+
'http.proxy_password' => :proxy_password,
|
|
84
|
+
'http.proxy_auth' => :proxy_auth
|
|
85
|
+
}.each do |setting_in_eric, setting_in_ruby|
|
|
86
|
+
define_method setting_in_ruby do
|
|
87
|
+
send(:[], setting_in_eric)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
define_method "#{setting_in_ruby}=" do |value|
|
|
91
|
+
send(:[]=, setting_in_eric, value)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def [](key)
|
|
96
|
+
convert_to_ruby(
|
|
97
|
+
Helpers::Invocation.with_result_buffer do |handle|
|
|
98
|
+
SDK::API.einstellung_lesen(key, handle)
|
|
99
|
+
end
|
|
100
|
+
)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def []=(key, value)
|
|
104
|
+
Helpers::Invocation.raise_on_error(
|
|
105
|
+
SDK::API.einstellung_setzen(
|
|
106
|
+
key,
|
|
107
|
+
convert_to_eric(value)
|
|
108
|
+
)
|
|
109
|
+
)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
private
|
|
113
|
+
|
|
114
|
+
def install_logger
|
|
115
|
+
Helpers::Invocation.raise_on_error(
|
|
116
|
+
SDK::API.registriere_log_callback(
|
|
117
|
+
SDK::API.generate_log_callback do |category, level, message|
|
|
118
|
+
if @logger.respond_to?(:add)
|
|
119
|
+
@logger.add(SDK::Types::LOGGER_SEVERITY[level], message, category)
|
|
120
|
+
end
|
|
121
|
+
end,
|
|
122
|
+
0, nil)
|
|
123
|
+
)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def convert_to_ruby(value)
|
|
127
|
+
if value.to_i.to_s == value
|
|
128
|
+
value.to_i
|
|
129
|
+
elsif ['ja', 'yes'].include?(value.downcase)
|
|
130
|
+
true
|
|
131
|
+
elsif ['nein', 'no'].include?(value.downcase)
|
|
132
|
+
false
|
|
133
|
+
else
|
|
134
|
+
value.force_encoding(SDK::Configuration::ENCODING).encode(Encoding::default_external)
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def convert_to_eric(value)
|
|
139
|
+
if [true, false].include?(value)
|
|
140
|
+
value ? 'ja' : 'nein'
|
|
141
|
+
else
|
|
142
|
+
value
|
|
143
|
+
end.to_s.encode(SDK::Configuration::ENCODING)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def get(key)
|
|
147
|
+
Helpers::Invocation.with_result_buffer(true) do |handle|
|
|
148
|
+
SDK::API.einstellung_lesen(key, handle)
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def set(key, value)
|
|
153
|
+
Helpers::Invocation.raise_on_error(SDK::API.einstellung_setzen(key, value))
|
|
154
|
+
true
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|