ba_upload 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +62 -0
- data/Rakefile +2 -0
- data/ba_upload.gemspec +25 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/ba_upload/connection.rb +32 -0
- data/lib/ba_upload/error_file.rb +24 -0
- data/lib/ba_upload/version.rb +3 -0
- data/lib/ba_upload.rb +20 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bc3deda2d99beece55b44a02744d0d7eaa3bfaa6
|
4
|
+
data.tar.gz: 25c10ec48c2c8066fcab6129c06ce16ae9e94481
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 64f2cd4028d7b65e9ae48ee9a65d3d41954af9fd715dbffef4ad222a1232c4a0fa2bbb57eca13263902730566dfd8b1829793172c8aa263bd51a3182e17c9701
|
7
|
+
data.tar.gz: cff9576502685a48c1d75a2dd92dde54ff8f01bfc71c314fcec61911994a05bf49bc03bf2076faa7967b5cbc9e525f9786220cf531de95416661e52dd9924cc7
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Stefan Wienert
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# Bundesagentur fuer Arbeit upload
|
2
|
+
|
3
|
+
This is a Ruby Gem that aids to simplify interaction with the API of the Arbeitsagentur of Germany.
|
4
|
+
|
5
|
+
Since early 2016 Arbeitsagentur switched to a HTTPS client certificate (hrbaxml.arbeitsagentur.de) instead their beloved FTP upload tool. The OpenSSL library helps to convert that cert to a format Mechanize/curl can understand.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Needs Ruby > 2.1 with OpenSSL.
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'ba_upload'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install ba_upload
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'ba_upload'
|
29
|
+
|
30
|
+
# your supplied certificate and passphrase
|
31
|
+
connection = BaUpload.open_connection(file_path: 'config/Zertifikat-1XXXX.p12', passphrase: 'YOURPASSPHRASE')
|
32
|
+
|
33
|
+
# Upload a xml-file
|
34
|
+
connection.upload(file: File.open('/opt/vam-transfer/data/DSP000132700_2016-08-08_05-00-09.xml'))
|
35
|
+
|
36
|
+
# later cronjob to download all error files
|
37
|
+
|
38
|
+
connection.error_files.each do |error_file|
|
39
|
+
target_path = "/opt/vam-transfer/data/#{error_file.filename}"
|
40
|
+
next if File.exists?(target_path)
|
41
|
+
tf = error_file.tempfile
|
42
|
+
FileUtils.cp(tf.path, target_path)
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
### Usage from outside Ruby (e.g. Cronjob/script):
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
#!/usr/bin/env ruby
|
50
|
+
require 'ba_upload'
|
51
|
+
connection = BaUpload.open_connection(file_path: 'config/Zertifikat-1XXXX.p12', passphrase: 'YOURPASSPHRASE')
|
52
|
+
connection.upload(file: File.open(ARGV[0]))
|
53
|
+
```
|
54
|
+
|
55
|
+
Save to a file and just run it with the xml file as argument
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
## License
|
60
|
+
|
61
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
62
|
+
|
data/Rakefile
ADDED
data/ba_upload.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ba_upload/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ba_upload"
|
8
|
+
spec.version = BaUpload::VERSION
|
9
|
+
spec.authors = ["Stefan Wienert"]
|
10
|
+
spec.email = ["stefan.wienert@pludoni.de"]
|
11
|
+
|
12
|
+
spec.summary = %q{Upload API for Bundesagentur fuer Arbeit (hrbaxml.arbeitsagentur)}
|
13
|
+
spec.description = %q{Upload API for Bundesagentur fuer Arbeit (hrbaxml.arbeitsagentur)}
|
14
|
+
spec.homepage = "https://github.com/pludoni/ba_upload"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "mechanize"
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ba_upload"
|
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,32 @@
|
|
1
|
+
require 'ba_upload/error_file'
|
2
|
+
module BaUpload
|
3
|
+
class Connection
|
4
|
+
attr_reader :m
|
5
|
+
|
6
|
+
def initialize(key_file, cert_file, ca_cert_file)
|
7
|
+
require 'mechanize'
|
8
|
+
@key = key_file
|
9
|
+
@cert = cert_file
|
10
|
+
@ca_cert = ca_cert_file
|
11
|
+
@m = Mechanize.new
|
12
|
+
@m.key = @key.path
|
13
|
+
@m.ca_file = @ca_cert.path
|
14
|
+
@m.cert = @cert.path
|
15
|
+
end
|
16
|
+
|
17
|
+
def upload(file: nil)
|
18
|
+
m.get 'https://hrbaxml.arbeitsagentur.de/in/'
|
19
|
+
form = m.page.forms.first
|
20
|
+
form.file_uploads.first.file_name = file
|
21
|
+
form.submit
|
22
|
+
end
|
23
|
+
|
24
|
+
def error_files
|
25
|
+
m.get 'https://hrbaxml.arbeitsagentur.de/'
|
26
|
+
links = m.page.links_with(text: /ESP|ESV/)
|
27
|
+
links.map do |link|
|
28
|
+
ErrorFile.new(link)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module BaUpload
|
2
|
+
class ErrorFile
|
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.xml.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
def filename
|
14
|
+
@mechanize_link.text
|
15
|
+
end
|
16
|
+
|
17
|
+
def tempfile
|
18
|
+
tf = Tempfile.new(['error_file', '.xml'])
|
19
|
+
tf.write(read)
|
20
|
+
tf.flush
|
21
|
+
tf
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/ba_upload.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "ba_upload/version"
|
2
|
+
require "openssl"
|
3
|
+
|
4
|
+
module BaUpload
|
5
|
+
def self.export_certificate(file_path:, passphrase:)
|
6
|
+
cert = OpenSSL::PKCS12.new(File.read(file_path), passphrase)
|
7
|
+
{
|
8
|
+
key: Tempfile.new(['key','.pem']).tap{|f| f.write(cert.key.to_s); f.flush},
|
9
|
+
cert: Tempfile.new(['cert','.pem']).tap{|f| f.write(cert.certificate.to_s); f.flush},
|
10
|
+
ca_cert: Tempfile.new(['ca_cert','.pem']).tap{|f| f.write(cert.ca_certs.reverse.join("\n")); f.flush }
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.open_connection(file_path:, passphrase:)
|
15
|
+
cert = BaUpload.export_certificate(file_path: file_path, passphrase: passphrase)
|
16
|
+
BaUpload::Connection.new(cert[:key], cert[:cert], cert[:ca_cert])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'ba_upload/connection'
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ba_upload
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stefan Wienert
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mechanize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: Upload API for Bundesagentur fuer Arbeit (hrbaxml.arbeitsagentur)
|
56
|
+
email:
|
57
|
+
- stefan.wienert@pludoni.de
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- ba_upload.gemspec
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- lib/ba_upload.rb
|
71
|
+
- lib/ba_upload/connection.rb
|
72
|
+
- lib/ba_upload/error_file.rb
|
73
|
+
- lib/ba_upload/version.rb
|
74
|
+
homepage: https://github.com/pludoni/ba_upload
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.6.13
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Upload API for Bundesagentur fuer Arbeit (hrbaxml.arbeitsagentur)
|
98
|
+
test_files: []
|