ibanchecker 0.1.0 → 0.1.2

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: 5959a043f0fe0044a65aa74d7203b57aeeafd050934efa28b7776dd938f3026b
4
- data.tar.gz: 891de691976d13de1c3e5a3a9bb50f4a79ffdbae62f3f2d4f45b445ca03ea125
3
+ metadata.gz: bf9e74cb7e1a343e35c3bdd80928cbbf38872341b2c3b0f51959fde4bec0d96a
4
+ data.tar.gz: f83727602f144aa5e9da5f6e33b96e25ae6dda5b45e01bdc0c3af90222f716b4
5
5
  SHA512:
6
- metadata.gz: bce4770bafedfb4fc03437f602200ecc469d8bc7ed2c85615797ad8a743ef98d4ce14510035b55785ab72f79514bdacca6b951772e1fa68715d6ced637188384
7
- data.tar.gz: 6b6186281e8edb97df2a3fb7b7ea6677df6a7850262265a518a0e06ac1f199d2d1798bf93184e146b66b313b11f20f5f4d91b13c5f649c8fc934d501ff3d7114
6
+ metadata.gz: 7eeb15b1513861115327946aabc8825a9c28cc985aca96edc69b9f9e1bb523e23911ed90eb51243f241ec7ca19159435d16c13ab96f9d12512fd196c3edb7ad8
7
+ data.tar.gz: 9f64287aa482efb5ab341ce5416280d17f3469b8d0e1a8136cb223472ca8257e813105e16afa293f67feed2cf719a55b5e485bdb19f29fb5d32ea5293c3fd2d2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.2
4
+
5
+ Documentation only.
6
+
7
+ - The API now requires a key for every call except `country_format`:
8
+ `lookup_bic` without one gets a 401 and the client raises
9
+ `AuthenticationError`. The hourly limit for requests without a key (100 an
10
+ hour per IP) now covers `country_format` only
11
+ - What a key can call follows its plan. The free key covers `validate`, 100
12
+ requests a month; `validate_bulk` and `lookup_bic` need Basic or above;
13
+ `extract` needs Growth or above. A key with a verified account can try the
14
+ calls its plan lacks, with up to 10 IBANs per bulk call and 5,000
15
+ characters per extraction; a trial call over that size gets a 400
16
+ (`TOO_MANY_IBANS` or `TEXT_TOO_LONG`)
17
+ - A call outside the key's plan gets a 403 with `error_code`
18
+ `PLAN_REQUIRED`, which the client raises as `APIError`; `#response` carries
19
+ `required_plan` and `upgrade_url`
20
+ - `validate_bulk` counts one request per IBAN and `extract` one per IBAN
21
+ found, at least one per call. A call that costs more than the requests left
22
+ this month gets a 429 `QUOTA_EXCEEDED`, raised as `RateLimitError`
23
+ - README and doc comments say which plan each call needs
24
+
25
+ The client's behaviour does not change.
26
+
27
+ ## 0.1.1
28
+
29
+ Documentation only; the client's behaviour is unchanged.
30
+
31
+ - The API now requires a key for `validate`, `validate_bulk` and `extract`:
32
+ without one it answers 401 and the client raises `AuthenticationError`. The
33
+ free key covers 100 requests a month
34
+ - `country_format` and `lookup_bic` still work without a key, limited to 100
35
+ requests an hour per IP
36
+ - README, examples and doc comments construct the client with a key and say
37
+ which calls need it
38
+
3
39
  ## 0.1.0
4
40
 
5
41
  First release.
data/README.md CHANGED
@@ -20,10 +20,12 @@ Requires Ruby 2.7 or newer. There are no runtime dependencies: the client is bui
20
20
 
21
21
  ## Quick start
22
22
 
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
+
23
25
  ```ruby
24
26
  require "ibanchecker"
25
27
 
26
- client = IbanChecker::Client.new # no API key needed for light use (100 requests/hour per IP)
28
+ client = IbanChecker::Client.new(ENV["IBANCHECKER_API_KEY"]) # or .new("iban_your_api_key")
27
29
 
28
30
  result = client.validate("DE89 3704 0044 0532 0130 00")
29
31
 
@@ -39,27 +41,51 @@ end
39
41
 
40
42
  ## Authentication
41
43
 
42
- An API key is optional. Without one, requests are limited to 100 per hour per IP. With a key, requests count against your plan quota. Get a free key at [ibanchecker.cash/api-docs](https://ibanchecker.cash/api-docs).
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
+
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.
43
47
 
44
48
  ```ruby
