ibancom 0.0.10 → 0.0.12

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db212a5427dbb25699bbdec0aac5cd33031d6ae19ba4b3be96e5e2408090fffe
4
- data.tar.gz: 527d056deb38d7c42cd8124a8e0dfa5fc67931057bb96cc5128feff794b1ca41
3
+ metadata.gz: 47cb70450c2d3171087a946ac9bb141c8d24fd23355bbaa3f281b1f0ff843b30
4
+ data.tar.gz: 18b1bb8d814c8688543a44175e90d480dd2bd31ed9a2a32a1aa38c074218e2bb
5
5
  SHA512:
6
- metadata.gz: b098efd3c946d7adfe126bda574ba28361a61fec806f34ab18ce641705fd6b38260a9f963a016f2bcdf7bec55240a8b581a8f6b1a784913ea2f3224335bdf4d4
7
- data.tar.gz: af899cab00d8c47782447a3d4004a4f7a8e9c2f690027c8fc9f41a70236782ae03e11b0b31d9d7e8dfe4f239be3abfe281df73d3b4ec030d57a4e0e4311c2dec
6
+ metadata.gz: 193f5a9634022ee954039f7287d3ac1532a8f73adba28eae1890dfc0de4fb4660f9c115959dae12ac83532b566889464665f3da9c3ea3caeb13b524329924356
7
+ data.tar.gz: e1de0d21ad7bc55b7a473fc987211286ff2487339a98ee459860a050758dc08e2d722800168c3b3b20de527671c06d783f981eab7aa187c7c3c684013b11d40f
data/Gemfile.lock CHANGED
@@ -1,14 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ibancom (0.0.10)
4
+ ibancom (0.0.12)
5
5
  faraday (>= 0.15)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- addressable (2.8.1)
11
- public_suffix (>= 2.0.2, < 6.0)
10
+ addressable (2.9.0)
11
+ public_suffix (>= 2.0.2, < 8.0)
12
12
  ast (2.4.2)
13
13
  coderay (1.1.3)
14
14
  crack (0.4.5)
@@ -51,14 +51,14 @@ GEM
51
51
  pry (0.14.2)
52
52
  coderay (~> 1.1)
53
53
  method_source (~> 1.0)
54
- public_suffix (5.0.1)
54
+ public_suffix (5.1.1)
55
55
  rainbow (3.1.1)
56
56
  rake (12.3.3)
57
57
  rb-fsevent (0.11.2)
58
58
  rb-inotify (0.10.1)
59
59
  ffi (~> 1.0)
60
60
  regexp_parser (2.7.0)
61
- rexml (3.2.5)
61
+ rexml (3.4.2)
62
62
  rspec (3.12.0)
63
63
  rspec-core (~> 3.12.0)
64
64
  rspec-expectations (~> 3.12.0)
@@ -106,6 +106,8 @@ GEM
106
106
  hashdiff (>= 0.4.0, < 2.0.0)
107
107
 
108
108
  PLATFORMS
109
+ arm64-darwin-22
110
+ arm64-darwin-25
109
111
  x86_64-linux
110
112
 
111
113
  DEPENDENCIES
data/README.md CHANGED
@@ -25,6 +25,7 @@ Or install it yourself as:
25
25
  This gem provides support for the following APIs:
26
26
 
27
27
  - Validation API v4
28
+ - Sortware API v4
28
29
 
29
30
  ## Usage
30
31
 
@@ -34,6 +35,18 @@ The first step for using this gem is to instantiate the client:
34
35
  client = Ibancom::Client.new(apikey: "YOUR_API_KEY")
35
36
  ```
36
37
 
38
+ HTTP logging is enabled by default through `Faraday::Response::Logger`. You can replace that middleware and pass extra options to it:
39
+
40
+ ```rb
41
+ client = Ibancom::Client.new(
42
+ apikey: "YOUR_API_KEY",
43
+ logger_middleware: CustomMiddleware,
44
+ logger_options: { log_level: :debug }
45
+ )
46
+ ```
47
+
48
+ `logger_options` are merged over `{ headers: true, bodies: true }`. The middleware is initialized as `Middleware.new(app, nil, options)` and receives the existing password filter block. Set `logger_enabled: false` to skip logging.
49
+
37
50
  Once you have an authenticated client, you can validate any IBAN easily by using the validations service:
38
51
 
39
52
  ```rb
@@ -79,6 +92,44 @@ iban.failed_checks
79
92
  # #<Ibancom::Resources::IBAN::Check:0x00007f384a576cf8 @code="203", @message="IBAN Length is not correct. Spain IBAN must be 24 characters long.", @response=nil, @type=:length>]
