aqbanking 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZTZkMjg0YzQzNWY3NWYwZWY0NjY2NjA5MDVkMjlkYjExMmIwMjk4OQ==
5
+ data.tar.gz: !binary |-
6
+ NTA5MzVmOTVkMmFiNzZmMGM1MzBjZGVkMWJlNDg2NjM0ZjBkZjg0Ng==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZDE5MjhjMjI2OGVlZTRmNjAyNGI4NjdhNTRkN2Q3ZjcyNjg5NTQzZWNmY2Jj
10
+ NGIyNDQ1ZDZiMmNlZjk4OTM5YWYwYzY2ZmU0NWNlOTgwOWRhNTQ0NjNmMGY5
11
+ NzcxYTIzMmE5MjU5OWFjMzQ4ZWEwMmY5ZjNmY2ZiMWZiYTFlNmQ=
12
+ data.tar.gz: !binary |-
13
+ NTU5MDUxMGNjYjUyNGQ3ZWY4YjY2OTZhNWZhODk5ZTdjMWZlNThiMjZlY2Uw
14
+ NDU4ZWUzNmFiODAxODM1MjYzNWMzOWVhMTQzMGZlMTFhNTBjNDIyMjliNDBl
15
+ NTQ1ZGYxMDVlNmRhY2NmZmRlZGNhMDM2YjcyN2M0ODVjYTY5Yzg=
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ /.ruby-gemset
19
+ /.ruby-version
20
+ /settings/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in aqbanking.gemspec
4
+ gemspec
@@ -0,0 +1,6 @@
1
+ guard :rspec do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { 'spec' }
5
+ watch(%r{^spec/support/(.+)\.rb$}) { 'spec' }
6
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Arthur Leonard Andersen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Aqbanking
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'aqbanking'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install aqbanking
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'aqbanking/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "aqbanking"
8
+ spec.version = AqBanking::VERSION
9
+ spec.authors = ["Arthur Leonard Andersen"]
10
+ spec.email = ["leoc.git@gmail.com"]
11
+ spec.description = %q{`aqbanking` is a simple wrapper around the AqBanking commandline utilities.}
12
+ spec.summary = %q{Use aqbanking features from ruby.}
13
+ spec.homepage = "http://github.com/leoc/ruby-aqbanking"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "guard"
25
+ spec.add_development_dependency "guard-rspec"
26
+ spec.add_development_dependency "rubocop"
27
+ end
@@ -0,0 +1,92 @@
1
+ require "aqbanking/version"
2
+ require "aqbanking/user"
3
+ require "aqbanking/account"
4
+ require "aqbanking/transaction"
5
+
6
+ module AqBanking
7
+ GLOBAL_ARGS = {
8
+ acceptvalidcerts: :flag,
9
+ noninteractive: :flag,
10
+ charset: :value,
11
+ cfgdir: :value,
12
+ cfgfile: :value,
13
+ pinfile: :value,
14
+ }
15
+
16
+ CMD_ARGS = {
17
+ tokentype: :value,
18
+ bank: :value,
19
+ user: :value,
20
+ server: :value,
21
+ username: :value
22
+ }
23
+
24
+ class << self
25
+
26
+ def config=(path)
27
+ @config = path
28
+ end
29
+
30
+ def config
31
+ @config ||= '.'
32
+ end
33
+
34
+ def with_secure_pin(user, pin, &block)
35
+ f = Tempfile.new("pin_#{user.bank}_#{user.user_id}", '/tmp')
36
+ File.chmod(0400, f.path)
37
+
38
+ f.write "PIN_#{user.bank}_#{user.user_id} = \"#{pin}\"\n"
39
+ f.flush
40
+
41
+ yield f if block_given?
42
+
43
+ f.close
44
+ f.unlink
45
+ end
46
+
47
+ def aqhbci(command, options = {})
48
+ options = {
49
+ pinfile: nil,
50
+ acceptvalidcerts: true,
51
+ noninteractive: true,
52
+ charset: 'utf-8',
53
+ cfgfile: AqBanking.config
54
+ }.merge(options)
55
+ [
56
+ 'aqhbci-tool4',
57
+ generate_arguments(options, GLOBAL_ARGS),
58
+ command,
59
+ generate_arguments(options, CMD_ARGS)
60
+ ].join(' ').strip
61
+ end
62
+
63
+ def aqcli(command, options = {})
64
+ options = {
65
+ pinfile: nil,
66
+ acceptvalidcerts: true,
67
+ noninteractive: true,
68
+ charset: 'utf-8',
69
+ cfgdir: AqBanking.config
70
+ }.merge(options)
71
+ [
72
+ 'aqbanking-cli',
73
+ generate_arguments(options, GLOBAL_ARGS),
74
+ command,
75
+ generate_arguments(options, CMD_ARGS)
76
+ ].join(' ').strip
77
+ end
78
+
79
+ private
80
+ def generate_arguments(hash, args)
81
+ args.keys.map do |key|
82
+ if args[key] == :flag && hash[key]
83
+ "--#{key.to_s}"
84
+ elsif args[key] == :value && hash[key]
85
+ "--#{key.to_s}=#{Shellwords.escape(hash[key])}"
86
+ end
87
+ end.compact.join(' ')
88
+ end
89
+
90
+ end
91
+
92
+ end
@@ -0,0 +1,5 @@
1
+ module AqBanking
2
+ class Account
3
+
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module AqBanking
2
+ class Transaction
3
+
4
+ end
5
+ end
@@ -0,0 +1,70 @@
1
+ require 'open3'
2
+
3
+ module AqBanking
4
+ class User
5
+ attr_accessor :name, :bank, :user_id, :server, :hbciversion
6
+
7
+ def initialize(options = {})
8
+ User.complain_missing_parameters(options)
9
+ end
10
+
11
+ class << self
12
+
13
+ def add(options = {})
14
+ pin = options.delete(:pin)
15
+ options = {
16
+ tokentype: 'pintan',
17
+ hbciversion: 300,
18
+ context: "1"
19
+ }.merge(options)
20
+
21
+ complain_missing_parameters(options)
22
+
23
+ user = nil
24
+ command = AqBanking::aqhbci('adduser', options)
25
+ stdin, stdout, stderr, wait_thr = Open3.popen3(command)
26
+
27
+ if wait_thr.value.success?
28
+ user = User.new(options)
29
+ else
30
+ raise Exception, "Unable to create user: \n#{stderr.read}"
31
+ end
32
+
33
+ if user && pin
34
+ AqBanking::with_secure_pin(user, pin) do |f|
35
+ sysid_command = AqBanking::aqhbci('getsysid',
36
+ user: options[:user],
37
+ pinfile: f.path.strip)
38
+ stdin, stdout, stderr, wait_thr = Open3.popen3(sysid_command)
39
+ unless wait_thr.value.success?
40
+ raise Exception, "Unable to get sysid:\n#{stderr.read}"
41
+ end
42
+ end
43
+ end
44
+
45
+ user
46
+ end
47
+
48
+ def remove(options = {})
49
+ raise "Missing options: user" unless options[:user]
50
+ command = AqBanking::aqhbci('deluser', user: options[:user])
51
+ _, _, stderr, status = Open3.popen3(command)
52
+ unless status.value.success?
53
+ raise Exception, "Unable to remove user:\n#{stderr.read}"
54
+ end
55
+ end
56
+
57
+ def complain_missing_parameters(hash)
58
+ missing = []
59
+ missing << :bank unless hash[:bank]
60
+ missing << :user unless hash[:user]
61
+ missing << :server unless hash[:server]
62
+ missing << :username unless hash[:username]
63
+ unless missing.empty?
64
+ raise Exception, "Missing options: #{missing.join(', ')}"
65
+ end
66
+ end
67
+
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,3 @@
1
+ module AqBanking
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe AqBanking::Account do
4
+
5
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe AqBanking do
4
+ context '#with_secure_pin' do
5
+ let(:user) { double('User', bank: '123', user_id: '456') }
6
+ let(:pin) { 'secure' }
7
+
8
+ it 'creates a temporary pinfile with 400' do
9
+ AqBanking::with_secure_pin(user, pin) do |f|
10
+ f.should_not be_nil
11
+ expect(File).to exist(f.path)
12
+ File.read(f.path).should == "PIN_123_456 = \"secure\"\n"
13
+ end
14
+ end
15
+
16
+ it 'deletes the file afterwards' do
17
+ path = nil
18
+ AqBanking::with_secure_pin(user, pin) do |f|
19
+ path = f.path.strip
20
+ end
21
+ expect(File).not_to exist(path)
22
+ end
23
+ end
24
+
25
+ context '#aqhbci' do
26
+ it 'returns a aqhbci-tool4 command' do
27
+ AqBanking::aqhbci('test').should == "aqhbci-tool4 --acceptvalidcerts --noninteractive --charset=utf-8 --cfgfile=. test"
28
+ end
29
+ end
30
+
31
+ context '#aqcli' do
32
+ it 'returns a aqbanking-cli command' do
33
+ AqBanking::aqcli('test').should == "aqbanking-cli --acceptvalidcerts --noninteractive --charset=utf-8 --cfgdir=. test"
34
+ end
35
+ end
36
+
37
+ context '#generate_arguments' do
38
+ it 'escapes value arguments' do
39
+ AqBanking.send(:generate_arguments, { cfgfile: '/tmp/some weird dir' }, AqBanking::GLOBAL_ARGS).
40
+ should == '--cfgfile=/tmp/some\\ weird\\ dir'
41
+ end
42
+
43
+ it 'returns only allowed arguments' do
44
+ AqBanking.send(:generate_arguments, { weird: true }, AqBanking::GLOBAL_ARGS).should == ''
45
+ end
46
+
47
+ it 'returns flags if the option is true' do
48
+ AqBanking.send(:generate_arguments, { noninteractive: true }, AqBanking::GLOBAL_ARGS).
49
+ should == '--noninteractive'
50
+ end
51
+
52
+ it 'does not return flags if the option is false' do
53
+ AqBanking.send(:generate_arguments, {noninteractive: false }, AqBanking::GLOBAL_ARGS).should == ''
54
+ end
55
+ end
56
+
57
+ end
@@ -0,0 +1,21 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ $: << File.join(File.dirname(__FILE__), '..', 'lib')
8
+
9
+ require 'aqbanking'
10
+
11
+ RSpec.configure do |config|
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ config.run_all_when_everything_filtered = true
14
+ config.filter_run :focus
15
+
16
+ # Run specs in random order to surface order dependencies. If you find an
17
+ # order dependency and want to debug it, you can fix the order by providing
18
+ # the seed, which is printed after each run.
19
+ # --seed 1234
20
+ config.order = 'random'
21
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe AqBanking::Transaction do
4
+
5
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe AqBanking::User do
4
+ describe '::add' do
5
+ it 'needs bank option' do
6
+ expect { AqBanking::User.add(username: "A", user: '123456789', server: 'http://www.google.com') }.to raise_error
7
+ end
8
+
9
+ it 'needs username option' do
10
+ expect { AqBanking::User.add(bank: '12030000', user: '123456789', server: 'http://www.google.com') }.to raise_error
11
+ end
12
+
13
+ it 'needs user option' do
14
+ expect { AqBanking::User.add(username: 'A', bank: '12030000', server: 'http://www.google.com') }.to raise_error
15
+ end
16
+
17
+ it 'needs server option' do
18
+ expect { AqBanking::User.add(username: 'A', bank: '12030000', user: '123456789') }.to raise_error
19
+ end
20
+
21
+ context 'on success' do
22
+ after(:each) do
23
+ AqBanking::User.remove(user: '123456789')
24
+ end
25
+
26
+ it 'returns the new user' do
27
+ user = AqBanking::User.add(username: "A", bank: '12030000', user: '123456789', server: 'http://www.google.com')
28
+ user.should be_a AqBanking::User
29
+ end
30
+ end
31
+ end
32
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aqbanking
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Arthur Leonard Andersen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: ! '`aqbanking` is a simple wrapper around the AqBanking commandline utilities.'
98
+ email:
99
+ - leoc.git@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .rspec
106
+ - Gemfile
107
+ - Guardfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - aqbanking.gemspec
112
+ - lib/aqbanking.rb
113
+ - lib/aqbanking/account.rb
114
+ - lib/aqbanking/transaction.rb
115
+ - lib/aqbanking/user.rb
116
+ - lib/aqbanking/version.rb
117
+ - spec/account_spec.rb
118
+ - spec/aqbanking_spec.rb
119
+ - spec/spec_helper.rb
120
+ - spec/transaction_spec.rb
121
+ - spec/user_spec.rb
122
+ homepage: http://github.com/leoc/ruby-aqbanking
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ! '>='
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.1.5
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Use aqbanking features from ruby.
146
+ test_files:
147
+ - spec/account_spec.rb
148
+ - spec/aqbanking_spec.rb
149
+ - spec/spec_helper.rb
150
+ - spec/transaction_spec.rb
151
+ - spec/user_spec.rb