ibanchecker 0.1.1 → 0.2.0

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: 703ae63dc085318f0be9dbea66816f2b2798fef508d2a3f3f6fe16d158c3834a
4
- data.tar.gz: 8f11660e9baa9c337dea6e73ad88e014199a4e3abe5c25b63f3ec15aab6e127e
3
+ metadata.gz: d00ef9634e78ac5fc15e6b8ecebd062ff3895aaf42bac32f25d5e22ba386dba0
4
+ data.tar.gz: a3ec40a1a31fd4ed438c866165efa6694fdada54d6a70daeb3f0117e7a9b6db2
5
5
  SHA512:
6
- metadata.gz: 6ffeb4593b42dc8d1b25aeb889c529046490d33779681816feca20dd3ff636337f25f805cb2e2e521b444a202517e4ac5d2c149a5d5281d560d5c7cc41697e8b
7
- data.tar.gz: '08d302dbe4737762672566fbc543e9bdd88bbcc1e5d63bef974747b772acc190d31e6f92f1083ca1ebd732791f7e24f606f1c5630a4679dc0864a88bf253e2a7'
6
+ metadata.gz: 92f3b4913894448f8bdcd31d63719f00b88d6ba43ea95b99ea7f66df0d4aa9ea39bf714bb587449259f63125c842aef8bad242f2b90ab044001c2209158e3d7f
7
+ data.tar.gz: 6e2e326f13f1abf1bcbff9e1ec47ae8ae4f1a1626cb0ef98d26f4d459d35006ae20c9551e272a614ee61bb0dda68655b8b72d83ece47e751757b08c6b914ea9d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.0
4
+
5
+ - `bank_logo` on `ValidationResult` and `BankRecord`, as a new `IbanChecker::BankLogo`: the bank's logo, from the API's new `bank_logo` field on validation, bulk validation, extraction and BIC lookup. It holds a file for light and for dark backgrounds, whether the dark file needs a light backing, and the format; it is empty when no verified logo is held for the bank
6
+
7
+ ## 0.1.2
8
+
9
+ Documentation only.
10
+
11
+ - The API now requires a key for every call except `country_format`:
12
+ `lookup_bic` without one gets a 401 and the client raises
13
+ `AuthenticationError`. The hourly limit for requests without a key (100 an
14
+ hour per IP) now covers `country_format` only
15
+ - What a key can call follows its plan. The free key covers `validate`, 100
16
+ requests a month; `validate_bulk` and `lookup_bic` need Basic or above;
17
+ `extract` needs Growth or above. A key with a verified account can try the
18
+ calls its plan lacks, with up to 10 IBANs per bulk call and 5,000
19
+ characters per extraction; a trial call over that size gets a 400
20
+ (`TOO_MANY_IBANS` or `TEXT_TOO_LONG`)
21
+ - A call outside the key's plan gets a 403 with `error_code`
22
+ `PLAN_REQUIRED`, which the client raises as `APIError`; `#response` carries
23
+ `required_plan` and `upgrade_url`
24
+ - `validate_bulk` counts one request per IBAN and `extract` one per IBAN
25
+ found, at least one per call. A call that costs more than the requests left
26
+ this month gets a 429 `QUOTA_EXCEEDED`, raised as `RateLimitError`
27
+ - README and doc comments say which plan each call needs
28
+
29
+ The client's behaviour does not change.
30
+
3
31
  ## 0.1.1
4
32
 
5
33
  Documentation only; the client's behaviour is unchanged.
data/README.md CHANGED
@@ -20,7 +20,7 @@ Requires Ruby 2.7 or newer. There are no runtime dependencies: the client is bui
20
20
 
21
21
  ## Quick start
22
22
 
