basecradle 0.8.0 → 0.9.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 +4 -4
- data/CHANGELOG.md +49 -0
- data/README.md +45 -5
- data/lib/basecradle/timeline.rb +48 -2
- data/lib/basecradle/version.rb +1 -1
- data/lib/basecradle/webhooks.rb +7 -5
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 52b94c60f28a4c6e40decde0c297a0129a7f772a3b418f1a92fca3f380278982
|
|
4
|
+
data.tar.gz: 107fd61b78588132abba3e3d958714f65dd572a5de40f5c690abd58d35f658e1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 56a8ab9c7774f5765cfb2b08096488c1784558095e8ae4e433a13ebd6ed502afee0871a571a0e01db81b77adbf8399a8466d351c4c5c43794dc9ea24c6b6f74c
|
|
7
|
+
data.tar.gz: d15b3da9c230433eeaddd427e4298dddce8042d37e1a4e6de5dd1e8a4b7384901ed7b41db5ef8d1f804787b21aef63bdf2db05757da50a702768f28fe45a81fa
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,54 @@ All notable changes to this project are documented here. The format is based on
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to
|
|
5
5
|
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [0.9.0] - 2026-09-30
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
- **A timeline item's `content` is typed by the item's `type`**
|
|
12
|
+
([#189](https://github.com/basecradle/basecradle-ruby/issues/189)). `item.content` now
|
|
13
|
+
reads as the same content model the record's own resource returns — `MessageContent`,
|
|
14
|
+
`AssetContent`, `TaskContent` or `WebhookEventContent` — where it was the raw wire
|
|
15
|
+
`Hash`. One record has one shape however you reach it, so everything those models add
|
|
16
|
+
reads down both paths: `timeline.items` gives an `AssetContent` whose `file` is an
|
|
17
|
+
`AssetFile`, and a `webhook_event` row's `content.headers` is the case-folding
|
|
18
|
+
`WebhookEventHeaders` 0.8.0 shipped, so `item.content.headers["X-GitHub-Delivery"]`
|
|
19
|
+
now finds the header it names. The previous release documented that split as a
|
|
20
|
+
boundary; it is now closed, and every future enrichment of a content model arrives on
|
|
21
|
+
both paths at once. The README documents `timeline.items` with a worked example for
|
|
22
|
+
the first time.
|
|
23
|
+
- **An item `type` this release does not know keeps reading.** The API is additive-only,
|
|
24
|
+
so an unrecognized `type` is never an error: its content comes back as a plain
|
|
25
|
+
`ApiObject`, and `content["any_field"]` still returns the wire value untouched.
|
|
26
|
+
Upgrading the SDK is what types it. An item carrying *no* `type` is a different thing
|
|
27
|
+
— a malformed response, not a new record kind — and raises `MissingFieldError` the way
|
|
28
|
+
`item.type` itself does, rather than being guessed into the generic case.
|
|
29
|
+
- The wire is untouched — `item["content"]`, `ApiObject`'s raw escape hatch, still hands
|
|
30
|
+
back exactly the `Hash` the API sent, and no field is renamed.
|
|
31
|
+
Decided in lockstep with the Python SDK's
|
|
32
|
+
[#210](https://github.com/basecradle/basecradle-python/issues/210); that port is still
|
|
33
|
+
in flight, so the two SDKs reach parity on this when it ships.
|
|
34
|
+
|
|
35
|
+
### Migrating
|
|
36
|
+
|
|
37
|
+
`item.content` was a `Hash` and is now an `ApiObject`. Reads of *named* fields get
|
|
38
|
+
better — `item.content.body` instead of `item.content["body"]`, and the models' own
|
|
39
|
+
enrichments come with them — but three things that worked on a `Hash` no longer do:
|
|
40
|
+
|
|
41
|
+
- **The `Hash` protocol is gone.** `item.content.fetch("body")`, `.each`, `.keys`,
|
|
42
|
+
`.dig(...)` and `.key?(...)` raise `NoMethodError`. Use the field reader, or
|
|
43
|
+
`item.content.to_h` for the wire `Hash` itself (`item["content"]` gives the same).
|
|
44
|
+
- **`to_json` no longer serializes the record.** `item.content.to_json` emits Ruby's
|
|
45
|
+
default `to_s` — `"#<BaseCradle::MessageContent:0x…>"`, an object address with no
|
|
46
|
+
field names — because `ApiObject` defines no `to_json`. That is long-standing for
|
|
47
|
+
every other model in the SDK and now reaches this path too. Serialize
|
|
48
|
+
`item.content.to_h` instead.
|
|
49
|
+
- **`inspect` and `==` change, both for the better.** `inspect` names the model and its
|
|
50
|
+
wire fields (`#<BaseCradle::MessageContent body, uuid>`) rather than printing a `Hash`;
|
|
51
|
+
and equality now *holds* between an item's content and the same record fetched
|
|
52
|
+
directly (`timeline.items.first.content == bc.messages.get(uuid).content`), where
|
|
53
|
+
comparing a `Hash` to an `ApiObject` was always false.
|
|
54
|
+
|
|
7
55
|
## [0.8.0] - 2026-09-30
|
|
8
56
|
|
|
9
57
|
### Changed
|
|
@@ -294,6 +342,7 @@ the Python SDK's behavior in idiomatic Ruby. Zero runtime dependencies.
|
|
|
294
342
|
- **Quality bars** — a README-as-tested-doc harness (every example runs against a mocked
|
|
295
343
|
API) and a spec drift-guard (CI fails if the live API grows beyond the SDK).
|
|
296
344
|
|
|
345
|
+
[0.9.0]: https://github.com/basecradle/basecradle-ruby/releases/tag/v0.9.0
|
|
297
346
|
[0.8.0]: https://github.com/basecradle/basecradle-ruby/releases/tag/v0.8.0
|
|
298
347
|
[0.7.0]: https://github.com/basecradle/basecradle-ruby/releases/tag/v0.7.0
|
|
299
348
|
[0.6.1]: https://github.com/basecradle/basecradle-ruby/releases/tag/v0.6.1
|
data/README.md
CHANGED
|
@@ -128,6 +128,39 @@ end
|
|
|
128
128
|
|
|
129
129
|
`cancel` withdraws a still-*pending* task — the scheduled-work equivalent of `timeline.lock`: its alarm never fires and the slot it held under your `max_pending_tasks` cap is freed at once. It is author-only (an admin may cancel any task) and works even on a locked timeline (cancellation is cleanup, not new content). Cancelling a task you did not author raises `BaseCradle::NotTaskAuthorError`; cancelling one that is no longer pending — already activated, blocked, or cancelled — raises `BaseCradle::TaskNotPendingError`. Create-then-cancel-and-reschedule gives you a rolling **dead man's switch**: a task that fires only if you stop renewing it.
|
|
130
130
|
|
|
131
|
+
## Reading a timeline's items
|
|
132
|
+
|
|
133
|
+
Fetching one timeline gives you everything on it inline — a single mixed list, **oldest
|
|
134
|
+
first** (it is the timeline as read, not a paginated feed). `item.type` says which record
|
|
135
|
+
each row is, and `item.content` is that record's own content model — the very object the
|
|
136
|
+
record's own resource returns:
|
|
137
|
+
|
|
138
|
+
```ruby
|
|
139
|
+
require "basecradle"
|
|
140
|
+
|
|
141
|
+
bc = BaseCradle::Client.new
|
|
142
|
+
|
|
143
|
+
bc.timelines.get("019e7750-66ee-7f53-829f-13a8a710b6da").items.each do |item|
|
|
144
|
+
case item.type
|
|
145
|
+
when "message" then puts item.content.body
|
|
146
|
+
when "asset" then puts item.content.file.filename
|
|
147
|
+
when "task" then puts item.content.status
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Two things the list does not carry. A **pending** task is not on it — a task appears only
|
|
153
|
+
once it activates — so survey scheduled work with `bc.tasks.filter(status: "pending")`
|
|
154
|
+
instead. And an item `type` this SDK release does not know is not an error: the API is
|
|
155
|
+
additive-only, so its content reads as a plain `BaseCradle::ApiObject` and
|
|
156
|
+
`content["any_field"]` still returns the wire value untouched.
|
|
157
|
+
|
|
158
|
+
Two fields are type-specific, so branch on `type` before reaching for them: a
|
|
159
|
+
`webhook_event` item has no author (it came from an external sender, not a peer), and it
|
|
160
|
+
alone carries `webhook_endpoint`, the endpoint it arrived on, embedded in full. Reading
|
|
161
|
+
either where it does not belong raises `BaseCradle::MissingFieldError` rather than
|
|
162
|
+
inventing a value.
|
|
163
|
+
|
|
131
164
|
## Webhooks
|
|
132
165
|
|
|
133
166
|
External services deliver into a timeline by POSTing to an endpoint's secret ingest URL. Each delivery becomes a readable event. This is the **inbound** direction — data arriving at BaseCradle. Its outbound counterpart is Event Delivery, the platform's push through your integration, which the SDK does not model.
|
|
@@ -187,11 +220,12 @@ fallback-less `fetch` raise `KeyError` naming the headers that did arrive, while
|
|
|
187
220
|
and the methods that reshape it (`slice`, `except`, `select`) work on those stored names,
|
|
188
221
|
case-sensitively.
|
|
189
222
|
|
|
190
|
-
|
|
191
|
-
`
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
223
|
+
This holds however you reach the record. A timeline item's `content` is typed by the
|
|
224
|
+
item's own `type`, so a `webhook_event` row of `timeline.items` is a `WebhookEventContent`
|
|
225
|
+
just like one from `bc.webhook_events` — `item.content.headers["X-GitHub-Delivery"]` folds
|
|
226
|
+
the same way. What gives the folding up is converting away from the type: both
|
|
227
|
+
`event.content["headers"]` (`ApiObject`'s raw-wire escape hatch, which wraps nothing) and
|
|
228
|
+
`headers.to_h` hand back a plain, case-sensitive `Hash`.
|
|
195
229
|
|
|
196
230
|
## Idempotent creates & safe retries
|
|
197
231
|
|
|
@@ -298,8 +332,14 @@ bundle exec rake # lint + tests (offline — the default)
|
|
|
298
332
|
bundle exec rake test:live # the spec drift-guard (one network call to the live spec)
|
|
299
333
|
bundle exec rubocop # lint only
|
|
300
334
|
gem build basecradle.gemspec # build the gem
|
|
335
|
+
actionlint # lint the GitHub workflows (CI runs this; see below)
|
|
301
336
|
```
|
|
302
337
|
|
|
338
|
+
CI additionally lints the workflow files with [actionlint](https://github.com/rhysd/actionlint)
|
|
339
|
+
(which runs `shellcheck` over each `run:` block). To reproduce that check locally, install
|
|
340
|
+
both and run `actionlint` from the repo root — CI pins actionlint by version and SHA256 in
|
|
341
|
+
`.github/workflows/ci.yml`; match that version to see what CI sees.
|
|
342
|
+
|
|
303
343
|
## Contributing
|
|
304
344
|
|
|
305
345
|
Human and AI contributors work under identical rules here: branch → PR → green CI → merge. See [`CLAUDE.md`](CLAUDE.md) for the project conventions and the issues for the roadmap.
|
data/lib/basecradle/timeline.rb
CHANGED
|
@@ -7,7 +7,7 @@ require_relative "webhooks"
|
|
|
7
7
|
|
|
8
8
|
module BaseCradle
|
|
9
9
|
# One item on a timeline — a message, asset, webhook event, or task. +type+ says which;
|
|
10
|
-
# +content+ is the item itself,
|
|
10
|
+
# +content+ is the item itself, typed by that +type+; +user+ is the author.
|
|
11
11
|
#
|
|
12
12
|
# An inline item is the record's own standalone form, with one difference: +created_at+
|
|
13
13
|
# is the *item's* — when the record landed on the timeline (for a task, its activation;
|
|
@@ -19,13 +19,59 @@ module BaseCradle
|
|
|
19
19
|
# Reading either where it does not belong raises +MissingFieldError+ rather than
|
|
20
20
|
# inventing a value.
|
|
21
21
|
class TimelineItem < ApiObject
|
|
22
|
+
# The content model each item +type+ reads as — the very class that +type+'s own
|
|
23
|
+
# resource returns, so one record has one shape however you reach it. A +type+ this
|
|
24
|
+
# release does not know is not in here on purpose; see +content+. Internal: the
|
|
25
|
+
# dispatch table is not API surface, so re-keying it is never a breaking change.
|
|
26
|
+
CONTENT_MODELS = {
|
|
27
|
+
"message" => MessageContent,
|
|
28
|
+
"asset" => AssetContent,
|
|
29
|
+
"task" => TaskContent,
|
|
30
|
+
"webhook_event" => WebhookEventContent
|
|
31
|
+
}.freeze
|
|
32
|
+
private_constant :CONTENT_MODELS
|
|
33
|
+
|
|
22
34
|
attribute :type
|
|
23
35
|
attribute :created_at
|
|
24
36
|
attribute :updated_at
|
|
25
37
|
attribute :user, wrap: User
|
|
26
38
|
attribute :timeline, wrap: Reference
|
|
27
39
|
attribute :webhook_endpoint, wrap: WebhookEndpoint # webhook_event items only
|
|
28
|
-
|
|
40
|
+
|
|
41
|
+
# The item itself, as the content model its +type+ names: a MessageContent,
|
|
42
|
+
# AssetContent, TaskContent or WebhookEventContent — the same object the record's own
|
|
43
|
+
# page hands back. So a record reads identically down either path, enrichments
|
|
44
|
+
# included (+item.content.headers+ folds case exactly as
|
|
45
|
+
# +bc.webhook_events.get(uuid).content.headers+ does), and an item's content +==+ the
|
|
46
|
+
# same record fetched directly.
|
|
47
|
+
#
|
|
48
|
+
# The API is additive-only, so an item +type+ newer than this SDK release must keep
|
|
49
|
+
# reading rather than raise: its content comes back as a plain ApiObject, whose +[]+
|
|
50
|
+
# still returns every wire field untouched. Upgrading the SDK is what types it.
|
|
51
|
+
def content
|
|
52
|
+
raise_missing("content") unless to_h.key?("content")
|
|
53
|
+
# The two ways a +type+ can be unusable are different answers, not one. A type the
|
|
54
|
+
# API sent that this release has no model for is the forward-compatible case and
|
|
55
|
+
# falls back below; an item carrying no +type+ at all is a malformed response (the
|
|
56
|
+
# spec marks it required), and the SDK raises rather than guessing which — the same
|
|
57
|
+
# promise ApiObject makes for every other withheld field.
|
|
58
|
+
raise_untypable unless to_h.key?("type")
|
|
59
|
+
|
|
60
|
+
wrap_value(to_h["content"], CONTENT_MODELS.fetch(type, ApiObject))
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
# Reading +type+ here would raise about a field the caller never asked for, on an
|
|
66
|
+
# object whose "fields present" list includes the +content+ they did ask for. Name
|
|
67
|
+
# the dependency between the two instead, and the escape hatch that still works.
|
|
68
|
+
def raise_untypable
|
|
69
|
+
raise MissingFieldError,
|
|
70
|
+
"This #{self.class}'s content cannot be typed: the API did not return " \
|
|
71
|
+
"\"type\" for it, and an item's content model is chosen by its type. The " \
|
|
72
|
+
"wire content is still readable with item[\"content\"]. " \
|
|
73
|
+
"Fields present: #{to_h.keys.sort.inspect}"
|
|
74
|
+
end
|
|
29
75
|
end
|
|
30
76
|
|
|
31
77
|
# A timeline: its metadata, owner, participants, lock state — and its verbs.
|
data/lib/basecradle/version.rb
CHANGED
data/lib/basecradle/webhooks.rb
CHANGED
|
@@ -196,11 +196,13 @@ module BaseCradle
|
|
|
196
196
|
# two are historical, and they are the only ones.
|
|
197
197
|
#
|
|
198
198
|
# +headers+ is the delivery's request headers as a +WebhookEventHeaders+ — the wire's
|
|
199
|
-
# own pairs, looked up case-insensitively.
|
|
200
|
-
#
|
|
201
|
-
#
|
|
202
|
-
#
|
|
203
|
-
#
|
|
199
|
+
# own pairs, looked up case-insensitively. This is the content model every read of the
|
|
200
|
+
# record returns, +timeline.items+ included: a +webhook_event+ row's +content+ is one of
|
|
201
|
+
# these (TimelineItem types content by the item's +type+), so the folding lookup is
|
|
202
|
+
# there too. What gives it up is converting away from the type — +content["headers"]+,
|
|
203
|
+
# ApiObject's raw-wire escape hatch, which wraps nothing, and the conversions
|
|
204
|
+
# WebhookEventHeaders names above (+to_h+ and friends) all hand back a plain,
|
|
205
|
+
# case-sensitive Hash.
|
|
204
206
|
class WebhookEventContent < ApiObject
|
|
205
207
|
attribute :uuid
|
|
206
208
|
attribute :content_type
|