nohead 0.21.0 → 0.23.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: 12718345b49b3cfdce0b7fe66bb9e9447be9e05c98d7e6c6c31b697cd333baa1
4
- data.tar.gz: bbcec79d66fde2237fb0459d33bc970e8ba1f3008bdc57a7e9e9d7c3a9a364d7
3
+ metadata.gz: a99211f471e2f677b87b48aee6ccf2343e95574763b69461ce33991f7f442491
4
+ data.tar.gz: 68d39ad922b0f0368699117e1b71d1a1391202b6e6896794e59f4db67c2b7353
5
5
  SHA512:
6
- metadata.gz: aa14190d22b2a93bfd7d2296c963d739e5ab404d5ff103427a02cb170b50178505f099c754ead1e8af83fb12b89ae44eb3f131785c4fe4e136fe9d7128842df6
7
- data.tar.gz: 3fce33534b094a2e4580231eea85f1cd40c33f19814bb90bee77642beddebe8d1151dad85d2a3aa8ad8ba8dfb756f3d4d3a317462e3390baa5a905720fe09a7a
6
+ metadata.gz: 2feda70365877cc8f3c199fb4021efdb80c026f3aff8871abc19ba95589087fe16e9fd0709cbb072590f47ed53161be2c662f80360edd8591f7f9fab36ad9896
7
+ data.tar.gz: 17783fc5240e96c4eb2ba6d1c13b271204af61da9403621b9af1fd88efa05f5df4e2b30a43973426acc69bad76b0c3dfc04268a55cc66bf1c4028662cc9b595d
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.23.0
9
+
10
+ - A webhook's `failing_since` and `last_succeeded_at` (its health) are
11
+ read as `Time`, like its other timestamps.
12
+
13
+ ## 0.22.0
14
+
15
+ - `ValidationError#field_errors`: the first message for each field, by its
16
+ key (`{ "email" => "is required" }`), to show beside a form's fields.
17
+ Details without a field are left out; `details` keeps every code.
18
+
8
19
  ## 0.21.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`.
@@ -90,9 +90,9 @@ module Nohead
90
90
  # The names of the timestamp fields in responses and webhook events.
91
91
  TIMESTAMPS = %w[
92
92
  at cancel_requested_at completed_at created_at deleted_at expires_at
93
- last_attempt_at last_built_at merge_at next_attempt_at publish_at published_at
94
- purge_after rebuild_requested_at started_at succeeded_at time unpublish_at
95
- updated_at uploaded_at
93
+ failing_since last_attempt_at last_built_at last_succeeded_at merge_at next_attempt_at
94
+ publish_at published_at purge_after rebuild_requested_at started_at succeeded_at
95
+ time unpublish_at updated_at uploaded_at
96
96
  ].to_set.freeze
97
97
 
98
98
  # The objects whose `data` is a record's field values.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nohead
4
- VERSION = "0.21.0"
4
+ VERSION = "0.23.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.21.0
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nohead