ba_upload 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +29 -2
- data/ba_upload.gemspec +1 -1
- data/lib/ba_upload/connection.rb +11 -2
- data/lib/ba_upload/statistic_file.rb +18 -0
- data/lib/ba_upload/version.rb +1 -1
- data/lib/ba_upload.rb +8 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a97b2695bf77d8a8693710f458561034c58ae2a43e737863f283e65301e8aa65
|
4
|
+
data.tar.gz: 8e3da29f1068f76f6f5320110ab68a99a0d3240e1b8d4ea589bb82771b02a676
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53b3dcee1f488d9b4758a03d9263bc6787a7b9b74680ef999d1ba1c01eb9625c3d2ea9210a2681a3804dd8727b43c9f745374e0f94567694a4470d9214c3d88a
|
7
|
+
data.tar.gz: 262b6794309cf833bc0d2a6301c0a757d036a3ac917a54c2eb9cea1301c02456359fa4a886e33b028ca8a264ac64dfeaadee8e3b9c67a2f30b057645e2b1c587
|
data/README.md
CHANGED
@@ -51,11 +51,23 @@ end
|
|
51
51
|
```ruby
|
52
52
|
#!/usr/bin/env ruby
|
53
53
|
require 'ba_upload'
|
54
|
-
|
54
|
+
BaUpload.open_connection(file_path: 'config/Zertifikat-1XXXX.p12', passphrase: 'YOURPASSPHRASE')
|
55
55
|
connection.upload(file: File.open(ARGV[0]))
|
56
56
|
```
|
57
57
|
|
58
|
-
Save to a file and just run it with the xml file as argument
|
58
|
+
Save to a file and just run it with the xml file as argument. It's important, because the file upload of BA validates the original file name.
|
59
|
+
|
60
|
+
|
61
|
+
### Memory safety
|
62
|
+
|
63
|
+
because we are using Mechanize under the hood, it's a good idea to always close sockets, (with connection.shutdown), or use the open helper:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
BaUpload.open(file_path: 'config/Zertifikat-1XXXX.p12', passphrase:) do |c|
|
67
|
+
c.upload(file: file_path)
|
68
|
+
c.error_files....
|
69
|
+
end
|
70
|
+
```
|
59
71
|
|
60
72
|
|
61
73
|
### Downloading "misc" files
|
@@ -71,6 +83,19 @@ connection.misc.each do |link|
|
|
71
83
|
end
|
72
84
|
```
|
73
85
|
|
86
|
+
### Downloading 'Statistiken' xlsx reports
|
87
|
+
|
88
|
+
Download XLSX reports (validation errors and "Stellenübersicht") from BA; You might use another Gem, like roo, axlsx etc. to parse those files if necessary.
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
connection.statistics.each do |link|
|
92
|
+
link.tempfile
|
93
|
+
|
94
|
+
# or:
|
95
|
+
link.read
|
96
|
+
end
|
97
|
+
```
|
98
|
+
|
74
99
|
### Usage with multiple client certificats
|
75
100
|
|
76
101
|
Since September 2022, users with multiple client certificats issued to the same email address need to provide their respective partner ID when using the API.
|
@@ -255,6 +280,7 @@ xsd.validate(doc)
|
|
255
280
|
|
256
281
|
<details>
|
257
282
|
<summary>Generate a filename</summary>
|
283
|
+
|
258
284
|
```ruby
|
259
285
|
# for historic reasons, you could transmit a bunch of files with the same timestamp using an index/offset, but usually, just putting 0 here should be enought
|
260
286
|
index = 0
|
@@ -264,6 +290,7 @@ flag = ended ? "E" : "C"
|
|
264
290
|
date = Time.zone.now.strftime "%Y-%m-%d_%H-%M-%S_F#{'%03d' % (index + 1)}#{flag}"
|
265
291
|
"DS#{SUPPLIER_ID}_#{date}.xml"
|
266
292
|
```
|
293
|
+
|
267
294
|
</details>
|
268
295
|
|
269
296
|
- Upload the file using this Gem. You should wait a "couple of minutes" (tip: enqueue a activeJob for 10 minutes later), to fetch the resulting **error file**, and analyse that.
|
data/ba_upload.gemspec
CHANGED
@@ -20,6 +20,6 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
22
|
spec.add_dependency "mechanize"
|
23
|
-
spec.add_development_dependency "bundler", "~>
|
23
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
25
25
|
end
|
data/lib/ba_upload/connection.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'ba_upload/error_file'
|
2
|
+
require 'ba_upload/statistic_file'
|
2
3
|
module BaUpload
|
3
4
|
class Connection
|
4
5
|
attr_reader :m
|
@@ -16,7 +17,7 @@ module BaUpload
|
|
16
17
|
|
17
18
|
def upload(file: nil, partner_id: nil)
|
18
19
|
url = base_url(partner_id) + "in/"
|
19
|
-
m.get
|
20
|
+
m.get(url)
|
20
21
|
form = m.page.forms.first
|
21
22
|
form.file_uploads.first.file_name = file
|
22
23
|
form.submit
|
@@ -24,13 +25,21 @@ module BaUpload
|
|
24
25
|
|
25
26
|
def error_files(partner_id: nil)
|
26
27
|
url = base_url(partner_id)
|
27
|
-
m.get
|
28
|
+
m.get(url)
|
28
29
|
links = m.page.links_with(text: /ESP|ESV/)
|
29
30
|
links.map do |link|
|
30
31
|
ErrorFile.new(link)
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
35
|
+
def statistics(partner_id: nil)
|
36
|
+
url = base_url(partner_id) + "Statistiken"
|
37
|
+
m.get(url)
|
38
|
+
m.page.links_with(text: /xlsx/).map do |link|
|
39
|
+
StatisticFile.new(link)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
34
43
|
def misc(partner_id: nil)
|
35
44
|
url = base_url(partner_id)
|
36
45
|
m.get url
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'ba_upload/error_file'
|
2
|
+
module BaUpload
|
3
|
+
class StatisticFile < ErrorFile
|
4
|
+
def tempfile
|
5
|
+
tf = Tempfile.new(['statistic_file', '.xlsx'])
|
6
|
+
tf.binmode
|
7
|
+
tf.write(read)
|
8
|
+
tf.flush
|
9
|
+
tf.rewind
|
10
|
+
tf
|
11
|
+
end
|
12
|
+
|
13
|
+
def read
|
14
|
+
@mechanize_link.click.body
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
data/lib/ba_upload/version.rb
CHANGED
data/lib/ba_upload.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "ba_upload/version"
|
2
2
|
require "openssl"
|
3
3
|
|
4
|
-
if OpenSSL::VERSION >= '3.0.0'
|
4
|
+
if OpenSSL::VERSION >= '3.0.0' && defined?(OpenSSL::Provider)
|
5
5
|
# import legacy
|
6
6
|
OpenSSL::Provider.load("legacy")
|
7
7
|
end
|
@@ -20,6 +20,13 @@ module BaUpload
|
|
20
20
|
cert = BaUpload.export_certificate(file_path: file_path, passphrase: passphrase)
|
21
21
|
BaUpload::Connection.new(cert[:key], cert[:cert], cert[:ca_cert])
|
22
22
|
end
|
23
|
+
|
24
|
+
def self.open(file_path:, passphrase:, &block)
|
25
|
+
conn = BaUpload.open_connection(file_path: file_path, passphrase: passphrase)
|
26
|
+
block.call(conn)
|
27
|
+
ensure
|
28
|
+
conn.shutdown
|
29
|
+
end
|
23
30
|
end
|
24
31
|
|
25
32
|
require 'ba_upload/connection'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ba_upload
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Wienert
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mechanize
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,6 +70,7 @@ files:
|
|
70
70
|
- lib/ba_upload.rb
|
71
71
|
- lib/ba_upload/connection.rb
|
72
72
|
- lib/ba_upload/error_file.rb
|
73
|
+
- lib/ba_upload/statistic_file.rb
|
73
74
|
- lib/ba_upload/version.rb
|
74
75
|
homepage: https://github.com/pludoni/ba_upload
|
75
76
|
licenses:
|
@@ -90,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
91
|
- !ruby/object:Gem::Version
|
91
92
|
version: '0'
|
92
93
|
requirements: []
|
93
|
-
rubygems_version: 3.
|
94
|
+
rubygems_version: 3.5.21
|
94
95
|
signing_key:
|
95
96
|
specification_version: 4
|
96
97
|
summary: Upload API for Bundesagentur fuer Arbeit (hrbaxml.arbeitsagentur)
|