kontoapi-rails 0.0.1 → 0.0.2

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.
data/Gemfile.lock CHANGED
@@ -2,12 +2,12 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  abstract (1.0.0)
5
- actionmailer (3.0.6)
6
- actionpack (= 3.0.6)
5
+ actionmailer (3.0.7)
6
+ actionpack (= 3.0.7)
7
7
  mail (~> 2.2.15)
8
- actionpack (3.0.6)
9
- activemodel (= 3.0.6)
10
- activesupport (= 3.0.6)
8
+ actionpack (3.0.7)
9
+ activemodel (= 3.0.7)
10
+ activesupport (= 3.0.7)
11
11
  builder (~> 2.1.2)
12
12
  erubis (~> 2.6.6)
13
13
  i18n (~> 0.5.0)
@@ -15,19 +15,19 @@ GEM
15
15
  rack-mount (~> 0.6.14)
16
16
  rack-test (~> 0.5.7)
17
17
  tzinfo (~> 0.3.23)
18
- activemodel (3.0.6)
19
- activesupport (= 3.0.6)
18
+ activemodel (3.0.7)
19
+ activesupport (= 3.0.7)
20
20
  builder (~> 2.1.2)
21
21
  i18n (~> 0.5.0)
22
- activerecord (3.0.6)
23
- activemodel (= 3.0.6)
24
- activesupport (= 3.0.6)
22
+ activerecord (3.0.7)
23
+ activemodel (= 3.0.7)
24
+ activesupport (= 3.0.7)
25
25
  arel (~> 2.0.2)
26
26
  tzinfo (~> 0.3.23)
27
- activeresource (3.0.6)
28
- activemodel (= 3.0.6)
29
- activesupport (= 3.0.6)
30
- activesupport (3.0.6)
27
+ activeresource (3.0.7)
28
+ activemodel (= 3.0.7)
29
+ activesupport (= 3.0.7)
30
+ activesupport (3.0.7)
31
31
  addressable (2.2.5)
32
32
  arel (2.0.9)
33
33
  builder (2.1.2)
@@ -43,7 +43,7 @@ GEM
43
43
  kontoapi-ruby (0.1.0)
44
44
  addressable
45
45
  yajl-ruby
46
- mail (2.2.16)
46
+ mail (2.2.17)
47
47
  activesupport (>= 2.3.6)
48
48
  i18n (>= 0.4.0)
49
49
  mime-types (~> 1.16)
@@ -55,17 +55,17 @@ GEM
55
55
  rack (>= 1.0.0)
56
56
  rack-test (0.5.7)
57
57
  rack (>= 1.0)
58
- rails (3.0.6)
59
- actionmailer (= 3.0.6)
60
- actionpack (= 3.0.6)
61
- activerecord (= 3.0.6)
62
- activeresource (= 3.0.6)
63
- activesupport (= 3.0.6)
58
+ rails (3.0.7)
59
+ actionmailer (= 3.0.7)
60
+ actionpack (= 3.0.7)
61
+ activerecord (= 3.0.7)
62
+ activeresource (= 3.0.7)
63
+ activesupport (= 3.0.7)
64
64
  bundler (~> 1.0)
65
- railties (= 3.0.6)
66
- railties (3.0.6)
67
- actionpack (= 3.0.6)
68
- activesupport (= 3.0.6)
65
+ railties (= 3.0.7)
66
+ railties (3.0.7)
67
+ actionpack (= 3.0.7)
68
+ activesupport (= 3.0.7)
69
69
  rake (>= 0.8.7)
70
70
  thor (~> 0.14.4)
71
71
  rake (0.8.7)
data/README.markdown CHANGED
@@ -30,17 +30,38 @@ Then, in one of the models you want to validate bank account data with:
30
30
 
31
31
  # account data validation
32
32
  # (really just a shortcut for `validates_with KontoAPI::BankAccountValidator`)
33
- # takes any of the following options (the defaults are shown here):
33
+ # Takes any of the following options (the defaults are shown here):
34
34
  # :account_number_field => :account_number,
35
35
  # :bank_code_field => :bank_code,
36
36
  # :allow_nil => true, <-- don't validate if one of them is nil
37
37
  # :on_timeout => :ignore <-- do nothing if a timeout occurs, others:
38
38
  # :fail <-- throw a validation error
39
39
  # :retry <-- (not supported yet)
40
+ #
41
+ # If validations fails, an error within the standard ActiveRecord I18n scopes
42
+ # will be added to the :account_number_field:
43
+ # :invalid <-- if it is invalid
44
+ # :timeout <-- if :on_timeout is set to :fail and the api call timed out
40
45
  validates_account_data
41
46
 
42
47
  end