45
49
  client = IbanChecker::Client.new("iban_your_api_key")
46
50
  client = IbanChecker::Client.new(ENV["IBANCHECKER_API_KEY"])
51
+
52
+ formats = IbanChecker::Client.new # country_format only
47
53
  ```
48
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
+
49
73
  ## Methods
50
74
 
51
- | Method | Description |
52
- | --- | --- |
53
- | `validate(iban)` | Validate a single IBAN. Returns a `ValidationResult`. |
54
- | `validate_bulk(ibans)` | Validate up to 100 IBANs. Returns a `BatchResult`. |
55
- | `extract(text)` | Find and validate IBANs in free text (up to 50,000 chars). Returns a `BatchResult`. |
56
- | `country_format(country)` | IBAN format spec for an ISO country code. Returns a `FormatSpec`. |
57
- | `lookup_bic(bic)` | Resolve an 8 or 11 character BIC. Returns a `BankRecord`. |
75
+ | Method | API key | Description |
76
+ | --- | --- | --- |
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`. |
80
+ | `country_format(country)` | optional | IBAN format spec for an ISO country code. Returns a `FormatSpec`. |
81
+ | `lookup_bic(bic)` | required, Basic or above | Resolve an 8 or 11 character BIC. Returns a `BankRecord`. |
58
82
 
59
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.
60
84
 
61
85
  ### Bulk validation
62
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
+
63
89
  ```ruby
64
90
  batch = client.validate_bulk([
65
91
  "DE89370400440532013000",
@@ -80,6 +106,8 @@ end
80
106
 
81
107
  ### Extract from text
82
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
+
83
111
  ```ruby
84
112
  batch = client.extract("Please wire to DE89 3704 0044 0532 0130 00 by Friday.")
85
113
 
@@ -89,6 +117,8 @@ batch.map { |r| [r.iban, r.bank_name] }
89
117
 
90
118
  ### Country format and BIC lookup
91
119
 
120
+ `country_format` works without a key. `lookup_bic` needs a key on the Basic plan or above, or a trial.
121
+
92
122
  ```ruby
93
123
  format = client.country_format("DE")
94
124
  format.length # => 22
@@ -130,16 +160,20 @@ rescue IbanChecker::RateLimitError => e
130
160
  puts "Slow down: #{e.message}"
131
161
  rescue IbanChecker::AuthenticationError
132
162
  puts "Check your API key"
163
+ rescue IbanChecker::APIError => e
164
+ raise unless e.error_code == "PLAN_REQUIRED"
165
+
166
+ puts "Needs the #{e.response["required_plan"]} plan: #{e.response["upgrade_url"]}"
133
167
  end
134
168
  ```
135
169
 
136
170
  | Class | Raised when |
137
171
  | --- | --- |
138
- | `IbanChecker::BadRequestError` | HTTP 400, the request was malformed |
139
- | `IbanChecker::AuthenticationError` | HTTP 401, the API key is missing, invalid or inactive |
172
+ | `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"`) |
173
+ | `IbanChecker::AuthenticationError` | HTTP 401, the API key is missing, invalid or inactive; every call except `country_format` gets this without a key |
140
174
  | `IbanChecker::NotFoundError` | HTTP 404, no such country code or BIC |
141
- | `IbanChecker::RateLimitError` | HTTP 429, hourly limit or monthly quota exceeded |
142
- | `IbanChecker::APIError` | any other error status, or a body that could not be read |
175
+ | `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"`) |
176
+ | `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 |
143
177
  | `IbanChecker::TransportError` | the request never reached the API: DNS, TLS, connection, timeout |
144
178
 
145
179
  All of them inherit from `IbanChecker::Error`, so one `rescue IbanChecker::Error` catches everything this gem raises. Each carries `#status`, `#error_code` and `#response`.
