ebics-jruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+ Gemfile.lock
20
+ Jarfile.lock
21
+ .jbundler
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
data/Jarfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'http://maven.simexplorer.org/repo'
2
+ jar 'org.kopi:ebics'
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ ebics-jruby
2
+ ===========
3
+
4
+ an ebics client using org.kopi.ebics java lib
data/bin/ebics ADDED
@@ -0,0 +1,6 @@
1
+ #!/bin/env ruby
2
+
3
+ require 'lib/ebics'
4
+ require 'ebics/cli'
5
+
6
+ Ebics::Cli.start(ARGV)
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/ebics/version', __FILE__)
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'ebics-jruby'
6
+ s.version = Ebics::VERSION
7
+ s.authors = ['Cyril LEPAGNOT']
8
+ s.email = ['cyril@lepagnot.fr']
9
+ s.homepage = 'https://github.com/cyrill62/ebics-jruby'
10
+ s.summary = 'an ebics client using org.kopi.ebics java lib'
11
+
12
+ s.require_paths = ['lib']
13
+ s.files = `git ls-files`.split($\)
14
+ s.executables = s.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+
16
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
17
+
18
+ s.add_dependency('thor', '>= 0.16.0')
19
+ s.add_dependency('jbundler', '>= 0.3.2')
20
+ end
@@ -0,0 +1 @@
1
+ require 'ebics'
data/lib/ebics.rb ADDED
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH << File.expand_path('../', __FILE__)
2
+ require 'ebics/base'
data/lib/ebics/base.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'java'
2
+ require 'rubygems'
3
+ require 'bundler/setup'
4
+ require 'jbundler'
5
+ Java::JavaSecurity::Security.addProvider Java::OrgBouncycastleJceProvider.BouncyCastleProvider.new
6
+ Java::OrgApacheXmlSecurity.Init.init
data/lib/ebics/cli.rb ADDED
@@ -0,0 +1,87 @@
1
+ require 'thor'
2
+ require 'ebics'
3
+ require 'ebics/client'
4
+
5
+ module Ebics
6
+ class Cli < Thor
7
+ include Thor::Actions
8
+ class_option :test, :aliases => '-t', :desc => 'do not send request to server (simulator mode)'
9
+ class_option :bank_name, :aliases => '-b', :desc => "set bank name (default = #{Ebics::Client::BANK_NAME})"
10
+ class_option :bank_url, :aliases => '-U', :desc => "set bank url (default = #{Ebics::Client::URL_EBICS_SERVER})"
11
+
12
+ desc 'download_certs', 'download bank certificates'
13
+ method_option :host_id, :aliases => '-h', :required => true
14
+ method_option :partner_id, :aliases => '-p', :required => true
15
+ method_option :user_id, :aliases => '-u', :required => true
16
+ method_option :password, :aliases => '-P'
17
+ def download_certs
18
+ require_password
19
+ require 'ebics/hbb'
20
+ requestor = Ebics::Hbb.new
21
+ requestor.run options
22
+ end
23
+
24
+
25
+ desc 'download FILE', 'download a file from the server'
26
+ method_option :host_id, :aliases => '-h', :required => true
27
+ method_option :partner_id, :aliases => '-p', :required => true
28
+ method_option :user_id, :aliases => '-u', :required => true
29
+ method_option :password, :aliases => '-P'
30
+ def download(file)
31
+ require_password
32
+ require 'ebics/file/download'
33
+ requestor = Ebics::File::Download.new
34
+ requestor.run file, options
35
+ end
36
+
37
+ desc 'upload FILE', 'send a file to the server'
38
+ method_option :host_id, :aliases => '-h', :required => true
39
+ method_option :partner_id, :aliases => '-p', :required => true
40
+ method_option :user_id, :aliases => '-u', :required => true
41
+ method_option :password, :aliases => '-P'
42
+ def upload(file)
43
+ require_password
44
+ require 'ebics/file/upload'
45
+ requestor = Ebics::File::Upload.new
46
+ requestor.run file, options
47
+ end
48
+
49
+ desc 'create_user [NAME] [EMAIL] [COUNTRY] [ORGANISATION]', 'create an user'
50
+ method_option :host_id, :aliases => '-h', :required => true
51
+ method_option :partner_id, :aliases => '-p', :required => true
52
+ method_option :user_id, :aliases => '-u', :required => true
53
+ method_option :password, :aliases => '-P'
54
+ def create(name = 'pebics', email = 'pebics@domaine.fr', country = 'France', organization = 'Euro-Information')
55
+ require_password
56
+ require 'ebics/user'
57
+ user = Ebics::User::Creator.new
58
+ user.run(
59
+ name,
60
+ email,
61
+ country,
62
+ organization,
63
+ true,
64
+ options
65
+ )
66
+ end
67
+
68
+ desc 'init_user', 'init an user on the server'
69
+ method_option :host_id, :aliases => '-h', :required => true
70
+ method_option :partner_id, :aliases => '-p', :required => true
71
+ method_option :user_id, :aliases => '-u', :required => true
72
+ method_option :password, :aliases => '-P'
73
+ def init_user
74
+ require_password
75
+ require 'ebics/user'
76
+ requestor = Ebics::User::Initiator.new
77
+ requestor.run options
78
+ end
79
+
80
+ no_tasks do
81
+ def require_password
82
+ self.options = options.dup # unfreeze options
83
+ self.options[:password] ||= ask('password:')
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,82 @@
1
+ module Ebics
2
+ class Client
3
+ attr_accessor :users, :partners, :banks, :conf
4
+
5
+ BANK_NAME = 'VALERIAN'
6
+ URL_EBICS_SERVER = 'https://server-ebics.webank.fr:28103/WbkPortalFileTransfert/EbicsProtocol'
7
+
8
+ def initialize
9
+ self.conf = Java::OrgKopiEbicsSession.DefaultConfiguration.new
10
+ self.users = {}
11
+ self.banks = {}
12
+ self.partners = {}
13
+ messages.locale = conf.locale
14
+
15
+ conf.init
16
+ end
17
+
18
+ def messages
19
+ Java::OrgKopiEbicsMessages.Messages
20
+ end
21
+
22
+ def t(name, *params)
23
+ messages.get_string(name, Java::OrgKopiEbicsUtils.Constants.APPLICATION_BUNDLE_NAME)
24
+ end
25
+
26
+ def log(name, *params)
27
+ conf.logger.info t(name, *params)
28
+ end
29
+
30
+ def create_user_directories(user)
31
+ log 'user.create.directories', user.user_id
32
+
33
+ %w(get_user_directory
34
+ get_transfer_trace_directory
35
+ get_keystore_directory
36
+ get_letters_directory).each do |dir|
37
+ FileUtils.mkdir conf.send(dir, user)
38
+ end
39
+ end
40
+
41
+ def create_bank(url, name, host_id)
42
+ banks[host_id] = Java::OrgKopiEbicsClient.Bank.new(Java::JavaNet::URL.new(url), name, host_id)
43
+ end
44
+
45
+ def create_partner(bank, id)
46
+ partners[id] = Java::OrgKopiEbicsClient.Partner.new(bank, id)
47
+ end
48
+
49
+ def load_user(bank_url, bank_name, host_id, partner_id, user_id, password)
50
+ #begin
51
+ bank = create_bank(bank_url, bank_name, host_id)
52
+ partner = create_partner(bank, partner_id)
53
+ users[user_id] = @user = Java::OrgKopiEbicsClient.User.new(partner, conf.serialization_manager.deserialize(user_id), password)
54
+ #rescue
55
+ # log 'user.load.error'
56
+ #end
57
+ end
58
+
59
+ def require_user(options)
60
+ pwd = Java::OrgKopiEbicsSecurity.UserPasswordHandler.new(options[:user_id], options[:password])
61
+
62
+ load_user(
63
+ options[:bank_url] || URL_EBICS_SERVER,
64
+ options[:bank_name] || BANK_NAME,
65
+ options[:host_id],
66
+ options[:partner_id],
67
+ options[:user_id],
68
+ pwd
69
+ )
70
+ end
71
+
72
+ def require_product(options)
73
+ @product = Java::OrgKopiEbicsSession.Product.new((options[:product_name] || 'kopiLeft Dev 1.0'), Java::JavaUtil.Locale::FRANCE, nil)
74
+ end
75
+
76
+ def require_user_and_product(options)
77
+ require_user options
78
+
79
+ require_product options
80
+ end
81
+ end
82
+ end
data/lib/ebics/file.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'ebics/file/upload'
2
+ require 'ebics/file/download'
@@ -0,0 +1,29 @@
1
+ require 'ebics/client'
2
+ module Ebics
3
+ module File
4
+ class Download < Ebics::Client
5
+ def fetch_file(path, user, product, test, date_start, date_end)
6
+ session = Java::OrgKopiEbicsSession.EbicsSession.new(user, conf)
7
+
8
+ session.add_session_param 'FORMAT', 'pain.xxx.cfonb160.dct'
9
+ session.add_session_param 'TEST', 'true' if test
10
+ session.product = product
11
+
12
+ conf.trace_manager.trace_directory = conf.get_transfer_trace_directory(user)
13
+
14
+ transfer_manager = Java::OrgKopiEbicsClient.FileTransfer.new(session)
15
+ transfer_manager.fetch_file(
16
+ Java::OrgKopiEbicsSession.OrderType::FDL,
17
+ date_start,
18
+ date_end,
19
+ Java::JavaIo.FileOutputStream.new(path)
20
+ )
21
+ end
22
+
23
+ def run(path, options)
24
+ require_user_and_product(options)
25
+ fetch_file(path, @user, @product, options[:test], options[:start], options[:end])
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,28 @@
1
+ require 'ebics/client'
2
+ module Ebics
3
+ module File
4
+ class Upload < Ebics::Client
5
+ def send_file(path, user, product)
6
+ session = Java::OrgKopiEbicsSession.EbicsSession.new(user, conf)
7
+
8
+ session.add_session_param 'FORMAT', 'pain.xxx.cfonb160.dct'
9
+ session.add_session_param 'TEST', 'true'
10
+ session.add_session_param 'EBCDIC', 'false'
11
+ session.product = product
12
+
13
+ conf.trace_manager.trace_directory = conf.get_transfer_trace_directory(user)
14
+
15
+ transfer_manager = Java::OrgKopiEbicsClient.FileTransfer.new(session)
16
+ transfer_manager.send_file(
17
+ Java::OrgKopiEbicsIo::IOUtils.get_file_content(path),
18
+ Java::OrgKopiEbicsSession.OrderType::FUL
19
+ )
20
+ end
21
+
22
+ def run(path, options)
23
+ require_user_and_product(options)
24
+ send_file(path, @user, @product)
25
+ end
26
+ end
27
+ end
28
+ end
data/lib/ebics/hbb.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'ebics/client'
2
+ module Ebics
3
+ class Hbb < Client
4
+ def download_certificates(user, product)
5
+ session = Java::OrgKopiEbicsSession.EbicsSession.new(user, conf)
6
+ session.product = product
7
+ keymanager = Java::OrgKopiEbicsClient.KeyManagement.new(session)
8
+ conf.trace_manager.trace_directory = conf.get_transfer_trace_directory(user)
9
+ keymanager.sendHPB
10
+ end
11
+
12
+ def run(options)
13
+ require_user_and_product(options)
14
+ download_certificates(@user, @product)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1 @@
1
+ require 'ebics/requestor/ful'
data/lib/ebics/user.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'ebics/user/creator'
2
+ require 'ebics/user/initiator'
@@ -0,0 +1,72 @@
1
+ require 'ebics/client'
2
+ module Ebics
3
+ module User
4
+ class Creator < Ebics::Client
5
+ def create_user(
6
+ bank_url,
7
+ bank_name,
8
+ host_id,
9
+ partner_id,
10
+ user_id,
11
+ name,
12
+ email,
13
+ country,
14
+ organization,
15
+ saveCertificates,
16
+ password)
17
+
18
+ bank = create_bank(bank_url, bank_name, host_id)
19
+ partner = create_partner(bank, partner_id)
20
+ pwd = Java::OrgKopiEbicsSecurity.UserPasswordHandler.new(user_id, password)
21
+
22
+ user = Java::OrgKopiEbicsClient.User.new(
23
+ partner,
24
+ user_id,
25
+ name,
26
+ email,
27
+ country,
28
+ organization,
29
+ pwd
30
+ )
31
+ create_user_directories(user)
32
+
33
+ user.save_user_certificates(conf.get_keystore_directory user) if saveCertificates
34
+
35
+ sm = conf.serialization_manager
36
+ [bank, partner, user].each do |o|
37
+ sm.serialize o
38
+ end
39
+
40
+ load_letters(user)
41
+
42
+ users[user_id] = user
43
+ end
44
+
45
+ def load_letters(user)
46
+ lm = conf.letter_manager
47
+ %w(a005 e002 x002).each do |format|
48
+ letter = lm.send("create_#{format}_letter", user)
49
+ letter.save(Java::JavaIo.FileOutputStream.new(
50
+ File.join(conf.get_letters_directory(user), letter.name)
51
+ ))
52
+ end
53
+ end
54
+
55
+ def run(name, email, country, organization, saveCertificates, options)
56
+ create_user(
57
+ options[:bank_url],
58
+ options[:bank_name],
59
+ options[:host_id],
60
+ options[:partner_id],
61
+ options[:user_id],
62
+ name,
63
+ email,
64
+ country,
65
+ organization,
66
+ saveCertificates,
67
+ options[:password]
68
+ )
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,33 @@
1
+ require 'ebics/client'
2
+ module Ebics
3
+ module User
4
+ class Initiator < Ebics::Client
5
+ def send_init_request(user, product)
6
+ return if user.initialized?
7
+ session = Java::OrgKopiEbicsSession.EbicsSession.new(user,conf)
8
+ session.product = product
9
+ keymanager = Java::OrgKopiEbicsClient.KeyManagement.new(session)
10
+ conf.trace_manager.trace_directory = conf.get_transfer_trace_directory(user)
11
+ keymanager.sendINI nil
12
+ user.initialized = true
13
+ end
14
+
15
+ def send_hia_request(user, product)
16
+ return if user.initialized_hia?
17
+ session = Java::OrgKopiEbicsSession.EbicsSession.new(user,conf)
18
+ session.product = product
19
+ keymanager = Java::OrgKopiEbicsClient.KeyManagement.new(session)
20
+ conf.trace_manager.trace_directory = conf.get_transfer_trace_directory(user)
21
+ keymanager.sendHIA nil
22
+ user.initialized_hia = true
23
+ end
24
+
25
+ def run(options)
26
+ require_user_and_product(options)
27
+ send_init_request(@user, @product)
28
+ send_hia_request(@user, @product)
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Ebics
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ebics-jruby
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Cyril LEPAGNOT
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ! '>='
19
+ - !ruby/object:Gem::Version
20
+ version: 0.16.0
21
+ none: false
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.16.0
27
+ none: false
28
+ prerelease: false
29
+ type: :runtime
30
+ - !ruby/object:Gem::Dependency
31
+ name: jbundler
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: 0.3.2
37
+ none: false
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: 0.3.2
43
+ none: false
44
+ prerelease: false
45
+ type: :runtime
46
+ description:
47
+ email:
48
+ - cyril@lepagnot.fr
49
+ executables:
50
+ - ebics
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - Jarfile
57
+ - README.md
58
+ - bin/ebics
59
+ - ebics-jruby.gemspec
60
+ - lib/ebics-jruby.rb
61
+ - lib/ebics.rb
62
+ - lib/ebics/base.rb
63
+ - lib/ebics/cli.rb
64
+ - lib/ebics/client.rb
65
+ - lib/ebics/file.rb
66
+ - lib/ebics/file/download.rb
67
+ - lib/ebics/file/upload.rb
68
+ - lib/ebics/hbb.rb
69
+ - lib/ebics/requestor.rb
70
+ - lib/ebics/user.rb
71
+ - lib/ebics/user/creator.rb
72
+ - lib/ebics/user/initiator.rb
73
+ - lib/ebics/version.rb
74
+ homepage: https://github.com/cyrill62/ebics-jruby
75
+ licenses: []
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: !binary |-
85
+ MA==
86
+ none: false
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: !binary |-
92
+ MA==
93
+ none: false
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 1.8.24
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: an ebics client using org.kopi.ebics java lib
100
+ test_files: []