iban-lookup 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  require 'active_support/all'
2
2
  require 'faraday'
3
- require 'devnull'
3
+ # require 'devnull'
4
4
 
5
5
  # Lookup a new iban number
6
6
  #
@@ -13,7 +13,7 @@ module IbanLookup
13
13
  attr_accessor :api_key, :service, :cache, :logger
14
14
 
15
15
  def initialize
16
- @logger ||= Logger.new(DevNull.new)
16
+ @logger ||= Logger.new(STDOUT)
17
17
  end
18
18
  end
19
19
 
@@ -29,71 +29,140 @@ module IbanLookup
29
29
 
30
30
  class IbanCom
31
31
  URL = 'https://www.iban.com'
32
- ENDPOINT = 'clients/api/ibanv2.php'
33
32
 
34
- attr_reader :params
33
+ attr_reader :object
35
34
 
36
- def initialize(iban)
37
- @params = {
38
- api_key: IbanLookup.configuration.api_key,
39
- format: :json,
40
- iban: iban,
41
- }
35
+ def initialize(iban = nil, options = {})
36
+ @object = if iban
37
+ IbanChecker.new(iban)
38
+ else
39
+ IbanCalc.new(options)
40
+ end
42
41
  end
43
42
 
44
- def valid?
45
- valid_codes = %w(001 002 003 004 005)
46
- json.fetch('validations', []).all? { |v| valid_codes.include? v['code'] }
47
- rescue => e
48
- logger.error "Unable to validate IBAN from IBAN json response (#{e.class}): #{e.message}"
49
- logger.debug e.backtrace.join("\n")
50
- false
51
- end
43
+ class IbanCalc
44
+ attr_reader :params
52
45
 
53
- def json
54
- @json ||= begin
55
- logger.info "Looking up #{params[:iban]}"
56
- body = if cache
57
- cache.get(params[:iban]).presence ||
58
- response.body.presence.tap { |j| cache.set(params[:iban], j) }
59
- else
60
- response.body.presence
61
- end
62
-
63
- JSON.parse(body.presence || '{}')
46
+ def initialize(options = {})
47
+ @params = options.merge({
48
+ :api_key => IbanLookup.configuration.api_key,
49
+ :format => :json,
50
+ })
51
+ end
52
+
53
+ def json
54
+ @json ||= begin
55
+ logger.info "Looking up #{params.to_query}"
56
+ body = if cache
57
+ cache.get(params.to_query).presence ||
58
+ response.body.presence.tap { |j| cache.set(params.to_query, j) }
59
+ else
60
+ response.body.presence
61
+ end
62
+
63
+ JSON.parse(body.presence || '{}')
64
+ end
65
+ rescue => e
66
+ logger.error "Unable to extract JSON from IBAN response (#{e.class}): #{e.message}"
67
+ logger.debug e.backtrace.join("\n")
68
+ {}
69
+ end
70
+
71
+ def response
72
+ url = "#{URL.chomp('/')}/clients/api/calc-api.php?#{params.to_query}"
73
+ logger.debug "IBAN url: #{url}"
74
+ Faraday.get(url).tap do |res|
75
+ logger.debug "IBAN response status: #{res.status}"
76
+ logger.debug "IBAN response body: #{res.body}"
77
+ end
64
78
  end
65
- rescue => e
66
- logger.error "Unable to extract JSON from IBAN response (#{e.class}): #{e.message}"
67
- logger.debug e.backtrace.join("\n")
68
- {}
69
- end
70
79
 
71
- def response
72
- url = "#{URL.chomp('/')}/#{ENDPOINT.chomp('/')}?#{params.to_query}"
73
- logger.debug "IBAN url: #{url}"
74
- Faraday.get(url).tap do |res|
75
- logger.debug "IBAN response status: #{res.status}"
76
- logger.debug "IBAN response body: #{res.body}"
80
+ def cache
81
+ IbanLookup.configuration.cache
77
82
  end
83
+
84
+ private
85
+
86
+ def method_missing(name, *args)
87
+ json.fetch(String(name), nil)
88
+ end
89
+
90
+ def logger
91
+ @logger ||= IbanLookup.configuration.logger
92
+ end
78
93
  end
79
94
 
80
- def cache
81
- IbanLookup.configuration.cache
95
+ class IbanChecker
96
+ attr_reader :params
97
+
98
+ def initialize(iban)
99
+ @params = {
100
+ :api_key => IbanLookup.configuration.api_key,
101
+ :format => :json,
102
+ :iban => iban,
103
+ }
104
+ end
105
+
106
+ def valid?
107
+ valid_codes = %w(001 002 003 004 005)
108
+ json.fetch('validations', []).all? { |v| valid_codes.include? v['code'] }
109
+ rescue => e
110
+ logger.error "Unable to validate IBAN from IBAN json response (#{e.class}): #{e.message}"
111
+ logger.debug e.backtrace.join("\n")
112
+ false
113
+ end
114
+
115
+ def json
116
+ @json ||= begin
117
+ logger.info "Looking up #{params[:iban]}"
118
+ body = if cache
119
+ cache.get(params[:iban]).presence ||
120
+ response.body.presence.tap { |j| cache.set(params[:iban], j) }
121
+ else
122
+ response.body.presence
123
+ end
124
+
125
+ JSON.parse(body.presence || '{}')
126
+ end
127
+ rescue => e
128
+ logger.error "Unable to extract JSON from IBAN response (#{e.class}): #{e.message}"
129
+ logger.debug e.backtrace.join("\n")
130
+ {}
131
+ end
132
+
133
+ def response
134
+ url = "#{URL.chomp('/')}/clients/api/ibanv2.php?#{params.to_query}"
135
+ logger.debug "IBAN url: #{url}"
136
+ Faraday.get(url).tap do |res|
137
+ logger.debug "IBAN response status: #{res.status}"
138
+ logger.debug "IBAN response body: #{res.body}"
139
+ end
140
+ end
141
+
142
+ def cache
143
+ IbanLookup.configuration.cache
144
+ end
145
+
146
+ private
147
+
148
+ def method_missing(name, *args)
149
+ json.fetch('bank_data', {}).fetch(String(name), nil)
150
+ end
151
+
152
+ def logger
153
+ @logger ||= IbanLookup.configuration.logger
154
+ end
82
155
  end
