nohead 0.13.0 → 0.15.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 +21 -0
- data/README.md +5 -2
- data/lib/nohead/client.rb +10 -5
- data/lib/nohead/resources/assets.rb +4 -2
- data/lib/nohead/resources/records.rb +6 -4
- data/lib/nohead/version.rb +1 -1
- 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: 5d0a05bd915d8f325b8b1579fdd8fc42242f0356d5ab8be4055db23194b9cd17
|
|
4
|
+
data.tar.gz: 0fe694a1823c5bfc3a3a5c1bc32347817a0d1cba727b9e707c4b2cb3ef8117c9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8b07886a3d4dbb7558359382e890e8139f1994d078358111eb3179cc489a1089d10ce2acec0794651ea293b9ac09321a76a62eb3fe4316767e8ad51c2ca5d9a0
|
|
7
|
+
data.tar.gz: d9b8d362856a150905d5c8ffca677641331d109a68101df9168840e6f258edc95512a902e181c2d45e7e2b7b2b438ac0379f7b71f03bf376b35292304f46b65c
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,27 @@ 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.15.0
|
|
9
|
+
|
|
10
|
+
- The client reads `NOHEAD_API_URL` as its default `base_url:`, as the CLI
|
|
11
|
+
does, so one environment points both at the same API (before, a script
|
|
12
|
+
sent its key to `https://api.nohead.io` whatever the CLI used). An explicit
|
|
13
|
+
`base_url:` still wins.
|
|
14
|
+
- `records.create` takes `publish: true`: the record is created published in
|
|
15
|
+
one request (with `upsert_on:`, a record already published stays so).
|
|
16
|
+
- `assets.upload` and `assets.create_upload` take `alt:`, the asset's alt
|
|
17
|
+
text from the start, so no `assets.update` follows each upload.
|
|
18
|
+
- `me.get`'s `api_key` has `collections`: for a key with `schema:write`,
|
|
19
|
+
its organization's active collections across all its projects and the
|
|
20
|
+
plan's limit (`nil` when unlimited), so a script can check new
|
|
21
|
+
collections fit before creating any; `nil` for other keys.
|
|
22
|
+
|
|
23
|
+
## 0.14.0
|
|
24
|
+
|
|
25
|
+
No changes in this SDK: the SDKs keep one version, and this release gives
|
|
26
|
+
the TypeScript SDK's Astro loader its schema and types, and its image
|
|
27
|
+
service defaults from astro.config.
|
|
28
|
+
|
|
8
29
|
## 0.13.0
|
|
9
30
|
|
|
10
31
|
No changes in this SDK: the SDKs keep one version, and this release adds
|
data/README.md
CHANGED
|
@@ -59,6 +59,7 @@ nohead = Nohead::Client.new(
|
|
|
59
59
|
| Option | Default | |
|
|
60
60
|
|---|---|---|
|
|
61
61
|
| `api_key:` | `NOHEAD_API_KEY` | A project API key (`nohead_sk_...`, or `nohead_pk_...` when published-only). Required. |
|
|
62
|
+
| `base_url:` | `NOHEAD_API_URL`, else `https://api.nohead.io` | The API's address. The CLI reads the same variable, so one environment points both at the same API. |
|
|
62
63
|
| `project_id:` | the key's project | Looked up once with `GET /v1/me` when omitted. |
|
|
63
64
|
| `max_retries:` | `2` | See [retries](#retries-and-idempotency). |
|
|
64
65
|
| `timeout:` | `60` | The longest wait in seconds without progress, per attempt: connecting, waiting for the response, and between reads and writes of a body. A response that keeps arriving doesn't time out. |
|
|
@@ -67,7 +68,7 @@ nohead = Nohead::Client.new(
|
|
|
67
68
|
| `on_retry:` | | Called before each retry's wait. See [retries](#retries-and-idempotency). |
|
|
68
69
|
| `rich_text:` | `"document"` | How rich text fields read: see [rich text](#rich-text). |
|
|
69
70
|
|
|
70
|
-
An empty string is the same as leaving an option out (`api_key: ""` reads `NOHEAD_API_KEY`).
|
|
71
|
+
An empty string is the same as leaving an option out (`api_key: ""` reads `NOHEAD_API_KEY`), and an empty environment variable the same as an unset one.
|
|
71
72
|
|
|
72
73
|
`with_options` gives a copy of the client with other settings (`timeout:`, `max_retries:`, `headers:`, added to the client's, `on_retry:` and `rich_text:`), sharing its project lookup:
|
|
73
74
|
|
|
@@ -93,6 +94,8 @@ Methods return the API's resources (see [Results](#results)) and raise on failur
|
|
|
93
94
|
|
|
94
95
|
**Upserts.** With `upsert_on:`, the key of a `unique` field, `create` updates the record holding that value instead, if one exists, so a content sync can run again without duplicates: `nohead.records.create("products", data: { sku: "TEE-01", title: "Tee" }, upsert_on: "sku")`.
|
|
95
96
|
|
|
97
|
+
**Creating it published.** `publish: true` creates the record published, in one request and one transaction, so it is never unpublished in between (the key's `records:write` scope covers it, as it covers publishing). With `upsert_on:`, a record already published stays published: `nohead.records.create("posts", data: { title: "Hello" }, publish: true)`.
|
|
98
|
+
|
|
96
99
|
**More:**
|
|
97
100
|
|
|
98
101
|
- `count`, and `bulk` (up to 100 records at once)
|
|
@@ -236,7 +239,7 @@ end
|
|
|
236
239
|
## Assets
|
|
237
240
|
|
|
238
241
|
```ruby
|
|
239
|
-
asset = nohead.assets.upload("cover.jpg")
|
|
242
|
+
asset = nohead.assets.upload("cover.jpg", alt: "The harbour at dawn") # alt: is optional
|
|
240
243
|
nohead.records.update(id, data: { cover: asset.id })
|
|
241
244
|
```
|
|
242
245
|
|
data/lib/nohead/client.rb
CHANGED
|
@@ -50,7 +50,7 @@ module Nohead
|
|
|
50
50
|
# api_key:: A project API key ("nohead_sk_...", or "nohead_pk_..." when
|
|
51
51
|
# published-only). Defaults to NOHEAD_API_KEY.
|
|
52
52
|
# base_url:: The API's address, an http or https URL. Defaults to
|
|
53
|
-
#
|
|
53
|
+
# NOHEAD_API_URL, as the CLI reads it, then https://api.nohead.io.
|
|
54
54
|
# project_id:: The key's project. Looked up once with GET /v1/me when omitted.
|
|
55
55
|
# max_retries:: Retries of failed requests (see the README, "Retries").
|
|
56
56
|
# timeout:: The longest wait in seconds without progress, per attempt:
|
|
@@ -70,7 +70,11 @@ module Nohead
|
|
|
70
70
|
headers: {}, warnings: true, on_retry: nil, rich_text: nil, transport: Transport.new)
|
|
71
71
|
@api_key = present(api_key) || present(ENV.fetch("NOHEAD_API_KEY", nil)) or
|
|
72
72
|
raise Error, "Missing API key: pass api_key or set NOHEAD_API_KEY"
|
|
73
|
-
|
|
73
|
+
# NOHEAD_API_URL, as the CLI reads it, so one environment points both
|
|
74
|
+
# at the same API.
|
|
75
|
+
from_env = present(ENV.fetch("NOHEAD_API_URL", nil)) unless present(base_url)
|
|
76
|
+
@base_url = checked_base_url(present(base_url) || from_env || DEFAULT_BASE_URL,
|
|
77
|
+
from_env ? "NOHEAD_API_URL" : "base_url")
|
|
74
78
|
@project = ProjectLookup.new(present(project_id))
|
|
75
79
|
@max_retries = max_retries
|
|
76
80
|
@timeout = timeout
|
|
@@ -340,7 +344,8 @@ module Nohead
|
|
|
340
344
|
raise ArgumentError, "if_match takes a revision number, or a record, draft or hash with a revision"
|
|
341
345
|
end
|
|
342
346
|
|
|
343
|
-
|
|
347
|
+
# The error names where the URL came from (`source`).
|
|
348
|
+
def checked_base_url(url, source)
|
|
344
349
|
# A loop rather than a regex, which backtracks on long runs of slashes.
|
|
345
350
|
url = url.to_s
|
|
346
351
|
stop = url.length
|
|
@@ -349,9 +354,9 @@ module Nohead
|
|
|
349
354
|
uri = URI.parse(url)
|
|
350
355
|
return url if %w[http https].include?(uri.scheme&.downcase) && !uri.host.to_s.empty?
|
|
351
356
|
|
|
352
|
-
raise Error, "
|
|
357
|
+
raise Error, "#{source} must be an http or https URL"
|
|
353
358
|
rescue URI::InvalidURIError
|
|
354
|
-
raise Error, "
|
|
359
|
+
raise Error, "#{source} must be an http or https URL"
|
|
355
360
|
end
|
|
356
361
|
|
|
357
362
|
def parse(response)
|
|
@@ -7,6 +7,7 @@ module Nohead
|
|
|
7
7
|
# Uploads a file and returns the `ready` asset: creates the upload, sends
|
|
8
8
|
# the bytes straight to storage, then completes it (which checks the
|
|
9
9
|
# file). `file` is a path or an IO; for bytes, pass StringIO.new(bytes).
|
|
10
|
+
# `alt:` is its alt text from the start, as `update` would set it later.
|
|
10
11
|
# Raises UploadError if the bytes don't reach storage (it refuses them,
|
|
11
12
|
# can't be reached or times out, with the ConnectionError as its
|
|
12
13
|
# `cause`), and ValidationError if the file fails the checks.
|
|
@@ -16,12 +17,13 @@ module Nohead
|
|
|
16
17
|
# returned without sending the bytes again. Once the upload's URL has
|
|
17
18
|
# expired (`upload.expires_at`), it raises UploadError: start over with
|
|
18
19
|
# a new key.
|
|
19
|
-
def upload(file, filename: nil, content_type: nil, byte_size: nil, idempotency_key: nil)
|
|
20
|
+
def upload(file, filename: nil, content_type: nil, byte_size: nil, alt: nil, idempotency_key: nil)
|
|
20
21
|
source = UploadSource.new(file, filename: filename, content_type: content_type,
|
|
21
22
|
byte_size: byte_size)
|
|
22
23
|
begin
|
|
23
24
|
created = create_upload(filename: source.filename, content_type: source.content_type,
|
|
24
|
-
byte_size: source.byte_size,
|
|
25
|
+
byte_size: source.byte_size, **{ alt: alt }.compact,
|
|
26
|
+
idempotency_key: idempotency_key)
|
|
25
27
|
# A replayed start returns the first run's asset, which may be done.
|
|
26
28
|
if idempotency_key
|
|
27
29
|
current = get(created.id)
|
|
@@ -61,10 +61,12 @@ module Nohead
|
|
|
61
61
|
@client.request("records_get", path: { record_id: record }, query: { expand: expand }, rich_text: rich_text)
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
# Creates an unpublished record: create("posts", data: { title: "Hello" })
|
|
65
|
-
#
|
|
66
|
-
#
|
|
67
|
-
#
|
|
64
|
+
# Creates an unpublished record: create("posts", data: { title: "Hello" }),
|
|
65
|
+
# or with publish: true a published one, in one request. With upsert_on:,
|
|
66
|
+
# the key of a unique field, it updates the record holding that value
|
|
67
|
+
# instead, if one exists, so a sync can run again without duplicates;
|
|
68
|
+
# if_match: then applies to that update (and with publish: true, a record
|
|
69
|
+
# already published stays published).
|
|
68
70
|
def create(collection, if_match: nil, idempotency_key: nil, change_note: nil, rich_text: nil, **params)
|
|
69
71
|
@client.request("records_create", path: { collection_id: collection }, body: body_of(params),
|
|
70
72
|
if_match: if_match, idempotency_key: idempotency_key,
|
data/lib/nohead/version.rb
CHANGED