ba_upload 0.4.0 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cceefb5de17f2e510d450c83e0ab44a231c23f8024f3b86c1cf4e55c9e2bee32
4
- data.tar.gz: 29f249da985d7e5213f1cdc8f56f0d1dfc3e352f26823731413ba66506e6672d
3
+ metadata.gz: 929ae4afa02061b2855f56812284f7353e446b10a9d5c331f10d9bfee70df29b
4
+ data.tar.gz: 5897f8e1d95d1b4252c0ad34119d92ba608edd7482267ce539ce42bc3b6becb3
5
5
  SHA512:
6
- metadata.gz: d4ba083e3d90f2d5d750127892b914dba63678a0b4423755b08c455d467cba9e28e02eb4bd5a4d900e19572f258d1befe2109a67af5c144fe10a36e8597552c2
7
- data.tar.gz: c45d8070153d9aca7842ede6b4dea90098608e6b078bdf4e4370a698e837b021382ddccdfe31b4f47c0121ea76e5e8749e15a86a6f8841f9022b635c7f8d6bca
6
+ metadata.gz: 572fb95d84d934a4679eb97621ecaf8205290328196a75ab4a5c900826ff4490f666cdfbc83b946cf7df67246ca51bf5c6ffe612ac1b0d5ecec36567b49c2954
7
+ data.tar.gz: 05d3339b30db3866917a28386fb7f080ba7e921aec04ff7d32b0bc52b7be66aa0601b0bb57f8708136774154e7e3b9863331a1013291d4ecacb52511f3f7da56
data/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ # Changelog
2
+
3
+ ## 0.6.0
4
+
5
+ - Feat: Add `Connection#job_proposals` to list Vermittlungsvorschlag zip files from the BA `VV/` directory
6
+ - Feat: New `BaUpload::JobProposalFile` wrapper (binary-safe read/tempfile) analogous to `ErrorFile`
data/README.md CHANGED
@@ -51,11 +51,23 @@ end
51
51
  ```ruby
52
52
  #!/usr/bin/env ruby
53
53
  require 'ba_upload'
54
- connection = BaUpload.open_connection(file_path: 'config/Zertifikat-1XXXX.p12', passphrase: 'YOURPASSPHRASE')
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
@@ -14,12 +14,17 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "https://github.com/pludoni/ba_upload"
15
15
  spec.license = "MIT"
16
16
 
17
+ spec.metadata = {
18
+ "source_code_uri" => "https://github.com/pludoni/ba_upload",
19
+ "changelog_uri" => "https://github.com/pludoni/ba_upload/blob/master/CHANGELOG.md",
20
+ }
21
+
17
22
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
23
  spec.bindir = "exe"
19
24
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
25
  spec.require_paths = ["lib"]
21
26
 
22
27
  spec.add_dependency "mechanize"
23
- spec.add_development_dependency "bundler", "~> 1.11"
28
+ spec.add_development_dependency "bundler", "~> 2.0"
24
29
  spec.add_development_dependency "rake", "~> 10.0"
25
30
  end
@@ -1,4 +1,6 @@
1
1
  require 'ba_upload/error_file'
2
+ require 'ba_upload/statistic_file'
3
+ require 'ba_upload/job_proposal_file'
2
4
  module BaUpload
3
5
  class Connection
4
6
  attr_reader :m
@@ -16,7 +18,7 @@ module BaUpload
16
18
 
17
19
  def upload(file: nil, partner_id: nil)
18
20
  url = base_url(partner_id) + "in/"
19
- m.get url
21
+ m.get(url)
20
22
  form = m.page.forms.first
21
23
  form.file_uploads.first.file_name = file
22
24
  form.submit
@@ -24,13 +26,33 @@ module BaUpload
24
26
 
25
27
  def error_files(partner_id: nil)
26
28
  url = base_url(partner_id)
27
- m.get url
29
+ m.get(url)
28
30
  links = m.page.links_with(text: /ESP|ESV/)
29
31
  links.map do |link|
30
32
  ErrorFile.new(link)
31
33
  end
32
34
  end
33
35
 
36
+ def statistics(partner_id: nil)
37
+ url = base_url(partner_id) + "Statistiken"
38
+ m.get(url)
39
+ m.page.links_with(text: /xlsx/).map do |link|
40
+ StatisticFile.new(link)
41
+ end
42
+ end
43
+
44
+ def job_proposals(partner_id: nil)
45
+ url = base_url(partner_id) + "VV/"
46
+ m.get(url)
47
+ m.page.links.reject { |l| l.href.to_s[/^\?|mailto:/] || l.href == "/" }.map do |link|
48
+ JobProposalFile.new(link)
49
+ end
50
+ rescue Mechanize::ResponseCodeError => e
51
+ return [] if e.response_code.to_i == 404
52
+
53
+ raise
54
+ end
55
+
34
56
  def misc(partner_id: nil)
35
57
  url = base_url(partner_id)
36
58
  m.get url
@@ -0,0 +1,25 @@
1
+ module BaUpload
2
+ class JobProposalFile
3
+ def initialize(mechanize_link)
4
+ @mechanize_link = mechanize_link
5
+ @link = mechanize_link.href
6
+ end
7
+
8
+ def read
9
+ response = @mechanize_link.click
10
+ response.body
11
+ end
12
+
13
+ def filename
14
+ @mechanize_link.text
15
+ end
16
+
17
+ def tempfile
18
+ tf = Tempfile.new(['job_proposal', '.zip'])
19
+ tf.binmode
20
+ tf.write(read)
21
+ tf.flush
22
+ tf
23
+ end
24
+ end
25
+ end
@@ -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
+
@@ -1,3 +1,3 @@
1
1
  module BaUpload
2
- VERSION = "0.4.0"
2
+ VERSION = "0.6.0"
3
3
  end
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.0
4
+ version: 0.6.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: 2023-09-26 00:00:00.000000000 Z
11
+ date: 2026-07-24 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: '1.11'
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: '1.11'
40
+ version: '2.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -60,6 +60,7 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - ".gitignore"
63
+ - CHANGELOG.md
63
64
  - Gemfile
64
65
  - LICENSE.txt
65
66
  - README.md
@@ -70,11 +71,15 @@ files:
70
71
  - lib/ba_upload.rb
71
72
  - lib/ba_upload/connection.rb
72
73
  - lib/ba_upload/error_file.rb
74
+ - lib/ba_upload/job_proposal_file.rb
75
+ - lib/ba_upload/statistic_file.rb
73
76
  - lib/ba_upload/version.rb
74
77
  homepage: https://github.com/pludoni/ba_upload
75
78
  licenses:
76
79
  - MIT
77
- metadata: {}
80
+ metadata:
81
+ source_code_uri: https://github.com/pludoni/ba_upload
82
+ changelog_uri: https://github.com/pludoni/ba_upload/blob/master/CHANGELOG.md
78
83
  post_install_message:
79
84
  rdoc_options: []
80
85
  require_paths:
@@ -90,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
95
  - !ruby/object:Gem::Version
91
96
  version: '0'
92
97
  requirements: []
93
- rubygems_version: 3.2.33
98
+ rubygems_version: 3.5.16
94
99
  signing_key:
95
100
  specification_version: 4
96
101
  summary: Upload API for Bundesagentur fuer Arbeit (hrbaxml.arbeitsagentur)