83
156
 
84
157
  private
85
158
 
86
159
  def method_missing(name, *args)
87
- json.fetch('bank_data', {}).fetch(String(name), nil)
88
- end
89
-
90
- def logger
91
- @logger ||= IbanLookup.configuration.logger
160
+ object.send(name, *args)
92
161
  end
93
162
  end
94
163
 
95
- def lookup(iban)
96
- "IbanLookup::#{configuration.service.classify}".constantize.new(iban)
164
+ def lookup(*args)
165
+ "IbanLookup::#{configuration.service.classify}".constantize.new(*args)
97
166
  end
98
167
  module_function :lookup
99
168
  end
@@ -1,5 +1,5 @@
1
1
  module Iban
2
2
  module Lookup
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,143 +1,101 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: iban-lookup
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.0
3
+ version: !ruby/object:Gem::Version
4
+ hash: 21
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 1
10
+ version: 1.0.1
5
11
  platform: ruby
6
- authors:
12
+ authors:
7
13
  - Emil Kampp
8
14
  autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
- date: 2016-07-07 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2016-12-01 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
14
22
  name: faraday
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '0.9'
20
- type: :runtime
21
23
  prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '0.9'
27
- - !ruby/object:Gem::Dependency
28
- name: activesupport
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '4.2'
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 59
30
+ segments:
31
+ - 0
32
+ - 9
33
+ - 0
34
+ version: 0.9.0
34
35
  type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: activesupport
35
39
  prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '4.2'
41
- - !ruby/object:Gem::Dependency
42
- name: devnull
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '0.1'
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ hash: 7
46
+ segments:
47
+ - 3
48
+ - 0
49
+ version: "3.0"
48
50
  type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '0.1'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '3.4'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '3.4'
69
- - !ruby/object:Gem::Dependency
70
- name: vcr
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '3.0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '3.0'
83
- - !ruby/object:Gem::Dependency
84
- name: webmock
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '1.24'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '1.24'
97
- - !ruby/object:Gem::Dependency
98
- name: memcache_mock
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '0.0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '0.0'
51
+ version_requirements: *id002
111
52
  description: IBAN Lookup wrapper for iban.com
112
- email:
53
+ email:
113
54
  - emil@kampp.me
114
55
  executables: []
56
+
115
57
  extensions: []
58
+
116
59
  extra_rdoc_files: []
117
- files:
60
+
61
+ files:
118
62
  - lib/iban-lookup.rb
119
63
  - lib/iban-lookup/version.rb
64
+ has_rdoc: true
120
65
  homepage: https://github.com/Inpay-Services/iban-lookup
121
- licenses: []
122
- metadata: {}
66
+ licenses:
67
+ - MIT
123
68
  post_install_message:
124
69
  rdoc_options: []
125
- require_paths:
70
+
71
+ require_paths:
126
72
  - lib
127
- required_ruby_version: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '1.9'
132
- required_rubygems_version: !ruby/object:Gem::Requirement
133
- requirements:
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - "="
77
+ - !ruby/object:Gem::Version
78
+ hash: 57
79
+ segments:
80
+ - 1
81
+ - 8
82
+ - 7
83
+ version: 1.8.7
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
134
87
  - - ">="
135
- - !ruby/object:Gem::Version
136
- version: '0'
88
+ - !ruby/object:Gem::Version
89
+ hash: 3
90
+ segments:
91
+ - 0
92
+ version: "0"
137
93
  requirements: []
94
+
138
95
  rubyforge_project:
139
- rubygems_version: 2.6.4
96
+ rubygems_version: 1.6.2
140
97
  signing_key:
141
- specification_version: 4
98
+ specification_version: 3
142
99
  summary: IBAN Lookup wrapper for iban.com
143
100
  test_files: []
101
+
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 2779f14a38bcc176964da975b11e28b8190105cb
4
- data.tar.gz: 5c03b6f7467831bbeb7f4cc63c5170a8e3b5c81e
5
- SHA512:
6
- metadata.gz: ae19345b58137c90c3a18ef8eaf94d545b20e914a10587c3501302a744669dda9fd83fe1f31b66669a77e83d82872d6c155687058fa187dd6b8f0ce2784b774f
7
- data.tar.gz: ada1d285be36850b296c09302d901064832dd494f23539972cd66fb6ddf9a90a600ad081daccd78838fbdd151a48f263d64563869d0a7728648142eb7cef7dfb