23
- Validation, bulk validation and extraction need an API key. A free key covers 100 requests a month and arrives by email in seconds from [ibanchecker.cash/api-docs](https://ibanchecker.cash/api-docs).
23
+ Every call except `country_format` needs an API key. A free key covers single IBAN validation, 100 requests a month, and arrives by email in seconds from [ibanchecker.cash/api-docs](https://ibanchecker.cash/api-docs).
24
24
 
25
25
  ```ruby
26
26
  require "ibanchecker"
@@ -41,31 +41,51 @@ end
41
41
 
42
42
  ## Authentication
43
43
 
44
- `validate`, `validate_bulk` and `extract` need an API key. Without one the API answers HTTP 401 and the client raises `IbanChecker::AuthenticationError`. The free key from [ibanchecker.cash/api-docs](https://ibanchecker.cash/api-docs) covers 100 requests a month; paid plans are at [ibanchecker.cash/pricing](https://ibanchecker.cash/pricing).
44
+ `validate`, `validate_bulk`, `extract` and `lookup_bic` need an API key. Without one the API answers HTTP 401 and the client raises `IbanChecker::AuthenticationError`. `lookup_bic` used to work without a key; it no longer does. The free key from [ibanchecker.cash/api-docs](https://ibanchecker.cash/api-docs) covers `validate` only, 100 requests a month; paid plans are at [ibanchecker.cash/pricing](https://ibanchecker.cash/pricing).
45
45
 
46
- `country_format` and `lookup_bic` work without a key, limited to 100 requests an hour per IP.
46
+ `country_format` is the only call that works without a key, limited to 100 requests an hour per IP. Beyond that the API answers HTTP 429 with `error_code` `"RATE_LIMIT_EXCEEDED"`. This hourly limit applies to `country_format` only.
47
47
 
48
48
  ```ruby
49
49
  client = IbanChecker::Client.new("iban_your_api_key")
50
50
  client = IbanChecker::Client.new(ENV["IBANCHECKER_API_KEY"])
51
51
 
52
- lookups = IbanChecker::Client.new # country_format and lookup_bic only
52
+ formats = IbanChecker::Client.new # country_format only
53
53
  ```
54
54
 
55
+ ### What each plan can call
56
+
57
+ | Method | Plan | Largest call |
58
+ | --- | --- | --- |
59
+ | `validate` | any key, including the free key | one IBAN |
60
+ | `validate_bulk` | Basic or above (Basic, Starter, Growth, Enterprise) | 100 IBANs |
61
+ | `lookup_bic` | Basic or above (Basic, Starter, Growth, Enterprise) | one BIC |
62
+ | `extract` | Growth or above (Growth, Enterprise) | 50,000 characters |
63
+ | `country_format` | no key needed | one country |
64
+
65
+ A key whose email address has a verified account at [ibanchecker.cash/dashboard](https://ibanchecker.cash/dashboard) can try the calls its plan lacks: `validate_bulk` with up to 10 IBANs per call, `lookup_bic`, and `extract` with up to 5,000 characters per call. This applies to any plan that lacks the call, so a Basic key with a verified account can try `extract` as well. A trial call over that size gets HTTP 400 with `error_code` `"TOO_MANY_IBANS"` (bulk) or `"TEXT_TOO_LONG"` (extraction), which the client raises as `IbanChecker::BadRequestError`.
66
+
67
+ A call outside the key's plan gets HTTP 403 with `error_code` `"PLAN_REQUIRED"`. The client has no class of its own for 403, so it raises `IbanChecker::APIError`; the decoded body on `#response` also carries `required_plan` (`"basic"` or `"growth"`) and `upgrade_url`. See [Error handling](#error-handling).
68
+
69
+ ### How requests are counted
70
+
71
+ `validate` and `lookup_bic` count one request each. `validate_bulk` counts one request per IBAN in the call, and `extract` counts one per IBAN found, with at least one per call. A call that costs more than the requests left this month gets HTTP 429 with `error_code` `"QUOTA_EXCEEDED"`, raised as `IbanChecker::RateLimitError`.
72
+
55
73
  ## Methods
56
74
 
57
75
  | Method | API key | Description |
58
76
  | --- | --- | --- |
59
- | `validate(iban)` | required | Validate a single IBAN. Returns a `ValidationResult`. |
60
- | `validate_bulk(ibans)` | required | Validate up to 100 IBANs. Returns a `BatchResult`. |
61
- | `extract(text)` | required | Find and validate IBANs in free text (up to 50,000 chars). Returns a `BatchResult`. |
77
+ | `validate(iban)` | required, any plan | Validate a single IBAN. Returns a `ValidationResult`. |
78
+ | `validate_bulk(ibans)` | required, Basic or above | Validate up to 100 IBANs (10 on a trial). Returns a `BatchResult`. |
79
+ | `extract(text)` | required, Growth or above | Find and validate IBANs in free text (up to 50,000 chars, 5,000 on a trial). Returns a `BatchResult`. |
62
80
  | `country_format(country)` | optional | IBAN format spec for an ISO country code. Returns a `FormatSpec`. |
63
- | `lookup_bic(bic)` | optional | Resolve an 8 or 11 character BIC. Returns a `BankRecord`. |
81
+ | `lookup_bic(bic)` | required, Basic or above | Resolve an 8 or 11 character BIC. Returns a `BankRecord`. |
64
82
 
65
83
  `country_format` is the one name that differs from the other ibanchecker clients, where it is `getFormat`. `format` is `Kernel#format`, Ruby's `sprintf`, so a method by that name on this class would shadow it for every line inside the class.
66
84
 
67
85
  ### Bulk validation
68
86
 
87
+ Needs a key on the Basic plan or above, or a trial (see [What each plan can call](#what-each-plan-can-call)). Each IBAN in the call counts as one request.
88
+
69
89
  ```ruby
70
90
  batch = client.validate_bulk([
71
91
  "DE89370400440532013000",
@@ -86,6 +106,8 @@ end
86
106
 
87
107
  ### Extract from text
88
108
 
109
+ Needs a key on the Growth plan or above, or a trial. Each IBAN found counts as one request, with at least one per call.
110
+
89
111
  ```ruby
90
112
  batch = client.extract("Please wire to DE89 3704 0044 0532 0130 00 by Friday.")
91
113
 
@@ -95,6 +117,8 @@ batch.map { |r| [r.iban, r.bank_name] }
95
117
 
96
118
  ### Country format and BIC lookup
97
119
 
120
+ `country_format` works without a key. `lookup_bic` needs a key on the Basic plan or above, or a trial.
121
+
98
122
  ```ruby
99
123
  format = client.country_format("DE")
100
124
  format.length # => 22
@@ -123,6 +147,16 @@ end
123
147
 
124
148
  `valid?` is the only predicate method on the models, because it is the only field that is always a boolean. `national_check_valid` and `sepa` can each be `nil`, and `nil` there means "not known for this IBAN" rather than "no", so they are plain readers and you compare them explicitly.
125
149
 
150
+ ### Bank logo
151
+
152
+ `result.bank_logo` and `bank.bank_logo` are an `IbanChecker::BankLogo`, or `nil` when no verified logo is held for the bank. It carries the mark the ibanchecker.cash result card shows: a file for light backgrounds, a file for dark backgrounds (the same URL when one file reads on both), whether the dark file needs a light chip behind it, and the format (`svg`, `png` or `webp`). Every logo is checked by hand against the bank's current mark, so not every bank has one yet; the field is empty then. The logos are the banks' trademarks, provided to identify the bank.
153
+
154
+ ```ruby
155
+ if (logo = result.bank_logo)
156
+ [logo.on_light, logo.on_dark, logo.dark_needs_light_backing, logo.format]
157
+ end
158
+ ```
159
+
126
160
  ## Error handling
127
161
 
128
162
  A malformed IBAN is **not** an error: `validate` returns a `ValidationResult` with `valid?` false. Errors are raised only for transport, authentication, quota and server-side problems.
@@ -136,16 +170,20 @@ rescue IbanChecker::RateLimitError => e
136
170
  puts "Slow down: #{e.message}"
137
171
  rescue IbanChecker::AuthenticationError
138
172
  puts "Check your API key"
173
+ rescue IbanChecker::APIError => e
174
+ raise unless e.error_code == "PLAN_REQUIRED"
175
+
176
+ puts "Needs the #{e.response["required_plan"]} plan: #{e.response["upgrade_url"]}"
139
177
  end
140
178
  ```
141
179
 
142
180
  | Class | Raised when |
143
181
  | --- | --- |
144
- | `IbanChecker::BadRequestError` | HTTP 400, the request was malformed |
145
- | `IbanChecker::AuthenticationError` | HTTP 401, the API key is missing, invalid or inactive |
182
+ | `IbanChecker::BadRequestError` | HTTP 400, the request was malformed, or a trial call was over the trial size (`error_code` `"TOO_MANY_IBANS"` or `"TEXT_TOO_LONG"`) |
183
+ | `IbanChecker::AuthenticationError` | HTTP 401, the API key is missing, invalid or inactive; every call except `country_format` gets this without a key |
146
184
  | `IbanChecker::NotFoundError` | HTTP 404, no such country code or BIC |
147
- | `IbanChecker::RateLimitError` | HTTP 429, the key's monthly quota (`error_code` `"QUOTA_EXCEEDED"`) or the hourly limit for requests without a key (`"RATE_LIMIT_EXCEEDED"`) was exceeded |
148
- | `IbanChecker::APIError` | any other error status, or a body that could not be read |
185
+ | `IbanChecker::RateLimitError` | HTTP 429, the key's monthly quota was exceeded or the call costs more than the requests left (`error_code` `"QUOTA_EXCEEDED"`), or `country_format` without a key went over 100 requests an hour (`"RATE_LIMIT_EXCEEDED"`) |
186
+ | `IbanChecker::APIError` | any other error status, including HTTP 403 for a call outside the key's plan (`error_code` `"PLAN_REQUIRED"`), or a body that could not be read |
149
187
  | `IbanChecker::TransportError` | the request never reached the API: DNS, TLS, connection, timeout |
150
188
 
151
189
  All of them inherit from `IbanChecker::Error`, so one `rescue IbanChecker::Error` catches everything this gem raises. Each carries `#status`, `#error_code` and `#response`.
@@ -9,11 +9,20 @@ module IbanChecker
9
9
  # extract IBANs from free text, look up country format specifications and
10
10
  # resolve SWIFT/BIC codes.
11
11
  #
12
- # validate, validate_bulk and extract need an API key; without one the API
13
- # answers 401 and AuthenticationError is raised. The free key from
14
- # https://ibanchecker.cash/api-docs covers 100 requests a month.
15
- # country_format and lookup_bic work without a key, limited to 100 requests
16
- # an hour per IP.
12
+ # Every call except country_format needs an API key; without one the API
13
+ # answers 401 and AuthenticationError is raised. That includes lookup_bic,
14
+ # which used to work without a key. The free key from
15
+ # https://ibanchecker.cash/api-docs covers validate only, 100 requests a
16
+ # month. validate_bulk and lookup_bic need the Basic plan or above, and
17
+ # extract the Growth plan or above. A key whose email address has a verified
18
+ # account at https://ibanchecker.cash/dashboard can try the calls its plan
19
+ # lacks (validate_bulk up to 10 IBANs, extract up to 5,000 characters per
20
+ # call). A call outside the key's plan gets a 403 with error_code
21
+ # "PLAN_REQUIRED", raised as APIError; its #response carries required_plan
22
+ # and upgrade_url.
23
+ #
24
+ # country_format works without a key, limited to 100 requests an hour per
25
+ # IP. That hourly limit applies to country_format only.
17
26
  #
18
27
  # client = IbanChecker::Client.new(ENV["IBANCHECKER_API_KEY"]) # or .new("iban_your_key")
19
28
  # result = client.validate("DE89 3704 0044 0532 0130 00")
@@ -46,7 +55,7 @@ module IbanChecker
46
55
  # A malformed IBAN is not an error: the result comes back with +valid?+
47
56
  # false and an +error+ plus +error_code+ explaining why.
48
57
  #
49
- # Needs an API key.
58
+ # Needs an API key; the free key covers it. Counts one request.
50
59
  def validate(iban)
51
60
  ValidationResult.from_api(request("POST", "/validate", "iban" => iban.to_s))
52
61
  end
@@ -54,7 +63,8 @@ module IbanChecker
54
63
  # Validate up to 100 IBANs in one request. Results come back in the same
55
64
  # order as the input.
56
65
  #
57
- # Needs an API key.
66
+ # Needs an API key on the Basic plan or above, or a trial of up to 10 IBANs
67
+ # per call for a key with a verified account. Counts one request per IBAN.
58
68
  def validate_bulk(ibans)
59
69
  BatchResult.from_api(
60
70
  request("POST", "/validate/bulk", "ibans" => Array(ibans).map(&:to_s))
@@ -64,7 +74,9 @@ module IbanChecker
64
74
  # Scan free text (emails, invoices) for IBAN-shaped strings and validate
65
75
  # each candidate. Up to 50,000 characters per request.
66
76
  #
67
- # Needs an API key.
77
+ # Needs an API key on the Growth plan or above, or a trial of up to 5,000
78
+ # characters per call for a key with a verified account. Counts one request
79
+ # per IBAN found, with at least one per call.
68
80
  def extract(text)
69
81
  BatchResult.from_api(request("POST", "/extract", "text" => text.to_s))
70
82
  end
@@ -74,11 +86,19 @@ module IbanChecker
74
86
  #
75
87
  # Named country_format rather than format because Kernel#format is
76
88
  # sprintf, and shadowing it inside this class would be a trap.
89
+ #
90
+ # The only call that works without a key, limited to 100 requests an hour
91
+ # per IP.
77
92
  def country_format(country)
78
93
  FormatSpec.from_api(request("GET", "/formats/#{escape(country.to_s.downcase)}"))
79
94
  end
80
95
 
81
96
  # Resolve an 8 or 11 character ISO 9362 BIC to a bank record.
97
+ #
98
+ # Needs an API key on the Basic plan or above, or a trial for a key with a
99
+ # verified account. Without a key the API answers 401 and
100
+ # AuthenticationError is raised; it no longer works keyless. Counts one
101
+ # request.
82
102
  def lookup_bic(bic)
83
103
  BankRecord.from_api(request("GET", "/swift/#{escape(bic.to_s.upcase)}"))
84
104
  end
@@ -24,20 +24,32 @@ module IbanChecker
24
24
  end
25
25
  end
26
26
 
27
- # The request was malformed (HTTP 400).
27
+ # The request was malformed, or a trial call was over the trial size
28
+ # ("TOO_MANY_IBANS" for bulk, "TEXT_TOO_LONG" for extraction) (HTTP 400).
28
29
  class BadRequestError < Error; end
29
30
 
30
31
  # The API key is missing, invalid or inactive (HTTP 401).
32
+ #
33
+ # Every call except Client#country_format needs a key, so a call without
34
+ # one, a Client#lookup_bic included, gets this from the API's 401.
31
35
  class AuthenticationError < Error; end
32
36
 
33
37
  # The requested country code or BIC was not found (HTTP 404).
34
38
  class NotFoundError < Error; end
35
39
 
36
- # The key's monthly quota ("QUOTA_EXCEEDED") or the hourly limit for requests
37
- # without a key ("RATE_LIMIT_EXCEEDED") was exceeded (HTTP 429).
40
+ # The key's monthly quota was exceeded, or the call costs more than the
41
+ # requests left this month ("QUOTA_EXCEEDED"), or Client#country_format
42
+ # without a key went over 100 requests an hour ("RATE_LIMIT_EXCEEDED")
43
+ # (HTTP 429). Bulk validation counts one request per IBAN and extraction one
44
+ # per IBAN found.
38
45
  class RateLimitError < Error; end
39
46
 
40
- # An unexpected server-side error, or a body that could not be read.
47
+ # Any error status without a class of its own, or a body that could not be
48
+ # read.
49
+ #
50
+ # This includes HTTP 403 for a call outside the key's plan: error_code is
51
+ # "PLAN_REQUIRED" and #response carries "required_plan" ("basic" or
52
+ # "growth") and "upgrade_url".
41
53
  class APIError < Error; end
42
54
 
43
55
  # The request never reached the API: DNS, TLS, connection or timeout.
@@ -27,6 +27,41 @@ module IbanChecker
27
27
  end
28
28
  end
29
29
 
30
+ # The bank's logo as the ibanchecker.cash result card shows it. The logos are
31
+ # the banks' trademarks, provided to identify the bank.
32
+ #
33
+ # +on_light+ is drawn on a light background and +on_dark+ on a dark one (the
34
+ # same URL when one file reads on both). When +dark_needs_light_backing+ is
35
+ # true, +on_dark+ has no dark variant and should sit on a light chip.
36
+ # +format+ is "svg", "png" or "webp".
37
+ class BankLogo
38
+ attr_reader :on_light, :on_dark, :dark_needs_light_backing, :format
39
+
40
+ # The untouched logo object from the API response.
41
+ attr_reader :raw
42
+
43
+ def initialize(on_light:, on_dark:, dark_needs_light_backing:, format:, raw: {})
44
+ @on_light = on_light
45
+ @on_dark = on_dark
46
+ @dark_needs_light_backing = dark_needs_light_backing
47
+ @format = format
48
+ @raw = raw
49
+ end
50
+
51
+ # nil when the API holds no verified logo for the bank.
52
+ def self.from_api(data)
53
+ return nil unless data.is_a?(Hash) && !data.empty?
54
+
55
+ new(
56
+ on_light: data["on_light"],
57
+ on_dark: data["on_dark"],
58
+ dark_needs_light_backing: data["dark_needs_light_backing"] == true,
59
+ format: data["format"],
60
+ raw: data
61
+ )
62
+ end
63
+ end
64
+
30
65
  # The result of validating one IBAN.
31
66
  #
32
67
  # +valid?+ is the primary flag. When it is false only +iban+, +formatted+,
@@ -38,7 +73,7 @@ module IbanChecker
38
73
  class ValidationResult
39
74
  ATTRIBUTES = %i[
40
75
  iban formatted check_digits bban country country_name
41
- bank_name bank_type bic bank_city bank_code branch_code account_number
76
+ bank_name bank_type bic bank_city bank_logo bank_code branch_code account_number
42
77
  national_check_valid currency currency_name transfer_type sepa flag
43
78
  error error_code
44
79
  ].freeze
@@ -78,6 +113,7 @@ module IbanChecker
78
113
  bank_type: data["bank_type"],
79
114
  bic: data["bic"],
80
115
  bank_city: data["bank_city"],
116
+ bank_logo: BankLogo.from_api(data["bank_logo"]),
81
117
  bank_code: data["bank_code"],
82
118
  branch_code: data["branch_code"],
83
119
  account_number: data["account_number"],
@@ -185,7 +221,7 @@ module IbanChecker
185
221
  class BankRecord
186
222
  ATTRIBUTES = %i[
187
223
  bic bic8 bank_code country_code location_code branch_code
188
- bank_name city country_name sepa type status
224
+ bank_name bank_logo city country_name sepa type status
189
225
  ].freeze
190
226
 
191
227
  attr_reader(*ATTRIBUTES)
@@ -207,6 +243,7 @@ module IbanChecker
207
243
  location_code: data["location_code"],
208
244
  branch_code: data["branch_code"],
209
245
  bank_name: data["bank_name"],
246
+ bank_logo: BankLogo.from_api(data["bank_logo"]),
210
247
  city: data["city"],
211
248
  country_name: data["country_name"],
212
249
  sepa: data["sepa"],
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IbanChecker
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ibanchecker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ibanchecker.cash