nohead 0.20.0 → 0.22.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: 8bf6d26be7e17af4065b68ec627ad62ebb99635b62ab8b2fa2dcd66e69515c91
4
- data.tar.gz: 35bb357014e3ae20c267cbf192961f332470624a7c3a39c5415566b50d8b20c9
3
+ metadata.gz: 1635a80aebc12509563ede6922a27454a90929d9b77095ff3fa0f44d8e265c1c
4
+ data.tar.gz: 7102d397fab4069d4390d839537ad46b5d62cf22b8dda241e7778133127304e3
5
5
  SHA512:
6
- metadata.gz: e93e7657f576da5b95f1c46d0c473aff95ee3af4a00b30bd4d6a355cc25e6f320aa2b826e5d80bb148a30accce61ea0fc854722314beffa04e62ebbc4fba4313
7
- data.tar.gz: 8f52054438991236c977b7c817260fba7379cadff8b2e3ca0aaa904fa344c9eb356b74123400e2aa24737138448aba3dd305e94e7d83cae92317b7aedc1af61b
6
+ metadata.gz: ef32fd9f6368e9048b00c05eeef555502c1c5d7c662102dc090fb3b3118d0f7350ebed31a5bc159ca7d8073a3b795bf5de1145afd1b506fdebdaa62116a39cd6
7
+ data.tar.gz: c358478c9b13b88326a2e952ffb51def1900250e8d6773c39971e4eea78d49e48444e859796d4ea67a12cf0c6d00ae581267dcedb5d8bd4ab8a7cdc2a2e5b442
data/CHANGELOG.md CHANGED
@@ -5,6 +5,17 @@ Changes to the `nohead` gem that you can notice. Versions follow
5
5
  releases; a change that could break your code is a major one. Each release's
6
6
  section is its GitHub release's notes.
7
7
 
8
+ ## 0.22.0
9
+
10
+ - `ValidationError#field_errors`: the first message for each field, by its
11
+ key (`{ "email" => "is required" }`), to show beside a form's fields.
12
+ Details without a field are left out; `details` keeps every code.
13
+
14
+ ## 0.21.0
15
+
16
+ - Nothing changed in the gem: the SDKs share one version, and this release
17
+ matches the TypeScript SDK's 0.21.0, whose public search changed.
18
+
8
19
  ## 0.20.0
9
20
 
10
21
  - Nothing changed in the gem: the SDKs share one version, and this release
data/README.md CHANGED
@@ -179,7 +179,7 @@ Every error is a `Nohead::Error`. API errors are `Nohead::APIError`s with `statu
179
179
  | `NotFoundError` | 404 |
180
180
  | `ConflictError` | 409 |
181
181
  | `PreconditionFailedError` | 412 (`current_revision`) |
182
- | `ValidationError` | 422 |
182
+ | `ValidationError` | 422 (`field_errors`) |
183
183
  | `RateLimitError` | 429 (`retry_after`) |
184
184
  | `InternalServerError` | 500 and other 5xx |
185
185
  | `ServiceUnavailableError` | 503 |
@@ -192,11 +192,14 @@ Other errors:
192
192
  - `Nohead::UploadError`
193
193
  - `Nohead::WebhookVerificationError`
194
194
 
195
+ A form that writes a record shows a `ValidationError`'s `field_errors` beside its fields: the first message for each field, by its key. `details` has every problem with its `code` (`required`, `taken`), for words of your own.
196
+
195
197
  ```ruby
196
- begin
197
- nohead.records.create("posts", data: {})
198
+ def apply(name, email)
199
+ nohead.records.create("applications", data: { name: name, email: email })
200
+ { sent: true }
198
201
  rescue Nohead::ValidationError => e
199
- e.details.each { |detail| puts "#{detail.field}: #{detail.message}" }
202
+ { sent: false, errors: e.field_errors } # { "email" => "is required" }
200
203
  end
201
204
  ```
202
205
 
data/lib/nohead/errors.rb CHANGED
@@ -67,7 +67,17 @@ module Nohead
67
67
  end
68
68
  end
69
69
 
70
- class ValidationError < APIError; end
70
+ class ValidationError < APIError
71
+ # The first message for each field, by its key: { "title" => "is required" },
72
+ # to show beside a form's fields. Details without a field are left out;
73
+ # `details` keeps their codes.
74
+ def field_errors
75
+ details.each_with_object({}) do |detail, errors|
76
+ field = detail["field"]
77
+ errors[field] = detail["message"] unless field.to_s.empty? || errors.key?(field)
78
+ end
79
+ end
80
+ end
71
81
 
72
82
  class RateLimitError < APIError
73
83
  # Seconds to wait before retrying, from `Retry-After`.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nohead
4
- VERSION = "0.20.0"
4
+ VERSION = "0.22.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nohead
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.0
4
+ version: 0.22.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nohead