80
93
  ```
81
94
 
95
+ You can also validate United Kingdom Sort Code and Account Numbers:
96
+
97
+ ```rb
98
+ scan = client.validations.validate_scan("200415", "38290008")
99
+ scan.valid? # true
100
+
101
+ # What is the bank/branch associated to this account?
102
+ bank = scan.bank # <Ibancom::Resources::SCAN::Bank:0x0000000107c0fc80 ...
103
+ bank.bank # "BARCLAYS BANK UK PLC"
104
+ bank.bic # "BUKBGB22XXX"
105
+ bank.branch # "BARCLAYBANK B'CARD N'PTON"
106
+ bank.address # "Dept AC Barclaycard House "
107
+ bank.city # "Northampton"
108
+ bank.zip # "NN4 7SG"
109
+ bank.phone # "01604 234234"
110
+ bank.country # "GB"
111
+
112
+ # What payment schemes does it support?
113
+ scan.supported_schemes
114
+ #[#<Ibancom::Resources::SCAN::Scheme:0x0000000107c0df70 @code=:FPS_PAYMENTS, @response=nil, @supported="YES">,
115
+ # #<Ibancom::Resources::SCAN::Scheme:0x0000000107c0def8 @code=:CHAPS, @response=nil, @supported="YES">,
116
+ # #<Ibancom::Resources::SCAN::Scheme:0x0000000107c0de80 @code=:BACS, @response=nil, @supported="YES">,
117
+ # #<Ibancom::Resources::SCAN::Scheme:0x0000000107c0de08 @code=:CCC_PAYMENTS, @response=nil, @supported="YES">]
118
+
119
+ # Does the SCAN supports faster payments?
120
+ scan.supported_scheme?(:FPS_PAYMENTS) # true
121
+ ```
122
+
123
+ In the same way as with the IBAN, when the SCAN is not valid the failed checks are available for inspection:
124
+
125
+ ```rb
126
+ scan = client.validations.validate_scan("000001", "00000002")
127
+ scan.valid? # false
128
+ scan.failed_checks
129
+ #[#<Ibancom::Resources::SCAN::Check:0x00000001088debf0 @code="202", @message="Sort Code not found in bank directory",
130
+ # @response=nil, @type=:length>]
131
+ ```
132
+
82
133
  ## Development
83
134
 
84
135
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -86,8 +137,12 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
86
137
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then tag and push the new version:
87
138
 
88
139
  ```git