@@ -147,7 +181,7 @@ All of them inherit from `IbanChecker::Error`, so one `rescue IbanChecker::Error
147
181
  ## Timeouts
148
182
 
149
183
  ```ruby
150
- client = IbanChecker::Client.new(timeout: 3.0) # seconds, applied to connect and read
184
+ client = IbanChecker::Client.new(ENV["IBANCHECKER_API_KEY"], timeout: 3.0) # seconds, applied to connect and read
151
185
  ```
152
186
 
153
187
  ## Using your own HTTP stack
@@ -9,10 +9,22 @@ module IbanChecker
9
9
  # extract IBANs from free text, look up country format specifications and
10
10
  # resolve SWIFT/BIC codes.
11
11
  #
12
- # An API key is optional. Without one, requests are limited to 100 per hour
13
- # per IP. Get a free key at https://ibanchecker.cash/api-docs.
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.
14
23
  #
15
- # client = IbanChecker::Client.new # or .new("iban_your_key")
24
+ # country_format works without a key, limited to 100 requests an hour per
25
+ # IP. That hourly limit applies to country_format only.
26
+ #
27
+ # client = IbanChecker::Client.new(ENV["IBANCHECKER_API_KEY"]) # or .new("iban_your_key")
16
28
  # result = client.validate("DE89 3704 0044 0532 0130 00")
17
29
  # puts "#{result.bank_name} #{result.bic}" if result.valid?
18
30
  class Client
@@ -42,12 +54,17 @@ module IbanChecker
42
54
  #
43
55
  # A malformed IBAN is not an error: the result comes back with +valid?+
44
56
  # false and an +error+ plus +error_code+ explaining why.
57
+ #
58
+ # Needs an API key; the free key covers it. Counts one request.
45
59
  def validate(iban)
46
60
  ValidationResult.from_api(request("POST", "/validate", "iban" => iban.to_s))
47
61
  end
48
62
 
49
63
  # Validate up to 100 IBANs in one request. Results come back in the same
50
64
  # order as the input.
65
+ #
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.
51
68
  def validate_bulk(ibans)
52
69
  BatchResult.from_api(
53
70
  request("POST", "/validate/bulk", "ibans" => Array(ibans).map(&:to_s))
@@ -56,6 +73,10 @@ module IbanChecker
56
73
 
57
74
  # Scan free text (emails, invoices) for IBAN-shaped strings and validate
58
75
  # each candidate. Up to 50,000 characters per request.
76
+ #
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.
59
80
  def extract(text)
60
81
  BatchResult.from_api(request("POST", "/extract", "text" => text.to_s))
61
82
  end
@@ -65,11 +86,19 @@ module IbanChecker
65
86
  #
66
87
  # Named country_format rather than format because Kernel#format is
67
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.
68
92
  def country_format(country)
69
93
  FormatSpec.from_api(request("GET", "/formats/#{escape(country.to_s.downcase)}"))
70
94
  end
71
95
 
72
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.
73
102
  def lookup_bic(bic)
74
103
  BankRecord.from_api(request("GET", "/swift/#{escape(bic.to_s.upcase)}"))
75
104
  end
@@ -24,19 +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 hourly rate limit or the monthly quota 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.
37
45
  class RateLimitError < Error; end
38
46
 
39
- # 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".
40
53
  class APIError < Error; end
41
54
 
42
55
  # The request never reached the API: DNS, TLS, connection or timeout.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IbanChecker
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
data/lib/ibanchecker.rb CHANGED
@@ -10,7 +10,7 @@ require_relative "ibanchecker/client"
10
10
  #
11
11
  # require "ibanchecker"
12
12
  #
13
- # client = IbanChecker::Client.new
13
+ # client = IbanChecker::Client.new(ENV["IBANCHECKER_API_KEY"])
14
14
  # result = client.validate("DE89370400440532013000")
15
15
  # result.valid? # => true
16
16
  # result.bank_name # => "Commerzbank AG Cologne"
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.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ibanchecker.cash
@@ -52,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  requirements: []
55
- rubygems_version: 4.0.16
55
+ rubygems_version: 4.0.20
56
56
  specification_version: 4
57
57
  summary: Official Ruby client for the ibanchecker.cash IBAN validation API
58
58
  test_files: []