43
48
 
49
+ And if you want to autocomplete the bank name:
50
+
51
+ class PaymentData < ActiveRecord::Base
52
+
53
+ # bank name autocompletion
54
+ # takes any of the following options (the defaults are shown here):
55
+ # :bank_code_field => :bank_code,
56
+ # :bank_name_field => :bank_name,
57
+ # :always_overwrite => false, <-- autocomplete even if bank name already present
58
+ # :on_timeout => :ignore <-- do nothing if a timeout occurs, others:
59
+ # :retry <-- (not supported yet)
60
+ # 'any string' <-- use this string as the value
61
+ autocomplete_bank_name
62
+
63
+ end
64
+
44
65
  Copyright
45
66
  ---------
46
67
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{kontoapi-rails}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jan Schwenzien"]
12
- s.date = %q{2011-04-18}
12
+ s.date = %q{2011-04-20}
13
13
  s.description = %q{This library is a wrapper for the Konto API (https://www.kontoapi.de/). It provides a validation method for models that checks if a given account number and bank code represent a valid combination.}
14
14
  s.email = %q{jan@schwenzien.org}
15
15
  s.extra_rdoc_files = [
@@ -8,6 +8,12 @@ module KontoAPI
8
8
  module ClassMethods
9
9
  def validates_bank_account(options={})
10
10
  options.symbolize_keys!
11
+ options.reverse_merge!(
12
+ :account_number_field => :account_number,
13
+ :bank_code_field => :bank_code,
14
+ :allow_nil => true,
15
+ :on_timeout => :ignore
16
+ )
11
17
  validates_with KontoAPI::BankAccountValidator, options
12
18
  end
13
19
 
@@ -15,13 +21,24 @@ module KontoAPI
15
21
  options.symbolize_keys!
16
22
  options.reverse_merge!(
17
23
  :bank_code_field => :bank_code,
18
- :bank_name_field => :bank_name
24
+ :bank_name_field => :bank_name,
25
+ :always_overwrite => false
19
26
  )
20
- #write_inheritable_attribute(:autocomplete_bank_name_options, options)
21
27
  define_method :autocomplete_bank_name do
22
28
  current_value = send(:"#{options[:bank_name_field]}")
23
29
  blz = send(:"#{options[:bank_code_field]}")
24
- self.send(:"#{options[:bank_name_field]}=", KontoAPI::bank_name(blz)) if current_value.blank? && blz.present?
30
+ begin
31
+ self.send(:"#{options[:bank_name_field]}=", KontoAPI::bank_name(blz)) if (options[:always_overwrite] || current_value.blank?) && blz.present?
32
+ rescue Timeout::Error => ex
33
+ case options[:on_timeout]
34
+ when String
35
+ self.send(:"#{options[:bank_name_field]}=", options[:on_timeout])
36
+ when nil, :ignore
37
+ # nop
38
+ when :retry
39
+ raise 'not implemented yet'
40
+ end
41
+ end
25
42
  end
26
43
  before_save :autocomplete_bank_name
27
44
  end
@@ -3,22 +3,15 @@ require 'active_model/validator'
3
3
  module KontoAPI
4
4
  class BankAccountValidator < ActiveModel::Validator
5
5
 
6
- DEFAULTS = {
7
- :account_number_field => :account_number,
8
- :bank_code_field => :bank_code,
9
- :allow_nil => true,
10
- :on_timeout => :ignore
11
- }
12
-
13
6
  def validate(record)
14
- record_options = options.reverse_merge(DEFAULTS)
15
- account_number = record.send(:"#{record_options[:account_number_field]}")
16
- bank_code = record.send(:"#{record_options[:bank_code_field]}")
17
- record.errors.add(:"#{record_options[:account_number_field]}", :invalid) unless KontoAPI::valid?(account_number, bank_code)
7
+ account_number = record.send(:"#{options[:account_number_field]}")
8
+ bank_code = record.send(:"#{options[:bank_code_field]}")
9
+ return true if options[:allow_nil] && (account_number.nil? || bank_code.nil?)
10
+ record.errors.add(:"#{options[:account_number_field]}", :invalid) unless KontoAPI::valid?(account_number, bank_code)
18
11
  rescue Timeout::Error => ex
19
- case record_options[:on_timeout]
12
+ case options[:on_timeout]
20
13
  when :fail
21
- record.errors.add(:"#{record_options[:account_number_field]}", :timeout)
14
+ record.errors.add(:"#{options[:account_number_field]}", :timeout)
22
15
  when :ignore
23
16
  # nop
24
17
  when :retry
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kontoapi-rails
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jan Schwenzien
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-18 00:00:00 Z
18
+ date: 2011-04-20 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rails