iban-lookup 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/iban-lookup.rb +20 -4
- data/lib/iban-lookup/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc2a0ad9e87dfbea8dd627048773654c8ca7195e
|
4
|
+
data.tar.gz: 3b46c945d1f56819f7a4de73943a9c6fcdd9cbc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f1e2821274d471b05e900c8a836a21fef71fd359ee286e8e962791d744f270a0fbb88b31b6098a2bf15021f06be2bad558db2d02be7c98e7ca56799212f2d5c
|
7
|
+
data.tar.gz: e9b7bdfcb3ae5d4b04dc822639786709849761168d9f228c8fadbc7637ecb65710c3127da3dfc15404014d76818813f91f828841f3c910513b13c65694aca394
|
data/lib/iban-lookup.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'active_support/all'
|
2
2
|
require 'faraday'
|
3
|
+
require 'devnull'
|
3
4
|
|
4
5
|
# Lookup a new iban number
|
5
6
|
#
|
@@ -9,9 +10,10 @@ require 'faraday'
|
|
9
10
|
#
|
10
11
|
module IbanLookup
|
11
12
|
class Configuration
|
12
|
-
attr_accessor :api_key, :service, :cache
|
13
|
+
attr_accessor :api_key, :service, :cache, :logger
|
13
14
|
|
14
15
|
def initialize
|
16
|
+
@logger ||= Logger.new(DevNull.new)
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
@@ -32,6 +34,7 @@ module IbanLookup
|
|
32
34
|
attr_reader :params
|
33
35
|
|
34
36
|
def initialize(iban)
|
37
|
+
logger.info "Looking up #{iban}"
|
35
38
|
@params = {
|
36
39
|
api_key: IbanLookup.configuration.api_key,
|
37
40
|
format: :json,
|
@@ -41,7 +44,11 @@ module IbanLookup
|
|
41
44
|
|
42
45
|
def valid?
|
43
46
|
valid_codes = %w(001 002 003 004 005)
|
44
|
-
json.fetch('validations', []).all? { valid_codes.include? v['code'] }
|
47
|
+
json.fetch('validations', []).all? { |v| valid_codes.include? v['code'] }
|
48
|
+
rescue => e
|
49
|
+
logger.error "Unable to validate IBAN from IBAN json response (#{e.class}): #{e.message}"
|
50
|
+
logger.debug e.backtrace.join("\n")
|
51
|
+
false
|
45
52
|
end
|
46
53
|
|
47
54
|
def json
|
@@ -52,12 +59,17 @@ module IbanLookup
|
|
52
59
|
else
|
53
60
|
response.body.presence
|
54
61
|
end
|
55
|
-
JSON.parse(body || '{}')
|
62
|
+
JSON.parse(body || '{}').tap do |j|
|
63
|
+
logger.debug "IBAN response: #{j}"
|
64
|
+
end
|
56
65
|
end
|
66
|
+
rescue => e
|
67
|
+
logger.error "Unable to extract JSON from IBAN response (#{e.class}): #{e.message}"
|
68
|
+
logger.debug e.backtrace.join("\n")
|
69
|
+
{}
|
57
70
|
end
|
58
71
|
|
59
72
|
def response
|
60
|
-
p 'hello'
|
61
73
|
Faraday.get("#{URL.chomp('/')}/#{ENDPOINT.chomp('/')}?#{params.to_query}")
|
62
74
|
end
|
63
75
|
|
@@ -70,6 +82,10 @@ module IbanLookup
|
|
70
82
|
def method_missing(name, *args)
|
71
83
|
json.fetch('bank_data', {}).fetch(String(name), nil)
|
72
84
|
end
|
85
|
+
|
86
|
+
def logger
|
87
|
+
@logger ||= IbanLookup.configuration.logger
|
88
|
+
end
|
73
89
|
end
|
74
90
|
|
75
91
|
def lookup(iban)
|
data/lib/iban-lookup/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iban-lookup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emil Kampp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
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'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.1'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|