89
- git tag vx.x.x main
90
- git push origin vx.x.x
140
+ bundle install
141
+ git add .
142
+ git commit -m 'feat(release): Bump to vX.X.X'
143
+ git push
144
+ git tag vX.X.X main
145
+ git push origin vX.X.X
91
146
  ```
92
147
 
93
148
  The tagging will trigger the GitHub action defined in `release.yml`, pushing the gem to [rubygems.org](https://rubygems.org).
@@ -4,9 +4,14 @@ module Ibancom
4
4
  module API
5
5
  class ValidationService < Service
6
6
  def validate(iban)
7
- response = client.post("/v4/iban/", { iban: iban, sci: 1 })
7
+ response = client.post("/v4/iban/", { iban: iban, sci: 1, sci_tips: 1 })
8
8
  Resources::IBAN::Validation.new(response, response.body)
9
9
  end
10
+
11
+ def validate_scan(sort_code, account_number)
12
+ response = client.post("/v4/sort/", { sortcode: sort_code, account: account_number })
13
+ Resources::SCAN::Validation.new(response, response.body)
14
+ end
10
15
  end
11
16
  end
12
17
  end
@@ -13,7 +13,7 @@ module Ibancom
13
13
 
14
14
  BASE_URL = "https://api.iban.com/clients/api"
15
15
 
16
- attr_reader :base_url, :user_agent, :proxy, :apikey, :logger_enabled
16
+ attr_reader :base_url, :user_agent, :proxy, :apikey, :logger_enabled, :logger_middleware, :logger_options
17
17
 
18
18
  def initialize(options = {})
19
19
  @base_url = options[:base_url] || BASE_URL
@@ -21,6 +21,8 @@ module Ibancom
21
21
  @proxy = options[:proxy]
22
22
  @apikey = options[:apikey] || ENV["IBANCOM_APIKEY"]
23
23
  @logger_enabled = options[:logger_enabled].nil? ? true : options[:logger_enabled]
24
+ @logger_middleware = options.fetch(:logger_middleware, Faraday::Response::Logger)
25
+ @logger_options = options.fetch(:logger_options, {})
24
26
  @services = {}
25
27
  end
26
28
 
@@ -34,7 +36,7 @@ module Ibancom
34
36
  parser_options: { symbolize_names: true }
35
37
  builder.proxy = @proxy if proxy
36
38
  if @logger_enabled
37
- builder.response :logger, nil, { headers: true, bodies: true } do |logger|
39
+ builder.use @logger_middleware, nil, { headers: true, bodies: true }.merge(@logger_options) do |logger|
38
40
  logger.filter(/("password":)"(\w+)"/, '\1[FILTERED]')
39
41
  end
40
42
  end
@@ -31,3 +31,10 @@ require_relative "iban/checks"
31
31
  require_relative "iban/check"
32
32
  require_relative "iban/schemes"
33
33
  require_relative "iban/scheme"
34
+ require_relative "scan/validation"
35
+ require_relative "scan/bank"
36
+ require_relative "scan/account"
37
+ require_relative "scan/checks"
38
+ require_relative "scan/check"
39
+ require_relative "scan/schemes"
40
+ require_relative "scan/scheme"
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibancom
4
+ module Resources
5
+ module SCAN
6
+ class Account < Base
7
+ attr_accessor :sortcode,
8
+ :account,
9
+ :iban
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibancom
4
+ module Resources
5
+ module SCAN
6
+ class Bank < Base
7
+ attr_accessor :bic,
8
+ :branch,
9
+ :bank,
10
+ :address,
11
+ :city,
12
+ :zip,
13
+ :phone,
14
+ :country
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibancom
4
+ module Resources
5
+ module SCAN
6
+ class Check < Base
7
+ PASSED_MESSAGES = {
8
+ "001" => "Modulus Success: Check digit is valid",
9
+ "002" => "Sort Code found in bank directory",
10
+ "006" => "Sort Code does not contain illegal characters",
11
+ "007" => "Account Number does not contain illegal characters",
12
+ "008" => "Sort Code length is correct",
13
+ "009" => "Account Number length is correct",
14
+ }.freeze
15
+
16
+ attr_accessor :type,
17
+ :code,
18
+ :message
19
+
20
+ def passed?
21
+ PASSED_MESSAGES[code] == message
22
+ end
23
+
24
+ def failed?
25
+ !passed?
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibancom
4
+ module Resources
5
+ module SCAN
6
+ class Checks < Collection
7
+ def initialize(response, attributes_collection)
8
+ parsed = attributes_collection.map do |check_attributes|
9
+ {
10
+ type: check_attributes[0],
11
+ code: check_attributes[1][:code],
12
+ message: check_attributes[1][:message],
13
+ }
14
+ end
15
+ super(response, Check, parsed)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibancom
4
+ module Resources
5
+ module SCAN
6
+ class Scheme < Base
7
+ attr_accessor :code,
8
+ :supported
9
+
10
+ def supported?
11
+ supported == "YES"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibancom
4
+ module Resources
5
+ module SCAN
6
+ class Schemes < Collection
7
+ def initialize(response, attributes_collection)
8
+ parsed = attributes_collection.map do |attributes|
9
+ {
10
+ code: attributes[0],
11
+ supported: attributes[1],
12
+ }
13
+ end
14
+ super(response, Scheme, parsed)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ibancom
4
+ module Resources
5
+ module SCAN
6
+ class Validation < Base
7
+ attr_reader :bank,
8
+ :account,
9
+ :checks,
10
+ :schemes
11
+
12
+ def initialize(response, attributes = {})
13
+ super(response, attributes)
14
+ @bank = Bank.new(response, attributes[:bank_data])
15
+ @account = Account.new(response, attributes[:account_data])
16
+ @checks = Checks.new(response, attributes[:validations])
17
+ @schemes = Schemes.new(response, attributes[:payment_schemes])
18
+ end
19
+
20
+ def valid?
21
+ checks.all?(&:passed?)
22
+ end
23
+
24
+ def failed_checks
25
+ checks.select(&:failed?)
26
+ end
27
+
28
+ def supported_schemes
29
+ schemes.select(&:supported?)
30
+ end
31
+
32
+ def supported_scheme?(code)
33
+ scheme = supported_schemes.find { |supported| supported.code == code }
34
+
35
+ return false if scheme.nil?
36
+
37
+ scheme.supported?
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ibancom
4
- VERSION = "0.0.10"
4
+ VERSION = "0.0.12"
5
5
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibancom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aitor García Rey
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-04-06 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: faraday
@@ -198,6 +197,13 @@ files:
198
197
  - lib/ibancom/resources/iban/scheme.rb
199
198
  - lib/ibancom/resources/iban/schemes.rb
200
199
  - lib/ibancom/resources/iban/validation.rb
200
+ - lib/ibancom/resources/scan/account.rb
201
+ - lib/ibancom/resources/scan/bank.rb
202
+ - lib/ibancom/resources/scan/check.rb
203
+ - lib/ibancom/resources/scan/checks.rb
204
+ - lib/ibancom/resources/scan/scheme.rb
205
+ - lib/ibancom/resources/scan/schemes.rb
206
+ - lib/ibancom/resources/scan/validation.rb
201
207
  - lib/ibancom/version.rb
202
208
  - sig/ibancom.rbs
203
209
  homepage: https://github.com/devengoapp/ibancom-ruby
@@ -207,7 +213,6 @@ metadata:
207
213
  homepage_uri: https://github.com/devengoapp/ibancom-ruby
208
214
  source_code_uri: https://github.com/devengoapp/ibancom-ruby
209
215
  rubygems_mfa_required: 'true'
210
- post_install_message:
211
216
  rdoc_options: []
212
217
  require_paths:
213
218
  - lib
@@ -222,8 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
222
227
  - !ruby/object:Gem::Version
223
228
  version: '0'
224
229
  requirements: []
225
- rubygems_version: 3.4.10
226
- signing_key:
230
+ rubygems_version: 3.6.9
227
231
  specification_version: 4
228
232
  summary: Ruby client for iban.com APIs
229
233
  test_files: []