iban-lookup 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a33ed10ccbdfe393a8edc671aee9732b81cce522
4
- data.tar.gz: 43c6bf6f667a942d08c636ca3ec6c6e22e2ac7b9
3
+ metadata.gz: a8b7733d28ed617952917053f247a28fa737fa67
4
+ data.tar.gz: 9f33173ccd290ad234debc076a97d8a4d0ec0a08
5
5
  SHA512:
6
- metadata.gz: c3a14c903bab895cbbd294ac05a617f2e844dfcfb4bde4dfead7ab58c84366b43c7180b409eb0d767a3d037bf88f23f4334cd678eba11bce41c76b9493378f6b
7
- data.tar.gz: e0860f2c4649f522a2d958456c1510d8d107f9ec12dab1848fb397bae3cb1dc2a22c5c650869dfa027920164f645fe0d255fa982813d305c5cd7f47bc99186d3
6
+ metadata.gz: de0c3e32f4e14c2283855938785060711eb9c5e88302bf5ca511995383f6c2dfe4629550a01f985c13880621e4fabdac02c56a03e69dc6118abf777dbf600f63
7
+ data.tar.gz: a1370925b097d710f4d83ca5802aaee51d82b07c8720fe1a15b0ee723fef3b6a6641491d06378fcc7478fba2a283a490b765660ebeee989791bbcc4800d81be9
data/lib/iban-lookup.rb CHANGED
@@ -9,7 +9,7 @@ require 'faraday'
9
9
  #
10
10
  module IbanLookup
11
11
  class Configuration
12
- attr_accessor :api_key, :service
12
+ attr_accessor :api_key, :service, :cache
13
13
 
14
14
  def initialize
15
15
  end
@@ -29,26 +29,46 @@ module IbanLookup
29
29
  URL = 'https://www.iban.com'
30
30
  ENDPOINT = 'clients/api/ibanv2.php'
31
31
 
32
- attr_reader :response
32
+ attr_reader :params
33
33
 
34
34
  def initialize(iban)
35
- params = {
35
+ @params = {
36
36
  api_key: IbanLookup.configuration.api_key,
37
37
  format: :json,
38
38
  iban: iban,
39
39
  }
40
- @response = Faraday.get("#{URL.chomp('/')}/#{ENDPOINT.chomp('/')}?#{params.to_query}")
41
40
  end
42
41
 
43
42
  def valid?
44
43
  valid_codes = %w(001 002 003 004 005)
45
- JSON.parse(response.body.presence || '{}').fetch('validations', []).all? { valid_codes.include? v['code'] }
44
+ json.fetch('validations', []).all? { valid_codes.include? v['code'] }
45
+ end
46
+
47
+ def json
48
+ @json ||= begin
49
+ body = if cache
50
+ cache.get(params[:iban]).presence ||
51
+ response.body.presence.tap { |j| cache.set(params[:iban], j) }
52
+ else
53
+ response.body.presence
54
+ end
55
+ JSON.parse(body || '{}')
56
+ end
57
+ end
58
+
59
+ def response
60
+ p 'hello'
61
+ Faraday.get("#{URL.chomp('/')}/#{ENDPOINT.chomp('/')}?#{params.to_query}")
62
+ end
63
+
64
+ def cache
65
+ IbanLookup.configuration.cache
46
66
  end
47
67
 
48
68
  private
49
69
 
50
70
  def method_missing(name, *args)
51
- JSON.parse(response.body.presence || '{}').fetch('bank_data', {}).fetch(String(name), nil)
71
+ json.fetch('bank_data', {}).fetch(String(name), nil)
52
72
  end
53
73
  end
54
74
 
@@ -1,5 +1,5 @@
1
1
  module Iban
2
2
  module Lookup
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
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.3
4
+ version: 0.0.4
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-25 00:00:00.000000000 Z
11
+ date: 2016-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.24'
83
+ - !ruby/object:Gem::Dependency
84
+ name: memcache_mock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.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.0'
83
97
  description: IBAN Lookup wrapper for iban.com
84
98
  email:
85
99
  - emil@kampp.me